Skip to content

Commit

Permalink
Fix Rack::Request subclassing and memoization issues
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Feb 1, 2009
1 parent df37a91 commit 7c03363
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rack/request.rb
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions test/spec_rack_request.rb
Expand Up @@ -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.