From f22f352ee3316a6f8da4b19e816802bc8d371db6 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 18 Mar 2006 20:10:52 +0000 Subject: Added easy support for testing file uploads with fixture_file_upload (closes #4105) [turnip@turnipspatch.com] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3939 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/test_test.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index 25c514d5a3..06a2ce3eb7 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -49,6 +49,10 @@ HTML def test_remote_addr render :text => (request.remote_addr || "not specified") end + + def test_file_upload + render :text => params[:file].size + end def rescue_action(e) raise e @@ -366,4 +370,27 @@ HTML end end end + + FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart' + + def test_test_uploaded_file + filename = 'mona_lisa.jpg' + path = "#{FILES_DIR}/#{filename}" + content_type = 'image/png' + + file = ActionController::TestUploadedFile.new(path, content_type) + assert_equal filename, file.original_filename + assert_equal content_type, file.content_type + assert_equal file.path, file.local_path + assert_equal File.read(path), file.read + end + + def test_fixture_file_upload + post :test_file_upload, :file => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") + assert_equal 159528, @response.body + end + + def test_test_uploaded_file_exception_when_file_doesnt_exist + assert_raise(RuntimeError) { ActionController::TestUploadedFile.new('non_existent_file') } + end end -- cgit v1.2.3