aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/session/active_record_store.rb16
-rw-r--r--actionpack/test/controller/active_record_store_test.rb7
2 files changed, 17 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/session/active_record_store.rb b/actionpack/lib/action_controller/session/active_record_store.rb
index 4700f2419a..60fd295fe8 100644
--- a/actionpack/lib/action_controller/session/active_record_store.rb
+++ b/actionpack/lib/action_controller/session/active_record_store.rb
@@ -251,24 +251,28 @@ class CGI
# Restore session state. The session model handles unmarshaling.
def restore
- @session.data
+ @session.data if @session
end
# Save session store.
def update
- @session.save!
+ @session.save! if @session
end
# Save and close the session store.
def close
- update
- @session = nil
+ if @session
+ update
+ @session = nil
+ end
end
# Delete and close the session store.
def delete
- @session.destroy rescue nil
- @session = nil
+ if @session
+ @session.destroy rescue nil
+ @session = nil
+ end
end
end
diff --git a/actionpack/test/controller/active_record_store_test.rb b/actionpack/test/controller/active_record_store_test.rb
index cc7f23bed5..b50d08447b 100644
--- a/actionpack/test/controller/active_record_store_test.rb
+++ b/actionpack/test/controller/active_record_store_test.rb
@@ -40,6 +40,13 @@ module CommonActiveRecordStoreTests
reloaded = CGI::Session.new(CGI.new, 'session_id' => @new_session.session_id, 'database_manager' => CGI::Session::ActiveRecordStore)
assert_equal 'bar', reloaded['foo']
end
+
+ def test_tolerates_close_close
+ assert_nothing_raised do
+ @new_session.close
+ @new_session.close
+ end
+ end
end
class ActiveRecordStoreTest < Test::Unit::TestCase