aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-18 20:10:52 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-18 20:10:52 +0000
commitf22f352ee3316a6f8da4b19e816802bc8d371db6 (patch)
tree1a72ace5d74539a255ce467413159b77b867ee47 /actionpack/test
parent8bf987140a40a523a34bb6a52dd23afb99f92331 (diff)
downloadrails-f22f352ee3316a6f8da4b19e816802bc8d371db6.tar.gz
rails-f22f352ee3316a6f8da4b19e816802bc8d371db6.tar.bz2
rails-f22f352ee3316a6f8da4b19e816802bc8d371db6.zip
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
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/test_test.rb27
-rw-r--r--actionpack/test/fixtures/multipart/mona_lisa.jpgbin0 -> 159528 bytes
2 files changed, 27 insertions, 0 deletions
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
diff --git a/actionpack/test/fixtures/multipart/mona_lisa.jpg b/actionpack/test/fixtures/multipart/mona_lisa.jpg
new file mode 100644
index 0000000000..5cf3bef3d0
--- /dev/null
+++ b/actionpack/test/fixtures/multipart/mona_lisa.jpg
Binary files differ