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
|
|
|
|
|
2012-01-05 19:55:54 -05:00
|
|
|
class AssetHostTest < ActiveSupport::TestCase
|
2008-11-25 06:27:32 -05:00
|
|
|
def setup
|
|
|
|
set_delivery_method :test
|
|
|
|
ActionMailer::Base.perform_deliveries = true
|
2010-01-23 19:15:42 -05:00
|
|
|
ActionMailer::Base.deliveries.clear
|
2010-03-04 04:12:16 -05:00
|
|
|
AssetHostMailer.configure do |c|
|
|
|
|
c.asset_host = "http://www.example.com"
|
|
|
|
c.assets_dir = ''
|
|
|
|
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
|
2010-05-18 21:47:24 -04:00
|
|
|
assert_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')
|
|
|
|
"http://images.example.com"
|
|
|
|
else
|
|
|
|
"http://assets.example.com"
|
|
|
|
end
|
|
|
|
}
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = AssetHostMailer.email_with_asset
|
2010-05-18 21:47:24 -04:00
|
|
|
assert_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
|
|
|
|
|
2011-03-01 19:18:32 -05:00
|
|
|
def test_asset_host_as_two_argument_proc
|
2010-03-04 20:44:16 -05:00
|
|
|
ActionController::Base.config.asset_host = Proc.new {|source,request|
|
2008-11-25 06:27:32 -05:00
|
|
|
if request && request.ssl?
|
|
|
|
"https://www.example.com"
|
|
|
|
else
|
|
|
|
"http://www.example.com"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
mail = nil
|
2010-01-24 11:31:18 -05:00
|
|
|
assert_nothing_raised { mail = AssetHostMailer.email_with_asset }
|
2010-05-18 21:47:24 -04:00
|
|
|
assert_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
|
2010-05-18 21:47:24 -04:00
|
|
|
end
|