Project

General

Profile

Feature #29771 » 29771-v3.patch

due_date in ascending order - Yuichi HARADA, 2018-11-05 04:15

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| (a.due_date <=> b.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_should_sort_issues_by_due_date
625
    user = User.find(2)
626
    Issue.generate!(:assigned_to => user, :due_date => 2.days.from_now, :subject => 'quux')
627
    Issue.generate!(:assigned_to => user, :due_date => 3.days.from_now, :subject => 'foobar')
628
    Issue.generate!(:assigned_to => user, :due_date => 0.days.from_now, :subject => 'baz')
629
    Issue.generate!(:assigned_to => user, :due_date => 1.days.from_now, :subject => 'qux')
630
    Issue.generate!(:assigned_to => user, :due_date => -1.days.from_now, :subject => 'foo')
631
    Issue.generate!(:assigned_to => user, :due_date => -1.days.from_now, :subject => 'bar')
632
    ActionMailer::Base.deliveries.clear
633

  
634
    Mailer.reminders(:days => 7, :users => [user.id])
635
    assert_equal 1, ActionMailer::Base.deliveries.size
636
    assert_select_email do
637
      assert_select 'li', 6
638
      assert_select 'li:nth-child(1)', /foo/
639
      assert_select 'li:nth-child(2)', /bar/
640
      assert_select 'li:nth-child(3)', /baz/
641
      assert_select 'li:nth-child(4)', /qux/
642
      assert_select 'li:nth-child(5)', /quux/
643
      assert_select 'li:nth-child(6)', /foobar/
644
    end
645
  end
646

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

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