1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionmailer/test/message_delivery_test.rb
2014-08-21 06:40:00 +09:00

103 lines
2.8 KiB
Ruby

# encoding: utf-8
gem 'activejob'
require 'active_job'
require 'abstract_unit'
require 'minitest/mock'
require_relative 'mailers/delayed_mailer'
class MessageDeliveryTest < ActiveSupport::TestCase
setup do
@previous_logger = ActiveJob::Base.logger
@previous_delivery_method = ActionMailer::Base.delivery_method
ActionMailer::Base.delivery_method = :test
ActiveJob::Base.logger = Logger.new(nil)
@mail = DelayedMailer.test_message(1, 2, 3)
ActionMailer::Base.deliveries.clear
end
teardown do
ActiveJob::Base.logger = @previous_logger
ActionMailer::Base.delivery_method = @previous_delivery_method
end
test 'should have a message' do
assert @mail.message
end
test 'its message should be a Mail::Message' do
assert_equal Mail::Message , @mail.message.class
end
test 'should respond to .deliver' do
assert_respond_to @mail, :deliver
end
test 'should respond to .deliver!' do
assert_respond_to @mail, :deliver!
end
test '.deliver is deprecated' do
assert_deprecated do
@mail.deliver
end
end
test '.deliver! is deprecated' do
assert_deprecated do
@mail.deliver!
end
end
test 'should respond to .deliver_later' do
assert_respond_to @mail, :deliver_later
end
test 'should respond to .deliver_later!' do
assert_respond_to @mail, :deliver_later!
end
test 'should respond to .deliver_now' do
assert_respond_to @mail, :deliver_now
end
test 'should respond to .deliver_now!' do
assert_respond_to @mail, :deliver_now!
end
def test_should_enqueue_and_run_correctly_in_activejob
@mail.deliver_later!
assert_equal 1, ActionMailer::Base.deliveries.size
ensure
ActionMailer::Base.deliveries.clear
end
test 'should enqueue the email with :deliver delivery method' do
ret = ActionMailer::DeliveryJob.stub :enqueue, ->(*args){ args } do
@mail.deliver_later
end
assert_equal ['DelayedMailer', 'test_message', 'deliver_now', 1, 2, 3], ret
end
test 'should enqueue the email with :deliver! delivery method' do
ret = ActionMailer::DeliveryJob.stub :enqueue, ->(*args){ args } do
@mail.deliver_later!
end
assert_equal ['DelayedMailer', 'test_message', 'deliver_now!', 1, 2, 3], ret
end
test 'should enqueue a delivery with a delay' do
ret = ActionMailer::DeliveryJob.stub :enqueue_in, ->(*args){ args } do
@mail.deliver_later in: 600
end
assert_equal [600, 'DelayedMailer', 'test_message', 'deliver_now', 1, 2, 3], ret
end
test 'should enqueue a delivery at a specific time' do
later_time = Time.now.to_i + 3600
ret = ActionMailer::DeliveryJob.stub :enqueue_at, ->(*args){ args } do
@mail.deliver_later at: later_time
end
assert_equal [later_time, 'DelayedMailer', 'test_message', 'deliver_now', 1, 2, 3], ret
end
end