BigW Consortium Gitlab

email_helpers.rb 842 Bytes
Newer Older
1
module EmailHelpers
2
  def sent_to_user?(user, recipients = email_recipients)
3
    recipients.include?(user.notification_email)
4 5
  end

6 7 8 9
  def reset_delivered_emails!
    ActionMailer::Base.deliveries.clear
  end

10 11
  def should_only_email(*users, kind: :to)
    recipients = email_recipients(kind: kind)
12 13 14

    users.each { |user| should_email(user, recipients) }

15 16 17
    expect(recipients.count).to eq(users.count)
  end

18
  def should_email(user, recipients = email_recipients)
19
    expect(sent_to_user?(user, recipients)).to be_truthy
20 21
  end

22
  def should_not_email(user, recipients = email_recipients)
23
    expect(sent_to_user?(user, recipients)).to be_falsey
24
  end
25

26
  def should_not_email_anyone
27 28
    expect(ActionMailer::Base.deliveries).to be_empty
  end
29

30 31
  def email_recipients(kind: :to)
    ActionMailer::Base.deliveries.flat_map(&kind)
32
  end
33
end