2010-08-26 9 views

Antwort

13

Dies ist der Code, der auf Rails 2.3.8 (der Test nicht Pass Zeilen kommentiert out) arbeitet:

test 'cookie testing should work' do 
    @request.cookies['foo'] = 'Foo' 
    # cookies['foo'] = 'Foo' 
    # this does not work to: CGI::Cookie.new('foo', 'bar') 
    get :index # does: cookies[:foo] = (cookies['foo'] || "") + " bar!" 
    # the cookie key in the controller can by a symbol, but not in the test 
    assert_response :success 
    assert_not_nil cookies['foo'], "Cookie with foo key should not be nil. Debug: Cookies=#{cookies.inspect}" 
    assert_equal "Foo bar!", cookies['foo'], "Debug: Cookies=#{cookies.inspect}" 
    # assert_not_nil @cookies['foo'], "Cookie with foo key should not be nil. Debug: Cookies=#{@cookies.inspect}" 
    # assert_not_nil @request.cookies['foo'], "Cookie with foo key should not be nil. Debug: Cookies=#{@request.cookies.inspect}" 
    # assert_equal "Foo bar!", @request.cookies['foo'], "Debug: Cookies=#{@request.cookies.inspect}" 
end 

Ich habe einige ziemlich lange Zeit damit verbringen, für die Antwort suchen.

+4

Nun, zehn Minuten scheint eine lange Zeit zu sein ;-)) – Arsen7

+2

Er he :) Ich habe bereits die Antwort, wenn ich es auf StackOverflow teilte;) –

+0

Hat mich verdammt noch mal um dieses herauszufinden, danke für die Hilfe – stephenmurdoch

Verwandte Themen