Project

General

Profile

Feature #29771 » 29771-reminders-order-due-date.patch

Yuichi HARADA, 2018-10-17 08:35

View differences:

app/models/mailer.rb
27 27
  include Roadie::Rails::Automatic
28 28

  
29 29
  # Overrides ActionMailer::Base#process in order to set the recipient as the current user
30
  # and his language as the default locale. 
30
  # and his language as the default locale.
31 31
  # The first argument of all actions of this Mailer must be a User (the recipient),
32 32
  # otherwise an ArgumentError is raised.
33 33
  def process(action, *args)
......
584 584
    issues_by_assignee.each do |assignee, issues|
585 585
      if assignee.is_a?(User) && assignee.active? && issues.present?
586 586
        visible_issues = issues.select {|i| i.visible?(assignee)}
587
        visible_issues.sort!{|a, b| (b.due_date <=> a.due_date).nonzero? || (a.id <=> b.id)}
587 588
        reminder(assignee, visible_issues, days).deliver_later if visible_issues.present?
588 589
      end
589 590
    end
test/unit/mailer_test.rb
621 621
    end
622 622
  end
623 623

  
624
  def test_reminders_order_descending_on_due_date
625
    with_settings :default_language => 'en' do
626
      user = User.find(2)
627
      issues = []
628
      issues << Issue.generate!(:assigned_to => user, :due_date => 5.days.from_now)
629
      issues << Issue.generate!(:assigned_to => user, :due_date => 5.days.from_now)
630
      issues << Issue.generate!(:assigned_to => user, :due_date => 6.days.from_now)
631
      issues << Issue.generate!(:assigned_to => user, :due_date => 6.days.from_now)
632
      issues.sort!{|a, b| (b.due_date <=> a.due_date).nonzero? || (a.id <=> b.id)}
633
      ActionMailer::Base.deliveries.clear
634

  
635
      Mailer.reminders(:days => 7, :users => [user.id])
636
      assert_equal 1, ActionMailer::Base.deliveries.size
637
      mail = last_email
638

  
639
      mailbody_issues = mail_body(mail).split(/\r\n/).select{|row| /^\*/ =~ row}
640
      mailbody_issues.collect!{|row| /^\*.+#(\d+):/ =~ row; $1.to_i rescue nil}
641

  
642
      assert_equal issues.collect(&:id), mailbody_issues
643
    end
644
  end
645

  
624 646
  def test_security_notification
625 647
    set_language_if_valid User.find(1).language
626 648
    with_settings :emails_footer => "footer without link" do
......
684 706
    # Send an email to a french user
685 707
    user = User.find(1)
686 708
    user.update_attribute :language, 'fr'
687
    
709

  
688 710
    Mailer.deliver_account_activated(user)
689 711
    mail = last_email
690 712
    assert_mail_body_match 'Votre compte', mail
(1-1/3)