summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/exemplars/attachment_exemplar.rb6
-rw-r--r--test/test_helper.rb10
-rw-r--r--test/unit/attachment_test.rb11
3 files changed, 13 insertions, 14 deletions
diff --git a/test/exemplars/attachment_exemplar.rb b/test/exemplars/attachment_exemplar.rb
index e86c4d32b..8100fe906 100644
--- a/test/exemplars/attachment_exemplar.rb
+++ b/test/exemplars/attachment_exemplar.rb
@@ -12,10 +12,6 @@ class Attachment < ActiveRecord::Base
end
def self.generate_file
- @file = 'a_file.png'
- @file.stubs(:original_filename).returns('a_file.png')
- @file.stubs(:content_type).returns('image/png')
- @file.stubs(:read).returns(false)
- @file
+ @file = mock_file
end
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index cb043fa89..1f735f5f6 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -61,6 +61,16 @@ class ActiveSupport::TestCase
def uploaded_test_file(name, mime)
ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime)
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
def set_tmp_attachments_directory
diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb
index f04aca4d4..b9ebbb67f 100644
--- a/test/unit/attachment_test.rb
+++ b/test/unit/attachment_test.rb
@@ -68,17 +68,10 @@ class AttachmentTest < ActiveSupport::TestCase
should "add unsaved files to the object as unsaved attachments" do
# Max size of 0 to force Attachment creation failures
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!
response = Attachment.attach_files(@project, {
- '1' => {'file' => @file, 'description' => 'test'},
- '2' => {'file' => @file, 'description' => 'test'}
+ '1' => {'file' => mock_file, 'description' => 'test'},
+ '2' => {'file' => mock_file, 'description' => 'test'}
})
assert response[:unsaved].present?