2016-02-12 09:58:39 -05:00
|
|
|
module EmailHelpers
|
2016-09-28 03:39:54 -04:00
|
|
|
def sent_to_user?(user, recipients = email_recipients)
|
2016-10-21 06:22:09 -04:00
|
|
|
recipients.include?(user.notification_email)
|
2016-02-12 09:58:39 -05:00
|
|
|
end
|
|
|
|
|
2016-08-16 12:08:43 -04:00
|
|
|
def reset_delivered_emails!
|
|
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
end
|
|
|
|
|
2016-10-18 08:02:35 -04:00
|
|
|
def should_only_email(*users, kind: :to)
|
|
|
|
recipients = email_recipients(kind: kind)
|
2016-09-19 02:01:58 -04:00
|
|
|
|
|
|
|
users.each { |user| should_email(user, recipients) }
|
|
|
|
|
2016-08-16 12:08:43 -04:00
|
|
|
expect(recipients.count).to eq(users.count)
|
|
|
|
end
|
|
|
|
|
2016-09-28 03:39:54 -04:00
|
|
|
def should_email(user, recipients = email_recipients)
|
2016-09-19 02:01:58 -04:00
|
|
|
expect(sent_to_user?(user, recipients)).to be_truthy
|
2016-02-12 09:58:39 -05:00
|
|
|
end
|
|
|
|
|
2016-09-28 03:39:54 -04:00
|
|
|
def should_not_email(user, recipients = email_recipients)
|
2016-09-19 02:01:58 -04:00
|
|
|
expect(sent_to_user?(user, recipients)).to be_falsey
|
2016-02-12 09:58:39 -05:00
|
|
|
end
|
2016-09-19 01:54:16 -04:00
|
|
|
|
2016-10-17 06:03:53 -04:00
|
|
|
def should_not_email_anyone
|
2016-09-19 01:54:16 -04:00
|
|
|
expect(ActionMailer::Base.deliveries).to be_empty
|
|
|
|
end
|
2016-09-28 03:39:54 -04:00
|
|
|
|
2016-10-18 08:02:35 -04:00
|
|
|
def email_recipients(kind: :to)
|
|
|
|
ActionMailer::Base.deliveries.flat_map(&kind)
|
2016-09-28 03:39:54 -04:00
|
|
|
end
|
2016-02-12 09:58:39 -05:00
|
|
|
end
|