2017-07-23 11:17:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:03:39 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "action_controller"
|
2008-11-25 06:27:32 -05:00
|
|
|
|
|
|
|
class AssetHostMailer < ActionMailer::Base
|
2010-01-24 11:31:18 -05:00
|
|
|
def email_with_asset
|
2016-08-06 13:03:39 -04:00
|
|
|
mail to: "test@localhost",
|
|
|
|
subject: "testing email containing asset path while asset_host is set",
|
|
|
|
from: "tester@example.com"
|
2008-11-25 06:27:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-19 22:53:19 -04:00
|
|
|
class AssetHostTest < ActionMailer::TestCase
|
2008-11-25 06:27:32 -05:00
|
|
|
def setup
|
2010-03-04 04:12:16 -05:00
|
|
|
AssetHostMailer.configure do |c|
|
|
|
|
c.asset_host = "http://www.example.com"
|
|
|
|
end
|
2008-11-25 06:27:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
restore_delivery_method
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_asset_host_as_string
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = AssetHostMailer.email_with_asset
|
2017-08-16 14:34:02 -04:00
|
|
|
assert_dom_equal '<img src="http://www.example.com/images/somelogo.png" />', mail.body.to_s.strip
|
2008-11-25 06:27:32 -05:00
|
|
|
end
|
|
|
|
|
2011-03-01 19:18:32 -05:00
|
|
|
def test_asset_host_as_one_argument_proc
|
2010-03-04 04:01:21 -05:00
|
|
|
AssetHostMailer.config.asset_host = Proc.new { |source|
|
2019-11-29 03:19:51 -05:00
|
|
|
if source.start_with?("/images")
|
2016-08-06 13:03:39 -04:00
|
|
|
"http://images.example.com"
|
2008-11-25 06:27:32 -05:00
|
|
|
end
|
|
|
|
}
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = AssetHostMailer.email_with_asset
|
2017-08-16 14:34:02 -04:00
|
|
|
assert_dom_equal '<img src="http://images.example.com/images/somelogo.png" />', mail.body.to_s.strip
|
2008-11-25 06:27:32 -05:00
|
|
|
end
|
2010-05-18 21:47:24 -04:00
|
|
|
end
|