Browse files

Merge pull request #3793 from marcandre/asset_host

Handle correctly optional parameters for callable asset_host.
  • Loading branch information...
2 parents 52a9884 + d3bc12b commit 913c42a6a949702c4305e03e0122f08306ef2b72 @josevalim josevalim committed Nov 28, 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 913c42a

Please sign in to comment.