]> git.openstreetmap.org Git - rails.git/blob - test/notifiers/new_follower_notifier_test.rb
Merge remote-tracking branch 'upstream/pull/7069'
[rails.git] / test / notifiers / new_follower_notifier_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class NewFollowerNotifierTest < ActiveSupport::TestCase
6   def setup
7     ActionMailer::Base.deliveries.clear
8   end
9
10   def test_send_email_when_subscribed
11     candidate_recipient = create(:user)
12     candidate_recipient.notification_preferences.update("new_follower" => ["email"])
13
14     trigger_notification(candidate_recipient)
15
16     email = ActionMailer::Base.deliveries.first
17     assert_equal [candidate_recipient.email], email.to
18   end
19
20   def test_do_not_send_email_when_not_subscribed
21     candidate_recipient = create(:user)
22     candidate_recipient.notification_preferences.update("new_follower" => [])
23
24     trigger_notification(candidate_recipient)
25
26     assert_empty ActionMailer::Base.deliveries
27   end
28
29   private
30
31   def trigger_notification(followee)
32     follow = create(:follow, :following => followee)
33     perform_enqueued_jobs do
34       NewFollowerNotifier.with(:record => follow).deliver
35     end
36   end
37 end