2013-02-05 14:16:51 -05:00
|
|
|
require 'spec_helper'
|
2013-03-18 17:52:29 -04:00
|
|
|
require_dependency 'post_destroyer'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
describe PostAlertObserver do
|
|
|
|
|
2013-04-13 10:31:20 -04:00
|
|
|
before do
|
2013-05-13 21:59:55 -04:00
|
|
|
ActiveRecord::Base.observers.enable :post_alert_observer
|
2013-04-13 10:31:20 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
let!(:evil_trout) { Fabricate(:evil_trout) }
|
|
|
|
let(:post) { Fabricate(:post) }
|
|
|
|
|
|
|
|
context 'liking' do
|
|
|
|
context 'when liking a post' do
|
|
|
|
it 'creates a notification' do
|
|
|
|
lambda {
|
2013-03-01 07:07:44 -05:00
|
|
|
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
2013-02-05 14:16:51 -05:00
|
|
|
}.should change(Notification, :count).by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when removing a liked post' do
|
|
|
|
before do
|
2013-03-01 07:07:44 -05:00
|
|
|
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-02-25 11:42:20 -05:00
|
|
|
it 'removes a notification' do
|
2013-02-05 14:16:51 -05:00
|
|
|
lambda {
|
2013-03-01 07:07:44 -05:00
|
|
|
PostAction.remove_act(evil_trout, post, PostActionType.types[:like])
|
2013-02-05 14:16:51 -05:00
|
|
|
}.should change(Notification, :count).by(-1)
|
|
|
|
end
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-02-25 11:42:20 -05:00
|
|
|
context 'when editing a post' do
|
2013-02-05 14:16:51 -05:00
|
|
|
it 'notifies a user of the revision' do
|
|
|
|
lambda {
|
2013-02-06 20:09:31 -05:00
|
|
|
post.revise(evil_trout, "world is the new body of the message")
|
2013-02-05 14:16:51 -05:00
|
|
|
}.should change(post.user.notifications, :count).by(1)
|
|
|
|
end
|
2014-06-11 11:14:00 -04:00
|
|
|
|
|
|
|
it 'does not notifiy a user of the revision when edit notifications are disabled' do
|
|
|
|
SiteSetting.stubs(:disable_edit_notifications).returns(true)
|
|
|
|
lambda {
|
|
|
|
post.revise(evil_trout, "world is the new body of the message")
|
|
|
|
}.should_not change(post.user.notifications, :count).by(1)
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-02-19 12:59:46 -05:00
|
|
|
context 'private message' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:mention_post) { Fabricate(:post, user: user, raw: 'Hello @eviltrout')}
|
2014-03-06 08:34:14 -05:00
|
|
|
let(:topic) do
|
|
|
|
topic = mention_post.topic
|
|
|
|
topic.update_column :archetype, Archetype.private_message
|
|
|
|
topic
|
|
|
|
end
|
2013-02-19 12:59:46 -05:00
|
|
|
|
|
|
|
it "won't notify someone who can't see the post" do
|
|
|
|
lambda {
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(instance_of(Post)).returns(false)
|
|
|
|
mention_post
|
2014-03-18 00:22:39 -04:00
|
|
|
PostAlerter.new.after_create_post(mention_post)
|
|
|
|
PostAlerter.new.after_save_post(mention_post)
|
2013-02-19 12:59:46 -05:00
|
|
|
}.should_not change(evil_trout.notifications, :count)
|
|
|
|
end
|
2014-03-06 08:34:14 -05:00
|
|
|
|
|
|
|
it 'creates like notifications' do
|
|
|
|
other_user = Fabricate(:user)
|
|
|
|
topic.allowed_users << user << other_user
|
|
|
|
lambda {
|
|
|
|
PostAction.act(other_user, mention_post, PostActionType.types[:like])
|
|
|
|
}.should change(user.notifications, :count)
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-05-23 11:42:41 -04:00
|
|
|
context 'moderator action post' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:first_post) { Fabricate(:post, user: user, raw: 'A useless post for you.')}
|
|
|
|
let(:topic) { first_post.topic }
|
|
|
|
|
|
|
|
it 'should not notify anyone' do
|
|
|
|
expect {
|
|
|
|
Fabricate(:post, topic: topic, raw: 'This topic is CLOSED', post_type: Post.types[:moderator_action])
|
|
|
|
}.to_not change { Notification.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|