Skip to content
Browse files

Fix Rack::Utils::HeaderHash#delete: it's supposed to return the delet…

…ed value, or nil if the key doesn't exist. [#54 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
1 parent e0322ed commit 07c18145496fe1833b20d31856f70a2bc50db18b @FooBarWidget FooBarWidget committed with josh Jun 17, 2009
Showing with 27 additions and 1 deletion.
  1. +3 −1 lib/rack/utils.rb
  2. +24 −0 test/spec_rack_utils.rb
View
4 lib/rack/utils.rb
@@ -211,6 +211,7 @@ def context(env, app=@app)
# header when set.
class HeaderHash < Hash
def initialize(hash={})
+ super()
@names = {}
hash.each { |k, v| self[k] = v }
end
@@ -238,8 +239,9 @@ def []=(k, v)
def delete(k)
canonical = k.downcase
- super @names.delete(canonical)
+ result = super @names.delete(canonical)
@names.delete_if { |name,| name.downcase == canonical }
+ result
end
def include?(k)
View
24 test/spec_rack_utils.rb
@@ -235,6 +235,30 @@
h.replace(j)
h["foo"].should.equal "bar"
end
+
+ specify "should be able to delete the given key case-sensitively" do
+ h = Rack::Utils::HeaderHash.new("foo" => "bar")
+ h.delete("foo")
+ h["foo"].should.be.nil
+ h["FOO"].should.be.nil
+ end
+
+ specify "should be able to delete the given key case-insensitively" do
+ h = Rack::Utils::HeaderHash.new("foo" => "bar")
+ h.delete("FOO")
+ h["foo"].should.be.nil
+ h["FOO"].should.be.nil
+ end
+
+ specify "should return the deleted value when #delete is called on an existing key" do
+ h = Rack::Utils::HeaderHash.new("foo" => "bar")
+ h.delete("Foo").should.equal("bar")
+ end
+
+ specify "should return nil when #delete is called on a non-existant key" do
+ h = Rack::Utils::HeaderHash.new("foo" => "bar")
+ h.delete("Hello").should.be.nil
+ end
end
context "Rack::Utils::Context" do

0 comments on commit 07c1814

Please sign in to comment.
Something went wrong with that request. Please try again.