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

Changeset 7160

Show
Ignore:
Timestamp:
07/01/07 23:27:59 (1 year ago)
Author:
nzkoz
Message:

Allow you to delete cookies with options. Closes #3685 [josh, Chris Wanstrath]

Files:

Legend:

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

    r7158 r7160  
    11*SVN* 
     2 
     3* Allow you to delete cookies with options. Closes #3685 [josh, Chris Wanstrath] 
    24 
    35* Allow you to render views with periods in the name.  Closes #8076 [norbert] 
  • trunk/actionpack/lib/action_controller/cookies.rb

    r5207 r7160  
    6363 
    6464    # Removes the cookie on the client machine by setting the value to an empty string 
    65     # and setting its expiration date into the past 
    66     def delete(name) 
    67       set_cookie("name" => name.to_s, "value" => "", "expires" => Time.at(0)) 
     65    # and setting its expiration date into the past.  Like []=, you can pass in an options 
     66    # hash to delete cookies with extra data such as a +path+. 
     67    def delete(name, options = {}) 
     68      options.stringify_keys! 
     69      set_cookie(options.merge("name" => name.to_s, "value" => "", "expires" => Time.at(0))) 
    6870    end 
    6971 
  • trunk/actionpack/test/controller/cookie_test.rb

    r5977 r7160  
    3030    def logout 
    3131      cookies.delete("user_name") 
     32    end 
     33 
     34    def delete_cookie_with_path 
     35      cookies.delete("user_name", :path => '/beaten') 
     36      render_text "hello world" 
    3237    end 
    3338 
     
    8691    assert_equal nil, jar["something_else"] 
    8792  end 
     93 
     94  def test_delete_cookie_with_path 
     95    get :delete_cookie_with_path 
     96    assert_equal "/beaten", @response.headers["cookie"].first.path 
     97    assert_not_equal "/", @response.headers["cookie"].first.path 
     98  end 
    8899end