Skip to content

Commit

Permalink
Allow custom asset host to be passed in asset_url
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertlepicki committed May 8, 2014
1 parent d2061a2 commit 5371106
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion actionview/lib/action_view/helpers/asset_url_helper.rb
Expand Up @@ -191,7 +191,8 @@ def compute_asset_path(source, options = {})
# (proc or otherwise). # (proc or otherwise).
def compute_asset_host(source = "", options = {}) def compute_asset_host(source = "", options = {})
request = self.request if respond_to?(:request) 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 host ||= request.base_url if request && options[:protocol] == :request


if host.respond_to?(:call) if host.respond_to?(:call)
Expand Down
15 changes: 15 additions & 0 deletions actionview/test/template/asset_tag_helper_test.rb
Expand Up @@ -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) assert_equal "gopher://www.example.com", compute_asset_host("foo", :protocol => :request)
end 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 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")) assert_dom_equal(%(http://www.example.com/images/xml.png), image_path("http://www.example.com/images/xml.png"))
end end
Expand Down Expand Up @@ -759,4 +763,15 @@ def config
assert @module.config.asset_host assert @module.config.asset_host
assert_equal "http://www.example.com/foo", @module.asset_url("foo") assert_equal "http://www.example.com/foo", @module.asset_url("foo")
end 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 end

0 comments on commit 5371106

Please sign in to comment.