Project

General

Profile

Feature #31225 » 31225_fix_test.patch

Yuichi HARADA, 2019-05-20 07:22

View differences:

test/unit/mailer_test.rb
620 620
  end
621 621

  
622 622
  def test_reminders
623
    Mailer.reminders(:days => 42)
624
    assert_equal 1, ActionMailer::Base.deliveries.size
625
    mail = last_email
626
    assert mail.bcc.include?('dlopper@somenet.foo')
627
    assert_mail_body_match 'Bug #3: Error 281 when updating a recipe (5 days late)', mail
628
    assert_mail_body_match 'View all issues (2 open)', mail
629
    assert_select_email do
630
      assert_select 'a[href=?]',
631
                    'http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc',
632
                    :text => 'View all issues'
633
      assert_select '/p:nth-last-of-type(1)', :text => 'View all issues (2 open)'
623
    travel_to Date.today.to_time(:utc) do
624
      Mailer.reminders(:days => 42)
625
      assert_equal 1, ActionMailer::Base.deliveries.size
626
      mail = last_email
627
      assert mail.bcc.include?('dlopper@somenet.foo')
628
      assert_mail_body_match 'Bug #3: Error 281 when updating a recipe (5 days late)', mail
629
      assert_mail_body_match 'View all issues (2 open)', mail
630
      assert_select_email do
631
        assert_select 'a[href=?]',
632
                      'http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc',
633
                      :text => 'View all issues'
634
        assert_select '/p:nth-last-of-type(1)', :text => 'View all issues (2 open)'
635
      end
636
      assert_equal '1 issue(s) due in the next 42 days', mail.subject
634 637
    end
635
    assert_equal '1 issue(s) due in the next 42 days', mail.subject
636 638
  end
637 639

  
638 640
  def test_reminders_language_auto
639 641
    with_settings :default_language => 'fr' do
640 642
      user = User.find(3)
641 643
      user.update_attribute :language, ''
642
      Mailer.reminders(:days => 42)
643
      assert_equal 1, ActionMailer::Base.deliveries.size
644
      mail = last_email
645
      assert mail.bcc.include?('dlopper@somenet.foo')
646
      assert_mail_body_match 'Bug #3: Error 281 when updating a recipe (En retard de 5 jours)', mail
647
      assert_equal "1 demande(s) arrivent à échéance (42)", mail.subject
644
      travel_to Date.today.to_time(:utc) do
645
        Mailer.reminders(:days => 42)
646
        assert_equal 1, ActionMailer::Base.deliveries.size
647
        mail = last_email
648
        assert mail.bcc.include?('dlopper@somenet.foo')
649
        assert_mail_body_match 'Bug #3: Error 281 when updating a recipe (En retard de 5 jours)', mail
650
        assert_equal "1 demande(s) arrivent à échéance (42)", mail.subject
651
      end
648 652
    end
649 653
  end
650 654

  
......
665 669
  end
666 670

  
667 671
  def test_reminders_for_users
668
    Mailer.reminders(:days => 42, :users => ['5'])
669
    assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
670
    Mailer.reminders(:days => 42, :users => ['3'])
671
    assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
672
    mail = last_email
673
    assert mail.bcc.include?('dlopper@somenet.foo')
674
    assert_mail_body_match 'Bug #3: Error 281 when updating a recipe (5 days late)', mail
672
    travel_to Date.today.to_time(:utc) do
673
      Mailer.reminders(:days => 42, :users => ['5'])
674
      assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
675
      Mailer.reminders(:days => 42, :users => ['3'])
676
      assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
677
      mail = last_email
678
      assert mail.bcc.include?('dlopper@somenet.foo')
679
      assert_mail_body_match 'Bug #3: Error 281 when updating a recipe (5 days late)', mail
680
    end
675 681
  end
676 682

  
677 683
  def test_reminder_should_include_issues_assigned_to_groups
......
683 689
      group.users << user_dlopper
684 690

  
685 691
      Issue.update_all(:assigned_to_id => nil)
686
      due_date = 10.days.from_now
687
      Issue.update(1, :due_date => due_date, :assigned_to_id => user_dlopper.id)
688
      Issue.update(2, :due_date => due_date, :assigned_to_id => group.id)
689
      Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
690
                      :subject => 'Assigned to group', :assigned_to => group,
691
                      :due_date => 5.days.from_now,
692
                      :author_id => 2)
693
      ActionMailer::Base.deliveries.clear
