aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/request/multipart_params_parsing_test.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-01-13 16:09:51 -0600
committerJoshua Peek <josh@joshpeek.com>2009-01-13 16:09:51 -0600
commit1adc1496f9152c893e1f08abcb1e5e7272829899 (patch)
tree85affcfeea0fd298b474e90e7e9870fcd2e60f77 /actionpack/test/controller/request/multipart_params_parsing_test.rb
parent5a43908c7414996354ca427354d98d789e0210e7 (diff)
downloadrails-1adc1496f9152c893e1f08abcb1e5e7272829899.tar.gz
rails-1adc1496f9152c893e1f08abcb1e5e7272829899.tar.bz2
rails-1adc1496f9152c893e1f08abcb1e5e7272829899.zip
Add RewindableInput wrapper to fix issues with middleware that impolitely eat up non-rewindable input
Diffstat (limited to 'actionpack/test/controller/request/multipart_params_parsing_test.rb')
-rw-r--r--actionpack/test/controller/request/multipart_params_parsing_test.rb45
1 files changed, 43 insertions, 2 deletions
diff --git a/actionpack/test/controller/request/multipart_params_parsing_test.rb b/actionpack/test/controller/request/multipart_params_parsing_test.rb
index ce28ff46fe..d976ab8512 100644
--- a/actionpack/test/controller/request/multipart_params_parsing_test.rb
+++ b/actionpack/test/controller/request/multipart_params_parsing_test.rb
@@ -123,14 +123,14 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
InputWrapper = Rack::Lint::InputWrapper
test "parses unwindable stream" do
- InputWrapper.any_instance.expects(:rewind).raises(Errno::ESPIPE)
+ InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
params = parse_multipart('large_text_file')
assert_equal %w(file foo), params.keys.sort
assert_equal 'bar', params['foo']
end
test "uploads and reads file with unwindable input" do
- InputWrapper.any_instance.expects(:rewind).raises(Errno::ESPIPE)
+ InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
with_test_routing do
post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
@@ -138,6 +138,26 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
end
end
+ test "passes through rack middleware and uploads file" do
+ with_muck_middleware do
+ with_test_routing do
+ post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
+ assert_equal "File: Hello", response.body
+ end
+ end
+ end
+
+ test "passes through rack middleware and uploads file with unwindable input" do
+ InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
+
+ with_muck_middleware do
+ with_test_routing do
+ post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
+ assert_equal "File: Hello", response.body
+ end
+ end
+ end
+
private
def fixture(name)
File.open(File.join(FIXTURE_PATH, name), 'rb') do |file|
@@ -164,4 +184,25 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
yield
end
end
+
+ class MuckMiddleware
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ req = Rack::Request.new(env)
+ req.params # Parse params
+ @app.call(env)
+ end
+ end
+
+ def with_muck_middleware
+ original_middleware = ActionController::Dispatcher.middleware
+ middleware = original_middleware.dup
+ middleware.use MuckMiddleware
+ ActionController::Dispatcher.middleware = middleware
+ yield
+ ActionController::Dispatcher.middleware = original_middleware
+ end
end