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

Changeset 21

Show
Ignore:
Timestamp:
11/26/04 02:09:38 (4 years ago)
Author:
david
Message:

Allow symbols to be used as keys for setting cookies

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/cookies.rb

    r20 r21  
    55  # 
    66  #   cookies["user_name"] = "david" # => Will set a simple session cookie 
    7   #   cookies["login"] = { "value" => "XJ-122", "expires" => Time.now + 360} # => Will set a cookie that expires in 1 hour 
     7  #   cookies["login"] = { :value => "XJ-122", :expires => Time.now + 360} # => Will set a cookie that expires in 1 hour 
    88  #    
    99  # Examples for reading: 
     
    1212  #   cookies.size         # => 2 
    1313  # 
    14   # All the options for setting cookies are: 
     14  # All the option symbols for setting cookies are: 
    1515  # 
    1616  # value:: the cookie's value or list of values (as an array). 
     
    4242    def []=(name, options) 
    4343      if options.is_a?(Hash) 
     44        options.each { |key, value| options[key.to_s] = value } 
    4445        options["name"] = name 
    4546      else 
  • trunk/actionpack/test/controller/cookie_test.rb

    r20 r21  
    1515    def authenticate_for_fourten_days 
    1616      cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) } 
     17      render_text "hello world" 
     18    end 
     19 
     20    def authenticate_for_fourten_days_with_symbols 
     21      cookies["user_name"] = { :value => "david", :expires => Time.local(2005, 10, 10) } 
    1722      render_text "hello world" 
    1823    end 
     
    5358  end 
    5459 
     60  def test_setting_cookie_for_fourteen_days_with_symbols 
     61    @request.action = "authenticate_for_fourten_days" 
     62    assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], process_request.headers["cookie"] 
     63  end 
     64 
    5565  def test_multiple_cookies 
    5666    @request.action = "set_multiple_cookies"