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