##// END OF EJS Templates
Merged r10501 from trunk...
Toshi MARUYAMA -
r10295:d69cae859f92
parent child
Show More
@@ -1,316 +1,321
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 User.current = nil
35 User.current = nil
36 set_fixtures_attachments_directory
36 set_fixtures_attachments_directory
37 end
37 end
38
38
39 def teardown
39 def teardown
40 set_tmp_attachments_directory
40 set_tmp_attachments_directory
41 end
41 end
42
42
43 def test_show_diff
43 def test_show_diff
44 ['inline', 'sbs'].each do |dt|
44 ['inline', 'sbs'].each do |dt|
45 # 060719210727_changeset_utf8.diff
45 # 060719210727_changeset_utf8.diff
46 get :show, :id => 14, :type => dt
46 get :show, :id => 14, :type => dt
47 assert_response :success
47 assert_response :success
48 assert_template 'diff'
48 assert_template 'diff'
49 assert_equal 'text/html', @response.content_type
49 assert_equal 'text/html', @response.content_type
50 assert_tag 'th',
50 assert_tag 'th',
51 :attributes => {:class => /filename/},
51 :attributes => {:class => /filename/},
52 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
52 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
53 assert_tag 'td',
53 assert_tag 'td',
54 :attributes => {:class => /line-code/},
54 :attributes => {:class => /line-code/},
55 :content => /Demande créée avec succès/
55 :content => /Demande créée avec succès/
56 end
56 end
57 set_tmp_attachments_directory
57 set_tmp_attachments_directory
58 end
58 end
59
59
60 def test_show_diff_replcace_cannot_convert_content
60 def test_show_diff_replcace_cannot_convert_content
61 with_settings :repositories_encodings => 'UTF-8' do
61 with_settings :repositories_encodings => 'UTF-8' do
62 ['inline', 'sbs'].each do |dt|
62 ['inline', 'sbs'].each do |dt|
63 # 060719210727_changeset_iso8859-1.diff
63 # 060719210727_changeset_iso8859-1.diff
64 get :show, :id => 5, :type => dt
64 get :show, :id => 5, :type => dt
65 assert_response :success
65 assert_response :success
66 assert_template 'diff'
66 assert_template 'diff'
67 assert_equal 'text/html', @response.content_type
67 assert_equal 'text/html', @response.content_type
68 assert_tag 'th',
68 assert_tag 'th',
69 :attributes => {:class => "filename"},
69 :attributes => {:class => "filename"},
70 :content => /issues_controller.rb\t\(r\?vision 1484\)/
70 :content => /issues_controller.rb\t\(r\?vision 1484\)/
71 assert_tag 'td',
71 assert_tag 'td',
72 :attributes => {:class => /line-code/},
72 :attributes => {:class => /line-code/},
73 :content => /Demande cr\?\?e avec succ\?s/
73 :content => /Demande cr\?\?e avec succ\?s/
74 end
74 end
75 end
75 end
76 set_tmp_attachments_directory
76 set_tmp_attachments_directory
77 end
77 end
78
78
79 def test_show_diff_latin_1
79 def test_show_diff_latin_1
80 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
80 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
81 ['inline', 'sbs'].each do |dt|
81 ['inline', 'sbs'].each do |dt|
82 # 060719210727_changeset_iso8859-1.diff
82 # 060719210727_changeset_iso8859-1.diff
83 get :show, :id => 5, :type => dt
83 get :show, :id => 5, :type => dt
84 assert_response :success
84 assert_response :success
85 assert_template 'diff'
85 assert_template 'diff'
86 assert_equal 'text/html', @response.content_type
86 assert_equal 'text/html', @response.content_type
87 assert_tag 'th',
87 assert_tag 'th',
88 :attributes => {:class => "filename"},
88 :attributes => {:class => "filename"},
89 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
89 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
90 assert_tag 'td',
90 assert_tag 'td',
91 :attributes => {:class => /line-code/},
91 :attributes => {:class => /line-code/},
92 :content => /Demande créée avec succès/
92 :content => /Demande créée avec succès/
93 end
93 end
94 end
94 end
95 set_tmp_attachments_directory
95 set_tmp_attachments_directory
96 end
96 end
97
97
98 def test_save_diff_type
98 def test_save_diff_type
99 @request.session[:user_id] = 1 # admin
99 user1 = User.find(1)
100 user1.pref[:diff_type] = nil
101 user1.preference.save
100 user = User.find(1)
102 user = User.find(1)
103 assert_nil user.pref[:diff_type]
104
105 @request.session[:user_id] = 1 # admin
101 get :show, :id => 5
106 get :show, :id => 5
102 assert_response :success
107 assert_response :success
103 assert_template 'diff'
108 assert_template 'diff'
104 user.reload
109 user.reload
105 assert_equal "inline", user.pref[:diff_type]
110 assert_equal "inline", user.pref[:diff_type]
106 get :show, :id => 5, :type => 'sbs'
111 get :show, :id => 5, :type => 'sbs'
107 assert_response :success
112 assert_response :success
108 assert_template 'diff'
113 assert_template 'diff'
109 user.reload
114 user.reload
110 assert_equal "sbs", user.pref[:diff_type]
115 assert_equal "sbs", user.pref[:diff_type]
111 end
116 end
112
117
113 def test_show_text_file
118 def test_show_text_file
114 get :show, :id => 4
119 get :show, :id => 4
115 assert_response :success
120 assert_response :success
116 assert_template 'file'
121 assert_template 'file'
117 assert_equal 'text/html', @response.content_type
122 assert_equal 'text/html', @response.content_type
118 set_tmp_attachments_directory
123 set_tmp_attachments_directory
119 end
124 end
120
125
121 def test_show_text_file_utf_8
126 def test_show_text_file_utf_8
122 set_tmp_attachments_directory
127 set_tmp_attachments_directory
123 a = Attachment.new(:container => Issue.find(1),
128 a = Attachment.new(:container => Issue.find(1),
124 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
129 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
125 :author => User.find(1))
130 :author => User.find(1))
126 assert a.save
131 assert a.save
127 assert_equal 'japanese-utf-8.txt', a.filename
132 assert_equal 'japanese-utf-8.txt', a.filename
128
133
129 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
134 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
130 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
135 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
131
136
132 get :show, :id => a.id
137 get :show, :id => a.id
133 assert_response :success
138 assert_response :success
134 assert_template 'file'
139 assert_template 'file'
135 assert_equal 'text/html', @response.content_type
140 assert_equal 'text/html', @response.content_type
136 assert_tag :tag => 'th',
141 assert_tag :tag => 'th',
137 :content => '1',
142 :content => '1',
138 :attributes => { :class => 'line-num' },
143 :attributes => { :class => 'line-num' },
139 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
144 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
140 end
145 end
141
146
142 def test_show_text_file_replcace_cannot_convert_content
147 def test_show_text_file_replcace_cannot_convert_content
143 set_tmp_attachments_directory
148 set_tmp_attachments_directory
144 with_settings :repositories_encodings => 'UTF-8' do
149 with_settings :repositories_encodings => 'UTF-8' do
145 a = Attachment.new(:container => Issue.find(1),
150 a = Attachment.new(:container => Issue.find(1),
146 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
151 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
147 :author => User.find(1))
152 :author => User.find(1))
148 assert a.save
153 assert a.save
149 assert_equal 'iso8859-1.txt', a.filename
154 assert_equal 'iso8859-1.txt', a.filename
150
155
151 get :show, :id => a.id
156 get :show, :id => a.id
152 assert_response :success
157 assert_response :success
153 assert_template 'file'
158 assert_template 'file'
154 assert_equal 'text/html', @response.content_type
159 assert_equal 'text/html', @response.content_type
155 assert_tag :tag => 'th',
160 assert_tag :tag => 'th',
156 :content => '7',
161 :content => '7',
157 :attributes => { :class => 'line-num' },
162 :attributes => { :class => 'line-num' },
158 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
163 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
159 end
164 end
160 end
165 end
161
166
162 def test_show_text_file_latin_1
167 def test_show_text_file_latin_1
163 set_tmp_attachments_directory
168 set_tmp_attachments_directory
164 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
169 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
165 a = Attachment.new(:container => Issue.find(1),
170 a = Attachment.new(:container => Issue.find(1),
166 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
171 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167 :author => User.find(1))
172 :author => User.find(1))
168 assert a.save
173 assert a.save
169 assert_equal 'iso8859-1.txt', a.filename
174 assert_equal 'iso8859-1.txt', a.filename
170
175
171 get :show, :id => a.id
176 get :show, :id => a.id
172 assert_response :success
177 assert_response :success
173 assert_template 'file'
178 assert_template 'file'
174 assert_equal 'text/html', @response.content_type
179 assert_equal 'text/html', @response.content_type
175 assert_tag :tag => 'th',
180 assert_tag :tag => 'th',
176 :content => '7',
181 :content => '7',
177 :attributes => { :class => 'line-num' },
182 :attributes => { :class => 'line-num' },
178 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
183 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
179 end
184 end
180 end
185 end
181
186
182 def test_show_text_file_should_send_if_too_big
187 def test_show_text_file_should_send_if_too_big
183 Setting.file_max_size_displayed = 512
188 Setting.file_max_size_displayed = 512
184 Attachment.find(4).update_attribute :filesize, 754.kilobyte
189 Attachment.find(4).update_attribute :filesize, 754.kilobyte
185
190
186 get :show, :id => 4
191 get :show, :id => 4
187 assert_response :success
192 assert_response :success
188 assert_equal 'application/x-ruby', @response.content_type
193 assert_equal 'application/x-ruby', @response.content_type
189 set_tmp_attachments_directory
194 set_tmp_attachments_directory
190 end
195 end
191
196
192 def test_show_other
197 def test_show_other
193 get :show, :id => 6
198 get :show, :id => 6
194 assert_response :success
199 assert_response :success
195 assert_equal 'application/octet-stream', @response.content_type
200 assert_equal 'application/octet-stream', @response.content_type
196 set_tmp_attachments_directory
201 set_tmp_attachments_directory
197 end
202 end
198
203
199 def test_show_file_from_private_issue_without_permission
204 def test_show_file_from_private_issue_without_permission
200 get :show, :id => 15
205 get :show, :id => 15
201 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
206 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
202 set_tmp_attachments_directory
207 set_tmp_attachments_directory
203 end
208 end
204
209
205 def test_show_file_from_private_issue_with_permission
210 def test_show_file_from_private_issue_with_permission
206 @request.session[:user_id] = 2
211 @request.session[:user_id] = 2
207 get :show, :id => 15
212 get :show, :id => 15
208 assert_response :success
213 assert_response :success
209 assert_tag 'h2', :content => /private.diff/
214 assert_tag 'h2', :content => /private.diff/
210 set_tmp_attachments_directory
215 set_tmp_attachments_directory
211 end
216 end
212
217
213 def test_show_file_without_container_should_be_denied
218 def test_show_file_without_container_should_be_denied
214 set_tmp_attachments_directory
219 set_tmp_attachments_directory
215 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
220 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
216
221
217 @request.session[:user_id] = 2
222 @request.session[:user_id] = 2
218 get :show, :id => attachment.id
223 get :show, :id => attachment.id
219 assert_response 403
224 assert_response 403
220 end
225 end
221
226
222 def test_show_invalid_should_respond_with_404
227 def test_show_invalid_should_respond_with_404
223 get :show, :id => 999
228 get :show, :id => 999
224 assert_response 404
229 assert_response 404
225 end
230 end
226
231
227 def test_download_text_file
232 def test_download_text_file
228 get :download, :id => 4
233 get :download, :id => 4
229 assert_response :success
234 assert_response :success
230 assert_equal 'application/x-ruby', @response.content_type
235 assert_equal 'application/x-ruby', @response.content_type
231 set_tmp_attachments_directory
236 set_tmp_attachments_directory
232 end
237 end
233
238
234 def test_download_version_file_with_issue_tracking_disabled
239 def test_download_version_file_with_issue_tracking_disabled
235 Project.find(1).disable_module! :issue_tracking
240 Project.find(1).disable_module! :issue_tracking
236 get :download, :id => 9
241 get :download, :id => 9
237 assert_response :success
242 assert_response :success
238 end
243 end
239
244
240 def test_download_should_assign_content_type_if_blank
245 def test_download_should_assign_content_type_if_blank
241 Attachment.find(4).update_attribute(:content_type, '')
246 Attachment.find(4).update_attribute(:content_type, '')
242
247
243 get :download, :id => 4
248 get :download, :id => 4
244 assert_response :success
249 assert_response :success
245 assert_equal 'text/x-ruby', @response.content_type
250 assert_equal 'text/x-ruby', @response.content_type
246 set_tmp_attachments_directory
251 set_tmp_attachments_directory
247 end
252 end
248
253
249 def test_download_missing_file
254 def test_download_missing_file
250 get :download, :id => 2
255 get :download, :id => 2
251 assert_response 404
256 assert_response 404
252 set_tmp_attachments_directory
257 set_tmp_attachments_directory
253 end
258 end
254
259
255 def test_anonymous_on_private_private
260 def test_anonymous_on_private_private
256 get :download, :id => 7
261 get :download, :id => 7
257 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
262 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
258 set_tmp_attachments_directory
263 set_tmp_attachments_directory
259 end
264 end
260
265
261 def test_destroy_issue_attachment
266 def test_destroy_issue_attachment
262 set_tmp_attachments_directory
267 set_tmp_attachments_directory
263 issue = Issue.find(3)
268 issue = Issue.find(3)
264 @request.session[:user_id] = 2
269 @request.session[:user_id] = 2
265
270
266 assert_difference 'issue.attachments.count', -1 do
271 assert_difference 'issue.attachments.count', -1 do
267 assert_difference 'Journal.count' do
272 assert_difference 'Journal.count' do
268 delete :destroy, :id => 1
273 delete :destroy, :id => 1
269 assert_redirected_to '/projects/ecookbook'
274 assert_redirected_to '/projects/ecookbook'
270 end
275 end
271 end
276 end
272 assert_nil Attachment.find_by_id(1)
277 assert_nil Attachment.find_by_id(1)
273 j = Journal.first(:order => 'id DESC')
278 j = Journal.first(:order => 'id DESC')
274 assert_equal issue, j.journalized
279 assert_equal issue, j.journalized
275 assert_equal 'attachment', j.details.first.property
280 assert_equal 'attachment', j.details.first.property
276 assert_equal '1', j.details.first.prop_key
281 assert_equal '1', j.details.first.prop_key
277 assert_equal 'error281.txt', j.details.first.old_value
282 assert_equal 'error281.txt', j.details.first.old_value
278 assert_equal User.find(2), j.user
283 assert_equal User.find(2), j.user
279 end
284 end
280
285
281 def test_destroy_wiki_page_attachment
286 def test_destroy_wiki_page_attachment
282 set_tmp_attachments_directory
287 set_tmp_attachments_directory
283 @request.session[:user_id] = 2
288 @request.session[:user_id] = 2
284 assert_difference 'Attachment.count', -1 do
289 assert_difference 'Attachment.count', -1 do
285 delete :destroy, :id => 3
290 delete :destroy, :id => 3
286 assert_response 302
291 assert_response 302
287 end
292 end
288 end
293 end
289
294
290 def test_destroy_project_attachment
295 def test_destroy_project_attachment
291 set_tmp_attachments_directory
296 set_tmp_attachments_directory
292 @request.session[:user_id] = 2
297 @request.session[:user_id] = 2
293 assert_difference 'Attachment.count', -1 do
298 assert_difference 'Attachment.count', -1 do
294 delete :destroy, :id => 8
299 delete :destroy, :id => 8
295 assert_response 302
300 assert_response 302
296 end
301 end
297 end
302 end
298
303
299 def test_destroy_version_attachment
304 def test_destroy_version_attachment
300 set_tmp_attachments_directory
305 set_tmp_attachments_directory
301 @request.session[:user_id] = 2
306 @request.session[:user_id] = 2
302 assert_difference 'Attachment.count', -1 do
307 assert_difference 'Attachment.count', -1 do
303 delete :destroy, :id => 9
308 delete :destroy, :id => 9
304 assert_response 302
309 assert_response 302
305 end
310 end
306 end
311 end
307
312
308 def test_destroy_without_permission
313 def test_destroy_without_permission
309 set_tmp_attachments_directory
314 set_tmp_attachments_directory
310 assert_no_difference 'Attachment.count' do
315 assert_no_difference 'Attachment.count' do
311 delete :destroy, :id => 3
316 delete :destroy, :id => 3
312 end
317 end
313 assert_response 302
318 assert_response 302
314 assert Attachment.find_by_id(3)
319 assert Attachment.find_by_id(3)
315 end
320 end
316 end
321 end
@@ -1,575 +1,580
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositoriesGitControllerTest < ActionController::TestCase
20 class RepositoriesGitControllerTest < ActionController::TestCase
21 tests RepositoriesController
21 tests RepositoriesController
22
22
23 fixtures :projects, :users, :roles, :members, :member_roles,
23 fixtures :projects, :users, :roles, :members, :member_roles,
24 :repositories, :enabled_modules
24 :repositories, :enabled_modules
25
25
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 PRJ_ID = 3
28 PRJ_ID = 3
29 CHAR_1_HEX = "\xc3\x9c"
29 CHAR_1_HEX = "\xc3\x9c"
30 NUM_REV = 28
30 NUM_REV = 28
31
31
32 ## Git, Mercurial and CVS path encodings are binary.
32 ## Git, Mercurial and CVS path encodings are binary.
33 ## Subversion supports URL encoding for path.
33 ## Subversion supports URL encoding for path.
34 ## Redmine Mercurial adapter and extension use URL encoding.
34 ## Redmine Mercurial adapter and extension use URL encoding.
35 ## Git accepts only binary path in command line parameter.
35 ## Git accepts only binary path in command line parameter.
36 ## So, there is no way to use binary command line parameter in JRuby.
36 ## So, there is no way to use binary command line parameter in JRuby.
37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
39
39
40 def setup
40 def setup
41 @ruby19_non_utf8_pass =
41 @ruby19_non_utf8_pass =
42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
43
43
44 User.current = nil
44 User.current = nil
45 @project = Project.find(PRJ_ID)
45 @project = Project.find(PRJ_ID)
46 @repository = Repository::Git.create(
46 @repository = Repository::Git.create(
47 :project => @project,
47 :project => @project,
48 :url => REPOSITORY_PATH,
48 :url => REPOSITORY_PATH,
49 :path_encoding => 'ISO-8859-1'
49 :path_encoding => 'ISO-8859-1'
50 )
50 )
51 assert @repository
51 assert @repository
52 @char_1 = CHAR_1_HEX.dup
52 @char_1 = CHAR_1_HEX.dup
53 if @char_1.respond_to?(:force_encoding)
53 if @char_1.respond_to?(:force_encoding)
54 @char_1.force_encoding('UTF-8')
54 @char_1.force_encoding('UTF-8')
55 end
55 end
56 end
56 end
57
57
58 def test_create_and_update
58 def test_create_and_update
59 @request.session[:user_id] = 1
59 @request.session[:user_id] = 1
60 assert_difference 'Repository.count' do
60 assert_difference 'Repository.count' do
61 post :create, :project_id => 'subproject1',
61 post :create, :project_id => 'subproject1',
62 :repository_scm => 'Git',
62 :repository_scm => 'Git',
63 :repository => {
63 :repository => {
64 :url => '/test',
64 :url => '/test',
65 :is_default => '0',
65 :is_default => '0',
66 :identifier => 'test-create',
66 :identifier => 'test-create',
67 :extra_report_last_commit => '1',
67 :extra_report_last_commit => '1',
68 }
68 }
69 end
69 end
70 assert_response 302
70 assert_response 302
71 repository = Repository.first(:order => 'id DESC')
71 repository = Repository.first(:order => 'id DESC')
72 assert_kind_of Repository::Git, repository
72 assert_kind_of Repository::Git, repository
73 assert_equal '/test', repository.url
73 assert_equal '/test', repository.url
74 assert_equal true, repository.extra_report_last_commit
74 assert_equal true, repository.extra_report_last_commit
75
75
76 put :update, :id => repository.id,
76 put :update, :id => repository.id,
77 :repository => {
77 :repository => {
78 :extra_report_last_commit => '0',
78 :extra_report_last_commit => '0',
79 :identifier => 'test-update',
79 :identifier => 'test-update',
80 }
80 }
81 assert_response 302
81 assert_response 302
82 repo2 = Repository.find(repository.id)
82 repo2 = Repository.find(repository.id)
83 assert_equal 'test-update', repo2.identifier
83 assert_equal 'test-update', repo2.identifier
84 assert_equal false, repo2.extra_report_last_commit
84 assert_equal false, repo2.extra_report_last_commit
85 end
85 end
86
86
87 if File.directory?(REPOSITORY_PATH)
87 if File.directory?(REPOSITORY_PATH)
88 ## Ruby uses ANSI api to fork a process on Windows.
88 ## Ruby uses ANSI api to fork a process on Windows.
89 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
89 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
90 ## and these are incompatible with ASCII.
90 ## and these are incompatible with ASCII.
91 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
91 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
92 ## http://code.google.com/p/msysgit/issues/detail?id=80
92 ## http://code.google.com/p/msysgit/issues/detail?id=80
93 ## So, Latin-1 path tests fail on Japanese Windows
93 ## So, Latin-1 path tests fail on Japanese Windows
94 WINDOWS_PASS = (Redmine::Platform.mswin? &&
94 WINDOWS_PASS = (Redmine::Platform.mswin? &&
95 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
95 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
96 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
96 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
97
97
98 def test_get_new
98 def test_get_new
99 @request.session[:user_id] = 1
99 @request.session[:user_id] = 1
100 @project.repository.destroy
100 @project.repository.destroy
101 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
101 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
102 assert_response :success
102 assert_response :success
103 assert_template 'new'
103 assert_template 'new'
104 assert_kind_of Repository::Git, assigns(:repository)
104 assert_kind_of Repository::Git, assigns(:repository)
105 assert assigns(:repository).new_record?
105 assert assigns(:repository).new_record?
106 end
106 end
107
107
108 def test_browse_root
108 def test_browse_root
109 assert_equal 0, @repository.changesets.count
109 assert_equal 0, @repository.changesets.count
110 @repository.fetch_changesets
110 @repository.fetch_changesets
111 @project.reload
111 @project.reload
112 assert_equal NUM_REV, @repository.changesets.count
112 assert_equal NUM_REV, @repository.changesets.count
113
113
114 get :show, :id => PRJ_ID
114 get :show, :id => PRJ_ID
115 assert_response :success
115 assert_response :success
116 assert_template 'show'
116 assert_template 'show'
117 assert_not_nil assigns(:entries)
117 assert_not_nil assigns(:entries)
118 assert_equal 9, assigns(:entries).size
118 assert_equal 9, assigns(:entries).size
119 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
119 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
120 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
120 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
121 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
121 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
122 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
122 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
123 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
123 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
124 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
124 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
125 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
125 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
126 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
126 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
127 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
127 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
128 assert_not_nil assigns(:changesets)
128 assert_not_nil assigns(:changesets)
129 assert assigns(:changesets).size > 0
129 assert assigns(:changesets).size > 0
130 end
130 end
131
131
132 def test_browse_branch
132 def test_browse_branch
133 assert_equal 0, @repository.changesets.count
133 assert_equal 0, @repository.changesets.count
134 @repository.fetch_changesets
134 @repository.fetch_changesets
135 @project.reload
135 @project.reload
136 assert_equal NUM_REV, @repository.changesets.count
136 assert_equal NUM_REV, @repository.changesets.count
137 get :show, :id => PRJ_ID, :rev => 'test_branch'
137 get :show, :id => PRJ_ID, :rev => 'test_branch'
138 assert_response :success
138 assert_response :success
139 assert_template 'show'
139 assert_template 'show'
140 assert_not_nil assigns(:entries)
140 assert_not_nil assigns(:entries)
141 assert_equal 4, assigns(:entries).size
141 assert_equal 4, assigns(:entries).size
142 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
142 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
143 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
143 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
144 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
144 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
145 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
145 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
146 assert_not_nil assigns(:changesets)
146 assert_not_nil assigns(:changesets)
147 assert assigns(:changesets).size > 0
147 assert assigns(:changesets).size > 0
148 end
148 end
149
149
150 def test_browse_tag
150 def test_browse_tag
151 assert_equal 0, @repository.changesets.count
151 assert_equal 0, @repository.changesets.count
152 @repository.fetch_changesets
152 @repository.fetch_changesets
153 @project.reload
153 @project.reload
154 assert_equal NUM_REV, @repository.changesets.count
154 assert_equal NUM_REV, @repository.changesets.count
155 [
155 [
156 "tag00.lightweight",
156 "tag00.lightweight",
157 "tag01.annotated",
157 "tag01.annotated",
158 ].each do |t1|
158 ].each do |t1|
159 get :show, :id => PRJ_ID, :rev => t1
159 get :show, :id => PRJ_ID, :rev => t1
160 assert_response :success
160 assert_response :success
161 assert_template 'show'
161 assert_template 'show'
162 assert_not_nil assigns(:entries)
162 assert_not_nil assigns(:entries)
163 assert assigns(:entries).size > 0
163 assert assigns(:entries).size > 0
164 assert_not_nil assigns(:changesets)
164 assert_not_nil assigns(:changesets)
165 assert assigns(:changesets).size > 0
165 assert assigns(:changesets).size > 0
166 end
166 end
167 end
167 end
168
168
169 def test_browse_directory
169 def test_browse_directory
170 assert_equal 0, @repository.changesets.count
170 assert_equal 0, @repository.changesets.count
171 @repository.fetch_changesets
171 @repository.fetch_changesets
172 @project.reload
172 @project.reload
173 assert_equal NUM_REV, @repository.changesets.count
173 assert_equal NUM_REV, @repository.changesets.count
174 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
174 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
175 assert_response :success
175 assert_response :success
176 assert_template 'show'
176 assert_template 'show'
177 assert_not_nil assigns(:entries)
177 assert_not_nil assigns(:entries)
178 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
178 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
179 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
179 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
180 assert_not_nil entry
180 assert_not_nil entry
181 assert_equal 'file', entry.kind
181 assert_equal 'file', entry.kind
182 assert_equal 'images/edit.png', entry.path
182 assert_equal 'images/edit.png', entry.path
183 assert_not_nil assigns(:changesets)
183 assert_not_nil assigns(:changesets)
184 assert assigns(:changesets).size > 0
184 assert assigns(:changesets).size > 0
185 end
185 end
186
186
187 def test_browse_at_given_revision
187 def test_browse_at_given_revision
188 assert_equal 0, @repository.changesets.count
188 assert_equal 0, @repository.changesets.count
189 @repository.fetch_changesets
189 @repository.fetch_changesets
190 @project.reload
190 @project.reload
191 assert_equal NUM_REV, @repository.changesets.count
191 assert_equal NUM_REV, @repository.changesets.count
192 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
192 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
193 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
193 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
194 assert_response :success
194 assert_response :success
195 assert_template 'show'
195 assert_template 'show'
196 assert_not_nil assigns(:entries)
196 assert_not_nil assigns(:entries)
197 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
197 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
198 assert_not_nil assigns(:changesets)
198 assert_not_nil assigns(:changesets)
199 assert assigns(:changesets).size > 0
199 assert assigns(:changesets).size > 0
200 end
200 end
201
201
202 def test_changes
202 def test_changes
203 get :changes, :id => PRJ_ID,
203 get :changes, :id => PRJ_ID,
204 :path => repository_path_hash(['images', 'edit.png'])[:param]
204 :path => repository_path_hash(['images', 'edit.png'])[:param]
205 assert_response :success
205 assert_response :success
206 assert_template 'changes'
206 assert_template 'changes'
207 assert_tag :tag => 'h2', :content => 'edit.png'
207 assert_tag :tag => 'h2', :content => 'edit.png'
208 end
208 end
209
209
210 def test_entry_show
210 def test_entry_show
211 get :entry, :id => PRJ_ID,
211 get :entry, :id => PRJ_ID,
212 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
212 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
213 assert_response :success
213 assert_response :success
214 assert_template 'entry'
214 assert_template 'entry'
215 # Line 19
215 # Line 19
216 assert_tag :tag => 'th',
216 assert_tag :tag => 'th',
217 :content => '11',
217 :content => '11',
218 :attributes => { :class => 'line-num' },
218 :attributes => { :class => 'line-num' },
219 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
219 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
220 end
220 end
221
221
222 def test_entry_show_latin_1
222 def test_entry_show_latin_1
223 if @ruby19_non_utf8_pass
223 if @ruby19_non_utf8_pass
224 puts_ruby19_non_utf8_pass()
224 puts_ruby19_non_utf8_pass()
225 elsif WINDOWS_PASS
225 elsif WINDOWS_PASS
226 puts WINDOWS_SKIP_STR
226 puts WINDOWS_SKIP_STR
227 elsif JRUBY_SKIP
227 elsif JRUBY_SKIP
228 puts JRUBY_SKIP_STR
228 puts JRUBY_SKIP_STR
229 else
229 else
230 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
230 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
231 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
231 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
232 get :entry, :id => PRJ_ID,
232 get :entry, :id => PRJ_ID,
233 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
233 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
234 :rev => r1
234 :rev => r1
235 assert_response :success
235 assert_response :success
236 assert_template 'entry'
236 assert_template 'entry'
237 assert_tag :tag => 'th',
237 assert_tag :tag => 'th',
238 :content => '1',
238 :content => '1',
239 :attributes => { :class => 'line-num' },
239 :attributes => { :class => 'line-num' },
240 :sibling => { :tag => 'td',
240 :sibling => { :tag => 'td',
241 :content => /test-#{@char_1}.txt/ }
241 :content => /test-#{@char_1}.txt/ }
242 end
242 end
243 end
243 end
244 end
244 end
245 end
245 end
246
246
247 def test_entry_download
247 def test_entry_download
248 get :entry, :id => PRJ_ID,
248 get :entry, :id => PRJ_ID,
249 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
249 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
250 :format => 'raw'
250 :format => 'raw'
251 assert_response :success
251 assert_response :success
252 # File content
252 # File content
253 assert @response.body.include?('WITHOUT ANY WARRANTY')
253 assert @response.body.include?('WITHOUT ANY WARRANTY')
254 end
254 end
255
255
256 def test_directory_entry
256 def test_directory_entry
257 get :entry, :id => PRJ_ID,
257 get :entry, :id => PRJ_ID,
258 :path => repository_path_hash(['sources'])[:param]
258 :path => repository_path_hash(['sources'])[:param]
259 assert_response :success
259 assert_response :success
260 assert_template 'show'
260 assert_template 'show'
261 assert_not_nil assigns(:entry)
261 assert_not_nil assigns(:entry)
262 assert_equal 'sources', assigns(:entry).name
262 assert_equal 'sources', assigns(:entry).name
263 end
263 end
264
264
265 def test_diff
265 def test_diff
266 assert_equal 0, @repository.changesets.count
266 assert_equal 0, @repository.changesets.count
267 @repository.fetch_changesets
267 @repository.fetch_changesets
268 @project.reload
268 @project.reload
269 assert_equal NUM_REV, @repository.changesets.count
269 assert_equal NUM_REV, @repository.changesets.count
270 # Full diff of changeset 2f9c0091
270 # Full diff of changeset 2f9c0091
271 ['inline', 'sbs'].each do |dt|
271 ['inline', 'sbs'].each do |dt|
272 get :diff,
272 get :diff,
273 :id => PRJ_ID,
273 :id => PRJ_ID,
274 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
274 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
275 :type => dt
275 :type => dt
276 assert_response :success
276 assert_response :success
277 assert_template 'diff'
277 assert_template 'diff'
278 # Line 22 removed
278 # Line 22 removed
279 assert_tag :tag => 'th',
279 assert_tag :tag => 'th',
280 :content => /22/,
280 :content => /22/,
281 :sibling => { :tag => 'td',
281 :sibling => { :tag => 'td',
282 :attributes => { :class => /diff_out/ },
282 :attributes => { :class => /diff_out/ },
283 :content => /def remove/ }
283 :content => /def remove/ }
284 assert_tag :tag => 'h2', :content => /2f9c0091/
284 assert_tag :tag => 'h2', :content => /2f9c0091/
285 end
285 end
286 end
286 end
287
287
288 def test_diff_with_rev_and_path
288 def test_diff_with_rev_and_path
289 assert_equal 0, @repository.changesets.count
289 assert_equal 0, @repository.changesets.count
290 @repository.fetch_changesets
290 @repository.fetch_changesets
291 @project.reload
291 @project.reload
292 assert_equal NUM_REV, @repository.changesets.count
292 assert_equal NUM_REV, @repository.changesets.count
293 with_settings :diff_max_lines_displayed => 1000 do
293 with_settings :diff_max_lines_displayed => 1000 do
294 # Full diff of changeset 2f9c0091
294 # Full diff of changeset 2f9c0091
295 ['inline', 'sbs'].each do |dt|
295 ['inline', 'sbs'].each do |dt|
296 get :diff,
296 get :diff,
297 :id => PRJ_ID,
297 :id => PRJ_ID,
298 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
298 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
299 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
299 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
300 :type => dt
300 :type => dt
301 assert_response :success
301 assert_response :success
302 assert_template 'diff'
302 assert_template 'diff'
303 # Line 22 removed
303 # Line 22 removed
304 assert_tag :tag => 'th',
304 assert_tag :tag => 'th',
305 :content => '22',
305 :content => '22',
306 :sibling => { :tag => 'td',
306 :sibling => { :tag => 'td',
307 :attributes => { :class => /diff_out/ },
307 :attributes => { :class => /diff_out/ },
308 :content => /def remove/ }
308 :content => /def remove/ }
309 assert_tag :tag => 'h2', :content => /2f9c0091/
309 assert_tag :tag => 'h2', :content => /2f9c0091/
310 end
310 end
311 end
311 end
312 end
312 end
313
313
314 def test_diff_truncated
314 def test_diff_truncated
315 assert_equal 0, @repository.changesets.count
315 assert_equal 0, @repository.changesets.count
316 @repository.fetch_changesets
316 @repository.fetch_changesets
317 @project.reload
317 @project.reload
318 assert_equal NUM_REV, @repository.changesets.count
318 assert_equal NUM_REV, @repository.changesets.count
319
319
320 with_settings :diff_max_lines_displayed => 5 do
320 with_settings :diff_max_lines_displayed => 5 do
321 # Truncated diff of changeset 2f9c0091
321 # Truncated diff of changeset 2f9c0091
322 with_cache do
322 with_cache do
323 with_settings :default_language => 'en' do
323 with_settings :default_language => 'en' do
324 get :diff, :id => PRJ_ID, :type => 'inline',
324 get :diff, :id => PRJ_ID, :type => 'inline',
325 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
325 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
326 assert_response :success
326 assert_response :success
327 assert @response.body.include?("... This diff was truncated")
327 assert @response.body.include?("... This diff was truncated")
328 end
328 end
329 with_settings :default_language => 'fr' do
329 with_settings :default_language => 'fr' do
330 get :diff, :id => PRJ_ID, :type => 'inline',
330 get :diff, :id => PRJ_ID, :type => 'inline',
331 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
331 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
332 assert_response :success
332 assert_response :success
333 assert ! @response.body.include?("... This diff was truncated")
333 assert ! @response.body.include?("... This diff was truncated")
334 assert @response.body.include?("... Ce diff")
334 assert @response.body.include?("... Ce diff")
335 end
335 end
336 end
336 end
337 end
337 end
338 end
338 end
339
339
340 def test_diff_two_revs
340 def test_diff_two_revs
341 assert_equal 0, @repository.changesets.count
341 assert_equal 0, @repository.changesets.count
342 @repository.fetch_changesets
342 @repository.fetch_changesets
343 @project.reload
343 @project.reload
344 assert_equal NUM_REV, @repository.changesets.count
344 assert_equal NUM_REV, @repository.changesets.count
345 ['inline', 'sbs'].each do |dt|
345 ['inline', 'sbs'].each do |dt|
346 get :diff,
346 get :diff,
347 :id => PRJ_ID,
347 :id => PRJ_ID,
348 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
348 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
349 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
349 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
350 :type => dt
350 :type => dt
351 assert_response :success
351 assert_response :success
352 assert_template 'diff'
352 assert_template 'diff'
353 diff = assigns(:diff)
353 diff = assigns(:diff)
354 assert_not_nil diff
354 assert_not_nil diff
355 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
355 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
356 end
356 end
357 end
357 end
358
358
359 def test_diff_latin_1
359 def test_diff_latin_1
360 if @ruby19_non_utf8_pass
360 if @ruby19_non_utf8_pass
361 puts_ruby19_non_utf8_pass()
361 puts_ruby19_non_utf8_pass()
362 else
362 else
363 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
363 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
364 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
364 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
365 ['inline', 'sbs'].each do |dt|
365 ['inline', 'sbs'].each do |dt|
366 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
366 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
367 assert_response :success
367 assert_response :success
368 assert_template 'diff'
368 assert_template 'diff'
369 assert_tag :tag => 'thead',
369 assert_tag :tag => 'thead',
370 :descendant => {
370 :descendant => {
371 :tag => 'th',
371 :tag => 'th',
372 :attributes => { :class => 'filename' } ,
372 :attributes => { :class => 'filename' } ,
373 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
373 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
374 },
374 },
375 :sibling => {
375 :sibling => {
376 :tag => 'tbody',
376 :tag => 'tbody',
377 :descendant => {
377 :descendant => {
378 :tag => 'td',
378 :tag => 'td',
379 :attributes => { :class => /diff_in/ },
379 :attributes => { :class => /diff_in/ },
380 :content => /test-#{@char_1}.txt/
380 :content => /test-#{@char_1}.txt/
381 }
381 }
382 }
382 }
383 end
383 end
384 end
384 end
385 end
385 end
386 end
386 end
387 end
387 end
388
388
389 def test_save_diff_type
389 def test_save_diff_type
390 @request.session[:user_id] = 1 # admin
390 user1 = User.find(1)
391 user1.pref[:diff_type] = nil
392 user1.preference.save
391 user = User.find(1)
393 user = User.find(1)
394 assert_nil user.pref[:diff_type]
395
396 @request.session[:user_id] = 1 # admin
392 get :diff,
397 get :diff,
393 :id => PRJ_ID,
398 :id => PRJ_ID,
394 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
399 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
395 assert_response :success
400 assert_response :success
396 assert_template 'diff'
401 assert_template 'diff'
397 user.reload
402 user.reload
398 assert_equal "inline", user.pref[:diff_type]
403 assert_equal "inline", user.pref[:diff_type]
399 get :diff,
404 get :diff,
400 :id => PRJ_ID,
405 :id => PRJ_ID,
401 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
406 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
402 :type => 'sbs'
407 :type => 'sbs'
403 assert_response :success
408 assert_response :success
404 assert_template 'diff'
409 assert_template 'diff'
405 user.reload
410 user.reload
406 assert_equal "sbs", user.pref[:diff_type]
411 assert_equal "sbs", user.pref[:diff_type]
407 end
412 end
408
413
409 def test_annotate
414 def test_annotate
410 get :annotate, :id => PRJ_ID,
415 get :annotate, :id => PRJ_ID,
411 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
416 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
412 assert_response :success
417 assert_response :success
413 assert_template 'annotate'
418 assert_template 'annotate'
414 # Line 24, changeset 2f9c0091
419 # Line 24, changeset 2f9c0091
415 assert_tag :tag => 'th', :content => '24',
420 assert_tag :tag => 'th', :content => '24',
416 :sibling => {
421 :sibling => {
417 :tag => 'td',
422 :tag => 'td',
418 :child => {
423 :child => {
419 :tag => 'a',
424 :tag => 'a',
420 :content => /2f9c0091/
425 :content => /2f9c0091/
421 }
426 }
422 }
427 }
423 assert_tag :tag => 'th', :content => '24',
428 assert_tag :tag => 'th', :content => '24',
424 :sibling => { :tag => 'td', :content => /jsmith/ }
429 :sibling => { :tag => 'td', :content => /jsmith/ }
425 assert_tag :tag => 'th', :content => '24',
430 assert_tag :tag => 'th', :content => '24',
426 :sibling => {
431 :sibling => {
427 :tag => 'td',
432 :tag => 'td',
428 :child => {
433 :child => {
429 :tag => 'a',
434 :tag => 'a',
430 :content => /2f9c0091/
435 :content => /2f9c0091/
431 }
436 }
432 }
437 }
433 assert_tag :tag => 'th', :content => '24',
438 assert_tag :tag => 'th', :content => '24',
434 :sibling => { :tag => 'td', :content => /watcher =/ }
439 :sibling => { :tag => 'td', :content => /watcher =/ }
435 end
440 end
436
441
437 def test_annotate_at_given_revision
442 def test_annotate_at_given_revision
438 assert_equal 0, @repository.changesets.count
443 assert_equal 0, @repository.changesets.count
439 @repository.fetch_changesets
444 @repository.fetch_changesets
440 @project.reload
445 @project.reload
441 assert_equal NUM_REV, @repository.changesets.count
446 assert_equal NUM_REV, @repository.changesets.count
442 get :annotate, :id => PRJ_ID, :rev => 'deff7',
447 get :annotate, :id => PRJ_ID, :rev => 'deff7',
443 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
448 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
444 assert_response :success
449 assert_response :success
445 assert_template 'annotate'
450 assert_template 'annotate'
446 assert_tag :tag => 'h2', :content => /@ deff712f/
451 assert_tag :tag => 'h2', :content => /@ deff712f/
447 end
452 end
448
453
449 def test_annotate_binary_file
454 def test_annotate_binary_file
450 get :annotate, :id => PRJ_ID,
455 get :annotate, :id => PRJ_ID,
451 :path => repository_path_hash(['images', 'edit.png'])[:param]
456 :path => repository_path_hash(['images', 'edit.png'])[:param]
452 assert_response 500
457 assert_response 500
453 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
458 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
454 :content => /cannot be annotated/
459 :content => /cannot be annotated/
455 end
460 end
456
461
457 def test_annotate_error_when_too_big
462 def test_annotate_error_when_too_big
458 with_settings :file_max_size_displayed => 1 do
463 with_settings :file_max_size_displayed => 1 do
459 get :annotate, :id => PRJ_ID,
464 get :annotate, :id => PRJ_ID,
460 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
465 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
461 :rev => 'deff712f'
466 :rev => 'deff712f'
462 assert_response 500
467 assert_response 500
463 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
468 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
464 :content => /exceeds the maximum text file size/
469 :content => /exceeds the maximum text file size/
465
470
466 get :annotate, :id => PRJ_ID,
471 get :annotate, :id => PRJ_ID,
467 :path => repository_path_hash(['README'])[:param],
472 :path => repository_path_hash(['README'])[:param],
468 :rev => '7234cb2'
473 :rev => '7234cb2'
469 assert_response :success
474 assert_response :success
470 assert_template 'annotate'
475 assert_template 'annotate'
471 end
476 end
472 end
477 end
473
478
474 def test_annotate_latin_1
479 def test_annotate_latin_1
475 if @ruby19_non_utf8_pass
480 if @ruby19_non_utf8_pass
476 puts_ruby19_non_utf8_pass()
481 puts_ruby19_non_utf8_pass()
477 elsif WINDOWS_PASS
482 elsif WINDOWS_PASS
478 puts WINDOWS_SKIP_STR
483 puts WINDOWS_SKIP_STR
479 elsif JRUBY_SKIP
484 elsif JRUBY_SKIP
480 puts JRUBY_SKIP_STR
485 puts JRUBY_SKIP_STR
481 else
486 else
482 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
487 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
483 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
488 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
484 get :annotate, :id => PRJ_ID,
489 get :annotate, :id => PRJ_ID,
485 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
490 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
486 :rev => r1
491 :rev => r1
487 assert_tag :tag => 'th',
492 assert_tag :tag => 'th',
488 :content => '1',
493 :content => '1',
489 :attributes => { :class => 'line-num' },
494 :attributes => { :class => 'line-num' },
490 :sibling => { :tag => 'td',
495 :sibling => { :tag => 'td',
491 :content => /test-#{@char_1}.txt/ }
496 :content => /test-#{@char_1}.txt/ }
492 end
497 end
493 end
498 end
494 end
499 end
495 end
500 end
496
501
497 def test_revision
502 def test_revision
498 assert_equal 0, @repository.changesets.count
503 assert_equal 0, @repository.changesets.count
499 @repository.fetch_changesets
504 @repository.fetch_changesets
500 @project.reload
505 @project.reload
501 assert_equal NUM_REV, @repository.changesets.count
506 assert_equal NUM_REV, @repository.changesets.count
502 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
507 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
503 get :revision, :id => PRJ_ID, :rev => r
508 get :revision, :id => PRJ_ID, :rev => r
504 assert_response :success
509 assert_response :success
505 assert_template 'revision'
510 assert_template 'revision'
506 end
511 end
507 end
512 end
508
513
509 def test_empty_revision
514 def test_empty_revision
510 assert_equal 0, @repository.changesets.count
515 assert_equal 0, @repository.changesets.count
511 @repository.fetch_changesets
516 @repository.fetch_changesets
512 @project.reload
517 @project.reload
513 assert_equal NUM_REV, @repository.changesets.count
518 assert_equal NUM_REV, @repository.changesets.count
514 ['', ' ', nil].each do |r|
519 ['', ' ', nil].each do |r|
515 get :revision, :id => PRJ_ID, :rev => r
520 get :revision, :id => PRJ_ID, :rev => r
516 assert_response 404
521 assert_response 404
517 assert_error_tag :content => /was not found/
522 assert_error_tag :content => /was not found/
518 end
523 end
519 end
524 end
520
525
521 def test_destroy_valid_repository
526 def test_destroy_valid_repository
522 @request.session[:user_id] = 1 # admin
527 @request.session[:user_id] = 1 # admin
523 assert_equal 0, @repository.changesets.count
528 assert_equal 0, @repository.changesets.count
524 @repository.fetch_changesets
529 @repository.fetch_changesets
525 @project.reload
530 @project.reload
526 assert_equal NUM_REV, @repository.changesets.count
531 assert_equal NUM_REV, @repository.changesets.count
527
532
528 assert_difference 'Repository.count', -1 do
533 assert_difference 'Repository.count', -1 do
529 delete :destroy, :id => @repository.id
534 delete :destroy, :id => @repository.id
530 end
535 end
531 assert_response 302
536 assert_response 302
532 @project.reload
537 @project.reload
533 assert_nil @project.repository
538 assert_nil @project.repository
534 end
539 end
535
540
536 def test_destroy_invalid_repository
541 def test_destroy_invalid_repository
537 @request.session[:user_id] = 1 # admin
542 @request.session[:user_id] = 1 # admin
538 @project.repository.destroy
543 @project.repository.destroy
539 @repository = Repository::Git.create!(
544 @repository = Repository::Git.create!(
540 :project => @project,
545 :project => @project,
541 :url => "/invalid",
546 :url => "/invalid",
542 :path_encoding => 'ISO-8859-1'
547 :path_encoding => 'ISO-8859-1'
543 )
548 )
544 @repository.fetch_changesets
549 @repository.fetch_changesets
545 @repository.reload
550 @repository.reload
546 assert_equal 0, @repository.changesets.count
551 assert_equal 0, @repository.changesets.count
547
552
548 assert_difference 'Repository.count', -1 do
553 assert_difference 'Repository.count', -1 do
549 delete :destroy, :id => @repository.id
554 delete :destroy, :id => @repository.id
550 end
555 end
551 assert_response 302
556 assert_response 302
552 @project.reload
557 @project.reload
553 assert_nil @project.repository
558 assert_nil @project.repository
554 end
559 end
555
560
556 private
561 private
557
562
558 def puts_ruby19_non_utf8_pass
563 def puts_ruby19_non_utf8_pass
559 puts "TODO: This test fails in Ruby 1.9 " +
564 puts "TODO: This test fails in Ruby 1.9 " +
560 "and Encoding.default_external is not UTF-8. " +
565 "and Encoding.default_external is not UTF-8. " +
561 "Current value is '#{Encoding.default_external.to_s}'"
566 "Current value is '#{Encoding.default_external.to_s}'"
562 end
567 end
563 else
568 else
564 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
569 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
565 def test_fake; assert true end
570 def test_fake; assert true end
566 end
571 end
567
572
568 private
573 private
569 def with_cache(&block)
574 def with_cache(&block)
570 before = ActionController::Base.perform_caching
575 before = ActionController::Base.perform_caching
571 ActionController::Base.perform_caching = true
576 ActionController::Base.perform_caching = true
572 block.call
577 block.call
573 ActionController::Base.perform_caching = before
578 ActionController::Base.perform_caching = before
574 end
579 end
575 end
580 end
General Comments 0
You need to be logged in to leave comments. Login now