vendor/rack/test/spec_rack_request.rb in relevance-castronaut-0.5.4 vs vendor/rack/test/spec_rack_request.rb in relevance-castronaut-0.6.0

- old
+ new

@@ -81,10 +81,30 @@ req.POST.should.be.empty req.params.should.equal "foo" => "quux" req.body.read.should.equal "foo=bar&quux=bla" end + specify "rewinds input after parsing POST data" do + input = StringIO.new("foo=bar&quux=bla") + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => 'application/x-www-form-urlencoded;foo=bar', + :input => input) + req.params.should.equal "foo" => "bar", "quux" => "bla" + input.read.should.equal "foo=bar&quux=bla" + end + + specify "does not rewind unwindable CGI input" do + input = StringIO.new("foo=bar&quux=bla") + input.instance_eval "undef :rewind" + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => 'application/x-www-form-urlencoded;foo=bar', + :input => input) + req.params.should.equal "foo" => "bar", "quux" => "bla" + end + specify "can get value by key from params with #[]" do req = Rack::Request.new \ Rack::MockRequest.env_for("?foo=quux") req['foo'].should.equal 'quux' req[:foo].should.equal 'quux' @@ -287,11 +307,11 @@ EOF req = Rack::Request.new Rack::MockRequest.env_for("/", "CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x", "CONTENT_LENGTH" => input.size, :input => input) - + req.POST["huge"][:tempfile].size.should.equal 32768 req.POST["mean"][:tempfile].size.should.equal 10 req.POST["mean"][:tempfile].read.should.equal "--AaB03xha" end @@ -395,7 +415,32 @@ parser.call("*").should.equal([["*", 1.0]]) parser.call("compress;q=0.5, gzip;q=1.0").should.equal([["compress", 0.5], ["gzip", 1.0]]) parser.call("gzip;q=1.0, identity; q=0.5, *;q=0").should.equal([["gzip", 1.0], ["identity", 0.5], ["*", 0] ]) lambda { parser.call("gzip ; q=1.0") }.should.raise(RuntimeError) + end + + specify 'should provide ip information' do + app = lambda { |env| + request = Rack::Request.new(env) + response = Rack::Response.new + response.write request.ip + response.finish + } + + mock = Rack::MockRequest.new(Rack::Lint.new(app)) + res = mock.get '/', 'REMOTE_ADDR' => '123.123.123.123' + res.body.should == '123.123.123.123' + + res = mock.get '/', + 'REMOTE_ADDR' => '123.123.123.123', + 'HTTP_X_FORWARDED_FOR' => '234.234.234.234' + + res.body.should == '234.234.234.234' + + res = mock.get '/', + 'REMOTE_ADDR' => '123.123.123.123', + 'HTTP_X_FORWARDED_FOR' => '234.234.234.234,212.212.212.212' + + res.body.should == '212.212.212.212' end end