Skip to content

Commit

Permalink
Handle correctly optional parameters for callable asset_host.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Nov 29, 2011
1 parent 52a9884 commit d3bc12b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/asset_paths.rb
Expand Up @@ -103,8 +103,8 @@ def compute_asset_host(source)
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)
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/template/sprockets_helper_test.rb
Expand Up @@ -41,6 +41,10 @@ def config
@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")
Expand Down Expand Up @@ -125,6 +129,10 @@ def config
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
Expand Down

0 comments on commit d3bc12b

Please sign in to comment.