Skip to content
Browse files

Fix Rack::Request subclassing and memoization issues

  • Loading branch information...
1 parent df37a91 commit 7c03363f1002fdd690cac0c4cec850a8e54379c4 @josh josh committed Jan 31, 2009
Showing with 35 additions and 1 deletion.
  1. +5 −1 lib/rack/request.rb
  2. +30 −0 test/spec_rack_request.rb
View
6 lib/rack/request.rb
@@ -18,7 +18,11 @@ class Request
attr_reader :env
def self.new(env)
- env["rack.request"] ||= super
+ if self == Rack::Request
+ env["rack.request"] ||= super
+ else
+ super
+ end
end
def initialize(env)
View
30 test/spec_rack_request.rb
@@ -492,4 +492,34 @@
rack_request_object_id.should.be.equal env['rack.request'].object_id
req2.should.equal env['rack.request']
end
+
+ class MyRequest < Rack::Request
+ def params
+ {:foo => "bar"}
+ end
+ end
+
+ specify "should allow subclass request to be instantiated after parent request" do
+ env = Rack::MockRequest.env_for("/?foo=bar")
+
+ req1 = Rack::Request.new(env)
+ req1.GET.should.equal "foo" => "bar"
+ req1.params.should.equal "foo" => "bar"
+
+ req2 = MyRequest.new(env)
+ req2.GET.should.equal "foo" => "bar"
+ req2.params.should.equal :foo => "bar"
+ end
+
+ specify "should allow parent request to be instantiated after subclass request" do
+ env = Rack::MockRequest.env_for("/?foo=bar")
+
+ req1 = MyRequest.new(env)
+ req1.GET.should.equal "foo" => "bar"
+ req1.params.should.equal :foo => "bar"
+
+ req2 = Rack::Request.new(env)
+ req2.GET.should.equal "foo" => "bar"
+ req2.params.should.equal "foo" => "bar"
+ end
end

0 comments on commit 7c03363

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