I have an application that sometimes needs to send an email to all users when the administrator does something. This works fine, but when there are many users, the admin page will wait until all the mail has been sent, which is undesirable.
To mitigate this, I tried sending the email to a new stream:
t = Thread.new do
User.all.each do |user|
Mailer.email(user).deliver
end
end
at_exit{ t.join }
This worked fine, but then in my test suite I can’t check if email sending works:
test "admin action should send email blast" do
assert_difference("ActionMailer::Base.deliveries.count", User.count) do
post :action
end
end
So my questions are:
- Is this method the best way to send email to a new stream? Or is there a gem that handles such interaction?
- , , ? , ?