aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb9
-rw-r--r--actionpack/test/controller/base_test.rb4
-rw-r--r--actionpack/test/controller/integration_test.rb11
-rw-r--r--actionpack/test/controller/rescue_test.rb4
-rw-r--r--actionpack/test/controller/resources_test.rb13
-rw-r--r--actionpack/test/controller/test_test.rb8
-rw-r--r--actionpack/test/controller/url_for_test.rb2
-rw-r--r--actionpack/test/controller/url_rewriter_test.rb32
8 files changed, 48 insertions, 35 deletions
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index d54be9bdc0..7c83a91f4d 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -253,12 +253,13 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
end
def test_assert_redirect_to_nested_named_route
+ @controller = Admin::InnerModuleController.new
+
with_routing do |set|
set.draw do |map|
match 'admin/inner_module', :to => 'admin/inner_module#index', :as => :admin_inner_module
match ':controller/:action'
end
- @controller = Admin::InnerModuleController.new
process :redirect_to_index
# redirection is <{"action"=>"index", "controller"=>"admin/admin/inner_module"}>
assert_redirected_to admin_inner_module_path
@@ -266,12 +267,13 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
end
def test_assert_redirected_to_top_level_named_route_from_nested_controller
+ @controller = Admin::InnerModuleController.new
+
with_routing do |set|
set.draw do |map|
match '/action_pack_assertions/:id', :to => 'action_pack_assertions#index', :as => :top_level
match ':controller/:action'
end
- @controller = Admin::InnerModuleController.new
process :redirect_to_top_level_named_route
# assert_redirected_to "http://test.host/action_pack_assertions/foo" would pass because of exact match early return
assert_redirected_to "/action_pack_assertions/foo"
@@ -279,13 +281,14 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
end
def test_assert_redirected_to_top_level_named_route_with_same_controller_name_in_both_namespaces
+ @controller = Admin::InnerModuleController.new
+
with_routing do |set|
set.draw do |map|
# this controller exists in the admin namespace as well which is the only difference from previous test
match '/user/:id', :to => 'user#index', :as => :top_level
match ':controller/:action'
end
- @controller = Admin::InnerModuleController.new
process :redirect_to_top_level_named_route
# assert_redirected_to top_level_url('foo') would pass because of exact match early return
assert_redirected_to top_level_path('foo')
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index 4fcfbacf4e..25006dda76 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -219,12 +219,14 @@ class EmptyUrlOptionsTest < ActionController::TestCase
end
def test_named_routes_with_path_without_doing_a_request_first
+ @controller = EmptyController.new
+
with_routing do |set|
set.draw do |map|
resources :things
end
- assert_equal '/things', EmptyController.new.send(:things_path)
+ assert_equal '/things', @controller.send(:things_path)
end
end
end
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 683ab5236c..29531d237a 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -86,7 +86,7 @@ class SessionTest < Test::Unit::TestCase
def test_url_for_without_controller
options = {:action => 'show'}
mock_rewriter = mock()
- mock_rewriter.expects(:rewrite).with(options).returns('/show')
+ mock_rewriter.expects(:rewrite).with(SharedTestRoutes, options).returns('/show')
@session.stubs(:generic_url_rewriter).returns(mock_rewriter)
@session.stubs(:controller).returns(nil)
assert_equal '/show', @session.url_for(options)
@@ -401,9 +401,14 @@ class IntegrationProcessTest < ActionController::IntegrationTest
private
def with_test_route_set
with_routing do |set|
+ controller = ::IntegrationProcessTest::IntegrationController.clone
+ controller.class_eval do
+ include set.named_url_helpers
+ end
+
set.draw do |map|
- match ':action', :to => ::IntegrationProcessTest::IntegrationController
- get 'get/:action', :to => ::IntegrationProcessTest::IntegrationController
+ match ':action', :to => controller
+ get 'get/:action', :to => controller
end
yield
end
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index 118b563a72..dd991898a8 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -326,7 +326,7 @@ class RescueTest < ActionController::IntegrationTest
end
test 'rescue routing exceptions' do
- @app = ActionDispatch::Rescue.new(ActionDispatch::Routing::Routes) do
+ @app = ActionDispatch::Rescue.new(SharedTestRoutes) do
rescue_from ActionController::RoutingError, lambda { |env| [200, {"Content-Type" => "text/html"}, ["Gotcha!"]] }
end
@@ -335,7 +335,7 @@ class RescueTest < ActionController::IntegrationTest
end
test 'unrescued exception' do
- @app = ActionDispatch::Rescue.new(ActionDispatch::Routing::Routes)
+ @app = ActionDispatch::Rescue.new(SharedTestRoutes)
assert_raise(ActionController::RoutingError) { get '/b00m' }
end
diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb
index cce98ac482..6f3c16f588 100644
--- a/actionpack/test/controller/resources_test.rb
+++ b/actionpack/test/controller/resources_test.rb
@@ -125,7 +125,7 @@ class ResourcesTest < ActionController::TestCase
def test_with_custom_conditions
with_restful_routing :messages, :conditions => { :subdomain => 'app' } do
- assert ActionDispatch::Routing::Routes.recognize_path("/messages", :method => :get, :subdomain => 'app')
+ assert @router.recognize_path("/messages", :method => :get, :subdomain => 'app')
end
end
@@ -394,7 +394,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
- ActionDispatch::Routing::Routes.recognize_path("/messages/new", :method => :post)
+ @router.recognize_path("/messages/new", :method => :post)
end
end
end
@@ -504,7 +504,7 @@ class ResourcesTest < ActionController::TestCase
def test_restful_routes_dont_generate_duplicates
with_restful_routing :messages do
- routes = ActionDispatch::Routing::Routes.routes
+ routes = @router.routes
routes.each do |route|
routes.each do |r|
next if route === r # skip the comparison instance
@@ -1162,8 +1162,8 @@ class ResourcesTest < ActionController::TestCase
options[:shallow_options] = options[:options]
end
- new_action = ActionDispatch::Routing::Routes.resources_path_names[:new] || "new"
- edit_action = ActionDispatch::Routing::Routes.resources_path_names[:edit] || "edit"
+ new_action = @router.resources_path_names[:new] || "new"
+ edit_action = @router.resources_path_names[:edit] || "edit"
if options[:path_names]
new_action = options[:path_names][:new] if options[:path_names][:new]
@@ -1230,6 +1230,8 @@ class ResourcesTest < ActionController::TestCase
end
@controller = "#{options[:options][:controller].camelize}Controller".constantize.new
+ # ROUTES TODO: Figure out a way to not extend the routing helpers here
+ @controller.metaclass.send(:include, @router.named_url_helpers)
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
get :index, options[:options]
@@ -1299,6 +1301,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.metaclass.send(:include, @router.named_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 3f5d60540f..d716dc2661 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -476,8 +476,8 @@ XML
end
def test_with_routing_places_routes_back
- assert ActionDispatch::Routing::Routes
- routes_id = ActionDispatch::Routing::Routes.object_id
+ assert @router
+ routes_id = @router.object_id
begin
with_routing { raise 'fail' }
@@ -485,8 +485,8 @@ XML
rescue RuntimeError
end
- assert ActionDispatch::Routing::Routes
- assert_equal routes_id, ActionDispatch::Routing::Routes.object_id
+ assert @router
+ assert_equal routes_id, @router.object_id
end
def test_remote_addr
diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb
index 749fa5861f..43e2f91693 100644
--- a/actionpack/test/controller/url_for_test.rb
+++ b/actionpack/test/controller/url_for_test.rb
@@ -5,7 +5,7 @@ module AbstractController
class UrlForTests < ActionController::TestCase
class W
- include ActionController::UrlFor
+ include SharedTestRoutes.url_helpers
end
def teardown
diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb
index c2b8cd85d8..199b824a7a 100644
--- a/actionpack/test/controller/url_rewriter_test.rb
+++ b/actionpack/test/controller/url_rewriter_test.rb
@@ -12,52 +12,52 @@ class UrlRewriterTests < ActionController::TestCase
def test_port
assert_equal('http://test.host:1271/c/a/i',
- @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :port => 1271)
+ @rewriter.rewrite(@router, :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(:protocol => 'https', :controller => 'c', :action => 'a', :id => 'i')
+ @rewriter.rewrite(@router, :protocol => 'https', :controller => 'c', :action => 'a', :id => 'i')
)
assert_equal('https://test.host/c/a/i',
- @rewriter.rewrite(:protocol => 'https://', :controller => 'c', :action => 'a', :id => 'i')
+ @rewriter.rewrite(@router, :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(:user => "david", :password => "secret", :controller => 'c', :action => 'a', :id => 'i')
+ @rewriter.rewrite(@router, :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(:user => "openid.aol.com/nextangler", :password => "one two?", :controller => 'c', :action => 'a', :id => 'i')
+ @rewriter.rewrite(@router, :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(:controller => 'c', :action => 'a', :id => 'i', :anchor => 'anchor')
+ @rewriter.rewrite(@router, :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(:controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anchor'))
+ @rewriter.rewrite(@router, :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(:controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anc/hor'))
+ @rewriter.rewrite(@router, :controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anc/hor'))
)
end
@@ -66,8 +66,8 @@ class UrlRewriterTests < ActionController::TestCase
@params[:action] = 'bye'
@params[:id] = '2'
- assert_equal '/hi/hi/2', @rewriter.rewrite(:only_path => true, :overwrite_params => {:action => 'hi'})
- u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:action => 'hi'})
+ assert_equal '/hi/hi/2', @rewriter.rewrite(@router, :only_path => true, :overwrite_params => {:action => 'hi'})
+ u = @rewriter.rewrite(@router, :only_path => false, :overwrite_params => {:action => 'hi'})
assert_match %r(/hi/hi/2$), u
end
@@ -76,8 +76,8 @@ class UrlRewriterTests < ActionController::TestCase
@params[:action] = 'list'
@params[:list_page] = 1
- assert_equal '/search/list?list_page=2', @rewriter.rewrite(:only_path => true, :overwrite_params => {"list_page" => 2})
- u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:list_page => 2})
+ assert_equal '/search/list?list_page=2', @rewriter.rewrite(@router, :only_path => true, :overwrite_params => {"list_page" => 2})
+ u = @rewriter.rewrite(@router, :only_path => false, :overwrite_params => {:list_page => 2})
assert_equal 'http://test.host/search/list?list_page=2', u
end
@@ -91,12 +91,12 @@ class UrlRewriterTests < ActionController::TestCase
def test_trailing_slash
options = {:controller => 'foo', :action => 'bar', :id => '3', :only_path => true}
- assert_equal '/foo/bar/3', @rewriter.rewrite(options)
- assert_equal '/foo/bar/3?query=string', @rewriter.rewrite(options.merge({:query => 'string'}))
+ assert_equal '/foo/bar/3', @rewriter.rewrite(@router, options)
+ assert_equal '/foo/bar/3?query=string', @rewriter.rewrite(@router, options.merge({:query => 'string'}))
options.update({:trailing_slash => true})
- assert_equal '/foo/bar/3/', @rewriter.rewrite(options)
+ assert_equal '/foo/bar/3/', @rewriter.rewrite(@router, options)
options.update({:query => 'string'})
- assert_equal '/foo/bar/3/?query=string', @rewriter.rewrite(options)
+ assert_equal '/foo/bar/3/?query=string', @rewriter.rewrite(@router, options)
end
end