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