2014-03-18 00:22:39 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PostAlerter do
|
|
|
|
|
|
|
|
let!(:evil_trout) { Fabricate(:evil_trout) }
|
|
|
|
|
|
|
|
def create_post_with_alerts(args={})
|
|
|
|
post = Fabricate(:post, args)
|
2014-03-18 21:07:48 -04:00
|
|
|
PostAlerter.post_created(post)
|
2014-03-18 00:22:39 -04:00
|
|
|
end
|
|
|
|
|
2015-10-19 16:31:48 -04:00
|
|
|
context "unread" do
|
|
|
|
it "does not return whispers as unread posts" do
|
|
|
|
op = Fabricate(:post)
|
2015-11-30 01:03:47 -05:00
|
|
|
_whisper = Fabricate(:post, raw: 'this is a whisper post',
|
2015-10-19 16:31:48 -04:00
|
|
|
user: Fabricate(:admin),
|
|
|
|
topic: op.topic,
|
|
|
|
reply_to_post_number: op.post_number,
|
|
|
|
post_type: Post.types[:whisper])
|
|
|
|
|
|
|
|
|
|
|
|
expect(PostAlerter.new.first_unread_post(op.user, op.topic)).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-18 22:31:36 -04:00
|
|
|
context 'likes' do
|
|
|
|
it 'does not double notify users on likes' do
|
|
|
|
ActiveRecord::Base.observers.enable :all
|
|
|
|
|
|
|
|
post = Fabricate(:post, raw: 'I love waffles')
|
|
|
|
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
|
|
|
|
|
|
|
admin = Fabricate(:admin)
|
|
|
|
post.revise(admin, {raw: 'I made a revision'})
|
|
|
|
|
|
|
|
PostAction.act(admin, post, PostActionType.types[:like])
|
|
|
|
|
|
|
|
# one like and one edit notification
|
|
|
|
expect(Notification.count(post_number: 1, topic_id: post.topic_id)).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-18 00:22:39 -04:00
|
|
|
context 'quotes' do
|
|
|
|
|
2015-03-23 20:55:22 -04:00
|
|
|
it 'does not notify for muted users' do
|
|
|
|
post = Fabricate(:post, raw: '[quote="EvilTrout, post:1"]whatup[/quote]')
|
|
|
|
MutedUser.create!(user_id: evil_trout.id, muted_user_id: post.user_id)
|
|
|
|
|
2015-04-25 11:18:35 -04:00
|
|
|
expect {
|
2015-03-23 20:55:22 -04:00
|
|
|
PostAlerter.post_created(post)
|
2015-04-25 11:18:35 -04:00
|
|
|
}.to change(evil_trout.notifications, :count).by(0)
|
2015-03-23 20:55:22 -04:00
|
|
|
end
|
|
|
|
|
2014-03-18 00:22:39 -04:00
|
|
|
it 'notifies a user by username' do
|
2015-04-25 11:18:35 -04:00
|
|
|
expect {
|
2014-03-18 00:22:39 -04:00
|
|
|
create_post_with_alerts(raw: '[quote="EvilTrout, post:1"]whatup[/quote]')
|
2015-04-25 11:18:35 -04:00
|
|
|
}.to change(evil_trout.notifications, :count).by(1)
|
2014-03-18 00:22:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "won't notify the user a second time on revision" do
|
|
|
|
p1 = create_post_with_alerts(raw: '[quote="Evil Trout, post:1"]whatup[/quote]')
|
2015-04-25 11:18:35 -04:00
|
|
|
expect {
|
2014-10-27 17:06:43 -04:00
|
|
|
p1.revise(p1.user, { raw: '[quote="Evil Trout, post:1"]whatup now?[/quote]' })
|
2015-04-25 11:18:35 -04:00
|
|
|
}.not_to change(evil_trout.notifications, :count)
|
2014-03-18 00:22:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify the poster" do
|
|
|
|
topic = create_post_with_alerts.topic
|
2015-04-25 11:18:35 -04:00
|
|
|
expect {
|
2014-03-18 00:22:39 -04:00
|
|
|
Fabricate(:post, topic: topic, user: topic.user, raw: '[quote="Bruce Wayne, post:1"]whatup[/quote]')
|
2015-04-25 11:18:35 -04:00
|
|
|
}.not_to change(topic.user.notifications, :count)
|
2014-03-18 00:22:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-18 21:07:48 -04:00
|
|
|
context 'linked' do
|
|
|
|
it "will notify correctly on linking" do
|
|
|
|
post1 = create_post
|
|
|
|
user = post1.user
|
|
|
|
create_post(raw: "my magic topic\n##{Discourse.base_url}#{post1.url}")
|
|
|
|
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(user.notifications.count).to eq(1)
|
2014-03-18 21:07:48 -04:00
|
|
|
|
|
|
|
create_post(user: user, raw: "my magic topic\n##{Discourse.base_url}#{post1.url}")
|
|
|
|
|
|
|
|
user.reload
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(user.notifications.count).to eq(1)
|
2014-07-29 01:40:05 -04:00
|
|
|
|
|
|
|
# don't notify on reflection
|
|
|
|
post1.reload
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(PostAlerter.new.extract_linked_users(post1).length).to eq(0)
|
2014-07-29 01:40:05 -04:00
|
|
|
|
2014-03-18 21:07:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-30 01:03:47 -05:00
|
|
|
context '@group mentions' do
|
|
|
|
|
|
|
|
it 'notifies users correctly' do
|
|
|
|
|
|
|
|
group = Fabricate(:group, name: 'group', alias_level: Group::ALIAS_LEVELS[:everyone])
|
|
|
|
group.add(evil_trout)
|
|
|
|
|
|
|
|
expect {
|
|
|
|
create_post_with_alerts(raw: "Hello @group how are you?")
|
|
|
|
}.to change(evil_trout.notifications, :count).by(1)
|
|
|
|
|
2015-12-01 00:52:43 -05:00
|
|
|
expect(GroupMention.count).to eq(1)
|
2015-11-30 01:03:47 -05:00
|
|
|
|
|
|
|
group.update_columns(alias_level: Group::ALIAS_LEVELS[:members_mods_and_admins])
|
|
|
|
|
|
|
|
expect {
|
|
|
|
create_post_with_alerts(raw: "Hello @group you are not mentionable")
|
|
|
|
}.to change(evil_trout.notifications, :count).by(0)
|
2015-12-01 00:52:43 -05:00
|
|
|
|
|
|
|
expect(GroupMention.count).to eq(2)
|
2015-11-30 01:03:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-18 00:22:39 -04:00
|
|
|
context '@mentions' do
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:mention_post) { create_post_with_alerts(user: user, raw: 'Hello @eviltrout')}
|
|
|
|
let(:topic) { mention_post.topic }
|
|
|
|
|
|
|
|
it 'notifies a user' do
|
2015-04-25 11:18:35 -04:00
|
|
|
expect {
|
2014-03-18 00:22:39 -04:00
|
|
|
mention_post
|
2015-04-25 11:18:35 -04:00
|
|
|
}.to change(evil_trout.notifications, :count).by(1)
|
2014-03-18 00:22:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "won't notify the user a second time on revision" do
|
|
|
|
mention_post
|
2015-04-25 11:18:35 -04:00
|
|
|
expect {
|
2014-10-27 17:06:43 -04:00
|
|
|
mention_post.revise(mention_post.user, { raw: "New raw content that still mentions @eviltrout" })
|
2015-04-25 11:18:35 -04:00
|
|
|
}.not_to change(evil_trout.notifications, :count)
|
2014-03-18 00:22:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify the user who created the topic in regular mode" do
|
|
|
|
topic.notify_regular!(user)
|
|
|
|
mention_post
|
2015-04-25 11:18:35 -04:00
|
|
|
expect {
|
2014-03-18 00:22:39 -04:00
|
|
|
create_post_with_alerts(user: user, raw: 'second post', topic: topic)
|
2015-04-25 11:18:35 -04:00
|
|
|
}.not_to change(user.notifications, :count)
|
2014-03-18 00:22:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|