From 130755df0a68ca528737c4e54dc6a6746f84bfb4 Mon Sep 17 00:00:00 2001 From: Tekin Suleyman Date: Mon, 17 Nov 2008 21:46:15 +0000 Subject: [PATCH] compute_asset_host no longer bombs if no request object present --- .../lib/action_view/helpers/asset_tag_helper.rb | 2 +- actionpack/test/template/asset_tag_helper_test.rb | 22 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 8bbe74b..6de681d 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -629,7 +629,7 @@ module ActionView if host.is_a?(Proc) case host.arity when 2 - host.call(source, request) + request? ? host.call(source, request) : host.call(source, nil) else host.call(source) end diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 1a3a6e8..2a62678 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -281,6 +281,28 @@ class AssetTagHelperTest < ActionView::TestCase assert_equal copy, source end + def test_can_still_compute_path_when_2_argument_asset_host_and_no_request + ActionController::Base.asset_host = Proc.new { |source, request| + if request && request.ssl? + "https//www.example.com" + else + "http://assets.example.com" + end + } + + assert_dom_equal( + "http://assets.example.com/images/xml.png", + image_path('/images/xml.png') + ) + + @controller = Class.new + + assert_dom_equal( + "http://assets.example.com/images/xml.png", + image_path('/images/xml.png') + ) + end + def test_caching_javascript_include_tag_when_caching_on ENV["RAILS_ASSET_ID"] = "" ActionController::Base.asset_host = 'http://a0.example.com' -- 1.5.5.4