Skip to content
Browse files

Handle correctly optional parameters for callable asset_host.

  • Loading branch information...
1 parent 52a9884 commit d3bc12b27feb96e8799e2bcdc6e52b2704360aa3 @marcandre marcandre committed Nov 29, 2011
Showing with 10 additions and 2 deletions.
  1. +2 −2 actionpack/lib/action_view/asset_paths.rb
  2. +8 −0 actionpack/test/template/sprockets_helper_test.rb
View
4 actionpack/lib/action_view/asset_paths.rb
@@ -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)
View
8 actionpack/test/template/sprockets_helper_test.rb
@@ -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")
@@ -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

0 comments on commit d3bc12b

Please sign in to comment.
Something went wrong with that request. Please try again.