2008-11-25 06:27:32 -05:00
|
|
|
require 'abstract_unit'
|
2010-02-03 15:30:08 -05:00
|
|
|
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
|
2012-10-07 13:54:14 -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
|
2014-10-07 18:40:59 -04:00
|
|
|
assert_dom_equal %Q{<img alt="Somelogo" 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|
|
2008-11-25 06:27:32 -05:00
|
|
|
if source.starts_with?('/images')
|
2014-02-10 08:24:27 -05: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
|
2014-10-07 18:40:59 -04:00
|
|
|
assert_dom_equal %Q{<img alt="Somelogo" 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
|