mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Handle correctly optional parameters for callable asset_host.
This commit is contained in:
parent
52a9884ce4
commit
d3bc12b27f
2 changed files with 10 additions and 2 deletions
|
@ -103,8 +103,8 @@ module ActionView
|
||||||
if host.respond_to?(:call)
|
if host.respond_to?(:call)
|
||||||
args = [source]
|
args = [source]
|
||||||
arity = arity_of(host)
|
arity = arity_of(host)
|
||||||
if arity > 1 && !has_request?
|
if (arity > 1 || arity < -2) && !has_request?
|
||||||
invalid_asset_host!("Remove the second argument to your asset_host Proc if you do not need the request.")
|
invalid_asset_host!("Remove the second argument to your asset_host Proc if you do not need the request, or make it optional.")
|
||||||
end
|
end
|
||||||
args << current_request if (arity > 1 || arity < 0) && has_request?
|
args << current_request if (arity > 1 || arity < 0) && has_request?
|
||||||
host.call(*args)
|
host.call(*args)
|
||||||
|
|
|
@ -41,6 +41,10 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
@controller ? @controller.config : @config
|
@controller ? @controller.config : @config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def compute_host(source, request, options = {})
|
||||||
|
raise "Should never get here"
|
||||||
|
end
|
||||||
|
|
||||||
test "asset_path" do
|
test "asset_path" do
|
||||||
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
||||||
asset_path("logo.png")
|
asset_path("logo.png")
|
||||||
|
@ -125,6 +129,10 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
assert_raises ActionController::RoutingError do
|
assert_raises ActionController::RoutingError do
|
||||||
asset_path("logo.png")
|
asset_path("logo.png")
|
||||||
end
|
end
|
||||||
|
@config.asset_host = method :compute_host
|
||||||
|
assert_raises ActionController::RoutingError do
|
||||||
|
asset_path("logo.png")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "image_tag" do
|
test "image_tag" do
|
||||||
|
|
Loading…
Reference in a new issue