1
0
Fork 0
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:
Marc-Andre Lafortune 2011-11-29 01:59:36 -05:00
parent 52a9884ce4
commit d3bc12b27f
2 changed files with 10 additions and 2 deletions

View file

@ -103,8 +103,8 @@ module ActionView
if host.respond_to?(:call)
args = [source]
arity = arity_of(host)
if arity > 1 && !has_request?
invalid_asset_host!("Remove the second argument to your asset_host Proc if you do not need the 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, or make it optional.")
end
args << current_request if (arity > 1 || arity < 0) && has_request?
host.call(*args)

View file

@ -41,6 +41,10 @@ class SprocketsHelperTest < ActionView::TestCase
@controller ? @controller.config : @config
end
def compute_host(source, request, options = {})
raise "Should never get here"
end
test "asset_path" do
assert_match %r{/assets/logo-[0-9a-f]+.png},
asset_path("logo.png")
@ -125,6 +129,10 @@ class SprocketsHelperTest < ActionView::TestCase
assert_raises ActionController::RoutingError do
asset_path("logo.png")
end
@config.asset_host = method :compute_host
assert_raises ActionController::RoutingError do
asset_path("logo.png")
end
end
test "image_tag" do