Repository: rails/rails
File: actionmailer/test/message_delivery_test.rb (Ruby)

Code before:
      assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_kwargs", "deliver_now", params: nil, args: [argument: 1]]) do
        ActionMailer.deliver_all_later(mail1, mail2)
      end
    end
  end

  test "deliver_all_later! enqueues multiple deliveries" do
    mail1 = DelayedMailer.test_message(1)
    mail2 = DelayedMailer.test_kwargs(argument: 1)

    assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now!", params: nil, args: [1]]) do
      assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_kwargs", "deliver_now!", params: nil, args: [argument: 1]]) do
        ActionMailer.deliver_all_later!(mail1, mail2)
      end
    end
  end

  test "deliver_all_later enqueues multiple deliveries with correct jobs" do
    old_delivery_job = BaseMailer.delivery_job
    BaseMailer.delivery_job = DummyJob

    mail1 = DelayedMailer.test_message
    mail2 = BaseMailer.welcome

    assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", params: nil, args: []]) do
      assert_performed_with(job: DummyJob, args: ["BaseMailer", "welcome", "deliver_now", params: nil, args: []]) do
        ActionMailer.deliver_all_later(mail1, mail2)
      end
    end
  ensure
    BaseMailer.delivery_job = old_delivery_job
  end

  test "deliver_all_later enqueues multiple deliveries with custom options" do
    mail1 = DelayedMailer.test_message(1)
    mail2 = DelayedMailer.test_message(2)

    assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", params: nil, args: [1]], queue: "another_queue") do
      assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", params: nil, args: [2]], queue: "another_queue") do
        ActionMailer.deliver_all_later(mail1, mail2, queue: :another_queue)
      end
    end
  end

  test "deliver_all_later enqueues parameterized emails" do
    mail1 = DelayedMailer.test_message(1)
    mail2 = ParamsMailer.with(inviter: "david@basecamp.com", invitee: "jason@basecamp.com").invitation

    assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", params: nil, args: [1]]) do
      assert_performed_with(job: ActionMailer::MailDeliveryJob,
                            args: ["ParamsMailer", "invitation", "deliver_now", args: [], params: { inviter: "david@basecamp.com", invitee: "jason@basecamp.com" }]) do

Review comment (suggestion):
thanks for merging @fatkodima . But sorry if you don't mind i'm going to add back at least the test where we pass an array to properly test `if deliveries.first.is_a?(Array)`



Code after:
      assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_kwargs", "deliver_now", params: nil, args: [argument: 1]]) do
        ActionMailer.deliver_all_later(mail1, mail2)
      end
    end
  end

  test "deliver_all_later! enqueues multiple deliveries" do
    mail1 = DelayedMailer.test_message(1)
    mail2 = DelayedMailer.test_kwargs(argument: 1)

    assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now!", params: nil, args: [1]]) do
      assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_kwargs", "deliver_now!", params: nil, args: [argument: 1]]) do
        ActionMailer.deliver_all_later!(mail1, mail2)
      end
    end
  end

  test "deliver_all_later does not inline process the mailers" do
    mail1 = DelayedMailer.test_message(1)
    mail2 = DelayedMailer.test_message(2)

    ActionMailer.deliver_all_later(mail1, mail2)

    assert_not mail1.processed?
    assert_not mail2.processed?
  end

  test "deliver_all_later enqueues multiple deliveries with correct jobs" do
    old_delivery_job = BaseMailer.delivery_job
    BaseMailer.delivery_job = DummyJob

    mail1 = DelayedMailer.test_message
    mail2 = BaseMailer.welcome

    assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", params: nil, args: []]) do
      assert_performed_with(job: DummyJob, args: ["BaseMailer", "welcome", "deliver_now", params: nil, args: []]) do
        ActionMailer.deliver_all_later(mail1, mail2)
      end
    end
  ensure
    BaseMailer.delivery_job = old_delivery_job
  end

  test "deliver_all_later enqueues multiple deliveries with custom options" do
    mail1 = DelayedMailer.test_message(1)
    mail2 = DelayedMailer.test_message(2)

    assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", params: nil, args: [1]], queue: "another_queue") do
      assert_performed_with(job: ActionMailer::MailDeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", params: nil, args: [2]], queue: "another_queue") do
        ActionMailer.deliver_all_later(mail1, mail2, queue: :another_queue)
      end