提交 5371106d 编写于 作者: H Hubert Łępicki

Allow custom asset host to be passed in asset_url

上级 d2061a22
......@@ -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)
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册