aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/header_test.rb
blob: 4c06200a8815ea3d74953df8617fd6f27832d289 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'abstract_unit'

class HeaderTest < ActiveSupport::TestCase
  def setup
    @headers = ActionDispatch::Http::Headers.new(
      "HTTP_CONTENT_TYPE" => "text/plain"
    )
  end

  def test_each
    headers = []
    @headers.each { |pair| headers << pair }
    assert_equal [["HTTP_CONTENT_TYPE", "text/plain"]], headers
  end

  def test_setter
    @headers['foo'] = "bar"
    assert_equal "bar", @headers['foo']
  end

  def test_key?
    assert @headers.key?('HTTP_CONTENT_TYPE')
    assert @headers.include?('HTTP_CONTENT_TYPE')
  end

  test "content type" do
    assert_equal "text/plain", @headers["Content-Type"]
    assert_equal "text/plain", @headers["content-type"]
    assert_equal "text/plain", @headers["CONTENT_TYPE"]
    assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
  end

  test "fetch" do
    assert_equal "text/plain", @headers.fetch("content-type", nil)
    assert_equal "not found", @headers.fetch('not-found', 'not found')
  end
end