Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't ignore nil positional arguments for url helpers - fixes #6196.

  • Loading branch information...
commit 09a48b2324207ccbf6f421e5e7caf7655f1e905a 1 parent e306ca3
@pixeltrix pixeltrix authored
View
2  actionpack/lib/action_dispatch/routing/route_set.rb
@@ -103,7 +103,7 @@ def handle_positional_args(args, options, segment_keys)
inner_options = args.extract_options!
result = options.dup
- if args.any?
+ if args.size > 0
keys = segment_keys
if args.size < keys.size - 1 # take format into account
keys -= self.url_options.keys if self.respond_to?(:url_options)
View
35 actionpack/test/dispatch/routing_test.rb
@@ -2571,3 +2571,38 @@ def app; Routes end
assert_equal '/foo', foo_path
end
end
+
+class TestNamedRouteUrlHelpers < ActionDispatch::IntegrationTest
+ class CategoriesController < ActionController::Base
+ def show
+ render :text => "categories#show"
+ end
+ end
+
+ class ProductsController < ActionController::Base
+ def show
+ render :text => "products#show"
+ end
+ end
+
+ Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
+ app.draw do
+ scope :module => "test_named_route_url_helpers" do
+ get "/categories/:id" => 'categories#show', :as => :category
+ get "/products/:id" => 'products#show', :as => :product
+ end
+ end
+ end
+
+ def app; Routes end
+
+ include Routes.url_helpers
+
+ test "url helpers do not ignore nil parameters when using non-optimized routes" do
+ Routes.stubs(:optimize_routes_generation?).returns(false)
+
+ get "/categories/1"
+ assert_response :success
+ assert_raises(ActionController::RoutingError) { product_path(nil) }
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.