##// END OF EJS Templates
Refactor: extract test method...
Eric Davis -
r3659:cf334cee3189
parent child
Show More
@@ -12,10 +12,6 class Attachment < ActiveRecord::Base
12 end
12 end
13
13
14 def self.generate_file
14 def self.generate_file
15 @file = 'a_file.png'
15 @file = mock_file
16 @file.stubs(:original_filename).returns('a_file.png')
17 @file.stubs(:content_type).returns('image/png')
18 @file.stubs(:read).returns(false)
19 @file
20 end
16 end
21 end
17 end
@@ -61,6 +61,16 class ActiveSupport::TestCase
61 def uploaded_test_file(name, mime)
61 def uploaded_test_file(name, mime)
62 ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime)
62 ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime)
63 end
63 end
64
65 # Mock out a file
66 def mock_file
67 file = 'a_file.png'
68 file.stubs(:size).returns(32)
69 file.stubs(:original_filename).returns('a_file.png')
70 file.stubs(:content_type).returns('image/png')
71 file.stubs(:read).returns(false)
72 file
73 end
64
74
65 # Use a temporary directory for attachment related tests
75 # Use a temporary directory for attachment related tests
66 def set_tmp_attachments_directory
76 def set_tmp_attachments_directory
@@ -68,17 +68,10 class AttachmentTest < ActiveSupport::TestCase
68 should "add unsaved files to the object as unsaved attachments" do
68 should "add unsaved files to the object as unsaved attachments" do
69 # Max size of 0 to force Attachment creation failures
69 # Max size of 0 to force Attachment creation failures
70 with_settings(:attachment_max_size => 0) do
70 with_settings(:attachment_max_size => 0) do
71 # Mock out a file
72 @file = 'a_file.png'
73 @file.stubs(:size).returns(32)
74 @file.stubs(:original_filename).returns('a_file.png')
75 @file.stubs(:content_type).returns('image/png')
76 @file.stubs(:read).returns(false)
77
78 @project = Project.generate!
71 @project = Project.generate!
79 response = Attachment.attach_files(@project, {
72 response = Attachment.attach_files(@project, {
80 '1' => {'file' => @file, 'description' => 'test'},
73 '1' => {'file' => mock_file, 'description' => 'test'},
81 '2' => {'file' => @file, 'description' => 'test'}
74 '2' => {'file' => mock_file, 'description' => 'test'}
82 })
75 })
83
76
84 assert response[:unsaved].present?
77 assert response[:unsaved].present?
General Comments 0
You need to be logged in to leave comments. Login now