From 5c18bdca321c9152ad2770a029636b9351e91666 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sat, 28 Apr 2012 22:23:58 +0100 Subject: Merge session arg with existing session instead of overwriting This may break existing tests that are asserting the whole session contents but should not break existing tests that are asserting individual keys - e.g: class SomeControllerTest < ActionController::TestCase setup do session['user_id'] = 1 end test "some test" do get :some_action, nil, { 'another_var' => 2 } # This assertion will now fail assert_equal({ 'another_var' => 2 }, session) # This assertion will still pass assert_equal 2, session['another_var] end end Fixes #1529. --- actionpack/CHANGELOG.md | 7 +++++++ actionpack/lib/action_controller/test_case.rb | 2 +- actionpack/test/controller/test_case_test.rb | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index b3d6ae0ac7..9f1c44ca66 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,12 @@ ## Rails 4.0.0 (unreleased) ## +* Session arguments passed to `process` calls in functional tests are now merged into + the existing session, whereas previously they would replace the existing session. + This change may break some existing tests if they are asserting the exact contents of + the session but should not break existing tests that only assert individual keys. + + *Andrew White* + * Add `index` method to FormBuilder class. *Jorge Bejar* * Remove the leading \n added by textarea on assert_select. *Santiago Pastorino* diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 66a4808e36..7db7d270e5 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -471,7 +471,7 @@ module ActionController @request.assign_parameters(@routes, controller_class_name, action.to_s, parameters) - @request.session = ActionController::TestSession.new(session) if session + @request.session.update(session) if session @request.session["flash"] = @request.flash.update(flash || {}) @request.session["flash"].sweep diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index e8411bae0c..03b7396d5b 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -224,6 +224,26 @@ XML assert_equal 'value2', session[:symbol] end + def test_process_merges_session_arg + session[:foo] = 'bar' + get :no_op, nil, { :bar => 'baz' } + assert_equal 'bar', session[:foo] + assert_equal 'baz', session[:bar] + end + + def test_merged_session_arg_is_retained_across_requests + get :no_op, nil, { :foo => 'bar' } + assert_equal 'bar', session[:foo] + get :no_op + assert_equal 'bar', session[:foo] + end + + def test_process_overwrites_existing_session_arg + session[:foo] = 'bar' + get :no_op, nil, { :foo => 'baz' } + assert_equal 'baz', session[:foo] + end + def test_session_is_cleared_from_controller_after_reset_session process :set_session process :reset_the_session -- cgit v1.2.3