Permalink
Browse files

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
  • Loading branch information...
1 parent c9770d8 commit 781985f7f229eb665b3eed693eb9642caebc44a0 @jeremy jeremy committed Feb 25, 2007
@@ -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]
@@ -65,7 +65,7 @@ def update; end
# 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 @@ def close
# Delete the session data by setting an expired cookie with no data.
def delete
+ @data = nil
write_cookie('value' => '', 'expires' => 1.year.ago)
end
@@ -68,11 +68,20 @@ def test_restore_unmarshals_good_cookies
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 @@ def test_close_marshals_and_writes_cookie
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 @@ def test_delete_writes_expired_empty_cookie
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

0 comments on commit 781985f

Please sign in to comment.