From 3213b5e165e40e70636baa66f0f421d170d5caa1 Mon Sep 17 00:00:00 2001 From: Mike Gaffney Date: Mon, 26 Jan 2009 18:42:45 -0600 Subject: [PATCH] moved update and delete to save_test_session and clear_test_session --- actionpack/lib/action_controller/test_process.rb | 26 +++++++- .../test/controller/session/test_session_test.rb | 65 ++++++++++++++++++++ 2 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 actionpack/test/controller/session/test_session_test.rb diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index 22b97fc..f66d9fc 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -300,17 +300,35 @@ module ActionController #:nodoc: data[key.to_s] = value end - def update + def save_test_session @saved_attributes = @attributes end - def delete + def clear_test_session @attributes = nil end + + def update(hash = nil) + if hash.nil? + ActiveSupport::Deprecation.warn('use save_test_session instead', caller) + save_test_session + else + @attributes.update(hash) + end + end + + def delete(key = nil) + if key.nil? + ActiveSupport::Deprecation.warn('use clear_test_session instead', caller) + clear_test_session + else + @attributes.delete(key) + end + end def close - update - delete + save_test_session + clear_test_session end end diff --git a/actionpack/test/controller/session/test_session_test.rb b/actionpack/test/controller/session/test_session_test.rb new file mode 100644 index 0000000..acd8dd2 --- /dev/null +++ b/actionpack/test/controller/session/test_session_test.rb @@ -0,0 +1,65 @@ +require 'abstract_unit' +require 'stringio' + +class ActionController::TestSessionTest < ActiveSupport::TestCase + + def test_calling_delete_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session + session = ActionController::TestSession.new + session.expects(:clear_test_session) + assert_deprecated(/clear_test_session instead/){ session.delete } + end + + def test_calling_update_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session + session = ActionController::TestSession.new + session.expects(:save_test_session) + assert_deprecated(/save_test_session instead/){ session.update } + end + + def test_calling_delete_with_params_passes_to_attributes + mock_attributes = mock + mock_attributes.expects(:stringify_keys).returns(mock_attributes) + session = ActionController::TestSession.new(mock_attributes) + mock_attributes.expects(:delete).with(:key) + session.delete(:key) + end + + def test_calling_update_with_params_passes_to_attributes + mock_attributes = mock + mock_attributes.expects(:stringify_keys).returns(mock_attributes) + session = ActionController::TestSession.new(mock_attributes) + params = {:key => 'value'} + mock_attributes.expects(:update).with(params) + session.update(params) + end + + def test_defaults + session = ActionController::TestSession.new + assert_equal({}, session.data) + assert_equal('', session.session_id) + end + + def test_clear_test_session_clears_attributes + session = ActionController::TestSession.new + session[:key] = 'value' + assert_equal('value', session[:key]) + session.clear_test_session + assert_nil(session[:key]) + end + + def test_saving_session_stores_session_variables + session = ActionController::TestSession.new + session[:key] = 'value' + assert_equal('value', session[:key]) + session.save_test_session + assert_equal('value', session[:key]) + end + + def test_closing_session_saves_and_clears + session = ActionController::TestSession.new + session[:key] = 'value' + assert_equal('value', session[:key]) + session.close + assert_equal('value', session[:key]) + end + +end -- 1.6.1