diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-01-02 18:46:01 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-01-02 18:46:01 -0600 |
commit | f7ee082bb3cde977a199b81207e5d12e1d7101b3 (patch) | |
tree | 11d4dd259411c9135396e3ba8de11dad35157671 | |
parent | 104898fcb7958bcb69ba0239d6de8aa37f2da9ba (diff) | |
download | rails-f7ee082bb3cde977a199b81207e5d12e1d7101b3.tar.gz rails-f7ee082bb3cde977a199b81207e5d12e1d7101b3.tar.bz2 rails-f7ee082bb3cde977a199b81207e5d12e1d7101b3.zip |
Add failing test for file uploads with unrewindable input
-rw-r--r-- | actionpack/test/controller/integration_upload_test.rb | 46 | ||||
-rw-r--r-- | actionpack/test/fixtures/multipart/hello.txt | 1 |
2 files changed, 37 insertions, 10 deletions
diff --git a/actionpack/test/controller/integration_upload_test.rb b/actionpack/test/controller/integration_upload_test.rb index 39d2e164e4..d579980c19 100644 --- a/actionpack/test/controller/integration_upload_test.rb +++ b/actionpack/test/controller/integration_upload_test.rb @@ -10,6 +10,10 @@ class UploadTestController < ActionController::Base SessionUploadTest.last_request_type = ActionController::Base.param_parsers[request.content_type] render :text => "got here" end + + def read + render :text => "File: #{params[:uploaded_data].read}" + end end class SessionUploadTest < ActionController::IntegrationTest @@ -19,21 +23,43 @@ class SessionUploadTest < ActionController::IntegrationTest attr_accessor :last_request_type end - # def setup - # @session = ActionController::Integration::Session.new - # end - def test_post_with_upload - uses_mocha "test_post_with_upload" do - ActiveSupport::Dependencies.stubs(:load?).returns(false) + def test_upload_and_read_file + with_test_routing do + post '/read', :uploaded_data => fixture_file_upload(FILES_DIR + "/hello.txt", "text/plain") + assert_equal "File: Hello", response.body + end + end + + # The lint wrapper is used in integration tests + # instead of a normal StringIO class + InputWrapper = Rack::Lint::InputWrapper + + def test_post_with_upload_with_unrewindable_input + InputWrapper.any_instance.expects(:rewind).raises(Errno::ESPIPE) + + with_test_routing do + post '/read', :uploaded_data => fixture_file_upload(FILES_DIR + "/hello.txt", "text/plain") + assert_equal "File: Hello", response.body + end + end + + def test_post_with_upload_with_params_parsing + with_test_routing do + params = { :uploaded_data => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") } + post '/update', params, :location => 'blah' + assert_equal(:multipart_form, SessionUploadTest.last_request_type) + end + end + + private + def with_test_routing with_routing do |set| set.draw do |map| map.update 'update', :controller => "upload_test", :action => "update", :method => :post + map.read 'read', :controller => "upload_test", :action => "read", :method => :post end - params = { :uploaded_data => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") } - post '/update', params, :location => 'blah' - assert_equal(:multipart_form, SessionUploadTest.last_request_type) + yield end end - end end diff --git a/actionpack/test/fixtures/multipart/hello.txt b/actionpack/test/fixtures/multipart/hello.txt new file mode 100644 index 0000000000..5ab2f8a432 --- /dev/null +++ b/actionpack/test/fixtures/multipart/hello.txt @@ -0,0 +1 @@ +Hello
\ No newline at end of file |