Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6226

Show
Ignore:
Timestamp:
02/25/07 16:35:24 (2 years ago)
Author:
bitsweat
Message:

Cookie session store: empty and unchanged sessions don't write a cookie.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6221 r6226  
    11*SVN* 
     2 
     3* Cookie session store: empty and unchanged sessions don't write a cookie.  [Jeremy Kemper] 
    24 
    35* Added helper(:all) as a way to include all helpers from app/helpers/**/*.rb in ApplicationController [DHH] 
  • trunk/actionpack/lib/action_controller/session/cookie_store.rb

    r6200 r6226  
    6666  # Write the session data cookie if it was loaded and has changed. 
    6767  def close 
    68     if defined? @data 
     68    if defined?(@data) && !@data.blank? 
    6969      updated = marshal(@data) 
    7070      raise CookieOverflow if updated.size > MAX 
     
    7575  # Delete the session data by setting an expired cookie with no data. 
    7676  def delete 
     77    @data = nil 
    7778    write_cookie('value' => '', 'expires' => 1.year.ago) 
    7879  end 
  • trunk/actionpack/test/controller/session/cookie_store_test.rb

    r6200 r6226  
    6969  end 
    7070 
     71  def test_close_doesnt_write_cookie_if_data_is_blank 
     72    new_session do |session| 
     73      assert_nil session.cgi.output_cookies, session.cgi.output_cookies.inspect 
     74      session.close 
     75      assert_nil session.cgi.output_cookies, session.cgi.output_cookies.inspect 
     76    end 
     77  end 
     78 
    7179  def test_close_doesnt_write_cookie_if_data_is_unchanged 
    7280    set_cookie! Cookies::TYPICAL.first 
     
    7482      assert_nil session.cgi.output_cookies, session.cgi.output_cookies.inspect 
    7583      session['user_id'] = session['user_id'] 
     84      session.close 
    7685      assert_nil session.cgi.output_cookies, session.cgi.output_cookies.inspect 
    7786    end 
     
    92101  end 
    93102 
    94   def test_delete_writes_expired_empty_cookie 
     103  def test_delete_writes_expired_empty_cookie_and_sets_data_to_nil 
    95104    set_cookie! Cookies::TYPICAL.first 
    96105    new_session do |session| 
     
    99108      assert_equal 1, session.cgi.output_cookies.size 
    100109      cookie = session.cgi.output_cookies.first 
     110      assert_equal ['_myapp_session', [], 1.year.ago.to_date], 
     111                   [cookie.name, cookie.value, cookie.expires.to_date] 
     112 
     113      # @data is set to nil so #close doesn't send another cookie. 
     114      session.close 
    101115      assert_equal ['_myapp_session', [], 1.year.ago.to_date], 
    102116                   [cookie.name, cookie.value, cookie.expires.to_date]