2016-04-01 05:33:25 +08:00
|
|
|
require 'rails_helper'
|
2013-03-19 05:52:29 +08:00
|
|
|
require_dependency 'post_destroyer'
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
describe PostAlertObserver do
|
|
|
|
|
2013-04-13 22:31:20 +08:00
|
|
|
before do
|
2013-05-14 09:59:55 +08:00
|
|
|
ActiveRecord::Base.observers.enable :post_alert_observer
|
2013-04-13 22:31:20 +08:00
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08: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
|
2014-12-31 22:55:03 +08:00
|
|
|
expect {
|
2013-03-01 20:07:44 +08:00
|
|
|
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
2014-07-23 09:42:24 +08:00
|
|
|
# one like (welcome badge deferred)
|
2014-12-31 22:55:03 +08:00
|
|
|
}.to change(Notification, :count).by(1)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when removing a liked post' do
|
2013-02-26 00:42:20 +08:00
|
|
|
it 'removes a notification' do
|
2016-04-01 05:33:25 +08:00
|
|
|
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
2014-12-31 22:55:03 +08:00
|
|
|
expect {
|
2013-03-01 20:07:44 +08:00
|
|
|
PostAction.remove_act(evil_trout, post, PostActionType.types[:like])
|
2014-12-31 22:55:03 +08:00
|
|
|
}.to change(Notification, :count).by(-1)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2013-02-26 00:42:20 +08:00
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
context 'when editing a post' do
|
2013-02-06 03:16:51 +08:00
|
|
|
it 'notifies a user of the revision' do
|
2014-12-31 22:55:03 +08:00
|
|
|
expect {
|
2014-10-28 05:06:43 +08:00
|
|
|
post.revise(evil_trout, { raw: "world is the new body of the message" })
|
2014-12-31 22:55:03 +08:00
|
|
|
}.to change(post.user.notifications, :count).by(1)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2014-06-11 23:14:00 +08:00
|
|
|
|
2014-09-10 00:56:04 +08:00
|
|
|
context "edit notifications are disabled" do
|
|
|
|
|
|
|
|
before { SiteSetting.stubs(:disable_edit_notifications).returns(true) }
|
|
|
|
|
|
|
|
|
|
|
|
it 'notifies a user of the revision made by another user' do
|
2014-12-31 22:55:03 +08:00
|
|
|
expect {
|
2014-10-28 05:06:43 +08:00
|
|
|
post.revise(evil_trout, { raw: "world is the new body of the message" })
|
2014-12-31 22:55:03 +08:00
|
|
|
}.to change(post.user.notifications, :count).by(1)
|
2014-09-10 00:56:04 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not notifiy a user of the revision made by the system user' do
|
2014-12-31 22:55:03 +08:00
|
|
|
expect {
|
2014-10-28 05:06:43 +08:00
|
|
|
post.revise(Discourse.system_user, { raw: "world is the new body of the message" })
|
2014-12-31 22:55:03 +08:00
|
|
|
}.not_to change(post.user.notifications, :count)
|
2014-09-10 00:56:04 +08:00
|
|
|
end
|
|
|
|
|
2014-06-11 23:14:00 +08:00
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2013-02-20 01:59:46 +08:00
|
|
|
context 'private message' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:mention_post) { Fabricate(:post, user: user, raw: 'Hello @eviltrout')}
|
2014-03-06 21:34:14 +08:00
|
|
|
let(:topic) do
|
|
|
|
topic = mention_post.topic
|
2014-09-11 15:39:20 +08:00
|
|
|
topic.update_columns archetype: Archetype.private_message, category_id: nil
|
2014-03-06 21:34:14 +08:00
|
|
|
topic
|
|
|
|
end
|
2013-02-20 01:59:46 +08:00
|
|
|
|
|
|
|
it "won't notify someone who can't see the post" do
|
2014-12-31 22:55:03 +08:00
|
|
|
expect {
|
2013-02-20 01:59:46 +08:00
|
|
|
Guardian.any_instance.expects(:can_see?).with(instance_of(Post)).returns(false)
|
|
|
|
mention_post
|
2016-04-01 05:33:25 +08:00
|
|
|
PostAlerter.post_created(mention_post)
|
2014-12-31 22:55:03 +08:00
|
|
|
}.not_to change(evil_trout.notifications, :count)
|
2013-02-20 01:59:46 +08:00
|
|
|
end
|
2014-03-06 21:34:14 +08:00
|
|
|
|
|
|
|
it 'creates like notifications' do
|
|
|
|
other_user = Fabricate(:user)
|
|
|
|
topic.allowed_users << user << other_user
|
2014-12-31 22:55:03 +08:00
|
|
|
expect {
|
2014-03-06 21:34:14 +08:00
|
|
|
PostAction.act(other_user, mention_post, PostActionType.types[:like])
|
2014-12-31 22:55:03 +08:00
|
|
|
}.to change(user.notifications, :count)
|
2014-03-06 21:34:14 +08:00
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2013-05-23 23:42:41 +08: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-06 03:16:51 +08:00
|
|
|
end
|