694

  
695
      Mailer.reminders(:days => 7)
696
      assert_equal 2, ActionMailer::Base.deliveries.size
697
      assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), recipients
698
      ActionMailer::Base.deliveries.each do |mail|
699
        assert_mail_body_match '1 issue(s) that are assigned to you are due in the next 7 days::', mail
700
        assert_mail_body_match 'Assigned to group (Due in 5 days)', mail
701
        assert_mail_body_match "View all issues (#{mail.bcc.include?('dlopper@somenet.foo') ? 3 : 2} open)", mail
692
      travel_to Date.today.to_time(:utc) do
693
        due_date = 10.days.from_now
694
        Issue.update(1, :due_date => due_date, :assigned_to_id => user_dlopper.id)
695
        Issue.update(2, :due_date => due_date, :assigned_to_id => group.id)
696
        Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
697
                        :subject => 'Assigned to group', :assigned_to => group,
698
                        :due_date => 5.days.from_now,
699
                        :author_id => 2)
700
        ActionMailer::Base.deliveries.clear
701

  
702
        Mailer.reminders(:days => 7)
703
        assert_equal 2, ActionMailer::Base.deliveries.size
704
        assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), recipients
705
        ActionMailer::Base.deliveries.each do |mail|
706
          assert_mail_body_match '1 issue(s) that are assigned to you are due in the next 7 days::', mail
707
          assert_mail_body_match 'Assigned to group (Due in 5 days)', mail
708
          assert_mail_body_match "View all issues (#{mail.bcc.include?('dlopper@somenet.foo') ? 3 : 2} open)", mail
709
        end
702 710
      end
703 711
    end
704 712
  end
......
736 744
  end
737 745

  
738 746
  def test_reminders_should_sort_issues_by_due_date
739
    user = User.find(2)
740
    Issue.generate!(:assigned_to => user, :due_date => 2.days.from_now, :subject => 'quux')
741
    Issue.generate!(:assigned_to => user, :due_date => 0.days.from_now, :subject => 'baz')
742
    Issue.generate!(:assigned_to => user, :due_date => 1.days.from_now, :subject => 'qux')
743
    Issue.generate!(:assigned_to => user, :due_date => -1.days.from_now, :subject => 'foo')
744
    Issue.generate!(:assigned_to => user, :due_date => -1.days.from_now, :subject => 'bar')
745
    ActionMailer::Base.deliveries.clear
747
    travel_to Date.today.to_time(:utc) do
748
      user = User.find(2)
749
      Issue.generate!(:assigned_to => user, :due_date => 2.days.from_now, :subject => 'quux')
750
      Issue.generate!(:assigned_to => user, :due_date => 0.days.from_now, :subject => 'baz')
751
      Issue.generate!(:assigned_to => user, :due_date => 1.days.from_now, :subject => 'qux')
752
      Issue.generate!(:assigned_to => user, :due_date => -1.days.from_now, :subject => 'foo')
753
      Issue.generate!(:assigned_to => user, :due_date => -1.days.from_now, :subject => 'bar')
754
      ActionMailer::Base.deliveries.clear
746 755

  
747
    Mailer.reminders(:days => 7, :users => [user.id])
748
    assert_equal 1, ActionMailer::Base.deliveries.size
749
    assert_select_email do
750
      assert_select 'li', 5
751
      assert_select 'li:nth-child(1)', /foo \(1 day late\)/
752
      assert_select 'li:nth-child(2)', /bar \(1 day late\)/
753
      assert_select 'li:nth-child(3)', /baz \(Due in 0 days\)/
754
      assert_select 'li:nth-child(4)', /qux \(Due in 1 day\)/
755
      assert_select 'li:nth-child(5)', /quux \(Due in 2 days\)/
756
      Mailer.reminders(:days => 7, :users => [user.id])
757
      assert_equal 1, ActionMailer::Base.deliveries.size
758
      assert_select_email do
759
        assert_select 'li', 5
760
        assert_select 'li:nth-child(1)', /foo \(1 day late\)/
761
        assert_select 'li:nth-child(2)', /bar \(1 day late\)/
762
        assert_select 'li:nth-child(3)', /baz \(Due in 0 days\)/
763
        assert_select 'li:nth-child(4)', /qux \(Due in 1 day\)/
764
        assert_select 'li:nth-child(5)', /quux \(Due in 2 days\)/
765
      end
756 766
    end
757 767
  end
758 768

  
(2-2/4)