Namespace
Methods
S
T
Instance Public methods
setup()
# File actionpack/test/dispatch/cookies_test.rb, line 207
def setup
  super
  @request.env["action_dispatch.key_generator"] = ActiveSupport::KeyGenerator.new("b3c631c314c0bbca50c1b2843150fe33", iterations: 2)
  @request.env["action_dispatch.signed_cookie_salt"] = "b3c631c314c0bbca50c1b2843150fe33"
  @request.env["action_dispatch.encrypted_cookie_salt"] = "b3c631c314c0bbca50c1b2843150fe33"
  @request.env["action_dispatch.encrypted_signed_cookie_salt"] = "b3c631c314c0bbca50c1b2843150fe33"
  @request.host = "www.nextangle.com"
end
test_can_set_request_cookies()
# File actionpack/test/dispatch/cookies_test.rb, line 1101
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 1073
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 1038
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 376
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 1128
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 1059
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 246
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 256
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_fetch()
# File actionpack/test/dispatch/cookies_test.rb, line 216
def test_fetch
  x = Object.new
  assert_not request.cookie_jar.key?('zzzzzz')
  assert_equal x, request.cookie_jar.fetch('zzzzzz', x)
  assert_not request.cookie_jar.key?('zzzzzz')
end
test_fetch_block()
# File actionpack/test/dispatch/cookies_test.rb, line 229
def test_fetch_block
  x = Object.new
  assert_not request.cookie_jar.key?('zzzzzz')
  assert_equal x, request.cookie_jar.fetch('zzzzzz') { x }
end
test_fetch_exists()
# File actionpack/test/dispatch/cookies_test.rb, line 223
def test_fetch_exists
  x = Object.new
  request.cookie_jar['foo'] = 'bar'
  assert_equal 'bar', request.cookie_jar.fetch('foo', x)
end
test_fetch_type_error()
# File actionpack/test/dispatch/cookies_test.rb, line 240
def test_fetch_type_error
  assert_raises(KeyError) do
    request.cookie_jar.fetch(:omglolwut)
  end
end
test_key_is_to_s()
# File actionpack/test/dispatch/cookies_test.rb, line 235
def test_key_is_to_s
  request.cookie_jar['foo'] = 'bar'
  assert_equal 'bar', request.cookie_jar.fetch(:foo)
end
test_key_methods()
# File actionpack/test/dispatch/cookies_test.rb, line 262
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 333
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 -0000\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 638
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 651
def test_raises_argument_error_if_missing_secret
  assert_raise(ArgumentError, nil.inspect) {
    @request.env["action_dispatch.key_generator"] = ActiveSupport::LegacyKeyGenerator.new(nil)
    get :set_signed_cookie
  }

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

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

  assert_raise(ArgumentError, "12345678901234567890123456789".inspect) {
    @request.env["action_dispatch.key_generator"] = ActiveSupport::LegacyKeyGenerator.new("12345678901234567890123456789")
    get :set_signed_cookie
  }
end
test_setting_request_cookies_is_indifferent_access()
# File actionpack/test/dispatch/cookies_test.rb, line 1047
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 289
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 644
def test_tampered_cookies
  assert_nothing_raised do
    get :tampered_cookies
    assert_response :success
  end
end