##// END OF EJS Templates
attachment: add missing diff type at functional tests (#2371, #9612)...
Toshi MARUYAMA -
r7765:8a8162c74352
parent child
Show More
@@ -1,255 +1,255
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 require 'attachments_controller'
22 22
23 23 # Re-raise errors caught by the controller.
24 24 class AttachmentsController; def rescue_action(e) raise e end; end
25 25
26 26 class AttachmentsControllerTest < ActionController::TestCase
27 27 fixtures :users, :projects, :roles, :members, :member_roles,
28 28 :enabled_modules, :issues, :trackers, :attachments,
29 29 :versions, :wiki_pages, :wikis, :documents
30 30
31 31 def setup
32 32 @controller = AttachmentsController.new
33 33 @request = ActionController::TestRequest.new
34 34 @response = ActionController::TestResponse.new
35 35 Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
36 36 User.current = nil
37 37 end
38 38
39 39 def test_show_diff
40 40 ['inline', 'sbs'].each do |dt|
41 41 # 060719210727_changeset_utf8.diff
42 42 get :show, :id => 14, :type => dt
43 43 assert_response :success
44 44 assert_template 'diff'
45 45 assert_equal 'text/html', @response.content_type
46 46 assert_tag 'th',
47 47 :attributes => {:class => /filename/},
48 48 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
49 49 assert_tag 'td',
50 50 :attributes => {:class => /line-code/},
51 51 :content => /Demande créée avec succès/
52 52 end
53 53 end
54 54
55 55 def test_show_diff_replcace_cannot_convert_content
56 56 with_settings :repositories_encodings => 'UTF-8' do
57 57 ['inline', 'sbs'].each do |dt|
58 58 # 060719210727_changeset_iso8859-1.diff
59 get :show, :id => 5
59 get :show, :id => 5, :type => dt
60 60 assert_response :success
61 61 assert_template 'diff'
62 62 assert_equal 'text/html', @response.content_type
63 63 assert_tag 'th',
64 64 :attributes => {:class => "filename"},
65 65 :content => /issues_controller.rb\t\(r\?vision 1484\)/
66 66 assert_tag 'td',
67 67 :attributes => {:class => /line-code/},
68 68 :content => /Demande cr\?\?e avec succ\?s/
69 69 end
70 70 end
71 71 end
72 72
73 73 def test_show_diff_latin_1
74 74 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
75 75 ['inline', 'sbs'].each do |dt|
76 76 # 060719210727_changeset_iso8859-1.diff
77 get :show, :id => 5
77 get :show, :id => 5, :type => dt
78 78 assert_response :success
79 79 assert_template 'diff'
80 80 assert_equal 'text/html', @response.content_type
81 81 assert_tag 'th',
82 82 :attributes => {:class => "filename"},
83 83 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
84 84 assert_tag 'td',
85 85 :attributes => {:class => /line-code/},
86 86 :content => /Demande créée avec succès/
87 87 end
88 88 end
89 89 end
90 90
91 91 def test_show_text_file
92 92 get :show, :id => 4
93 93 assert_response :success
94 94 assert_template 'file'
95 95 assert_equal 'text/html', @response.content_type
96 96 end
97 97
98 98 def test_show_text_file_utf_8
99 99 set_tmp_attachments_directory
100 100 a = Attachment.new(:container => Issue.find(1),
101 101 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
102 102 :author => User.find(1))
103 103 assert a.save
104 104 assert_equal 'japanese-utf-8.txt', a.filename
105 105
106 106 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
107 107 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
108 108
109 109 get :show, :id => a.id
110 110 assert_response :success
111 111 assert_template 'file'
112 112 assert_equal 'text/html', @response.content_type
113 113 assert_tag :tag => 'th',
114 114 :content => '1',
115 115 :attributes => { :class => 'line-num' },
116 116 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
117 117 end
118 118
119 119 def test_show_text_file_replcace_cannot_convert_content
120 120 set_tmp_attachments_directory
121 121 with_settings :repositories_encodings => 'UTF-8' do
122 122 a = Attachment.new(:container => Issue.find(1),
123 123 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
124 124 :author => User.find(1))
125 125 assert a.save
126 126 assert_equal 'iso8859-1.txt', a.filename
127 127
128 128 get :show, :id => a.id
129 129 assert_response :success
130 130 assert_template 'file'
131 131 assert_equal 'text/html', @response.content_type
132 132 assert_tag :tag => 'th',
133 133 :content => '7',
134 134 :attributes => { :class => 'line-num' },
135 135 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
136 136 end
137 137 end
138 138
139 139 def test_show_text_file_latin_1
140 140 set_tmp_attachments_directory
141 141 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
142 142 a = Attachment.new(:container => Issue.find(1),
143 143 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
144 144 :author => User.find(1))
145 145 assert a.save
146 146 assert_equal 'iso8859-1.txt', a.filename
147 147
148 148 get :show, :id => a.id
149 149 assert_response :success
150 150 assert_template 'file'
151 151 assert_equal 'text/html', @response.content_type
152 152 assert_tag :tag => 'th',
153 153 :content => '7',
154 154 :attributes => { :class => 'line-num' },
155 155 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
156 156 end
157 157 end
158 158
159 159 def test_show_text_file_should_send_if_too_big
160 160 Setting.file_max_size_displayed = 512
161 161 Attachment.find(4).update_attribute :filesize, 754.kilobyte
162 162
163 163 get :show, :id => 4
164 164 assert_response :success
165 165 assert_equal 'application/x-ruby', @response.content_type
166 166 end
167 167
168 168 def test_show_other
169 169 get :show, :id => 6
170 170 assert_response :success
171 171 assert_equal 'application/octet-stream', @response.content_type
172 172 end
173 173
174 174 def test_show_file_from_private_issue_without_permission
175 175 get :show, :id => 15
176 176 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
177 177 end
178 178
179 179 def test_show_file_from_private_issue_with_permission
180 180 @request.session[:user_id] = 2
181 181 get :show, :id => 15
182 182 assert_response :success
183 183 assert_tag 'h2', :content => /private.diff/
184 184 end
185 185
186 186 def test_download_text_file
187 187 get :download, :id => 4
188 188 assert_response :success
189 189 assert_equal 'application/x-ruby', @response.content_type
190 190 end
191 191
192 192 def test_download_should_assign_content_type_if_blank
193 193 Attachment.find(4).update_attribute(:content_type, '')
194 194
195 195 get :download, :id => 4
196 196 assert_response :success
197 197 assert_equal 'text/x-ruby', @response.content_type
198 198 end
199 199
200 200 def test_download_missing_file
201 201 get :download, :id => 2
202 202 assert_response 404
203 203 end
204 204
205 205 def test_anonymous_on_private_private
206 206 get :download, :id => 7
207 207 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
208 208 end
209 209
210 210 def test_destroy_issue_attachment
211 211 issue = Issue.find(3)
212 212 @request.session[:user_id] = 2
213 213
214 214 assert_difference 'issue.attachments.count', -1 do
215 215 post :destroy, :id => 1
216 216 end
217 217 # no referrer
218 218 assert_redirected_to '/projects/ecookbook'
219 219 assert_nil Attachment.find_by_id(1)
220 220 j = issue.journals.find(:first, :order => 'created_on DESC')
221 221 assert_equal 'attachment', j.details.first.property
222 222 assert_equal '1', j.details.first.prop_key
223 223 assert_equal 'error281.txt', j.details.first.old_value
224 224 end
225 225
226 226 def test_destroy_wiki_page_attachment
227 227 @request.session[:user_id] = 2
228 228 assert_difference 'Attachment.count', -1 do
229 229 post :destroy, :id => 3
230 230 assert_response 302
231 231 end
232 232 end
233 233
234 234 def test_destroy_project_attachment
235 235 @request.session[:user_id] = 2
236 236 assert_difference 'Attachment.count', -1 do
237 237 post :destroy, :id => 8
238 238 assert_response 302
239 239 end
240 240 end
241 241
242 242 def test_destroy_version_attachment
243 243 @request.session[:user_id] = 2
244 244 assert_difference 'Attachment.count', -1 do
245 245 post :destroy, :id => 9
246 246 assert_response 302
247 247 end
248 248 end
249 249
250 250 def test_destroy_without_permission
251 251 post :destroy, :id => 3
252 252 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
253 253 assert Attachment.find_by_id(3)
254 254 end
255 255 end
General Comments 0
You need to be logged in to leave comments. Login now