aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-02-25 16:35:24 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-02-25 16:35:24 +0000
commit781985f7f229eb665b3eed693eb9642caebc44a0 (patch)
treeb87cd67949c03e89af269652622a73589d027224 /actionpack
parentc9770d8a5ac1c477943ba431396e5d7e6b7389b0 (diff)
downloadrails-781985f7f229eb665b3eed693eb9642caebc44a0.tar.gz
rails-781985f7f229eb665b3eed693eb9642caebc44a0.tar.bz2
rails-781985f7f229eb665b3eed693eb9642caebc44a0.zip
Cookie session store: empty and unchanged sessions don't write a cookie.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6226 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/session/cookie_store.rb3
-rwxr-xr-xactionpack/test/controller/session/cookie_store_test.rb16
3 files changed, 19 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 20258b536e..396fa98a76 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Cookie session store: empty and unchanged sessions don't write a cookie. [Jeremy Kemper]
+
* Added helper(:all) as a way to include all helpers from app/helpers/**/*.rb in ApplicationController [DHH]
* Integration tests: introduce methods for other HTTP methods. #6353 [caboose]
diff --git a/actionpack/lib/action_controller/session/cookie_store.rb b/actionpack/lib/action_controller/session/cookie_store.rb
index 8763a4933a..1754eb34b1 100644
--- a/actionpack/lib/action_controller/session/cookie_store.rb
+++ b/actionpack/lib/action_controller/session/cookie_store.rb
@@ -65,7 +65,7 @@ class CGI::Session::CookieStore
# Write the session data cookie if it was loaded and has changed.
def close
- if defined? @data
+ if defined?(@data) && !@data.blank?
updated = marshal(@data)
raise CookieOverflow if updated.size > MAX
write_cookie('value' => updated) unless updated == @original
@@ -74,6 +74,7 @@ class CGI::Session::CookieStore
# Delete the session data by setting an expired cookie with no data.
def delete
+ @data = nil
write_cookie('value' => '', 'expires' => 1.year.ago)
end
diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb
index 7a12fb4650..353785825b 100755
--- a/actionpack/test/controller/session/cookie_store_test.rb
+++ b/actionpack/test/controller/session/cookie_store_test.rb
@@ -68,11 +68,20 @@ class CookieStoreTest < Test::Unit::TestCase
end
end
+ def test_close_doesnt_write_cookie_if_data_is_blank
+ new_session do |session|
+ assert_nil session.cgi.output_cookies, session.cgi.output_cookies.inspect
+ session.close
+ assert_nil session.cgi.output_cookies, session.cgi.output_cookies.inspect
+ end
+ end
+
def test_close_doesnt_write_cookie_if_data_is_unchanged
set_cookie! Cookies::TYPICAL.first
new_session do |session|
assert_nil session.cgi.output_cookies, session.cgi.output_cookies.inspect
session['user_id'] = session['user_id']
+ session.close
assert_nil session.cgi.output_cookies, session.cgi.output_cookies.inspect
end
end
@@ -91,7 +100,7 @@ class CookieStoreTest < Test::Unit::TestCase
end
end
- def test_delete_writes_expired_empty_cookie
+ def test_delete_writes_expired_empty_cookie_and_sets_data_to_nil
set_cookie! Cookies::TYPICAL.first
new_session do |session|
assert_nil session.cgi.output_cookies, session.cgi.output_cookies.inspect
@@ -100,6 +109,11 @@ class CookieStoreTest < Test::Unit::TestCase
cookie = session.cgi.output_cookies.first
assert_equal ['_myapp_session', [], 1.year.ago.to_date],
[cookie.name, cookie.value, cookie.expires.to_date]
+
+ # @data is set to nil so #close doesn't send another cookie.
+ session.close
+ assert_equal ['_myapp_session', [], 1.year.ago.to_date],
+ [cookie.name, cookie.value, cookie.expires.to_date]
end
end