Try to slightly optimize EmailHeleprs
This commit is contained in:
parent
230bae9d48
commit
beb47c257a
|
@ -1,6 +1,8 @@
|
||||||
module EmailHelpers
|
module EmailHelpers
|
||||||
def sent_to_user?(user)
|
def sent_to_user?(user, recipients = nil)
|
||||||
ActionMailer::Base.deliveries.flat_map(&:to).count(user.email) == 1
|
recipients ||= ActionMailer::Base.deliveries.flat_map(&:to)
|
||||||
|
|
||||||
|
recipients.count(user.email) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_delivered_emails!
|
def reset_delivered_emails!
|
||||||
|
@ -8,17 +10,19 @@ module EmailHelpers
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_only_email(*users)
|
def should_only_email(*users)
|
||||||
users.each {|user| should_email(user) }
|
|
||||||
recipients = ActionMailer::Base.deliveries.flat_map(&:to)
|
recipients = ActionMailer::Base.deliveries.flat_map(&:to)
|
||||||
|
|
||||||
|
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)
|
def should_email(user, recipients = nil)
|
||||||
expect(sent_to_user?(user)).to be_truthy
|
expect(sent_to_user?(user, recipients)).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_not_email(user)
|
def should_not_email(user, recipients = nil)
|
||||||
expect(sent_to_user?(user)).to be_falsey
|
expect(sent_to_user?(user, recipients)).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_email_no_one
|
def should_email_no_one
|
||||||
|
|
Loading…
Reference in New Issue