Mercurial > hg > soundsoftware-site
comparison test/unit/attachment_test.rb @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | e248c7af89ec |
children | fb9a13467253 |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
20 require File.expand_path('../../test_helper', __FILE__) | 20 require File.expand_path('../../test_helper', __FILE__) |
21 | 21 |
22 class AttachmentTest < ActiveSupport::TestCase | 22 class AttachmentTest < ActiveSupport::TestCase |
23 fixtures :users, :projects, :roles, :members, :member_roles, | 23 fixtures :users, :projects, :roles, :members, :member_roles, |
24 :enabled_modules, :issues, :trackers, :attachments | 24 :enabled_modules, :issues, :trackers, :attachments |
25 | 25 |
26 class MockFile | 26 class MockFile |
27 attr_reader :original_filename, :content_type, :content, :size | 27 attr_reader :original_filename, :content_type, :content, :size |
28 | 28 |
29 def initialize(attributes) | 29 def initialize(attributes) |
30 @original_filename = attributes[:original_filename] | 30 @original_filename = attributes[:original_filename] |
31 @content_type = attributes[:content_type] | 31 @content_type = attributes[:content_type] |
32 @content = attributes[:content] || "Content" | 32 @content = attributes[:content] || "Content" |
33 @size = content.size | 33 @size = content.size |
151 a2 = Attachment.create!(:container => Issue.find(1), | 151 a2 = Attachment.create!(:container => Issue.find(1), |
152 :file => uploaded_test_file("testfile.txt", ""), | 152 :file => uploaded_test_file("testfile.txt", ""), |
153 :author => User.find(1)) | 153 :author => User.find(1)) |
154 assert a1.disk_filename != a2.disk_filename | 154 assert a1.disk_filename != a2.disk_filename |
155 end | 155 end |
156 | 156 |
157 def test_filename_should_be_basenamed | 157 def test_filename_should_be_basenamed |
158 a = Attachment.new(:file => MockFile.new(:original_filename => "path/to/the/file")) | 158 a = Attachment.new(:file => MockFile.new(:original_filename => "path/to/the/file")) |
159 assert_equal 'file', a.filename | 159 assert_equal 'file', a.filename |
160 end | 160 end |
161 | 161 |
162 def test_filename_should_be_sanitized | 162 def test_filename_should_be_sanitized |
163 a = Attachment.new(:file => MockFile.new(:original_filename => "valid:[] invalid:?%*|\"'<>chars")) | 163 a = Attachment.new(:file => MockFile.new(:original_filename => "valid:[] invalid:?%*|\"'<>chars")) |
164 assert_equal 'valid_[] invalid_chars', a.filename | 164 assert_equal 'valid_[] invalid_chars', a.filename |
165 end | 165 end |
166 | 166 |
212 '1' => { | 212 '1' => { |
213 'file' => uploaded_test_file('testfile.txt', 'text/plain'), | 213 'file' => uploaded_test_file('testfile.txt', 'text/plain'), |
214 'description' => 'test' | 214 'description' => 'test' |
215 }) | 215 }) |
216 end | 216 end |
217 | 217 attachment = Attachment.order('id DESC').first |
218 attachment = Attachment.first(:order => 'id DESC') | |
219 assert_equal issue, attachment.container | 218 assert_equal issue, attachment.container |
220 assert_equal 'testfile.txt', attachment.filename | 219 assert_equal 'testfile.txt', attachment.filename |
221 assert_equal 59, attachment.filesize | 220 assert_equal 59, attachment.filesize |
222 assert_equal 'test', attachment.description | 221 assert_equal 'test', attachment.description |
223 assert_equal 'text/plain', attachment.content_type | 222 assert_equal 'text/plain', attachment.content_type |
238 assert_equal 2, response[:unsaved].length | 237 assert_equal 2, response[:unsaved].length |
239 assert response[:unsaved].first.new_record? | 238 assert response[:unsaved].first.new_record? |
240 assert response[:unsaved].second.new_record? | 239 assert response[:unsaved].second.new_record? |
241 assert_equal response[:unsaved], @project.unsaved_attachments | 240 assert_equal response[:unsaved], @project.unsaved_attachments |
242 end | 241 end |
242 end | |
243 | |
244 test "Attachment.attach_files should preserve the content_type of attachments added by token" do | |
245 @project = Project.find(1) | |
246 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", ""), :author_id => 1, :created_on => 2.days.ago) | |
247 assert_equal 'text/plain', attachment.content_type | |
248 Attachment.attach_files(@project, { '1' => {'token' => attachment.token } }) | |
249 attachment.reload | |
250 assert_equal 'text/plain', attachment.content_type | |
243 end | 251 end |
244 | 252 |
245 def test_latest_attach | 253 def test_latest_attach |
246 set_fixtures_attachments_directory | 254 set_fixtures_attachments_directory |
247 a1 = Attachment.find(16) | 255 a1 = Attachment.find(16) |