Skip to content

Commit

Permalink
Add multipart tests for input that does not support rewinding
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jan 17, 2009
1 parent f622ae7 commit 0f99727
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/spec_rack_utils.rb
Expand Up @@ -214,9 +214,32 @@ def test_app2.context env; end
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params["submit-name"].should.equal "Larry"
params["files"][:filename].should.equal "file1.txt"
input.read.length.should.equal 197
end

specify "does not try to rewind input if it is not supported" do
options = multipart_fixture(:text)
input = options[:input]
input.instance_eval "undef :rewind"
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params["submit-name"].should.equal "Larry"
params["files"][:filename].should.equal "file1.txt"
end

specify "does not try to rewind input Apache/CGI input" do
options = multipart_fixture(:text)
input = options[:input]
input.instance_eval do
def rewind; raise Errno::ESPIPE; end
end
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params["submit-name"].should.equal "Larry"
params["files"][:filename].should.equal "file1.txt"
end

private
def multipart_fixture(name)
file = File.join(File.dirname(__FILE__), "multipart", name.to_s)
Expand Down

0 comments on commit 0f99727

Please sign in to comment.