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

Ticket #3685: delete_cookies_with_options.2.diff

File delete_cookies_with_options.2.diff, 1.7 kB (added by josh, 1 year ago)

Updated patch against [6372].

  • actionpack/test/controller/cookie_test.rb

    old new  
    3131      cookies.delete("user_name") 
    3232    end 
    3333 
     34    def delete_cookie_with_path 
     35      cookies.delete("user_name", :path => '/beaten') 
     36      render_text "hello world" 
     37    end 
     38 
    3439    def rescue_action(e)  
    3540      raise unless ActionController::MissingTemplate # No templates here, and we don't care about the output  
    3641    end 
     
    8590    assert_equal "david", jar["user_name"] 
    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 
  • actionpack/lib/action_controller/cookies.rb

    old new  
    6262    end 
    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 
    7072    private