aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2011-07-02 12:51:59 -0700
committerSantiago Pastorino <santiago@wyeworks.com>2011-07-02 12:51:59 -0700
commit9d6e5e64dcd129132c3c565d0b6ead8c9bf45c2f (patch)
tree1031021cbc569ce800c99a0d33edc5eaef00be2e /actionpack
parent908be47781de892779639d5ae83b3471d46e6e48 (diff)
parentac15bcebf2d560a34286ffba7ed6a687574f2d9d (diff)
downloadrails-9d6e5e64dcd129132c3c565d0b6ead8c9bf45c2f.tar.gz
rails-9d6e5e64dcd129132c3c565d0b6ead8c9bf45c2f.tar.bz2
rails-9d6e5e64dcd129132c3c565d0b6ead8c9bf45c2f.zip
Merge pull request #1940 from dmathieu/missing_location
Provide a more explicit message when we try to redirect to a missing location
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/polymorphic_routes.rb4
-rw-r--r--actionpack/test/activerecord/polymorphic_routes_test.rb8
-rw-r--r--actionpack/test/controller/mime_responds_test.rb7
3 files changed, 18 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
index 82c4fadb50..49aef0bf72 100644
--- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
+++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -182,10 +182,12 @@ module ActionDispatch
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)
diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb
index f9e47d5118..20d11377f6 100644
--- a/actionpack/test/activerecord/polymorphic_routes_test.rb
+++ b/actionpack/test/activerecord/polymorphic_routes_test.rb
@@ -87,6 +87,14 @@ class PolymorphicRoutesTest < ActionController::TestCase
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
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 288682aa07..afb2d39955 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -659,6 +659,13 @@ class RespondWithControllerTest < ActionController::TestCase
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