From 4a4b2c1bde9ce00929df2d5458915e342b9c1ea1 Mon Sep 17 00:00:00 2001 From: Adam Tanner Date: Fri, 15 Mar 2013 16:01:48 -0400 Subject: [PATCH 1/2] Don't clobber uri.query when it's present. --- lib/rack/test.rb | 4 ++-- spec/rack/test_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/rack/test.rb b/lib/rack/test.rb index 6b010598..0d1054a1 100644 --- a/lib/rack/test.rb +++ b/lib/rack/test.rb @@ -209,8 +209,8 @@ def env_for(path, env) # merge :params with the query string if params = env[:params] params = parse_nested_query(params) if params.is_a?(String) - params.update(parse_nested_query(uri.query)) - uri.query = build_nested_query(params) + + uri.query = [uri.query, build_nested_query(params)].compact.join("&") end elsif !env.has_key?(:input) env["CONTENT_TYPE"] ||= "application/x-www-form-urlencoded" diff --git a/spec/rack/test_spec.rb b/spec/rack/test_spec.rb index ba862b28..377eb1f9 100644 --- a/spec/rack/test_spec.rb +++ b/spec/rack/test_spec.rb @@ -127,6 +127,11 @@ last_request.query_string.should == "a=1&b=2&c=3&e=4&d=5+%20" end + it "does not overwrite multiple query string keys" do + request "/foo?a=1&a=2", :params => { :bar => 1 } + last_request.query_string.should == "a=1&a=2&bar=1" + end + it "accepts params and builds url encoded params for POST requests" do request "/foo", :method => :post, :params => {:foo => {:bar => "1"}} last_request.env["rack.input"].read.should == "foo[bar]=1" From 55c1d95c12e5f5c9524998c897c5836584f820fa Mon Sep 17 00:00:00 2001 From: Adam Tanner Date: Sat, 30 Aug 2014 15:13:51 -0700 Subject: [PATCH 2/2] Fix Rakefile to only run rack-test specs. --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index d7197692..69f18bb7 100644 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,7 @@ require 'rspec/core' require "rspec/core/rake_task" RSpec::Core::RakeTask.new do |t| - t.pattern = "./**/*_spec.rb" + t.pattern = "spec/**/*_spec.rb" t.ruby_opts = "-w" end