Refactor: extract test method
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3773 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
c56c0f411c
commit
cf334cee31
|
@ -12,10 +12,6 @@ class Attachment < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.generate_file
|
def self.generate_file
|
||||||
@file = 'a_file.png'
|
@file = mock_file
|
||||||
@file.stubs(:original_filename).returns('a_file.png')
|
|
||||||
@file.stubs(:content_type).returns('image/png')
|
|
||||||
@file.stubs(:read).returns(false)
|
|
||||||
@file
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,6 +61,16 @@ class ActiveSupport::TestCase
|
||||||
def uploaded_test_file(name, mime)
|
def uploaded_test_file(name, mime)
|
||||||
ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime)
|
ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Mock out a file
|
||||||
|
def mock_file
|
||||||
|
file = 'a_file.png'
|
||||||
|
file.stubs(:size).returns(32)
|
||||||
|
file.stubs(:original_filename).returns('a_file.png')
|
||||||
|
file.stubs(:content_type).returns('image/png')
|
||||||
|
file.stubs(:read).returns(false)
|
||||||
|
file
|
||||||
|
end
|
||||||
|
|
||||||
# Use a temporary directory for attachment related tests
|
# Use a temporary directory for attachment related tests
|
||||||
def set_tmp_attachments_directory
|
def set_tmp_attachments_directory
|
||||||
|
|
|
@ -68,17 +68,10 @@ class AttachmentTest < ActiveSupport::TestCase
|
||||||
should "add unsaved files to the object as unsaved attachments" do
|
should "add unsaved files to the object as unsaved attachments" do
|
||||||
# Max size of 0 to force Attachment creation failures
|
# Max size of 0 to force Attachment creation failures
|
||||||
with_settings(:attachment_max_size => 0) do
|
with_settings(:attachment_max_size => 0) do
|
||||||
# Mock out a file
|
|
||||||
@file = 'a_file.png'
|
|
||||||
@file.stubs(:size).returns(32)
|
|
||||||
@file.stubs(:original_filename).returns('a_file.png')
|
|
||||||
@file.stubs(:content_type).returns('image/png')
|
|
||||||
@file.stubs(:read).returns(false)
|
|
||||||
|
|
||||||
@project = Project.generate!
|
@project = Project.generate!
|
||||||
response = Attachment.attach_files(@project, {
|
response = Attachment.attach_files(@project, {
|
||||||
'1' => {'file' => @file, 'description' => 'test'},
|
'1' => {'file' => mock_file, 'description' => 'test'},
|
||||||
'2' => {'file' => @file, 'description' => 'test'}
|
'2' => {'file' => mock_file, 'description' => 'test'}
|
||||||
})
|
})
|
||||||
|
|
||||||
assert response[:unsaved].present?
|
assert response[:unsaved].present?
|
||||||
|
|
Loading…
Reference in New Issue