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

Ticket #3685: delete_cookies_with_options.diff

File delete_cookies_with_options.diff, 1.7 kB (added by Chris Wanstrath, 2 years ago)
  • actionpack/test/controller/cookie_test.rb

    old new  
    3333      render_text "hello world" 
    3434    end 
    3535 
     36    def delete_cookie_with_path 
     37      cookies.delete("user_name", :path => '/beaten') 
     38      render_text "hello world" 
     39    end 
     40 
    3641    def rescue_action(e) raise end 
    3742  end 
    3843 
     
    7378    assert_nothing_raised { process_request } 
    7479  end 
    7580 
     81  def test_delete_cookie_with_path 
     82    @request.action = "delete_cookie_with_path" 
     83    assert_equal "/beaten", process_request.headers["cookie"].first.path 
     84    assert_not_equal "/", process_request.headers["cookie"].first.path 
     85  end 
     86 
    7687  private 
    7788    def process_request 
    7889      TestController.process(@request, @response) 
  • 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