提交 acfeec51 编写于 作者: J Joshua Peek

Allow integration test rack app to be set with "@app" ivar instead of using open_session

上级 02413baa
......@@ -168,8 +168,8 @@ def cookies
attr_accessor :request_count
# Create and initialize a new Session instance.
def initialize(app = nil)
@app = app || ActionController::Dispatcher.new
def initialize(app)
@app = app
reset!
end
......@@ -354,6 +354,7 @@ def reset!
# can use this method to open multiple sessions that ought to be tested
# simultaneously.
def open_session(app = nil)
app ||= @app ||= ActionController::Dispatcher.new
session = Integration::Session.new(app)
# delegate the fixture accessors back to the test instance
......
......@@ -119,14 +119,10 @@ def test_prevents_session_fixation
reset!
get '/set_session_value', :_session_id => session_id, :foo => "baz"
assert_response :success
assert_equal nil, cookies['_session_id']
get '/get_session_value', :_session_id => session_id
assert_response :success
assert_equal 'foo: nil', response.body
assert_equal nil, cookies['_session_id']
assert_not_equal session_id, cookies['_session_id']
end
end
......@@ -142,6 +138,8 @@ def test_allows_session_fixation
session_id = cookies['_session_id']
assert session_id
reset!
get '/set_session_value', :_session_id => session_id, :foo => "baz"
assert_response :success
assert_equal session_id, cookies['_session_id']
......@@ -159,9 +157,8 @@ def with_test_route_set(options = {})
set.draw do |map|
map.connect "/:action", :controller => "active_record_store_test/test"
end
options = {:key => '_session_id'}.merge(options)
app = ActiveRecord::SessionStore.new(set, options)
@integration_session = open_session(app)
@app = ActiveRecord::SessionStore.new(set, options.reverse_merge(:key => '_session_id'))
reset!
yield
end
end
......
......@@ -394,7 +394,7 @@ def self.call(env)
end
def setup
@integration_session = ActionController::Integration::Session.new(Poller)
@app = Poller
end
def test_successful_get
......
......@@ -326,19 +326,16 @@ def show_errors(exception)
end
test 'rescue routing exceptions' do
app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) do
@app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) do
rescue_from ActionController::RoutingError, lambda { |env| [200, {"Content-Type" => "text/html"}, "Gotcha!"] }
end
@integration_session = open_session(app)
get '/b00m'
assert_equal "Gotcha!", response.body
end
test 'unrescued exception' do
app = ActionDispatch::Rescue.new(ActionController::Routing::Routes)
@integration_session = open_session(app)
@app = ActionDispatch::Rescue.new(ActionController::Routing::Routes)
assert_raise(ActionController::RoutingError) { get '/b00m' }
end
......
......@@ -245,8 +245,8 @@ def test_typecast_as_yaml
private
def with_params_parsers(parsers = {})
old_session = @integration_session
app = ActionDispatch::ParamsParser.new(ActionController::Routing::Routes, parsers)
@integration_session = open_session(app)
@app = ActionDispatch::ParamsParser.new(ActionController::Routing::Routes, parsers)
reset!
yield
ensure
@integration_session = old_session
......
......@@ -222,8 +222,8 @@ def with_test_route_set(options = {})
map.connect "/:action", :controller => "cookie_store_test/test"
end
options = {:key => SessionKey, :secret => SessionSecret}.merge(options)
app = ActionDispatch::Session::CookieStore.new(set, options)
@integration_session = open_session(app)
@app = ActionDispatch::Session::CookieStore.new(set, options)
reset!
yield
end
end
......
......@@ -101,7 +101,7 @@ def test_prevents_session_fixation
get '/set_session_value', :_session_id => session_id
assert_response :success
assert_equal nil, cookies['_session_id']
assert_not_equal session_id, cookies['_session_id']
end
end
rescue LoadError, RuntimeError
......@@ -114,8 +114,8 @@ def with_test_route_set
set.draw do |map|
map.connect "/:action", :controller => "mem_cache_store_test/test"
end
app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id')
@integration_session = open_session(app)
@app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id')
reset!
yield
end
end
......
......@@ -35,7 +35,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest
DevelopmentApp = ActionDispatch::ShowExceptions.new(Boomer, true)
test "rescue in public from a remote ip" do
@integration_session = open_session(ProductionApp)
@app = ProductionApp
self.remote_addr = '208.77.188.166'
get "/"
......@@ -52,7 +52,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest
end
test "rescue locally from a local request" do
@integration_session = open_session(ProductionApp)
@app = ProductionApp
self.remote_addr = '127.0.0.1'
get "/"
......@@ -73,7 +73,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest
old_locale, I18n.locale = I18n.locale, :da
begin
@integration_session = open_session(ProductionApp)
@app = ProductionApp
self.remote_addr = '208.77.188.166'
get "/"
......@@ -89,7 +89,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest
end
test "always rescue locally in development mode" do
@integration_session = open_session(DevelopmentApp)
@app = DevelopmentApp
self.remote_addr = '208.77.188.166'
get "/"
......
......@@ -17,7 +17,8 @@ def app(create=false)
# create a new session. If a block is given, the new session will be yielded
# to the block before being returned.
def new_session
session = ActionController::Integration::Session.new
app = ActionController::Dispatcher.new
session = ActionController::Integration::Session.new(app)
yield session if block_given?
session
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册