Skip to content

Commit

Permalink
Don't ignore nil positional arguments for url helpers - fixes rails#6196
Browse files Browse the repository at this point in the history
.
  • Loading branch information
pixeltrix committed May 10, 2012
1 parent 7336b33 commit e98893b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/routing/route_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def #{selector}(*args)
options = args.extract_options!
result = #{options.inspect}
if args.any?
if args.size > 0
result[:_positional_args] = args
result[:_positional_keys] = #{route.segment_keys.inspect}
end
Expand Down
33 changes: 33 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2571,3 +2571,36 @@ def app; Routes end
assert_equal "bar", @request.params[:bar]
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" do
get "/categories/1"
assert_response :success
assert_raises(ActionController::RoutingError) { product_path(nil) }
end
end

0 comments on commit e98893b

Please sign in to comment.