Fix flaky emails spec.
These tests were failing randomly because there is no guarantee the methods `Budget#email_selected` and `Budget#email_unselected` will always send the emails in the same order, because `investments.selected` and `investments.unselected` don't necessarily return the records in the order they were created. Ordering by id is certainly not very elegant; however, ordering by another field like `created_at` is dangerous because the record could be created at (almost) the exact same time. Related to issue #2446 and issue #2519.
This commit is contained in:
@@ -152,13 +152,13 @@ class Budget < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def email_selected
|
||||
investments.selected.each do |investment|
|
||||
investments.selected.order(:id).each do |investment|
|
||||
Mailer.budget_investment_selected(investment).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
def email_unselected
|
||||
investments.unselected.each do |investment|
|
||||
investments.unselected.order(:id).each do |investment|
|
||||
Mailer.budget_investment_unselected(investment).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user