diff options
author | Lukas Oberhuber <lukas.oberhuber@simplybusiness.co.uk> | 2020-06-06 23:21:28 +0100 |
---|---|---|
committer | Lukas Oberhuber <lukas.oberhuber@simplybusiness.co.uk> | 2020-06-06 23:21:28 +0100 |
commit | 19de40a029ded49630b643e77f0f252178496abd (patch) | |
tree | 981ce5f0009c6ed57f6631d68369d239e07ff4e1 /test/spec_utils.rb | |
parent | 846e7662885985df512e360d5801395878a553e3 (diff) | |
download | rack-19de40a029ded49630b643e77f0f252178496abd.tar.gz |
Case insensitive fetch on HeaderHash
Diffstat (limited to 'test/spec_utils.rb')
-rw-r--r-- | test/spec_utils.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/spec_utils.rb b/test/spec_utils.rb index b39f4a00..66514761 100644 --- a/test/spec_utils.rb +++ b/test/spec_utils.rb @@ -639,6 +639,38 @@ describe Rack::Utils::HeaderHash do h.wont_include 'ETag' end + it "fetches values via case-insensitive keys" do + h = Rack::Utils::HeaderHash.new("Content-MD5" => "d5ff4e2a0 ...") + v = h.fetch("content-MD5", "nope") + v.must_equal "d5ff4e2a0 ..." + end + + it "fetches values via case-insensitive keys without defaults" do + h = Rack::Utils::HeaderHash.new("Content-MD5" => "d5ff4e2a0 ...") + v = h.fetch("content-MD5") + v.must_equal "d5ff4e2a0 ..." + end + + it "correctly raises an exception on fetch for a non-existent key" do + h = Rack::Utils::HeaderHash.new("Content-MD5" => "d5ff4e2a0 ...") + + -> { h.fetch("Set-Cookie") }.must_raise(KeyError) + end + + it "returns default on fetch miss" do + h = Rack::Utils::HeaderHash.new("Content-MD5" => "d5ff4e2a0 ...") + + v = h.fetch("Missing-Header", "default") + v.must_equal "default" + end + + it "returns default on fetch miss using block" do + h = Rack::Utils::HeaderHash.new("Content-MD5" => "d5ff4e2a0 ...") + + v = h.fetch("Missing-Header") { |el| "Didn't find #{el}" } + v.must_equal "Didn't find Missing-Header" + end + it "create deep HeaderHash copy on dup" do h1 = Rack::Utils::HeaderHash.new("Content-MD5" => "d5ff4e2a0 ...") h2 = h1.dup |