Permalink
Browse files

Merge pull request #28 from econsultancy/econsultancy-20110119

Fix for issue 12
  • Loading branch information...
2 parents d196334 + 7edd5bc commit 362ec782feefcf243429a9b6eeccbe154d37cffe @brynary brynary committed May 23, 2011
Showing with 10 additions and 6 deletions.
  1. +6 −1 lib/rack/test/utils.rb
  2. +2 −4 spec/rack/test/multipart_spec.rb
  3. +2 −1 spec/rack/test/utils_spec.rb
View
@@ -103,12 +103,17 @@ def build_parts(parameters)
end
def build_primitive_part(parameter_name, value)
+ unless value.is_a? Array
+ value = [value]
+ end
+ value.map do |v|
<<-EOF
--#{MULTIPART_BOUNDARY}\r
Content-Disposition: form-data; name="#{parameter_name}"\r
\r
-#{value}\r
+#{v}\r
EOF
+ end.join
end
def build_file_part(parameter_name, uploaded_file)
@@ -42,10 +42,8 @@ def second_uploaded_file
end
it "sends params with arrays" do
- pending "FIXME: should work the same with and without multipart" do
- post "/", "photo" => uploaded_file, "foo" => ["1", "2"]
- last_request.POST["foo"].should == ["1", "2"]
- end
+ post "/", "photo" => uploaded_file, "foo" => ["1", "2"]
+ last_request.POST["foo"].should == ["1", "2"]
end
it "sends params with encoding sensitive values" do
@@ -89,7 +89,7 @@
it "builds nested multipart bodies" do
files = Rack::Test::UploadedFile.new(multipart_file("foo.txt"))
- data = build_multipart("people" => [{"submit-name" => "Larry", "files" => files}])
+ data = build_multipart("people" => [{"submit-name" => "Larry", "files" => files}], "foo" => ['1', '2'])
options = {
"CONTENT_TYPE" => "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}",
@@ -101,6 +101,7 @@
check params["people"][0]["submit-name"].should == "Larry"
check params["people"][0]["files"][:filename].should == "foo.txt"
params["people"][0]["files"][:tempfile].read.should == "bar\n"
+ check params["foo"].should == ["1", "2"]
end
it "returns nil if no UploadedFiles were used" do

0 comments on commit 362ec78

Please sign in to comment.