Permalink
Browse files

Add custom "with_routing" to internal tests to fix reseting session a…

…fter using

with_routing. This only affects our internal AP tests.
  • Loading branch information...
1 parent 89630a7 commit 84e94551f62d3bcbc71f1c6f3fda738342d984e2 @josh josh committed Oct 4, 2009
@@ -53,12 +53,33 @@
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
class ActionController::IntegrationTest < ActiveSupport::TestCase
- @@app = ActionDispatch::MiddlewareStack.new { |middleware|
- middleware.use "ActionDispatch::ShowExceptions"
- middleware.use "ActionDispatch::Callbacks"
- middleware.use "ActionDispatch::ParamsParser"
- middleware.use "Rack::Head"
- }.build(ActionController::Routing::Routes)
+ def self.build_app(routes = nil)
+ ActionDispatch::MiddlewareStack.new { |middleware|
+ middleware.use "ActionDispatch::ShowExceptions"
+ middleware.use "ActionDispatch::Callbacks"
+ middleware.use "ActionDispatch::ParamsParser"
+ middleware.use "Rack::Head"
+ }.build(routes || ActionController::Routing::Routes)
+ end
+
+ self.app = build_app
+
+ def with_routing(&block)
+ real_routes = ActionController::Routing::Routes
+ ActionController::Routing.module_eval { remove_const :Routes }
+
+ temporary_routes = ActionController::Routing::RouteSet.new
+ self.class.app = self.class.build_app(temporary_routes)
+ ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
+
+ yield temporary_routes
+ ensure
+ if ActionController::Routing.const_defined? :Routes
+ ActionController::Routing.module_eval { remove_const :Routes }
+ end
+ ActionController::Routing.const_set(:Routes, real_routes) if real_routes
+ self.class.app = self.class.build_app
+ end
end
module ActionView
@@ -158,7 +158,6 @@ def with_test_route_set(options = {})
map.connect "/:action", :controller => "active_record_store_test/test"
end
@app = ActiveRecord::SessionStore.new(set, options.reverse_merge(:key => '_session_id'))
- reset!
yield
end
end
@@ -372,11 +372,8 @@ def test_generate_url_with_controller
def with_test_route_set
with_routing do |set|
set.draw do |map|
- map.with_options :controller => "IntegrationProcessTest::Integration" do |c|
- c.connect "/:action"
- end
+ map.connect "/:action", :controller => "integration_process_test/integration"
end
- reset!
yield
end
end
@@ -347,7 +347,6 @@ def with_test_routing
map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid'
map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m'
end
- reset!
yield
end
end
@@ -259,7 +259,6 @@ def with_test_route_set
c.connect "/", :action => "assign_parameters"
end
end
- reset!
yield
end
end
@@ -59,7 +59,6 @@ def with_test_routing
set.draw do |map|
map.connect ':action', :controller => "json_params_parsing_test/test"
end
- reset!
yield
end
end
@@ -153,7 +153,6 @@ def with_test_routing
set.draw do |map|
map.connect ':action', :controller => "multipart_params_parsing_test/test"
end
- reset!
yield
end
end
@@ -111,7 +111,6 @@ def assert_parses(expected, actual)
set.draw do |map|
map.connect ':action', :controller => "query_string_parsing_test/test"
end
- reset!
get "/parse", actual
assert_response :ok
@@ -132,7 +132,6 @@ def with_test_routing
set.draw do |map|
map.connect ':action', :controller => "url_encoded_params_parsing_test/test"
end
- reset!
yield
end
end
@@ -86,7 +86,6 @@ def with_test_routing
set.draw do |map|
map.connect ':action', :controller => "xml_params_parsing_test/test"
end
- reset!
yield
end
end
@@ -223,7 +223,6 @@ def with_test_route_set(options = {})
end
options = {:key => SessionKey, :secret => SessionSecret}.merge(options)
@app = ActionDispatch::Session::CookieStore.new(set, options)
- reset!
yield
end
end
@@ -115,7 +115,6 @@ def with_test_route_set
map.connect "/:action", :controller => "mem_cache_store_test/test"
end
@app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id')
- reset!
yield
end
end
@@ -18,6 +18,7 @@ class HiController < ActionController::Base; end
class BraveController < ActionController::Base; end
class ImageController < ActionController::Base; end
class WeblogController < ActionController::Base; end
+class BarController < ActionController::Base; end
# For speed test
class SpeedController < ActionController::Base; end
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'controller/fake_controllers'
module ActionView
class TestCase

0 comments on commit 84e9455

Please sign in to comment.