Commit da41007e by tady

fix notify spec

parent 7c401621
......@@ -8,7 +8,6 @@ class PostsController < ApplicationController
# GET /posts/1
# GET /posts/1.json
def show
current_user.visit_post!(@post)
@post.tags.each do |_tag|
......
......@@ -17,7 +17,7 @@
FactoryGirl.define do
factory :post do
association :author, factory: :alice
association :author, factory: :acrelice
title 'sample title'
body 'sample body'
specified_date Date.new(2014, 4, 1)
......
......@@ -40,6 +40,14 @@ FactoryGirl.define do
google_token_expires_at Time.now - 1.hour
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
name 'Test User'
email 'example@example.com'
......
......@@ -17,21 +17,34 @@ require 'rails_helper'
describe Notification do
describe 'Instance method' do
let(:bob) { create(:bob) }
let(:charley) { create(:charley) }
let(:post) { create(:post) }
it "notifies on post edited" do
bob.watch!(post: post)
post.update!(title: post.title + ' [New!]')
expect(bob.notifications.size).to eq(1)
end
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
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
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
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
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