diff options
author | Joshua Peek <josh@joshpeek.com> | 2010-03-30 14:05:42 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2010-03-30 14:05:42 -0500 |
commit | cdf8c35ffdfb39f4de4b030576b1abb06c482668 (patch) | |
tree | 16f3973a7f844aa3e55c72c26ba9266c24a6fa72 /actionpack/test | |
parent | 17f0c1e9e8a5bfa7c4d2e1632c3b8b91f4678f03 (diff) | |
download | rails-cdf8c35ffdfb39f4de4b030576b1abb06c482668.tar.gz rails-cdf8c35ffdfb39f4de4b030576b1abb06c482668.tar.bz2 rails-cdf8c35ffdfb39f4de4b030576b1abb06c482668.zip |
Consistent routing language
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/abstract_unit.rb | 15 | ||||
-rw-r--r-- | actionpack/test/activerecord/polymorphic_routes_test.rb | 164 | ||||
-rw-r--r-- | actionpack/test/controller/caching_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/resources_test.rb | 14 | ||||
-rw-r--r-- | actionpack/test/controller/test_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/controller/url_rewriter_test.rb | 28 | ||||
-rw-r--r-- | actionpack/test/controller/webservice_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/test_case_test.rb | 2 |
8 files changed, 119 insertions, 120 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 5b2ff3e871..143491a640 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -95,7 +95,7 @@ module ActiveSupport map.connect ':controller/:action/:id' end - ActionController::IntegrationTest.app.router.draw do |map| + ActionController::IntegrationTest.app.routes.draw do |map| # FIXME: match ':controller(/:action(/:id))' map.connect ':controller/:action/:id' end @@ -104,12 +104,11 @@ module ActiveSupport end class RoutedRackApp - attr_reader :router - alias routes router + attr_reader :routes - def initialize(router, &blk) - @router = router - @stack = ActionDispatch::MiddlewareStack.new(&blk).build(@router) + def initialize(routes, &blk) + @routes = routes + @stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes) end def call(env) @@ -234,7 +233,7 @@ module ActionView # Must repeat the setup because AV::TestCase is a duplication # of AC::TestCase setup do - @router = SharedTestRoutes + @routes = SharedTestRoutes end end end @@ -250,7 +249,7 @@ module ActionController include ActionDispatch::TestProcess setup do - @router = SharedTestRoutes + @routes = SharedTestRoutes end end end diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index 5643ad5ad6..9f5e8ec657 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -40,12 +40,12 @@ class PolymorphicRoutesTest < ActionController::TestCase end def test_with_record - with_test_routes do + with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url(@project) end end - + def test_with_class with_test_routes do assert_equal "http://example.com/projects", polymorphic_url(@project.class) @@ -53,67 +53,67 @@ class PolymorphicRoutesTest < ActionController::TestCase end def test_with_new_record - with_test_routes do + with_test_routes do assert_equal "http://example.com/projects", polymorphic_url(@project) end end def test_with_destroyed_record - with_test_routes do + with_test_routes do @project.destroy assert_equal "http://example.com/projects", polymorphic_url(@project) end end def test_with_record_and_action - with_test_routes do + with_test_routes do assert_equal "http://example.com/projects/new", polymorphic_url(@project, :action => 'new') end end def test_url_helper_prefixed_with_new - with_test_routes do + with_test_routes do assert_equal "http://example.com/projects/new", new_polymorphic_url(@project) end end def test_url_helper_prefixed_with_edit - with_test_routes do + with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}/edit", edit_polymorphic_url(@project) end end - + def test_url_helper_prefixed_with_edit_with_url_options - with_test_routes do + with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}/edit?param1=10", edit_polymorphic_url(@project, :param1 => '10') end end - + def test_url_helper_with_url_options - with_test_routes do + with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}?param1=10", polymorphic_url(@project, :param1 => '10') end end def test_format_option - with_test_routes do + with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}.pdf", polymorphic_url(@project, :format => :pdf) end end - + def test_format_option_with_url_options - with_test_routes do + with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}.pdf?param1=10", polymorphic_url(@project, :format => :pdf, :param1 => '10') end end - + def test_id_and_format_option - with_test_routes do + with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}.pdf", polymorphic_url(:id => @project, :format => :pdf) end @@ -126,14 +126,14 @@ class PolymorphicRoutesTest < ActionController::TestCase assert_equal "http://example.com/projects/#{@project.id}/tasks/#{@task.id}", polymorphic_url([@project, @task]) end end - + def test_with_nested_unsaved with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}/tasks", polymorphic_url([@project, @task]) end end - + def test_with_nested_destroyed with_test_routes do @project.save @@ -141,63 +141,63 @@ class PolymorphicRoutesTest < ActionController::TestCase assert_equal "http://example.com/projects/#{@project.id}/tasks", polymorphic_url([@project, @task]) end end - + def test_with_nested_class with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}/tasks", polymorphic_url([@project, @task.class]) end end - + def test_class_with_array_and_namespace - with_admin_test_routes do + with_admin_test_routes do assert_equal "http://example.com/admin/projects", polymorphic_url([:admin, @project.class]) end end - + def test_new_with_array_and_namespace - with_admin_test_routes do + with_admin_test_routes do assert_equal "http://example.com/admin/projects/new", polymorphic_url([:admin, @project], :action => 'new') end end - + def test_unsaved_with_array_and_namespace - with_admin_test_routes do + with_admin_test_routes do assert_equal "http://example.com/admin/projects", polymorphic_url([:admin, @project]) end end - + def test_nested_unsaved_with_array_and_namespace - with_admin_test_routes do + with_admin_test_routes do @project.save assert_equal "http://example.com/admin/projects/#{@project.id}/tasks", polymorphic_url([:admin, @project, @task]) end end - + def test_nested_with_array_and_namespace - with_admin_test_routes do + with_admin_test_routes do @project.save @task.save assert_equal "http://example.com/admin/projects/#{@project.id}/tasks/#{@task.id}", polymorphic_url([:admin, @project, @task]) end end - + def test_ordering_of_nesting_and_namespace - with_admin_and_site_test_routes do + with_admin_and_site_test_routes do @project.save @task.save @step.save assert_equal "http://example.com/admin/projects/#{@project.id}/site/tasks/#{@task.id}/steps/#{@step.id}", polymorphic_url([:admin, @project, :site, @task, @step]) end end - + def test_nesting_with_array_ending_in_singleton_resource with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}/bid", polymorphic_url([@project, :bid]) end end - + def test_nesting_with_array_containing_singleton_resource with_test_routes do @project.save @@ -205,7 +205,7 @@ class PolymorphicRoutesTest < ActionController::TestCase assert_equal "http://example.com/projects/#{@project.id}/bid/tasks/#{@task.id}", polymorphic_url([@project, :bid, @task]) end end - + def test_nesting_with_array_containing_singleton_resource_and_format with_test_routes do @project.save @@ -213,7 +213,7 @@ class PolymorphicRoutesTest < ActionController::TestCase assert_equal "http://example.com/projects/#{@project.id}/bid/tasks/#{@task.id}.pdf", polymorphic_url([@project, :bid, @task], :format => :pdf) end end - + def test_nesting_with_array_containing_namespace_and_singleton_resource with_admin_test_routes do @project.save @@ -221,47 +221,47 @@ class PolymorphicRoutesTest < ActionController::TestCase assert_equal "http://example.com/admin/projects/#{@project.id}/bid/tasks/#{@task.id}", polymorphic_url([:admin, @project, :bid, @task]) end end - + def test_nesting_with_array_containing_nil with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}/bid", polymorphic_url([@project, nil, :bid]) end end - + def test_with_array_containing_single_object - with_test_routes do + with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url([nil, @project]) end end - + def test_with_array_containing_single_name - with_test_routes do + with_test_routes do @project.save assert_equal "http://example.com/projects", polymorphic_url([:projects]) end end - + def test_with_array_containing_symbols with_test_routes do assert_equal "http://example.com/series/new", polymorphic_url([:new, :series]) end end - + def test_with_hash - with_test_routes do + with_test_routes do @project.save assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url(:id => @project) end end - + def test_polymorphic_path_accepts_options - with_test_routes do + with_test_routes do assert_equal "/projects/new", polymorphic_path(@project, :action => 'new') end end - + def test_polymorphic_path_does_not_modify_arguments with_admin_test_routes do @project.save @@ -275,108 +275,108 @@ class PolymorphicRoutesTest < ActionController::TestCase assert_equal original_args, [object_array, options] end end - + # Tests for names where .plural.singular doesn't round-trip def test_with_irregular_plural_record - with_test_routes do + with_test_routes do @tax.save assert_equal "http://example.com/taxes/#{@tax.id}", polymorphic_url(@tax) end end - + def test_with_irregular_plural_class - with_test_routes do + with_test_routes do assert_equal "http://example.com/taxes", polymorphic_url(@tax.class) end end - + def test_with_irregular_plural_new_record - with_test_routes do + with_test_routes do assert_equal "http://example.com/taxes", polymorphic_url(@tax) end end def test_with_irregular_plural_destroyed_record with_test_routes do - @tax.destroy + @tax.destroy assert_equal "http://example.com/taxes", polymorphic_url(@tax) end end - + def test_with_irregular_plural_record_and_action - with_test_routes do + with_test_routes do assert_equal "http://example.com/taxes/new", polymorphic_url(@tax, :action => 'new') end end - + def test_irregular_plural_url_helper_prefixed_with_new - with_test_routes do + with_test_routes do assert_equal "http://example.com/taxes/new", new_polymorphic_url(@tax) end end - + def test_irregular_plural_url_helper_prefixed_with_edit - with_test_routes do + with_test_routes do @tax.save assert_equal "http://example.com/taxes/#{@tax.id}/edit", edit_polymorphic_url(@tax) end end - + def test_with_nested_irregular_plurals - with_test_routes do + with_test_routes do @tax.save @fax.save assert_equal "http://example.com/taxes/#{@tax.id}/faxes/#{@fax.id}", polymorphic_url([@tax, @fax]) end end - + def test_with_nested_unsaved_irregular_plurals - with_test_routes do + with_test_routes do @tax.save assert_equal "http://example.com/taxes/#{@tax.id}/faxes", polymorphic_url([@tax, @fax]) end end - + def test_new_with_irregular_plural_array_and_namespace - with_admin_test_routes do + with_admin_test_routes do assert_equal "http://example.com/admin/taxes/new", polymorphic_url([:admin, @tax], :action => 'new') end end - + def test_class_with_irregular_plural_array_and_namespace - with_admin_test_routes do + with_admin_test_routes do assert_equal "http://example.com/admin/taxes", polymorphic_url([:admin, @tax.class]) end end - + def test_unsaved_with_irregular_plural_array_and_namespace - with_admin_test_routes do + with_admin_test_routes do assert_equal "http://example.com/admin/taxes", polymorphic_url([:admin, @tax]) end end - + def test_nesting_with_irregular_plurals_and_array_ending_in_singleton_resource - with_test_routes do + with_test_routes do @tax.save assert_equal "http://example.com/taxes/#{@tax.id}/bid", polymorphic_url([@tax, :bid]) end end - + def test_with_array_containing_single_irregular_plural_object - with_test_routes do + with_test_routes do @tax.save assert_equal "http://example.com/taxes/#{@tax.id}", polymorphic_url([nil, @tax]) end end - + def test_with_array_containing_single_name_irregular_plural - with_test_routes do + with_test_routes do @tax.save assert_equal "http://example.com/taxes", polymorphic_url([:taxes]) end end - - # Tests for uncountable names + + # Tests for uncountable names def test_uncountable_resource with_test_routes do @series.save @@ -400,11 +400,11 @@ class PolymorphicRoutesTest < ActionController::TestCase map.resources :series end - self.class.send(:include, @router.url_helpers) + self.class.send(:include, @routes.url_helpers) yield end end - + def with_admin_test_routes(options = {}) with_routing do |set| set.draw do |map| @@ -422,11 +422,11 @@ class PolymorphicRoutesTest < ActionController::TestCase end end - self.class.send(:include, @router.url_helpers) + self.class.send(:include, @routes.url_helpers) yield end end - + def with_admin_and_site_test_routes(options = {}) with_routing do |set| set.draw do |map| @@ -441,7 +441,7 @@ class PolymorphicRoutesTest < ActionController::TestCase end end - self.class.send(:include, @router.url_helpers) + self.class.send(:include, @routes.url_helpers) yield end end diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index f0ad652d50..217260fdcd 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -81,9 +81,9 @@ class PageCachingTest < ActionController::TestCase match '/', :to => 'posts#index', :as => :main end @params[:format] = 'rss' - assert_equal '/posts.rss', @router.url_for(@params) + assert_equal '/posts.rss', @routes.url_for(@params) @params[:format] = nil - assert_equal '/', @router.url_for(@params) + assert_equal '/', @routes.url_for(@params) end end @@ -518,7 +518,7 @@ class ActionCacheTest < ActionController::TestCase @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @controller = ActionCachingTestController.new - @controller.singleton_class.send(:include, @router.url_helpers) + @controller.singleton_class.send(:include, @routes.url_helpers) @request.host = 'hostname.com' end diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 17c645c04c..a9d1c55c05 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -126,7 +126,7 @@ class ResourcesTest < ActionController::TestCase def test_with_custom_conditions with_restful_routing :messages, :conditions => { :subdomain => 'app' } do - assert @router.recognize_path("/messages", :method => :get, :subdomain => 'app') + assert @routes.recognize_path("/messages", :method => :get, :subdomain => 'app') end end @@ -395,7 +395,7 @@ class ResourcesTest < ActionController::TestCase assert_restful_routes_for :messages do |options| assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get) assert_raise(ActionController::RoutingError) do - @router.recognize_path("/messages/new", :method => :post) + @routes.recognize_path("/messages/new", :method => :post) end end end @@ -505,7 +505,7 @@ class ResourcesTest < ActionController::TestCase def test_restful_routes_dont_generate_duplicates with_restful_routing :messages do - routes = @router.routes + routes = @routes.routes routes.each do |route| routes.each do |r| next if route === r # skip the comparison instance @@ -1169,8 +1169,8 @@ class ResourcesTest < ActionController::TestCase options[:shallow_options] = options[:options] end - new_action = @router.resources_path_names[:new] || "new" - edit_action = @router.resources_path_names[:edit] || "edit" + new_action = @routes.resources_path_names[:new] || "new" + edit_action = @routes.resources_path_names[:edit] || "edit" if options[:path_names] new_action = options[:path_names][:new] if options[:path_names][:new] @@ -1237,7 +1237,7 @@ class ResourcesTest < ActionController::TestCase end @controller = "#{options[:options][:controller].camelize}Controller".constantize.new - @controller.singleton_class.send(:include, @router.url_helpers) + @controller.singleton_class.send(:include, @routes.url_helpers) @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new get :index, options[:options] @@ -1307,7 +1307,7 @@ class ResourcesTest < ActionController::TestCase def assert_singleton_named_routes_for(singleton_name, options = {}) (options[:options] ||= {})[:controller] ||= singleton_name.to_s.pluralize @controller = "#{options[:options][:controller].camelize}Controller".constantize.new - @controller.singleton_class.send(:include, @router.url_helpers) + @controller.singleton_class.send(:include, @routes.url_helpers) @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new get :show, options[:options] diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index f6ba275849..8910454b8b 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -478,8 +478,8 @@ XML end def test_with_routing_places_routes_back - assert @router - routes_id = @router.object_id + assert @routes + routes_id = @routes.object_id begin with_routing { raise 'fail' } @@ -487,8 +487,8 @@ XML rescue RuntimeError end - assert @router - assert_equal routes_id, @router.object_id + assert @routes + assert_equal routes_id, @routes.object_id end def test_remote_addr diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index 7b46a48a1d..a8d7b75372 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -10,8 +10,8 @@ class UrlRewriterTests < ActionController::TestCase } end - def rewrite(router, options) - router.url_for(@options.merge(options)) + def rewrite(routes, options) + routes.url_for(@options.merge(options)) end end @@ -23,63 +23,63 @@ class UrlRewriterTests < ActionController::TestCase def test_port assert_equal('http://test.host:1271/c/a/i', - @rewriter.rewrite(@router, :controller => 'c', :action => 'a', :id => 'i', :port => 1271) + @rewriter.rewrite(@routes, :controller => 'c', :action => 'a', :id => 'i', :port => 1271) ) end def test_protocol_with_and_without_separator assert_equal('https://test.host/c/a/i', - @rewriter.rewrite(@router, :protocol => 'https', :controller => 'c', :action => 'a', :id => 'i') + @rewriter.rewrite(@routes, :protocol => 'https', :controller => 'c', :action => 'a', :id => 'i') ) assert_equal('https://test.host/c/a/i', - @rewriter.rewrite(@router, :protocol => 'https://', :controller => 'c', :action => 'a', :id => 'i') + @rewriter.rewrite(@routes, :protocol => 'https://', :controller => 'c', :action => 'a', :id => 'i') ) end def test_user_name_and_password assert_equal( 'http://david:secret@test.host/c/a/i', - @rewriter.rewrite(@router, :user => "david", :password => "secret", :controller => 'c', :action => 'a', :id => 'i') + @rewriter.rewrite(@routes, :user => "david", :password => "secret", :controller => 'c', :action => 'a', :id => 'i') ) end def test_user_name_and_password_with_escape_codes assert_equal( 'http://openid.aol.com%2Fnextangler:one+two%3F@test.host/c/a/i', - @rewriter.rewrite(@router, :user => "openid.aol.com/nextangler", :password => "one two?", :controller => 'c', :action => 'a', :id => 'i') + @rewriter.rewrite(@routes, :user => "openid.aol.com/nextangler", :password => "one two?", :controller => 'c', :action => 'a', :id => 'i') ) end def test_anchor assert_equal( 'http://test.host/c/a/i#anchor', - @rewriter.rewrite(@router, :controller => 'c', :action => 'a', :id => 'i', :anchor => 'anchor') + @rewriter.rewrite(@routes, :controller => 'c', :action => 'a', :id => 'i', :anchor => 'anchor') ) end def test_anchor_should_call_to_param assert_equal( 'http://test.host/c/a/i#anchor', - @rewriter.rewrite(@router, :controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anchor')) + @rewriter.rewrite(@routes, :controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anchor')) ) end def test_anchor_should_be_cgi_escaped assert_equal( 'http://test.host/c/a/i#anc%2Fhor', - @rewriter.rewrite(@router, :controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anc/hor')) + @rewriter.rewrite(@routes, :controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anc/hor')) ) end def test_trailing_slash options = {:controller => 'foo', :action => 'bar', :id => '3', :only_path => true} - assert_equal '/foo/bar/3', @rewriter.rewrite(@router, options) - assert_equal '/foo/bar/3?query=string', @rewriter.rewrite(@router, options.merge({:query => 'string'})) + assert_equal '/foo/bar/3', @rewriter.rewrite(@routes, options) + assert_equal '/foo/bar/3?query=string', @rewriter.rewrite(@routes, options.merge({:query => 'string'})) options.update({:trailing_slash => true}) - assert_equal '/foo/bar/3/', @rewriter.rewrite(@router, options) + assert_equal '/foo/bar/3/', @rewriter.rewrite(@routes, options) options.update({:query => 'string'}) - assert_equal '/foo/bar/3/?query=string', @rewriter.rewrite(@router, options) + assert_equal '/foo/bar/3/?query=string', @rewriter.rewrite(@routes, options) end end diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index 05545395fb..5942950b15 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -245,7 +245,7 @@ class WebServiceTest < ActionController::IntegrationTest private def with_params_parsers(parsers = {}) old_session = @integration_session - @app = ActionDispatch::ParamsParser.new(app.router, parsers) + @app = ActionDispatch::ParamsParser.new(app.routes, parsers) reset! yield ensure diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index 195a6ea3ae..c1a38a25de 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -114,7 +114,7 @@ module ActionView end test "is able to use routes" do - controller.request.assign_parameters(@router, 'foo', 'index') + controller.request.assign_parameters(@routes, 'foo', 'index') assert_equal '/foo', url_for assert_equal '/bar', url_for(:controller => 'bar') end |