Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow custom asset host to be passed in asset_url

  • Loading branch information...
commit 5371106d530e64cfb221492714fb7cef32fa45c3 1 parent d2061a2
Hubert Łępicki hubertlepicki authored
3  actionview/lib/action_view/helpers/asset_url_helper.rb
View
@@ -191,7 +191,8 @@ def compute_asset_path(source, options = {})
# (proc or otherwise).
def compute_asset_host(source = "", options = {})
request = self.request if respond_to?(:request)
- host = config.asset_host if defined? config.asset_host
+ host = options[:host]
+ host ||= config.asset_host if defined? config.asset_host
host ||= request.base_url if request && options[:protocol] == :request
if host.respond_to?(:call)
15 actionview/test/template/asset_tag_helper_test.rb
View
@@ -596,6 +596,10 @@ def test_should_current_request_host_is_always_returned_for_request
assert_equal "gopher://www.example.com", compute_asset_host("foo", :protocol => :request)
end
+ def test_should_return_custom_host_if_passed_in_options
+ assert_equal "http://custom.example.com", compute_asset_host("foo", :host => "http://custom.example.com")
+ end
+
def test_should_ignore_relative_root_path_on_complete_url
assert_dom_equal(%(http://www.example.com/images/xml.png), image_path("http://www.example.com/images/xml.png"))
end
@@ -759,4 +763,15 @@ def config
assert @module.config.asset_host
assert_equal "http://www.example.com/foo", @module.asset_url("foo")
end
+
+ def test_asset_url_with_custom_asset_host
+ @module.instance_eval do
+ def config
+ Struct.new(:asset_host).new("http://www.example.com")
+ end
+ end
+
+ assert @module.config.asset_host
+ assert_equal "http://custom.example.com/foo", @module.asset_url("foo", :host => "http://custom.example.com")
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.