diff --git a/app/models/upload.rb b/app/models/upload.rb index 3611e98e4..53f35f403 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -260,7 +260,7 @@ class Upload < ActiveRecord::Base self.file_path = temp_file_path - if file.tempfile + if file.respond_to?(:tempfile) && file.tempfile FileUtils.cp(file.tempfile.path, file_path) else File.open(file_path, 'wb') do |out| diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index dba826462..5e9197c7d 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -64,7 +64,9 @@ class UploadsControllerTest < ActionController::TestCase context "create action" do should "create a new upload" do assert_difference("Upload.count", 1) do - post :create, {:upload => {:file => upload_jpeg("#{Rails.root}/test/files/test.jpg"), :tag_string => "aaa", :rating => "q", :source => "aaa"}}, {:user_id => @user.id} + file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg") + file.stubs(:tempfile).returns(file) + post :create, {:upload => {:file => file, :tag_string => "aaa", :rating => "q", :source => "aaa"}}, {:user_id => @user.id} end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 66e7adb60..e64bc3780 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -18,7 +18,7 @@ module UploadTestMethods define_method(:original_filename) {filename} define_method(:content_type) {content_type} end - + tempfile end diff --git a/tmp/test.jpg b/tmp/test.jpg deleted file mode 100644 index 253c508d9..000000000 Binary files a/tmp/test.jpg and /dev/null differ