aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/activerecord/polymorphic_routes_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionview/test/activerecord/polymorphic_routes_test.rb')
-rw-r--r--actionview/test/activerecord/polymorphic_routes_test.rb36
1 files changed, 34 insertions, 2 deletions
diff --git a/actionview/test/activerecord/polymorphic_routes_test.rb b/actionview/test/activerecord/polymorphic_routes_test.rb
index 0d97ddb2f6..a259c359f0 100644
--- a/actionview/test/activerecord/polymorphic_routes_test.rb
+++ b/actionview/test/activerecord/polymorphic_routes_test.rb
@@ -183,16 +183,33 @@ class PolymorphicRoutesTest < ActionController::TestCase
end
end
- def test_with_nil_in_list
+ def test_with_entirely_nil_list
with_test_routes do
exception = assert_raise ArgumentError do
@series.save
- polymorphic_url([nil, @series])
+ polymorphic_url([nil, nil])
end
assert_equal "Nil location provided. Can't build URI.", exception.message
end
end
+ def test_with_nil_in_list_for_resource_that_could_be_top_level_or_nested
+ with_top_level_and_nested_routes do
+ @blog_post.save
+ assert_equal "http://example.com/posts/#{@blog_post.id}", polymorphic_url([nil, @blog_post])
+ end
+ end
+
+ def test_with_nil_in_list_does_not_generate_invalid_link
+ with_top_level_and_nested_routes do
+ exception = assert_raise NoMethodError do
+ @series.save
+ polymorphic_url([nil, @series])
+ end
+ assert_match /undefined method `series_url' for/, exception.message
+ end
+ end
+
def test_with_record
with_test_routes do
@project.save
@@ -626,6 +643,21 @@ class PolymorphicRoutesTest < ActionController::TestCase
end
end
+ def with_top_level_and_nested_routes(options = {})
+ with_routing do |set|
+ set.draw do
+ resources :blogs do
+ resources :posts
+ resources :series
+ end
+ resources :posts
+ end
+
+ extend @routes.url_helpers
+ yield
+ end
+ end
+
def with_admin_test_routes(options = {})
with_routing do |set|
set.draw do