Commit 9622ef64 authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent 12a6bbc3
module EmailHelpers module EmailHelpers
def sent_to_user?(user, recipients = nil) def sent_to_user?(user, recipients = email_recipients)
recipients ||= ActionMailer::Base.deliveries.flat_map(&:to) recipients.include?(user.email)
recipients.count(user.email) == 1
end end
def reset_delivered_emails! def reset_delivered_emails!
...@@ -10,22 +8,26 @@ module EmailHelpers ...@@ -10,22 +8,26 @@ module EmailHelpers
end end
def should_only_email(*users) def should_only_email(*users)
recipients = ActionMailer::Base.deliveries.flat_map(&:to) recipients = email_recipients
users.each { |user| should_email(user, recipients) } users.each { |user| should_email(user, recipients) }
expect(recipients.count).to eq(users.count) expect(recipients.count).to eq(users.count)
end end
def should_email(user, recipients = nil) def should_email(user, recipients = email_recipients)
expect(sent_to_user?(user, recipients)).to be_truthy expect(sent_to_user?(user, recipients)).to be_truthy
end end
def should_not_email(user, recipients = nil) def should_not_email(user, recipients = email_recipients)
expect(sent_to_user?(user, recipients)).to be_falsey expect(sent_to_user?(user, recipients)).to be_falsey
end end
def should_email_no_one def should_email_no_one
expect(ActionMailer::Base.deliveries).to be_empty expect(ActionMailer::Base.deliveries).to be_empty
end end
def email_recipients
ActionMailer::Base.deliveries.flat_map(&:to)
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment