Commit da41007e by tady

fix notify spec

parent 7c401621
...@@ -8,7 +8,6 @@ class PostsController < ApplicationController ...@@ -8,7 +8,6 @@ class PostsController < ApplicationController
# GET /posts/1 # GET /posts/1
# GET /posts/1.json # GET /posts/1.json
def show def show
current_user.visit_post!(@post) current_user.visit_post!(@post)
@post.tags.each do |_tag| @post.tags.each do |_tag|
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
FactoryGirl.define do FactoryGirl.define do
factory :post do factory :post do
association :author, factory: :alice association :author, factory: :acrelice
title 'sample title' title 'sample title'
body 'sample body' body 'sample body'
specified_date Date.new(2014, 4, 1) specified_date Date.new(2014, 4, 1)
......
...@@ -40,6 +40,14 @@ FactoryGirl.define do ...@@ -40,6 +40,14 @@ FactoryGirl.define do
google_token_expires_at Time.now - 1.hour google_token_expires_at Time.now - 1.hour
end end
factory :charley, class: User do
name 'Charley'
email 'charley@mail.com'
nickname 'charley'
password Devise.friendly_token[0, 20]
google_token_expires_at Time.now - 1.hour
end
factory :login_user_1, class: User do factory :login_user_1, class: User do
name 'Test User' name 'Test User'
email 'example@example.com' email 'example@example.com'
......
...@@ -17,21 +17,34 @@ require 'rails_helper' ...@@ -17,21 +17,34 @@ require 'rails_helper'
describe Notification do describe Notification do
describe 'Instance method' do describe 'Instance method' do
let(:bob) { create(:bob) } let(:bob) { create(:bob) }
let(:charley) { create(:charley) }
let(:post) { create(:post) } let(:post) { create(:post) }
it "notifies on post edited" do it "notifies on post edited" do
bob.watch!(post: post)
post.update!(title: post.title + ' [New!]')
expect(bob.notifications.size).to eq(1)
end end
it "notifies on post commented" do it "notifies on post commented" do
bob.watch!(post: post)
post.comments.build(comment_params.merge(author: charley))
expect(bob.notifications.size).to eq(1)
end end
it "set watch on user create a new post" do it "set watch on user create a new post" do
new_post = Post.create!(author: bob, title: 'title', body: 'body')
expect(bob.watching?(post: new_post)).to be_truthy
end end
it "set watch on user edit a post" do it "set watch on user edit a post" do
post.update!(author: bob, title: 'new title')
expect(bob.watching?(post: new_post)).to be_truthy
end end
it "set watch on user comment a post" do it "set watch on user comment a post" do
post.comments.build(comment_params.merge(author: bob))
expect(bob.watching?(post: new_post)).to be_truthy
end end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment