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

Ticket #5924: cookies_symbols_and_strings_are_synonymous.diff

File cookies_symbols_and_strings_are_synonymous.diff, 1.5 kB (added by sandofsky, 2 years ago)

In tests, makes symbols and strings in cookies synonymous.

  • test/controller/cookie_test.rb

    old new  
    5959    assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"] 
    6060  end 
    6161 
     62  def test_cookie_keys_are_synonymous_as_strings_or_symbols 
     63    get :authenticate_for_fourten_days 
     64    assert_equal @response.cookies["user_name"], @response.cookies[:user_name] 
     65  end 
     66 
    6267  def test_setting_cookie_for_fourteen_days_with_symbols 
    6368    get :authenticate_for_fourten_days 
    6469    assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"] 
  • lib/action_controller/test_process.rb

    old new  
    252252    #  
    253253    # assert_equal ['AuthorOfNewPage'], r.cookies['author'].value 
    254254    def cookies 
    255       headers['cookie'].inject({}) { |hash, cookie| hash[cookie.name] = cookie; hash } 
     255      cookie_hash = Hash.new { |hash, key| key.kind_of?(Symbol) ? hash[key.to_s] : nil } 
     256      headers['cookie'].inject(cookie_hash) { |hash, cookie| hash[cookie.name] = cookie; hash } 
    256257    end 
    257258 
    258259    # Returns binary content (downloadable file), converted to a String