FIX: if people link own post, watchers not notified

This commit is contained in:
Sam 2015-12-31 10:51:58 +11:00
parent f0694d491a
commit cba76db53b
2 changed files with 9 additions and 2 deletions

View File

@ -283,7 +283,7 @@ class PostAlerter
if !linked_post && topic = link.link_topic
linked_post = topic.posts(post_number: 1).first
end
linked_post && post.user_id != linked_post.user_id && linked_post.user
(linked_post && post.user_id != linked_post.user_id && linked_post.user) || nil
end.compact
end

View File

@ -80,11 +80,18 @@ describe PostAlerter do
expect(user.notifications.count).to eq(1)
create_post(user: user, raw: "my magic topic\n##{Discourse.base_url}#{post1.url}")
topic = Fabricate(:topic)
watcher = Fabricate(:user)
TopicUser.create!(user_id: watcher.id, topic_id: topic.id, notification_level: TopicUser.notification_levels[:watching])
create_post(topic_id: topic.id, user: user, raw: "my magic topic\n##{Discourse.base_url}#{post1.url}")
user.reload
expect(user.notifications.count).to eq(1)
expect(watcher.notifications.count).to eq(1)
# don't notify on reflection
post1.reload
expect(PostAlerter.new.extract_linked_users(post1).length).to eq(0)