diff options
author | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-24 17:21:17 +0000 |
---|---|---|
committer | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-24 17:21:17 +0000 |
commit | 9887f238871bb2dd73de6ce8855615bcc5d8d079 (patch) | |
tree | 74fa9ff9524a51701cfa23f708b3f777c65b7fe5 /actionpack/test/activerecord/polymorphic_routes_test.rb | |
parent | aff821508a16245ebc03510ba29c70379718dfb7 (diff) | |
parent | 5214e73850916de3c9127d35a4ecee0424d364a3 (diff) | |
download | rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.tar.gz rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.tar.bz2 rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.zip |
Merge branch 'master' of https://github.com/rails/rails
Diffstat (limited to 'actionpack/test/activerecord/polymorphic_routes_test.rb')
-rw-r--r-- | actionpack/test/activerecord/polymorphic_routes_test.rb | 82 |
1 files changed, 73 insertions, 9 deletions
diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index 90a1ef982c..f9e47d5118 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -25,6 +25,22 @@ class Series < ActiveRecord::Base set_table_name 'projects' end +module Blog + class Post < ActiveRecord::Base + set_table_name 'projects' + end + + class Blog < ActiveRecord::Base + set_table_name 'projects' + end + + def self._railtie + o = Object.new + def o.railtie_name; "blog" end + o + end +end + class PolymorphicRoutesTest < ActionController::TestCase include SharedTestRoutes.url_helpers self.default_url_options[:host] = 'example.com' @@ -37,6 +53,38 @@ class PolymorphicRoutesTest < ActionController::TestCase @tax = Tax.new @fax = Fax.new @series = Series.new + @blog_post = Blog::Post.new + @blog_blog = Blog::Blog.new + end + + def test_passing_routes_proxy + with_namespaced_routes(:blog) do + proxy = ActionDispatch::Routing::RoutesProxy.new(_routes, self) + @blog_post.save + assert_equal "http://example.com/posts/#{@blog_post.id}", polymorphic_url([proxy, @blog_post]) + end + end + + def test_namespaced_model + with_namespaced_routes(:blog) do + @blog_post.save + assert_equal "http://example.com/posts/#{@blog_post.id}", polymorphic_url(@blog_post) + end + end + + def test_namespaced_model_with_name_the_same_as_namespace + with_namespaced_routes(:blog) do + @blog_blog.save + assert_equal "http://example.com/blogs/#{@blog_blog.id}", polymorphic_url(@blog_blog) + end + end + + def test_namespaced_model_with_nested_resources + with_namespaced_routes(:blog) do + @blog_post.save + @blog_blog.save + assert_equal "http://example.com/blogs/#{@blog_blog.id}/posts/#{@blog_post.id}", polymorphic_url([@blog_blog, @blog_post]) + end end def test_with_record @@ -385,20 +433,36 @@ class PolymorphicRoutesTest < ActionController::TestCase end end + def with_namespaced_routes(name) + with_routing do |set| + set.draw do + scope(:module => name) do + resources :blogs do + resources :posts + end + resources :posts + end + end + + self.class.send(:include, @routes.url_helpers) + yield + end + end + def with_test_routes(options = {}) with_routing do |set| - set.draw do |map| - map.resources :projects do |projects| - projects.resources :tasks - projects.resource :bid do |bid| - bid.resources :tasks + set.draw do + resources :projects do + resources :tasks + resource :bid do + resources :tasks end end - map.resources :taxes do |taxes| - taxes.resources :faxes - taxes.resource :bid + resources :taxes do + resources :faxes + resource :bid end - map.resources :series + resources :series end self.class.send(:include, @routes.url_helpers) |