diff --git a/test/fixtures/mentions.yml b/test/fixtures/mentions.yml new file mode 100644 index 000000000..70373600f --- /dev/null +++ b/test/fixtures/mentions.yml @@ -0,0 +1,4 @@ +logo_card_david_mention_by_jz: + source: logo (card) + mentioner: jz + mentionee: david diff --git a/test/models/concerns/mentions_test.rb b/test/models/concerns/mentions_test.rb index b9e5dc751..3e856ab16 100644 --- a/test/models/concerns/mentions_test.rb +++ b/test/models/concerns/mentions_test.rb @@ -5,19 +5,11 @@ class MentionsTest < ActiveSupport::TestCase Current.session = sessions(:david) end - test "collect mentions on create" do + test "create mentions when creating messages" do assert_difference -> { Mention.count }, +1 do perform_enqueued_jobs only: Mention::CreateJob do collections(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, @david?" end end end - - test "collect mentions on update" do - assert_difference -> { Mention.count }, +1 do - perform_enqueued_jobs only: Mention::CreateJob do - cards(:logo).update! description: "Did you finish up with the cleanup, @david?" - end - end - end end diff --git a/test/models/notifier_test.rb b/test/models/notifier/event_notifier_test.rb similarity index 78% rename from test/models/notifier_test.rb rename to test/models/notifier/event_notifier_test.rb index d27379464..ca4f0b4b5 100644 --- a/test/models/notifier_test.rb +++ b/test/models/notifier/event_notifier_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class NotifierTest < ActiveSupport::TestCase +class Notifier::EventNotifierTest < ActiveSupport::TestCase test "for returns the matching notifier class for the event" do assert_kind_of Notifier::EventNotifier, Notifier.for(events(:logo_published)) end @@ -62,4 +62,20 @@ class NotifierTest < ActiveSupport::TestCase assert_empty notifications end + + test "don't create notifications on publish for mentionees" do + users(:kevin).mentioned_by(users(:david), at: cards(:logo)) + + assert_no_difference -> { users(:kevin).notifications.count } do + Notifier.for(events(:logo_published)).notify + end + end + + test "don't create notifications on comment for mentionees" do + users(:david).mentioned_by(users(:kevin), at: cards(:layout)) + + assert_no_difference -> { users(:david).notifications.count } do + Notifier.for(events(:layout_commented)).notify + end + end end diff --git a/test/models/notifier/mention_notifier_test.rb b/test/models/notifier/mention_notifier_test.rb new file mode 100644 index 000000000..833f55ec8 --- /dev/null +++ b/test/models/notifier/mention_notifier_test.rb @@ -0,0 +1,27 @@ +require "test_helper" + +class Notifier::EventNotifierTest < ActiveSupport::TestCase + test "for returns the matching notifier class for the mention" do + assert_kind_of Notifier::MentionNotifier, Notifier.for(mentions(:logo_card_david_mention_by_jz)) + end + + test "notify the mentionee" do + users(:kevin).mentioned_by(users(:david), at: cards(:logo)) + + assert_no_difference -> { users(:kevin).notifications.count } do + Notifier.for(mentions(:logo_card_david_mention_by_jz)).notify + end + end + + test "create notifications for mentionee" do + assert_no_difference -> { users(:david).notifications.count } do + Notifier.for(events(:layout_commented)).notify + end + end + + test "don't create notifications for self-mentions" do + assert_no_difference -> { users(:jz).notifications.count } do + Notifier.for(events(:layout_commented)).notify + end + end +end diff --git a/test/models/user/mentionable_test.rb b/test/models/user/mentionable_test.rb index 48fb339a1..7231553c0 100644 --- a/test/models/user/mentionable_test.rb +++ b/test/models/user/mentionable_test.rb @@ -4,4 +4,15 @@ class User::MentionableTest < ActiveSupport::TestCase test "mentionable handles" do assert_equal [ "dhh", "david", "davidh" ], User.new(name: "David Heinemeier-Hansson").mentionable_handles end + + test "mentioned by" do + assert_difference -> { users(:david).mentions.count }, +1 do + users(:david).mentioned_by users(:jz), at: cards(:logo) + end + + # No dups + assert_no_difference -> { users(:david).mentions.count }, +1 do + users(:david).mentioned_by users(:jz), at: cards(:logo) + end + end end