diff options
author | José Valim <jose.valim@gmail.com> | 2012-06-01 07:40:41 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-06-01 07:40:41 -0700 |
commit | 5b6b0df8c585326266275b2fb25cfdfce924fe9b (patch) | |
tree | f4c3a2e75b707f876e03a7e1c10c0f38eef6b28e /actionpack/test | |
parent | b13d89ea9ee03467dc80a9ad29e3b10cece67b35 (diff) | |
parent | 537ede912895d421b24acfcbc86daf08f8f22157 (diff) | |
download | rails-5b6b0df8c585326266275b2fb25cfdfce924fe9b.tar.gz rails-5b6b0df8c585326266275b2fb25cfdfce924fe9b.tar.bz2 rails-5b6b0df8c585326266275b2fb25cfdfce924fe9b.zip |
Merge pull request #6588 from nbibler/polymorphic_to_model
Correct the use of to_model in polymorphic routing
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/activerecord/polymorphic_routes_test.rb | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index 90e7f4ae59..afb714484b 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -25,6 +25,24 @@ class Series < ActiveRecord::Base self.table_name = 'projects' end +class ModelDelegator < ActiveRecord::Base + self.table_name = 'projects' + + def to_model + ModelDelegate.new + end +end + +class ModelDelegate + def self.model_name + ActiveModel::Name.new(self) + end + + def to_param + 'overridden' + end +end + module Blog class Post < ActiveRecord::Base self.table_name = 'projects' @@ -50,6 +68,7 @@ class PolymorphicRoutesTest < ActionController::TestCase @bid = Bid.new @tax = Tax.new @fax = Fax.new + @delegator = ModelDelegator.new @series = Series.new @blog_post = Blog::Post.new @blog_blog = Blog::Blog.new @@ -439,6 +458,13 @@ class PolymorphicRoutesTest < ActionController::TestCase end end + def test_routing_a_to_model_delegate + with_test_routes do + @delegator.save + assert_equal "http://example.com/model_delegates/overridden", polymorphic_url(@delegator) + end + end + def with_namespaced_routes(name) with_routing do |set| set.draw do @@ -469,6 +495,7 @@ class PolymorphicRoutesTest < ActionController::TestCase resource :bid end resources :series + resources :model_delegates end self.class.send(:include, @routes.url_helpers) @@ -516,5 +543,4 @@ class PolymorphicRoutesTest < ActionController::TestCase yield end end - end |