diff options
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/cookie_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 47 | ||||
-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/dispatch/rack_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 45 | ||||
-rw-r--r-- | actionpack/test/template/active_model_helper_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/template/asset_tag_helper_test.rb | 16 | ||||
-rw-r--r-- | actionpack/test/template/test_case_test.rb | 2 |
15 files changed, 239 insertions, 128 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/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index 36498d13a9..278cae1415 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' -ActionController::Base.cookie_verifier_secret = "thisISverySECRET123" +ActionController::Base.config.secret = "thisISverySECRET123" class CookieTest < ActionController::TestCase class TestController < ActionController::Base diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index c9782856bd..1e2ee06adc 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -430,3 +430,50 @@ class MetalIntegrationTest < ActionController::IntegrationTest assert_equal 'http://www.example.com/foo', url_for(:controller => "foo") end end + +class ApplicationIntegrationTest < ActionController::IntegrationTest + class TestController < ActionController::Base + def index + render :text => "index" + end + end + + def self.call(env) + routes.call(env) + end + + def self.routes + @routes ||= ActionDispatch::Routing::RouteSet.new + end + + routes.draw do + match 'foo', :to => 'application_integration_test/test#index', :as => :foo + match 'bar', :to => 'application_integration_test/test#index', :as => :bar + end + + def app + self.class + end + + test "includes route helpers" do + assert_equal '/foo', foo_path + assert_equal '/bar', bar_path + end + + test "route helpers after controller access" do + get '/foo' + assert_equal '/foo', foo_path + + get '/bar' + assert_equal '/bar', bar_path + end + + test "missing route helper before controller access" do + assert_raise(NameError) { missing_path } + end + + test "missing route helper after controller access" do + get '/foo' + assert_raise(NameError) { missing_path } + end +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/dispatch/rack_test.rb b/actionpack/test/dispatch/rack_test.rb index 94eba2a24f..504bebbb86 100644 --- a/actionpack/test/dispatch/rack_test.rb +++ b/actionpack/test/dispatch/rack_test.rb @@ -122,7 +122,7 @@ class RackRequestTest < BaseRackTest test "cgi environment variables" do assert_equal "Basic", @request.auth_type assert_equal 0, @request.content_length - assert_equal nil, @request.content_type + assert_equal nil, @request.content_mime_type assert_equal "CGI/1.1", @request.gateway_interface assert_equal "*/*", @request.accept assert_equal "UTF-8", @request.accept_charset @@ -177,12 +177,12 @@ end class RackRequestContentTypeTest < BaseRackTest test "html content type verification" do @request.env['CONTENT_TYPE'] = Mime::HTML.to_s - assert @request.content_type.verify_request? + assert @request.content_mime_type.verify_request? end test "xml content type verification" do @request.env['CONTENT_TYPE'] = Mime::XML.to_s - assert !@request.content_type.verify_request? + assert !@request.content_mime_type.verify_request? end end diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index badef4e92e..9093e1ed65 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -295,7 +295,7 @@ class RequestTest < ActiveSupport::TestCase test "content type" do request = stub_request 'CONTENT_TYPE' => 'text/html' - assert_equal Mime::HTML, request.content_type + assert_equal Mime::HTML, request.content_mime_type end test "can override format with parameter" do @@ -310,17 +310,17 @@ class RequestTest < ActiveSupport::TestCase test "no content type" do request = stub_request - assert_equal nil, request.content_type + assert_equal nil, request.content_mime_type end test "content type is XML" do request = stub_request 'CONTENT_TYPE' => 'application/xml' - assert_equal Mime::XML, request.content_type + assert_equal Mime::XML, request.content_mime_type end test "content type with charset" do request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8' - assert_equal Mime::XML, request.content_type + assert_equal Mime::XML, request.content_mime_type end test "user agent" do diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index c4e71a8689..e58653cb8c 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -114,6 +114,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :comments, :except => :destroy end + resources :sheep + match 'sprockets.js' => ::TestRoutingMapper::SprocketsApp match 'people/:id/update', :to => 'people#update', :as => :update_person @@ -171,6 +173,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :descriptions root :to => 'projects#index' end + + resources :products, :constraints => { :id => /\d{4}/ } do + resources :images + end + + resource :dashboard, :constraints => { :ip => /192\.168\.1\.\d{1,3}/ } end end @@ -525,6 +533,23 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_resource_with_slugs_in_ids + with_test_routes do + get '/posts/rails-rocks' + assert_equal 'posts#show', @response.body + assert_equal '/posts/rails-rocks', post_path(:id => 'rails-rocks') + end + end + + def test_resources_for_uncountable_names + with_test_routes do + assert_equal '/sheep', sheep_index_path + assert_equal '/sheep/1', sheep_path(1) + assert_equal '/sheep/new', new_sheep_path + assert_equal '/sheep/1/edit', edit_sheep_path(1) + end + end + def test_path_names with_test_routes do get '/es/projeto' @@ -794,6 +819,26 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_resource_constraints + with_test_routes do + assert_raise(ActionController::RoutingError) { get '/products/1' } + get '/products' + assert_equal 'products#index', @response.body + get '/products/0001' + assert_equal 'products#show', @response.body + + assert_raise(ActionController::RoutingError) { get '/products/1/images' } + get '/products/0001/images' + assert_equal 'images#index', @response.body + get '/products/0001/images/1' + assert_equal 'images#show', @response.body + + assert_raise(ActionController::RoutingError) { get '/dashboard', {}, {'REMOTE_ADDR' => '10.0.0.100'} } + get '/dashboard', {}, {'REMOTE_ADDR' => '192.168.1.100'} + assert_equal 'dashboards#show', @response.body + end + end + private def with_test_routes yield diff --git a/actionpack/test/template/active_model_helper_test.rb b/actionpack/test/template/active_model_helper_test.rb index 7a665b00bc..1a5316a689 100644 --- a/actionpack/test/template/active_model_helper_test.rb +++ b/actionpack/test/template/active_model_helper_test.rb @@ -266,6 +266,10 @@ class ActiveModelHelperTest < ActionView::TestCase assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after') end + def test_error_message_on_with_tag_option_in_options_hash + assert_dom_equal "<span class=\"differentError\">beforecan't be emptyafter</span>", error_message_on(:post, :author_name, :html_tag => "span", :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after') + end + def test_error_message_on_handles_empty_errors assert_equal "", error_message_on(@post, :tag) end diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index c471df861d..fbd504ae7d 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -373,6 +373,22 @@ class AssetTagHelperTest < ActionView::TestCase assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png") end + def test_string_asset_id + @controller.config.asset_path = "/assets.v12345%s" + + expected_path = "/assets.v12345/images/rails.png" + assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png") + end + + def test_proc_asset_id + @controller.config.asset_path = Proc.new do |asset_path| + "/assets.v12345#{asset_path}" + end + + expected_path = "/assets.v12345/images/rails.png" + assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png") + end + def test_timebased_asset_id_with_relative_url_root @controller.config.relative_url_root = "/collaboration/hieraki" expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s 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 |