Namespace
Methods
S
T
Instance Public methods
setup()
# File actionpack/test/dispatch/cookies_test.rb, line 145
def setup
  super
  @request.env["action_dispatch.secret_token"] = "b3c631c314c0bbca50c1b2843150fe33"
  @request.host = "www.nextangle.com"
end
test_can_set_request_cookies()
# File actionpack/test/dispatch/cookies_test.rb, line 523
def test_can_set_request_cookies
  @request.cookies['user_name'] = 'david'
  get :noop
  assert_equal 'david', cookies['user_name']
  assert_equal 'david', cookies[:user_name]

  get :noop
  assert_equal 'david', cookies['user_name']
  assert_equal 'david', cookies[:user_name]

  @request.cookies[:user_name] = 'andrew'
  get :noop
  assert_equal 'andrew', cookies['user_name']
  assert_equal 'andrew', cookies[:user_name]
end
test_cookies_can_be_cleared()
# File actionpack/test/dispatch/cookies_test.rb, line 495
def test_cookies_can_be_cleared
  get :symbol_key
  assert_equal "david", cookies[:user_name]

  cookies.clear
  get :noop
  assert_nil cookies[:user_name]

  get :symbol_key
  assert_equal "david", cookies[:user_name]
end
test_cookies_hash_is_indifferent_access()
# File actionpack/test/dispatch/cookies_test.rb, line 458
def test_cookies_hash_is_indifferent_access
    get :symbol_key
    assert_equal "david", cookies[:user_name]
    assert_equal "david", cookies['user_name']
    get :string_key
    assert_equal "dhh", cookies[:user_name]
    assert_equal "dhh", cookies['user_name']
end
test_cookies_persist_throughout_request()
# File actionpack/test/dispatch/cookies_test.rb, line 260
def test_cookies_persist_throughout_request
  response = get :authenticate
  assert response.headers["Set-Cookie"] =~ /user_name=david/
end
test_cookies_precedence_over_request_cookies()
# File actionpack/test/dispatch/cookies_test.rb, line 550
def test_cookies_precedence_over_request_cookies
  @request.cookies['user_name'] = 'andrew'
  get :authenticate
  assert_equal 'david', cookies['user_name']
  assert_equal 'david', cookies[:user_name]

  get :noop
  assert_equal 'david', cookies['user_name']
  assert_equal 'david', cookies[:user_name]
end
test_cookies_retained_across_requests()
# File actionpack/test/dispatch/cookies_test.rb, line 481
def test_cookies_retained_across_requests
  get :symbol_key
  assert_cookie_header "user_name=david; path=/"
  assert_equal "david", cookies[:user_name]

  get :noop
  assert_nil @response.headers["Set-Cookie"]
  assert_equal "david", cookies[:user_name]

  get :noop
  assert_nil @response.headers["Set-Cookie"]
  assert_equal "david", cookies[:user_name]
end
test_each()
# File actionpack/test/dispatch/cookies_test.rb, line 151
def test_each
  request.cookie_jar['foo'] = :bar
  list = []
  request.cookie_jar.each do |k,v|
    list << [k, v]
  end

  assert_equal [['foo', :bar]], list
end
test_enumerable()
# File actionpack/test/dispatch/cookies_test.rb, line 161
def test_enumerable
  request.cookie_jar['foo'] = :bar
  actual = request.cookie_jar.map { |k,v| [k.to_s, v.to_s] }
  assert_equal [['foo', 'bar']], actual
end
test_key_methods()
# File actionpack/test/dispatch/cookies_test.rb, line 167
def test_key_methods
  assert !request.cookie_jar.key?(:foo)
  assert !request.cookie_jar.has_key?("foo")

  request.cookie_jar[:foo] = :bar
  assert request.cookie_jar.key?(:foo)
  assert request.cookie_jar.has_key?("foo")
end
test_multiple_cookies()
# File actionpack/test/dispatch/cookies_test.rb, line 238
def test_multiple_cookies
  get :set_multiple_cookies
  assert_equal 2, @response.cookies.size
  assert_cookie_header "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT\nlogin=XJ-122; path=/"
  assert_equal({"login" => "XJ-122", "user_name" => "david"}, @response.cookies)
end
test_raise_data_overflow()
# File actionpack/test/dispatch/cookies_test.rb, line 293
def test_raise_data_overflow
  assert_raise(ActionDispatch::Cookies::CookieOverflow) do
    get :raise_data_overflow
  end
end
test_raises_argument_error_if_missing_secret()
# File actionpack/test/dispatch/cookies_test.rb, line 306
def test_raises_argument_error_if_missing_secret
  assert_raise(ArgumentError, nil.inspect) {
    @request.env["action_dispatch.secret_token"] = nil
    get :set_signed_cookie
  }

  assert_raise(ArgumentError, ''.inspect) {
    @request.env["action_dispatch.secret_token"] = ""
    get :set_signed_cookie
  }
end
test_raises_argument_error_if_secret_is_probably_insecure()
# File actionpack/test/dispatch/cookies_test.rb, line 318
def test_raises_argument_error_if_secret_is_probably_insecure
  assert_raise(ArgumentError, "password".inspect) {
    @request.env["action_dispatch.secret_token"] = "password"
    get :set_signed_cookie
  }

  assert_raise(ArgumentError, "secret".inspect) {
    @request.env["action_dispatch.secret_token"] = "secret"
    get :set_signed_cookie
  }

  assert_raise(ArgumentError, "12345678901234567890123456789".inspect) {
    @request.env["action_dispatch.secret_token"] = "12345678901234567890123456789"
    get :set_signed_cookie
  }
end
test_setting_request_cookies_is_indifferent_access()
# File actionpack/test/dispatch/cookies_test.rb, line 469
def test_setting_request_cookies_is_indifferent_access
  cookies.clear
  cookies[:user_name] = "andrew"
  get :string_key_mock
  assert_equal "david", cookies['user_name']

  cookies.clear
  cookies['user_name'] = "andrew"
  get :symbol_key_mock
  assert_equal "david", cookies[:user_name]
end
test_setting_with_escapable_characters()
# File actionpack/test/dispatch/cookies_test.rb, line 194
def test_setting_with_escapable_characters
  get :set_with_with_escapable_characters
  assert_cookie_header "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/"
  assert_equal({"that & guy" => "foo & bar => baz"}, @response.cookies)
end
test_tampered_cookies()
# File actionpack/test/dispatch/cookies_test.rb, line 299
def test_tampered_cookies
  assert_nothing_raised do
    get :tampered_cookies
    assert_response :success
  end
end