Skip to content

Commit

Permalink
Merge pull request rails#1940 from dmathieu/missing_location
Browse files Browse the repository at this point in the history
Provide a more explicit message when we try to redirect to a missing location
  • Loading branch information
spastorino committed Jul 2, 2011
2 parents 908be47 + ac15bce commit 9d6e5e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ def build_named_route_call(records, inflection, options = {})

if record.is_a?(Symbol) || record.is_a?(String)
route << record
else
elsif record
route << ActiveModel::Naming.route_key(record)
route = [route.join("_").singularize] if inflection == :singular
route << "index" if ActiveModel::Naming.uncountable?(record) && inflection == :plural
else
raise ArgumentError, "Nil location provided. Can't build URI."
end

route << routing_type(options)
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/activerecord/polymorphic_routes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def test_namespaced_model_with_nested_resources
end
end

def test_with_nil
with_test_routes do
assert_raise ArgumentError, "Nil location provided. Can't build URI." do
polymorphic_url(nil)
end
end
end

def test_with_record
with_test_routes do
@project.save
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/mime_responds_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,13 @@ def test_using_hash_resource
assert_equal %Q[{"result":{"name":"david","id":13}}], @response.body
end

def test_using_hash_resource_with_post
@request.accept = "application/json"
assert_raise ArgumentError, "Nil location provided. Can't build URI." do
post :using_hash_resource
end
end

def test_using_resource_with_block
@request.accept = "*/*"
get :using_resource_with_block
Expand Down

0 comments on commit 9d6e5e6

Please sign in to comment.