mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Cleanup route reloading in tests. Prefer with_routing over using ActionController::Routing::Routes directly
This commit is contained in:
parent
ccf28d2499
commit
24ad9ae3d2
14 changed files with 149 additions and 141 deletions
|
@ -213,7 +213,7 @@ module ActionController
|
||||||
self.routes = []
|
self.routes = []
|
||||||
self.named_routes = NamedRouteCollection.new
|
self.named_routes = NamedRouteCollection.new
|
||||||
|
|
||||||
clear_recognize_optimized!
|
clear!
|
||||||
end
|
end
|
||||||
|
|
||||||
# Subclasses and plugins may override this method to specify a different
|
# Subclasses and plugins may override this method to specify a different
|
||||||
|
@ -223,6 +223,7 @@ module ActionController
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
|
clear!
|
||||||
yield Mapper.new(self)
|
yield Mapper.new(self)
|
||||||
install_helpers
|
install_helpers
|
||||||
end
|
end
|
||||||
|
@ -230,8 +231,10 @@ module ActionController
|
||||||
def clear!
|
def clear!
|
||||||
routes.clear
|
routes.clear
|
||||||
named_routes.clear
|
named_routes.clear
|
||||||
|
|
||||||
@combined_regexp = nil
|
@combined_regexp = nil
|
||||||
@routes_by_controller = nil
|
@routes_by_controller = nil
|
||||||
|
|
||||||
# This will force routing/recognition_optimization.rb
|
# This will force routing/recognition_optimization.rb
|
||||||
# to refresh optimisations.
|
# to refresh optimisations.
|
||||||
clear_recognize_optimized!
|
clear_recognize_optimized!
|
||||||
|
@ -262,7 +265,6 @@ module ActionController
|
||||||
|
|
||||||
def load!
|
def load!
|
||||||
Routing.use_controllers!(nil) # Clear the controller cache so we may discover new ones
|
Routing.use_controllers!(nil) # Clear the controller cache so we may discover new ones
|
||||||
clear!
|
|
||||||
load_routes!
|
load_routes!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -286,7 +288,9 @@ module ActionController
|
||||||
configuration_files.each { |config| load(config) }
|
configuration_files.each { |config| load(config) }
|
||||||
@routes_last_modified = routes_changed_at
|
@routes_last_modified = routes_changed_at
|
||||||
else
|
else
|
||||||
add_route ":controller/:action/:id"
|
draw do |map|
|
||||||
|
map.connect ":controller/:action/:id"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@ module ActionView
|
||||||
ActionController::Routing::Routes.draw do |map|
|
ActionController::Routing::Routes.draw do |map|
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
ActionController::Routing::Routes.reload!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -70,12 +74,17 @@ module ActionController
|
||||||
|
|
||||||
class TestCase
|
class TestCase
|
||||||
include TestProcess
|
include TestProcess
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
ActionController::Routing::Routes.draw do |map|
|
ActionController::Routing::Routes.draw do |map|
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
ActionController::Routing::Routes.reload!
|
||||||
|
end
|
||||||
|
|
||||||
def assert_template(options = {}, message = nil)
|
def assert_template(options = {}, message = nil)
|
||||||
validate_request!
|
validate_request!
|
||||||
|
|
||||||
|
|
|
@ -185,13 +185,9 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
|
||||||
# let's get this party started
|
# let's get this party started
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
ActionController::Routing::Routes.reload
|
|
||||||
ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
|
|
||||||
end
|
|
||||||
|
|
||||||
def teardown
|
ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
|
||||||
super
|
ActionController::Routing::Routes.load_routes!
|
||||||
ActionController::Routing::Routes.reload
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# -- assertion-based testing ------------------------------------------------
|
# -- assertion-based testing ------------------------------------------------
|
||||||
|
|
|
@ -177,7 +177,8 @@ class DefaultUrlOptionsTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_default_url_options_are_used_if_set
|
def test_default_url_options_are_used_if_set
|
||||||
ActionController::Routing::Routes.draw do |map|
|
with_routing do |set|
|
||||||
|
set.draw do |map|
|
||||||
map.default_url_options 'default_url_options', :controller => 'default_url_options'
|
map.default_url_options 'default_url_options', :controller => 'default_url_options'
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
end
|
end
|
||||||
|
@ -186,8 +187,7 @@ class DefaultUrlOptionsTest < ActionController::TestCase
|
||||||
|
|
||||||
assert_equal 'http://www.override.com/default_url_options/new?bacon=chunky', @controller.url_for(:controller => 'default_url_options')
|
assert_equal 'http://www.override.com/default_url_options/new?bacon=chunky', @controller.url_for(:controller => 'default_url_options')
|
||||||
assert_equal 'http://www.override.com/default_url_options?bacon=chunky', @controller.send(:default_url_options_url)
|
assert_equal 'http://www.override.com/default_url_options?bacon=chunky', @controller.send(:default_url_options_url)
|
||||||
ensure
|
end
|
||||||
ActionController::Routing::Routes.load!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -206,15 +206,15 @@ class EmptyUrlOptionsTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class EnsureNamedRoutesWorksTicket22BugTest < Test::Unit::TestCase
|
class EnsureNamedRoutesWorksTicket22BugTest < ActionController::TestCase
|
||||||
def test_named_routes_still_work
|
def test_named_routes_still_work
|
||||||
ActionController::Routing::Routes.draw do |map|
|
with_routing do |set|
|
||||||
|
set.draw do |map|
|
||||||
map.resources :things
|
map.resources :things
|
||||||
end
|
end
|
||||||
EmptyController.send :include, ActionController::UrlWriter
|
EmptyController.send :include, ActionController::UrlWriter
|
||||||
|
|
||||||
assert_equal '/things', EmptyController.new.send(:things_path)
|
assert_equal '/things', EmptyController.new.send(:things_path)
|
||||||
ensure
|
end
|
||||||
ActionController::Routing::Routes.load!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,8 +48,6 @@ class PageCachingTest < ActionController::TestCase
|
||||||
super
|
super
|
||||||
ActionController::Base.perform_caching = true
|
ActionController::Base.perform_caching = true
|
||||||
|
|
||||||
ActionController::Routing::Routes.clear!
|
|
||||||
|
|
||||||
ActionController::Routing::Routes.draw do |map|
|
ActionController::Routing::Routes.draw do |map|
|
||||||
map.main '', :controller => 'posts', :format => nil
|
map.main '', :controller => 'posts', :format => nil
|
||||||
map.formatted_posts 'posts.:format', :controller => 'posts'
|
map.formatted_posts 'posts.:format', :controller => 'posts'
|
||||||
|
@ -72,7 +70,6 @@ class PageCachingTest < ActionController::TestCase
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
|
FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
|
||||||
ActionController::Routing::Routes.clear!
|
|
||||||
ActionController::Base.perform_caching = false
|
ActionController::Base.perform_caching = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -531,6 +531,7 @@ class RespondWithControllerTest < ActionController::TestCase
|
||||||
ActionController::Routing::Routes.draw do |map|
|
ActionController::Routing::Routes.draw do |map|
|
||||||
map.resources :customers
|
map.resources :customers
|
||||||
map.resources :quiz_stores, :has_many => :customers
|
map.resources :quiz_stores, :has_many => :customers
|
||||||
|
map.connect ":controller/:action/:id"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,8 @@ class RedirectTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_redirect_to_record
|
def test_redirect_to_record
|
||||||
ActionController::Routing::Routes.draw do |map|
|
with_routing do |set|
|
||||||
|
set.draw do |map|
|
||||||
map.resources :workshops
|
map.resources :workshops
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
end
|
end
|
||||||
|
@ -244,6 +245,7 @@ class RedirectTest < ActionController::TestCase
|
||||||
assert_equal "http://test.host/workshops", redirect_to_url
|
assert_equal "http://test.host/workshops", redirect_to_url
|
||||||
assert_redirected_to Workshop.new(5, true)
|
assert_redirected_to Workshop.new(5, true)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_redirect_to_nil
|
def test_redirect_to_nil
|
||||||
assert_raise(ActionController::ActionControllerError) do
|
assert_raise(ActionController::ActionControllerError) do
|
||||||
|
|
|
@ -1086,7 +1086,8 @@ class RenderTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_head_with_location_object
|
def test_head_with_location_object
|
||||||
ActionController::Routing::Routes.draw do |map|
|
with_routing do |set|
|
||||||
|
set.draw do |map|
|
||||||
map.resources :customers
|
map.resources :customers
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
end
|
end
|
||||||
|
@ -1096,6 +1097,7 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
|
assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_head_with_custom_header
|
def test_head_with_custom_header
|
||||||
get :head_with_custom_header
|
get :head_with_custom_header
|
||||||
|
|
|
@ -55,7 +55,8 @@ class RenderTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rendering_with_object_location_should_set_header_with_url_for
|
def test_rendering_with_object_location_should_set_header_with_url_for
|
||||||
ActionController::Routing::Routes.draw do |map|
|
with_routing do |set|
|
||||||
|
set.draw do |map|
|
||||||
map.resources :customers
|
map.resources :customers
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
end
|
end
|
||||||
|
@ -63,6 +64,7 @@ class RenderTest < ActionController::TestCase
|
||||||
get :render_with_object_location
|
get :render_with_object_location
|
||||||
assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
|
assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_should_render_formatted_xml_erb_template
|
def test_should_render_formatted_xml_erb_template
|
||||||
get :formatted_xml_erb, :format => :xml
|
get :formatted_xml_erb, :format => :xml
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
require 'abstract_unit'
|
require 'abstract_unit'
|
||||||
require 'digest/sha1'
|
require 'digest/sha1'
|
||||||
|
|
||||||
ActionController::Routing::Routes.draw do |map|
|
|
||||||
map.connect ':controller/:action/:id'
|
|
||||||
end
|
|
||||||
|
|
||||||
# common controller actions
|
# common controller actions
|
||||||
module RequestForgeryProtectionActions
|
module RequestForgeryProtectionActions
|
||||||
def index
|
def index
|
||||||
|
|
|
@ -102,8 +102,7 @@ class RoutingTest < Test::Unit::TestCase
|
||||||
ActionController::Routing.use_controllers! true_possible_controllers
|
ActionController::Routing.use_controllers! true_possible_controllers
|
||||||
Object.send(:remove_const, :RAILS_ROOT) rescue nil
|
Object.send(:remove_const, :RAILS_ROOT) rescue nil
|
||||||
|
|
||||||
ActionController::Routing::Routes.clear!
|
ActionController::Routing::Routes.reload!
|
||||||
ActionController::Routing::Routes.load_routes!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_with_controllers
|
def test_with_controllers
|
||||||
|
|
|
@ -123,15 +123,11 @@ XML
|
||||||
@controller = TestController.new
|
@controller = TestController.new
|
||||||
@request = ActionController::TestRequest.new
|
@request = ActionController::TestRequest.new
|
||||||
@response = ActionController::TestResponse.new
|
@response = ActionController::TestResponse.new
|
||||||
|
|
||||||
ActionController::Routing.use_controllers! %w(content admin/user test_test/test)
|
ActionController::Routing.use_controllers! %w(content admin/user test_test/test)
|
||||||
ActionController::Routing::Routes.load_routes!
|
ActionController::Routing::Routes.load_routes!
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
|
||||||
super
|
|
||||||
ActionController::Routing::Routes.reload
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_raw_post_handling
|
def test_raw_post_handling
|
||||||
params = {:page => {:name => 'page name'}, 'some key' => 123}
|
params = {:page => {:name => 'page name'}, 'some key' => 123}
|
||||||
post :render_raw_post, params.dup
|
post :render_raw_post, params.dup
|
||||||
|
|
|
@ -195,7 +195,8 @@ class UrlWriterTests < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_named_routes
|
def test_named_routes
|
||||||
ActionController::Routing::Routes.draw do |map|
|
with_routing do |set|
|
||||||
|
set.draw do |map|
|
||||||
map.no_args '/this/is/verbose', :controller => 'home', :action => 'index'
|
map.no_args '/this/is/verbose', :controller => 'home', :action => 'index'
|
||||||
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
|
@ -211,15 +212,15 @@ class UrlWriterTests < ActionController::TestCase
|
||||||
assert_equal("/home/sweet/home/alabama", controller.send(:home_path, :user => 'alabama', :host => 'unused'))
|
assert_equal("/home/sweet/home/alabama", controller.send(:home_path, :user => 'alabama', :host => 'unused'))
|
||||||
assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'www.basecamphq.com'))
|
assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'www.basecamphq.com'))
|
||||||
assert_equal("http://www.basecamphq.com/this/is/verbose", controller.send(:no_args_url, :host=>'www.basecamphq.com'))
|
assert_equal("http://www.basecamphq.com/this/is/verbose", controller.send(:no_args_url, :host=>'www.basecamphq.com'))
|
||||||
ensure
|
end
|
||||||
ActionController::Routing::Routes.load!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_relative_url_root_is_respected_for_named_routes
|
def test_relative_url_root_is_respected_for_named_routes
|
||||||
orig_relative_url_root = ActionController::Base.relative_url_root
|
orig_relative_url_root = ActionController::Base.relative_url_root
|
||||||
ActionController::Base.relative_url_root = '/subdir'
|
ActionController::Base.relative_url_root = '/subdir'
|
||||||
|
|
||||||
ActionController::Routing::Routes.draw do |map|
|
with_routing do |set|
|
||||||
|
set.draw do |map|
|
||||||
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -228,13 +229,14 @@ class UrlWriterTests < ActionController::TestCase
|
||||||
|
|
||||||
assert_equal 'http://www.basecamphq.com/subdir/home/sweet/home/again',
|
assert_equal 'http://www.basecamphq.com/subdir/home/sweet/home/again',
|
||||||
controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
|
controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
|
||||||
|
end
|
||||||
ensure
|
ensure
|
||||||
ActionController::Routing::Routes.load!
|
|
||||||
ActionController::Base.relative_url_root = orig_relative_url_root
|
ActionController::Base.relative_url_root = orig_relative_url_root
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_only_path
|
def test_only_path
|
||||||
ActionController::Routing::Routes.draw do |map|
|
with_routing do |set|
|
||||||
|
set.draw do |map|
|
||||||
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
end
|
end
|
||||||
|
@ -248,8 +250,7 @@ class UrlWriterTests < ActionController::TestCase
|
||||||
|
|
||||||
assert_equal("/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'unused', :only_path => true))
|
assert_equal("/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'unused', :only_path => true))
|
||||||
assert_equal("/home/sweet/home/alabama", controller.send(:home_path, 'alabama'))
|
assert_equal("/home/sweet/home/alabama", controller.send(:home_path, 'alabama'))
|
||||||
ensure
|
end
|
||||||
ActionController::Routing::Routes.load!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_one_parameter
|
def test_one_parameter
|
||||||
|
@ -302,12 +303,13 @@ class UrlWriterTests < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_named_routes_with_nil_keys
|
def test_named_routes_with_nil_keys
|
||||||
ActionController::Routing::Routes.clear!
|
with_routing do |set|
|
||||||
ActionController::Routing::Routes.draw do |map|
|
set.draw do |map|
|
||||||
map.main '', :controller => 'posts', :format => nil
|
map.main '', :controller => 'posts', :format => nil
|
||||||
map.resources :posts
|
map.resources :posts
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
end
|
end
|
||||||
|
|
||||||
# We need to create a new class in order to install the new named route.
|
# We need to create a new class in order to install the new named route.
|
||||||
kls = Class.new { include ActionController::UrlWriter }
|
kls = Class.new { include ActionController::UrlWriter }
|
||||||
kls.default_url_options[:host] = 'www.basecamphq.com'
|
kls.default_url_options[:host] = 'www.basecamphq.com'
|
||||||
|
@ -317,12 +319,12 @@ class UrlWriterTests < ActionController::TestCase
|
||||||
assert_equal("http://www.basecamphq.com/posts.xml", controller.send(:url_for, params))
|
assert_equal("http://www.basecamphq.com/posts.xml", controller.send(:url_for, params))
|
||||||
params[:format] = nil
|
params[:format] = nil
|
||||||
assert_equal("http://www.basecamphq.com/", controller.send(:url_for, params))
|
assert_equal("http://www.basecamphq.com/", controller.send(:url_for, params))
|
||||||
ensure
|
end
|
||||||
ActionController::Routing::Routes.load!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_formatted_url_methods_are_deprecated
|
def test_formatted_url_methods_are_deprecated
|
||||||
ActionController::Routing::Routes.draw do |map|
|
with_routing do |set|
|
||||||
|
set.draw do |map|
|
||||||
map.resources :posts
|
map.resources :posts
|
||||||
end
|
end
|
||||||
# We need to create a new class in order to install the new named route.
|
# We need to create a new class in order to install the new named route.
|
||||||
|
@ -335,8 +337,7 @@ class UrlWriterTests < ActionController::TestCase
|
||||||
assert_deprecated do
|
assert_deprecated do
|
||||||
assert_equal("/posts/1.xml", controller.send(:formatted_post_path, 1, :xml))
|
assert_equal("/posts/1.xml", controller.send(:formatted_post_path, 1, :xml))
|
||||||
end
|
end
|
||||||
ensure
|
end
|
||||||
ActionController::Routing::Routes.load!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multiple_includes_maintain_distinct_options
|
def test_multiple_includes_maintain_distinct_options
|
||||||
|
|
|
@ -112,7 +112,10 @@ class VerificationTest < ActionController::TestCase
|
||||||
tests TestController
|
tests TestController
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
ActionController::Routing::Routes.add_named_route :foo, '/foo', :controller => 'test', :action => 'foo'
|
ActionController::Routing::Routes.draw do |map|
|
||||||
|
map.foo '/foo', :controller => 'test', :action => 'foo'
|
||||||
|
map.connect ":controller/:action/:id"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_using_symbol_back_with_no_referrer
|
def test_using_symbol_back_with_no_referrer
|
||||||
|
|
Loading…
Reference in a new issue