spec/rack/test/utils_spec.rb in rack-test-0.5.3 vs spec/rack/test/utils_spec.rb in rack-test-0.5.4
- old
+ new
@@ -31,10 +31,14 @@
it "converts arrays with multiple elements" do
build_nested_query(:a => [1, 2]).should == "a[]=1&a[]=2"
end
+ it "converts arrays with brackets '[]' in the name" do
+ build_nested_query("a[]" => [1, 2]).should == "a%5B%5D=1&a%5B%5D=2"
+ end
+
it "converts nested hashes" do
build_nested_query(:a => { :b => 1 }).should == "a[b]=1"
end
it "converts arrays nested in a hash" do
@@ -59,9 +63,29 @@
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
check params["submit-name"].should == "Larry"
check params["files"][:filename].should == "foo.txt"
params["files"][:tempfile].read.should == "bar\n"
+ end
+
+ it "builds multipart bodies from array of files" do
+ files = [Rack::Test::UploadedFile.new(multipart_file("foo.txt")), Rack::Test::UploadedFile.new(multipart_file("bar.txt"))]
+ data = build_multipart("submit-name" => "Larry", "files" => files)
+
+ options = {
+ "CONTENT_TYPE" => "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}",
+ "CONTENT_LENGTH" => data.length.to_s,
+ :input => StringIO.new(data)
+ }
+ env = Rack::MockRequest.env_for("/", options)
+ params = Rack::Utils::Multipart.parse_multipart(env)
+ check params["submit-name"].should == "Larry"
+
+ check params["files"][0][:filename].should == "foo.txt"
+ params["files"][0][:tempfile].read.should == "bar\n"
+
+ check params["files"][1][:filename].should == "bar.txt"
+ params["files"][1][:tempfile].read.should == "baz\n"
end
it "builds nested multipart bodies" do
files = Rack::Test::UploadedFile.new(multipart_file("foo.txt"))
data = build_multipart("people" => [{"submit-name" => "Larry", "files" => files}])