Skip to content

Commit

Permalink
Clean up session integration tests so they don't reference AC::Dispat…
Browse files Browse the repository at this point in the history
…cher
  • Loading branch information
josh committed Sep 26, 2009
1 parent db65bb5 commit 0c638b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 52 deletions.
27 changes: 6 additions & 21 deletions actionpack/test/activerecord/active_record_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def rescue_action(e) raise end

def setup
ActiveRecord::SessionStore.session_class.create_table!
reset_app!
end

def teardown
Expand Down Expand Up @@ -132,9 +131,7 @@ def test_prevents_session_fixation
end

def test_allows_session_fixation
with_test_route_set do
reset_with_fixation!

with_test_route_set(:cookie_only => false) do
get '/set_session_value'
assert_response :success
assert cookies['_session_id']
Expand All @@ -145,8 +142,6 @@ def test_allows_session_fixation
session_id = cookies['_session_id']
assert session_id

reset_with_fixation!

get '/set_session_value', :_session_id => session_id, :foo => "baz"
assert_response :success
assert_equal session_id, cookies['_session_id']
Expand All @@ -159,24 +154,14 @@ def test_allows_session_fixation
end

private
def reset_app!
app = ActiveRecord::SessionStore.new(ActionController::Dispatcher.new, :key => '_session_id')
@integration_session = open_session(app)
end

def reset_with_fixation!
app = ActiveRecord::SessionStore.new(ActionController::Dispatcher.new, :key => '_session_id', :cookie_only => false)
@integration_session = open_session(app)
end

def with_test_route_set
def with_test_route_set(options = {})
with_routing do |set|
set.draw do |map|
map.with_options :controller => "active_record_store_test/test" do |c|
c.connect "/:action"
end
map.connect "/:action", :controller => "active_record_store_test/test"
end
reset_app!
options = {:key => '_session_id'}.merge(options)
app = ActiveRecord::SessionStore.new(set, options)
@integration_session = open_session(app)
yield
end
end
Expand Down
25 changes: 6 additions & 19 deletions actionpack/test/dispatch/session/cookie_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ def raise_data_overflow
def rescue_action(e) raise end
end

def setup
reset_app!
end

def test_raises_argument_error_if_missing_session_key
assert_raise(ArgumentError, nil.inspect) {
ActionDispatch::Session::CookieStore.new(nil,
Expand Down Expand Up @@ -193,10 +189,7 @@ def test_persistent_session_id
end

def test_session_store_with_expire_after
with_test_route_set do
app = ActionDispatch::Session::CookieStore.new(ActionController::Dispatcher.new, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours)
@integration_session = open_session(app)

with_test_route_set(:expire_after => 5.hours) do
# First request accesses the session
time = Time.local(2008, 4, 24)
Time.stubs(:now).returns(time)
Expand Down Expand Up @@ -226,20 +219,14 @@ def test_session_store_with_expire_after
end

private
def reset_app!
app = ActionDispatch::Session::CookieStore.new(ActionController::Dispatcher.new,
:key => SessionKey, :secret => SessionSecret)
@integration_session = open_session(app)
end

def with_test_route_set
def with_test_route_set(options = {})
with_routing do |set|
set.draw do |map|
map.with_options :controller => "cookie_store_test/test" do |c|
c.connect "/:action"
end
map.connect "/:action", :controller => "cookie_store_test/test"
end
reset_app!
options = {:key => SessionKey, :secret => SessionSecret}.merge(options)
app = ActionDispatch::Session::CookieStore.new(set, options)
@integration_session = open_session(app)
yield
end
end
Expand Down
15 changes: 3 additions & 12 deletions actionpack/test/dispatch/session/mem_cache_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def rescue_action(e) raise end
end

begin
App = ActionDispatch::Session::MemCacheStore.new(ActionController::Dispatcher.new, :key => '_session_id')

def test_setting_and_getting_session_value
with_test_route_set do
get '/set_session_value'
Expand Down Expand Up @@ -107,20 +105,13 @@ def test_prevents_session_fixation
end

private
def reset_app!
app = ActionDispatch::Session::MemCacheStore.new(
ActionController::Dispatcher.new, :key => '_session_id')
@integration_session = open_session(app)
end

def with_test_route_set
with_routing do |set|
set.draw do |map|
map.with_options :controller => "mem_cache_store_test/test" do |c|
c.connect "/:action"
end
map.connect "/:action", :controller => "mem_cache_store_test/test"
end
reset_app!
app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id')
@integration_session = open_session(app)
yield
end
end
Expand Down

0 comments on commit 0c638b3

Please sign in to comment.