##// END OF EJS Templates
remove trailing white-spaces from test/unit/attachment_test.rb....
Toshi MARUYAMA -
r6585:e667cab36401
parent child
Show More
@@ -1,106 +1,106
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2011 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21
22 22 class AttachmentTest < ActiveSupport::TestCase
23 23 fixtures :issues, :users
24 24
25 25 def setup
26 26 end
27 27
28 28 def test_create
29 29 a = Attachment.new(:container => Issue.find(1),
30 30 :file => uploaded_test_file("testfile.txt", "text/plain"),
31 31 :author => User.find(1))
32 32 assert a.save
33 33 assert_equal 'testfile.txt', a.filename
34 34 assert_equal 59, a.filesize
35 35 assert_equal 'text/plain', a.content_type
36 36 assert_equal 0, a.downloads
37 37 assert_equal '1478adae0d4eb06d35897518540e25d6', a.digest
38 38 assert File.exist?(a.diskfile)
39 39 assert_equal 59, File.size(a.diskfile)
40 40 end
41 41
42 42 def test_create_should_auto_assign_content_type
43 43 a = Attachment.new(:container => Issue.find(1),
44 44 :file => uploaded_test_file("testfile.txt", ""),
45 45 :author => User.find(1))
46 46 assert a.save
47 47 assert_equal 'text/plain', a.content_type
48 48 end
49 49
50 50 def test_identical_attachments_at_the_same_time_should_not_overwrite
51 51 a1 = Attachment.create!(:container => Issue.find(1),
52 52 :file => uploaded_test_file("testfile.txt", ""),
53 53 :author => User.find(1))
54 54 a2 = Attachment.create!(:container => Issue.find(1),
55 55 :file => uploaded_test_file("testfile.txt", ""),
56 56 :author => User.find(1))
57 57 assert a1.disk_filename != a2.disk_filename
58 58 end
59 59
60 60 def test_diskfilename
61 61 assert Attachment.disk_filename("test_file.txt") =~ /^\d{12}_test_file.txt$/
62 62 assert_equal 'test_file.txt', Attachment.disk_filename("test_file.txt")[13..-1]
63 63 assert_equal '770c509475505f37c2b8fb6030434d6b.txt', Attachment.disk_filename("test_accentuΓ©.txt")[13..-1]
64 64 assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentuΓ©")[13..-1]
65 65 assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentuΓ©.Γ§a")[13..-1]
66 66 end
67 67
68 68 context "Attachmnet.attach_files" do
69 69 should "attach the file" do
70 70 issue = Issue.first
71 71 assert_difference 'Attachment.count' do
72 72 Attachment.attach_files(issue,
73 73 '1' => {
74 74 'file' => uploaded_test_file('testfile.txt', 'text/plain'),
75 75 'description' => 'test'
76 76 })
77 77 end
78
78
79 79 attachment = Attachment.first(:order => 'id DESC')
80 80 assert_equal issue, attachment.container
81 81 assert_equal 'testfile.txt', attachment.filename
82 82 assert_equal 59, attachment.filesize
83 83 assert_equal 'test', attachment.description
84 84 assert_equal 'text/plain', attachment.content_type
85 85 assert File.exists?(attachment.diskfile)
86 86 assert_equal 59, File.size(attachment.diskfile)
87 87 end
88
88
89 89 should "add unsaved files to the object as unsaved attachments" do
90 90 # Max size of 0 to force Attachment creation failures
91 91 with_settings(:attachment_max_size => 0) do
92 92 @project = Project.generate!
93 93 response = Attachment.attach_files(@project, {
94 94 '1' => {'file' => mock_file, 'description' => 'test'},
95 95 '2' => {'file' => mock_file, 'description' => 'test'}
96 96 })
97 97
98 98 assert response[:unsaved].present?
99 99 assert_equal 2, response[:unsaved].length
100 100 assert response[:unsaved].first.new_record?
101 101 assert response[:unsaved].second.new_record?
102 102 assert_equal response[:unsaved], @project.unsaved_attachments
103 103 end
104 104 end
105 105 end
106 106 end
General Comments 0
You need to be logged in to leave comments. Login now