diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 468e6c21a..492ca976d 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -27,7 +27,7 @@ class Mailer < ActionMailer::Base include Roadie::Rails::Automatic # Overrides ActionMailer::Base#process in order to set the recipient as the current user - # and his language as the default locale. + # and his language as the default locale. # The first argument of all actions of this Mailer must be a User (the recipient), # otherwise an ArgumentError is raised. def process(action, *args) @@ -584,6 +584,7 @@ class Mailer < ActionMailer::Base issues_by_assignee.each do |assignee, issues| if assignee.is_a?(User) && assignee.active? && issues.present? visible_issues = issues.select {|i| i.visible?(assignee)} + visible_issues.sort!{|a, b| (a.due_date <=> b.due_date).nonzero? || (a.id <=> b.id)} reminder(assignee, visible_issues, days).deliver_later if visible_issues.present? end end diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index c340a41ff..9c5f5815f 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -621,6 +621,29 @@ class MailerTest < ActiveSupport::TestCase end end + def test_reminders_should_sort_issues_by_due_date + user = User.find(2) + Issue.generate!(:assigned_to => user, :due_date => 2.days.from_now, :subject => 'quux') + Issue.generate!(:assigned_to => user, :due_date => 3.days.from_now, :subject => 'foobar') + Issue.generate!(:assigned_to => user, :due_date => 0.days.from_now, :subject => 'baz') + Issue.generate!(:assigned_to => user, :due_date => 1.days.from_now, :subject => 'qux') + Issue.generate!(:assigned_to => user, :due_date => -1.days.from_now, :subject => 'foo') + Issue.generate!(:assigned_to => user, :due_date => -1.days.from_now, :subject => 'bar') + ActionMailer::Base.deliveries.clear + + Mailer.reminders(:days => 7, :users => [user.id]) + assert_equal 1, ActionMailer::Base.deliveries.size + assert_select_email do + assert_select 'li', 6 + assert_select 'li:nth-child(1)', /foo/ + assert_select 'li:nth-child(2)', /bar/ + assert_select 'li:nth-child(3)', /baz/ + assert_select 'li:nth-child(4)', /qux/ + assert_select 'li:nth-child(5)', /quux/ + assert_select 'li:nth-child(6)', /foobar/ + end + end + def test_security_notification set_language_if_valid User.find(1).language with_settings :emails_footer => "footer without link" do @@ -684,7 +707,7 @@ class MailerTest < ActiveSupport::TestCase # Send an email to a french user user = User.find(1) user.update_attribute :language, 'fr' - + Mailer.deliver_account_activated(user) mail = last_email assert_mail_body_match 'Votre compte', mail