Permalink
Browse files

Fixed missing ènv`argument to session in pop_detour

  • Loading branch information...
donv committed May 2, 2016
1 parent 6a0dc7f commit 413e99e32c643aebcc74fa111f69156083ef9d86
@@ -32,7 +32,7 @@ def store_detour_from_params
def back(response_status_and_flash)
return false if session[:detours].nil?
detour = pop_detour
detour = pop_detour(session)
post = detour.delete(:request_method) == :post
if post
set_flash(response_status_and_flash)
@@ -62,15 +62,6 @@ def set_flash(response_status_and_flash)
end
private :set_flash
def pop_detour
detours = session[:detours]
return nil unless detours
detour = detours.pop
logger.debug "popped detour: #{detour.inspect} #{session[:detours].size} more"
reset_workflow(session) if detours.empty?
detour
end
def redirect_to_post(options)
url = url_for options
render :text => <<EOF, :layout => false
@@ -9,6 +9,15 @@ def store_detour_in_session(session, options)
Rails.logger.try(:debug, "Added detour (#{session[:detours].try(:size) || 0}): #{options.inspect}")
end
def pop_detour(session)
detours = session[:detours]
return nil unless detours
detour = detours.pop
Rails.logger.debug "popped detour: #{detour.inspect} #{session[:detours].size} more"
reset_workflow(session) if detours.empty?
detour
end
def reset_workflow(session)
session.delete(:detours)
end
@@ -75,8 +75,8 @@ def store_detour_from_params(env)
if params(env)[:detour]
store_detour_in_session(session(env), params(env)[:detour])
end
if params(env)[:return_from_detour] && session[:detours]
pop_detour
if params(env)[:return_from_detour] && session(env)[:detours]
pop_detour(session(env))
end
end
@@ -1,3 +1,3 @@
module SimpleWorkflow
VERSION = '1.1.1'
VERSION = '1.1.2'
end
View
@@ -31,6 +31,18 @@ def test_deprecated_store_detour_from_params
assert_equal({}, session)
end
# ODOT
def test_back
store_detour({controller: :mycontroller, action: :myaction})
back({})
assert_equal({}, session)
end
private
def redirect_to(path, response_status_and_flash)
# NOOP
end
end
class TestApp < Rails::Application
View
@@ -72,6 +72,21 @@ def test_huge_detour_over_4k
assert_equal(%w(session_id), headers['rack.session'].to_hash.keys)
end
def test_return_from_detour
_, headers1, _ = @stack.call env_for('/?detour[controller]=test_first')
env = env_for('/?return_from_detour=true',
'rack.session' => headers1['rack.session'],
'rack.session.options' => headers1['rack.session.options']
)
status, headers, response = @stack.call env
assert_equal 200, status
assert_equal(env, headers)
assert_equal 'app response', response
assert_equal(['session_id'], headers['rack.session'].to_hash.keys)
assert_equal(nil, headers['rack.session'].to_hash['detours'])
end
private
def env_for(url, opts={})

0 comments on commit 413e99e

Please sign in to comment.