discourse/spec/services/post_action_notifier_spec.rb

84 lines
2.6 KiB
Ruby
Raw Normal View History

require 'rails_helper'
2013-02-05 14:16:51 -05:00
describe PostActionNotifier do
2013-02-05 14:16:51 -05:00
2013-04-13 10:31:20 -04:00
before do
PostActionNotifier.enable
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) }
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
expect {
2017-07-27 21:20:09 -04:00
post.revise(evil_trout, raw: "world is the new body of the message")
}.to change(post.user.notifications, :count).by(1)
2013-02-05 14:16:51 -05:00
end
it 'stores the revision number with the notification' do
post.revise(evil_trout, raw: "world is the new body of the message")
notification_data = JSON.parse post.user.notifications.last.data
expect(notification_data['revision_number']).to eq post.post_revisions.last.number
end
context "edit notifications are disabled" do
before { SiteSetting.disable_edit_notifications = true }
it 'notifies a user of the revision made by another user' do
expect {
2017-07-27 21:20:09 -04:00
post.revise(evil_trout, raw: "world is the new body of the message")
}.to change(post.user.notifications, :count).by(1)
end
it 'does not notifiy a user of the revision made by the system user' do
expect {
2017-07-27 21:20:09 -04:00
post.revise(Discourse.system_user, raw: "world is the new body of the message")
}.not_to change(post.user.notifications, :count)
end
end
2013-02-05 14:16:51 -05:00
end
context 'private message' do
let(:user) { Fabricate(:user) }
2017-07-27 21:20:09 -04:00
let(:mention_post) { Fabricate(:post, user: user, raw: 'Hello @eviltrout') }
let(:topic) do
topic = mention_post.topic
topic.update_columns archetype: Archetype.private_message, category_id: nil
topic
end
it "won't notify someone who can't see the post" do
expect {
Guardian.any_instance.expects(:can_see?).with(instance_of(Post)).returns(false)
mention_post
PostAlerter.post_created(mention_post)
}.not_to change(evil_trout.notifications, :count)
end
it 'creates like notifications' do
other_user = Fabricate(:user)
topic.allowed_users << user << other_user
expect {
PostActionCreator.like(other_user, mention_post)
}.to change(user.notifications, :count)
end
2013-02-05 14:16:51 -05:00
end
context 'moderator action post' do
let(:user) { Fabricate(:user) }
2017-07-27 21:20:09 -04:00
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