##// END OF EJS Templates
Merged r12139, r12140 and r12141 from trunk to 2.3-stable (#14931)...
Toshi MARUYAMA -
r11914:bcae8790916a
parent child
Show More
@@ -1,198 +1,187
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoriesBazaarControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :roles, :members, :member_roles,
24 24 :repositories, :enabled_modules
25 25
26 26 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s
27 27 PRJ_ID = 3
28 28
29 29 def setup
30 30 User.current = nil
31 31 @project = Project.find(PRJ_ID)
32 32 @repository = Repository::Bazaar.create(
33 33 :project => @project,
34 34 :url => REPOSITORY_PATH,
35 35 :log_encoding => 'UTF-8')
36 36 assert @repository
37 37 end
38 38
39 39 if File.directory?(REPOSITORY_PATH)
40 40 def test_get_new
41 41 @request.session[:user_id] = 1
42 42 @project.repository.destroy
43 43 get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
44 44 assert_response :success
45 45 assert_template 'new'
46 46 assert_kind_of Repository::Bazaar, assigns(:repository)
47 47 assert assigns(:repository).new_record?
48 48 end
49 49
50 50 def test_browse_root
51 51 get :show, :id => PRJ_ID
52 52 assert_response :success
53 53 assert_template 'show'
54 54 assert_not_nil assigns(:entries)
55 55 assert_equal 2, assigns(:entries).size
56 56 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
57 57 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
58 58 end
59 59
60 60 def test_browse_directory
61 61 get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param]
62 62 assert_response :success
63 63 assert_template 'show'
64 64 assert_not_nil assigns(:entries)
65 65 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
66 66 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
67 67 assert_not_nil entry
68 68 assert_equal 'file', entry.kind
69 69 assert_equal 'directory/edit.png', entry.path
70 70 end
71 71
72 72 def test_browse_at_given_revision
73 73 get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param],
74 74 :rev => 3
75 75 assert_response :success
76 76 assert_template 'show'
77 77 assert_not_nil assigns(:entries)
78 78 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
79 79 assigns(:entries).collect(&:name)
80 80 end
81 81
82 82 def test_changes
83 83 get :changes, :id => PRJ_ID,
84 84 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
85 85 assert_response :success
86 86 assert_template 'changes'
87 87 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
88 88 end
89 89
90 90 def test_entry_show
91 91 get :entry, :id => PRJ_ID,
92 92 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
93 93 assert_response :success
94 94 assert_template 'entry'
95 95 # Line 19
96 96 assert_tag :tag => 'th',
97 97 :content => /29/,
98 98 :attributes => { :class => /line-num/ },
99 99 :sibling => { :tag => 'td', :content => /Show help message/ }
100 100 end
101 101
102 102 def test_entry_download
103 103 get :entry, :id => PRJ_ID,
104 104 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
105 105 :format => 'raw'
106 106 assert_response :success
107 107 # File content
108 108 assert @response.body.include?('Show help message')
109 109 end
110 110
111 111 def test_directory_entry
112 112 get :entry, :id => PRJ_ID,
113 113 :path => repository_path_hash(['directory'])[:param]
114 114 assert_response :success
115 115 assert_template 'show'
116 116 assert_not_nil assigns(:entry)
117 117 assert_equal 'directory', assigns(:entry).name
118 118 end
119 119
120 120 def test_diff
121 121 # Full diff of changeset 3
122 122 ['inline', 'sbs'].each do |dt|
123 123 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
124 124 assert_response :success
125 125 assert_template 'diff'
126 126 # Line 11 removed
127 127 assert_tag :tag => 'th',
128 128 :content => '11',
129 129 :sibling => { :tag => 'td',
130 130 :attributes => { :class => /diff_out/ },
131 131 :content => /Display more information/ }
132 132 end
133 133 end
134 134
135 135 def test_annotate
136 136 get :annotate, :id => PRJ_ID,
137 137 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
138 138 assert_response :success
139 139 assert_template 'annotate'
140 assert_tag :tag => 'th', :content => '2',
141 :sibling => {
142 :tag => 'td',
143 :child => {
144 :tag => 'a',
145 :content => '3'
146 }
147 }
148 assert_tag :tag => 'th', :content => '2',
149 :sibling => { :tag => 'td', :content => /jsmith/ }
150 assert_tag :tag => 'th', :content => '2',
151 :sibling => {
152 :tag => 'td',
153 :child => {
154 :tag => 'a',
155 :content => '3'
156 }
157 }
158 assert_tag :tag => 'th', :content => '2',
159 :sibling => { :tag => 'td', :content => /Main purpose/ }
140 assert_select "th.line-num", :text => '2' do
141 assert_select "+ td.revision" do
142 assert_select "a", :text => '3'
143 assert_select "+ td.author", :text => "jsmith@" do
144 assert_select "+ td",
145 :text => "Main purpose:"
146 end
147 end
148 end
160 149 end
161 150
162 151 def test_destroy_valid_repository
163 152 @request.session[:user_id] = 1 # admin
164 153 assert_equal 0, @repository.changesets.count
165 154 @repository.fetch_changesets
166 155 assert @repository.changesets.count > 0
167 156
168 157 assert_difference 'Repository.count', -1 do
169 158 delete :destroy, :id => @repository.id
170 159 end
171 160 assert_response 302
172 161 @project.reload
173 162 assert_nil @project.repository
174 163 end
175 164
176 165 def test_destroy_invalid_repository
177 166 @request.session[:user_id] = 1 # admin
178 167 @project.repository.destroy
179 168 @repository = Repository::Bazaar.create!(
180 169 :project => @project,
181 170 :url => "/invalid",
182 171 :log_encoding => 'UTF-8')
183 172 @repository.fetch_changesets
184 173 @repository.reload
185 174 assert_equal 0, @repository.changesets.count
186 175
187 176 assert_difference 'Repository.count', -1 do
188 177 delete :destroy, :id => @repository.id
189 178 end
190 179 assert_response 302
191 180 @project.reload
192 181 assert_nil @project.repository
193 182 end
194 183 else
195 184 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
196 185 def test_fake; assert true end
197 186 end
198 187 end
@@ -1,525 +1,510
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoriesMercurialControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :roles, :members, :member_roles,
24 24 :repositories, :enabled_modules
25 25
26 26 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
27 27 CHAR_1_HEX = "\xc3\x9c"
28 28 PRJ_ID = 3
29 29 NUM_REV = 32
30 30
31 31 ruby19_non_utf8_pass =
32 32 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
33 33
34 34 def setup
35 35 User.current = nil
36 36 @project = Project.find(PRJ_ID)
37 37 @repository = Repository::Mercurial.create(
38 38 :project => @project,
39 39 :url => REPOSITORY_PATH,
40 40 :path_encoding => 'ISO-8859-1'
41 41 )
42 42 assert @repository
43 43 @diff_c_support = true
44 44 @char_1 = CHAR_1_HEX.dup
45 45 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
46 46 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
47 47 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
48 48 if @char_1.respond_to?(:force_encoding)
49 49 @char_1.force_encoding('UTF-8')
50 50 @tag_char_1.force_encoding('UTF-8')
51 51 @branch_char_0.force_encoding('UTF-8')
52 52 @branch_char_1.force_encoding('UTF-8')
53 53 end
54 54 end
55 55
56 56 if ruby19_non_utf8_pass
57 57 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
58 58 "and Encoding.default_external is not UTF-8. " +
59 59 "Current value is '#{Encoding.default_external.to_s}'"
60 60 def test_fake; assert true end
61 61 elsif File.directory?(REPOSITORY_PATH)
62 62
63 63 def test_get_new
64 64 @request.session[:user_id] = 1
65 65 @project.repository.destroy
66 66 get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial'
67 67 assert_response :success
68 68 assert_template 'new'
69 69 assert_kind_of Repository::Mercurial, assigns(:repository)
70 70 assert assigns(:repository).new_record?
71 71 end
72 72
73 73 def test_show_root
74 74 assert_equal 0, @repository.changesets.count
75 75 @repository.fetch_changesets
76 76 @project.reload
77 77 assert_equal NUM_REV, @repository.changesets.count
78 78 get :show, :id => PRJ_ID
79 79 assert_response :success
80 80 assert_template 'show'
81 81 assert_not_nil assigns(:entries)
82 82 assert_equal 4, assigns(:entries).size
83 83 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
84 84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
85 85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
86 86 assert_not_nil assigns(:changesets)
87 87 assert assigns(:changesets).size > 0
88 88 end
89 89
90 90 def test_show_directory
91 91 assert_equal 0, @repository.changesets.count
92 92 @repository.fetch_changesets
93 93 @project.reload
94 94 assert_equal NUM_REV, @repository.changesets.count
95 95 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
96 96 assert_response :success
97 97 assert_template 'show'
98 98 assert_not_nil assigns(:entries)
99 99 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
100 100 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
101 101 assert_not_nil entry
102 102 assert_equal 'file', entry.kind
103 103 assert_equal 'images/edit.png', entry.path
104 104 assert_not_nil assigns(:changesets)
105 105 assert assigns(:changesets).size > 0
106 106 end
107 107
108 108 def test_show_at_given_revision
109 109 assert_equal 0, @repository.changesets.count
110 110 @repository.fetch_changesets
111 111 @project.reload
112 112 assert_equal NUM_REV, @repository.changesets.count
113 113 [0, '0', '0885933ad4f6'].each do |r1|
114 114 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
115 115 :rev => r1
116 116 assert_response :success
117 117 assert_template 'show'
118 118 assert_not_nil assigns(:entries)
119 119 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
120 120 assert_not_nil assigns(:changesets)
121 121 assert assigns(:changesets).size > 0
122 122 end
123 123 end
124 124
125 125 def test_show_directory_sql_escape_percent
126 126 assert_equal 0, @repository.changesets.count
127 127 @repository.fetch_changesets
128 128 @project.reload
129 129 assert_equal NUM_REV, @repository.changesets.count
130 130 [13, '13', '3a330eb32958'].each do |r1|
131 131 get :show, :id => PRJ_ID,
132 132 :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param],
133 133 :rev => r1
134 134 assert_response :success
135 135 assert_template 'show'
136 136
137 137 assert_not_nil assigns(:entries)
138 138 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
139 139 assigns(:entries).collect(&:name)
140 140 changesets = assigns(:changesets)
141 141 assert_not_nil changesets
142 142 assert assigns(:changesets).size > 0
143 143 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
144 144 end
145 145 end
146 146
147 147 def test_show_directory_latin_1_path
148 148 assert_equal 0, @repository.changesets.count
149 149 @repository.fetch_changesets
150 150 @project.reload
151 151 assert_equal NUM_REV, @repository.changesets.count
152 152 [21, '21', 'adf805632193'].each do |r1|
153 153 get :show, :id => PRJ_ID,
154 154 :path => repository_path_hash(['latin-1-dir'])[:param],
155 155 :rev => r1
156 156 assert_response :success
157 157 assert_template 'show'
158 158
159 159 assert_not_nil assigns(:entries)
160 160 assert_equal ["make-latin-1-file.rb",
161 161 "test-#{@char_1}-1.txt",
162 162 "test-#{@char_1}-2.txt",
163 163 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
164 164 changesets = assigns(:changesets)
165 165 assert_not_nil changesets
166 166 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
167 167 end
168 168 end
169 169
170 170 def show_should_show_branch_selection_form
171 171 @repository.fetch_changesets
172 172 @project.reload
173 173 get :show, :id => PRJ_ID
174 174 assert_tag 'form', :attributes => {:id => 'revision_selector', :action => '/projects/subproject1/repository/show'}
175 175 assert_tag 'select', :attributes => {:name => 'branch'},
176 176 :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}},
177 177 :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}}
178 178 end
179 179
180 180 def test_show_branch
181 181 assert_equal 0, @repository.changesets.count
182 182 @repository.fetch_changesets
183 183 @project.reload
184 184 assert_equal NUM_REV, @repository.changesets.count
185 185 [
186 186 'default',
187 187 @branch_char_1,
188 188 'branch (1)[2]&,%.-3_4',
189 189 @branch_char_0,
190 190 'test_branch.latin-1',
191 191 'test-branch-00',
192 192 ].each do |bra|
193 193 get :show, :id => PRJ_ID, :rev => bra
194 194 assert_response :success
195 195 assert_template 'show'
196 196 assert_not_nil assigns(:entries)
197 197 assert assigns(:entries).size > 0
198 198 assert_not_nil assigns(:changesets)
199 199 assert assigns(:changesets).size > 0
200 200 end
201 201 end
202 202
203 203 def test_show_tag
204 204 assert_equal 0, @repository.changesets.count
205 205 @repository.fetch_changesets
206 206 @project.reload
207 207 assert_equal NUM_REV, @repository.changesets.count
208 208 [
209 209 @tag_char_1,
210 210 'tag_test.00',
211 211 'tag-init-revision'
212 212 ].each do |tag|
213 213 get :show, :id => PRJ_ID, :rev => tag
214 214 assert_response :success
215 215 assert_template 'show'
216 216 assert_not_nil assigns(:entries)
217 217 assert assigns(:entries).size > 0
218 218 assert_not_nil assigns(:changesets)
219 219 assert assigns(:changesets).size > 0
220 220 end
221 221 end
222 222
223 223 def test_changes
224 224 get :changes, :id => PRJ_ID,
225 225 :path => repository_path_hash(['images', 'edit.png'])[:param]
226 226 assert_response :success
227 227 assert_template 'changes'
228 228 assert_tag :tag => 'h2', :content => 'edit.png'
229 229 end
230 230
231 231 def test_entry_show
232 232 get :entry, :id => PRJ_ID,
233 233 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
234 234 assert_response :success
235 235 assert_template 'entry'
236 236 # Line 10
237 237 assert_tag :tag => 'th',
238 238 :content => '10',
239 239 :attributes => { :class => 'line-num' },
240 240 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
241 241 end
242 242
243 243 def test_entry_show_latin_1_path
244 244 [21, '21', 'adf805632193'].each do |r1|
245 245 get :entry, :id => PRJ_ID,
246 246 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
247 247 :rev => r1
248 248 assert_response :success
249 249 assert_template 'entry'
250 250 assert_tag :tag => 'th',
251 251 :content => '1',
252 252 :attributes => { :class => 'line-num' },
253 253 :sibling => { :tag => 'td',
254 254 :content => /Mercurial is a distributed version control system/ }
255 255 end
256 256 end
257 257
258 258 def test_entry_show_latin_1_contents
259 259 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
260 260 [27, '27', '7bbf4c738e71'].each do |r1|
261 261 get :entry, :id => PRJ_ID,
262 262 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
263 263 :rev => r1
264 264 assert_response :success
265 265 assert_template 'entry'
266 266 assert_tag :tag => 'th',
267 267 :content => '1',
268 268 :attributes => { :class => 'line-num' },
269 269 :sibling => { :tag => 'td',
270 270 :content => /test-#{@char_1}.txt/ }
271 271 end
272 272 end
273 273 end
274 274
275 275 def test_entry_download
276 276 get :entry, :id => PRJ_ID,
277 277 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
278 278 :format => 'raw'
279 279 assert_response :success
280 280 # File content
281 281 assert @response.body.include?('WITHOUT ANY WARRANTY')
282 282 end
283 283
284 284 def test_entry_binary_force_download
285 285 get :entry, :id => PRJ_ID, :rev => 1,
286 286 :path => repository_path_hash(['images', 'edit.png'])[:param]
287 287 assert_response :success
288 288 assert_equal 'image/png', @response.content_type
289 289 end
290 290
291 291 def test_directory_entry
292 292 get :entry, :id => PRJ_ID,
293 293 :path => repository_path_hash(['sources'])[:param]
294 294 assert_response :success
295 295 assert_template 'show'
296 296 assert_not_nil assigns(:entry)
297 297 assert_equal 'sources', assigns(:entry).name
298 298 end
299 299
300 300 def test_diff
301 301 assert_equal 0, @repository.changesets.count
302 302 @repository.fetch_changesets
303 303 @project.reload
304 304 assert_equal NUM_REV, @repository.changesets.count
305 305 [4, '4', 'def6d2f1254a'].each do |r1|
306 306 # Full diff of changeset 4
307 307 ['inline', 'sbs'].each do |dt|
308 308 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
309 309 assert_response :success
310 310 assert_template 'diff'
311 311 if @diff_c_support
312 312 # Line 22 removed
313 313 assert_tag :tag => 'th',
314 314 :content => '22',
315 315 :sibling => { :tag => 'td',
316 316 :attributes => { :class => /diff_out/ },
317 317 :content => /def remove/ }
318 318 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
319 319 end
320 320 end
321 321 end
322 322 end
323 323
324 324 def test_diff_two_revs
325 325 assert_equal 0, @repository.changesets.count
326 326 @repository.fetch_changesets
327 327 @project.reload
328 328 assert_equal NUM_REV, @repository.changesets.count
329 329 [2, '400bb8672109', '400', 400].each do |r1|
330 330 [4, 'def6d2f1254a'].each do |r2|
331 331 ['inline', 'sbs'].each do |dt|
332 332 get :diff,
333 333 :id => PRJ_ID,
334 334 :rev => r1,
335 335 :rev_to => r2,
336 336 :type => dt
337 337 assert_response :success
338 338 assert_template 'diff'
339 339 diff = assigns(:diff)
340 340 assert_not_nil diff
341 341 assert_tag :tag => 'h2',
342 342 :content => /4:def6d2f1254a 2:400bb8672109/
343 343 end
344 344 end
345 345 end
346 346 end
347 347
348 348 def test_diff_latin_1_path
349 349 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
350 350 [21, 'adf805632193'].each do |r1|
351 351 ['inline', 'sbs'].each do |dt|
352 352 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
353 353 assert_response :success
354 354 assert_template 'diff'
355 355 assert_tag :tag => 'thead',
356 356 :descendant => {
357 357 :tag => 'th',
358 358 :attributes => { :class => 'filename' } ,
359 359 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
360 360 },
361 361 :sibling => {
362 362 :tag => 'tbody',
363 363 :descendant => {
364 364 :tag => 'td',
365 365 :attributes => { :class => /diff_in/ },
366 366 :content => /It is written in Python/
367 367 }
368 368 }
369 369 end
370 370 end
371 371 end
372 372 end
373 373
374 374 def test_diff_should_show_modified_filenames
375 375 get :diff, :id => PRJ_ID, :rev => '400bb8672109', :type => 'inline'
376 376 assert_response :success
377 377 assert_template 'diff'
378 378 assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
379 379 end
380 380
381 381 def test_diff_should_show_deleted_filenames
382 382 get :diff, :id => PRJ_ID, :rev => 'b3a615152df8', :type => 'inline'
383 383 assert_response :success
384 384 assert_template 'diff'
385 385 assert_select 'th.filename', :text => 'sources/welcome_controller.rb'
386 386 end
387 387
388 388 def test_annotate
389 389 get :annotate, :id => PRJ_ID,
390 390 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
391 391 assert_response :success
392 392 assert_template 'annotate'
393 393
394 394 # Line 22, revision 4:def6d2f1254a
395 395 assert_select 'tr' do
396 396 assert_select 'th.line-num', :text => '22'
397 397 assert_select 'td.revision', :text => '4:def6d2f1254a'
398 398 assert_select 'td.author', :text => 'jsmith'
399 399 assert_select 'td', :text => /remove_watcher/
400 400 end
401 401 end
402 402
403 403 def test_annotate_not_in_tip
404 404 assert_equal 0, @repository.changesets.count
405 405 @repository.fetch_changesets
406 406 @project.reload
407 407 assert_equal NUM_REV, @repository.changesets.count
408 408 get :annotate, :id => PRJ_ID,
409 409 :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param]
410 410 assert_response 404
411 411 assert_error_tag :content => /was not found/
412 412 end
413 413
414 414 def test_annotate_at_given_revision
415 415 assert_equal 0, @repository.changesets.count
416 416 @repository.fetch_changesets
417 417 @project.reload
418 418 assert_equal NUM_REV, @repository.changesets.count
419 419 [2, '400bb8672109', '400', 400].each do |r1|
420 420 get :annotate, :id => PRJ_ID, :rev => r1,
421 421 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
422 422 assert_response :success
423 423 assert_template 'annotate'
424 424 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
425 425 end
426 426 end
427 427
428 428 def test_annotate_latin_1_path
429 429 [21, '21', 'adf805632193'].each do |r1|
430 430 get :annotate, :id => PRJ_ID,
431 431 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
432 432 :rev => r1
433 433 assert_response :success
434 434 assert_template 'annotate'
435 assert_tag :tag => 'th',
436 :content => '1',
437 :attributes => { :class => 'line-num' },
438 :sibling =>
439 {
440 :tag => 'td',
441 :attributes => { :class => 'revision' },
442 :child => { :tag => 'a', :content => '20:709858aafd1b' }
443 }
444 assert_tag :tag => 'th',
445 :content => '1',
446 :attributes => { :class => 'line-num' },
447 :sibling =>
448 {
449 :tag => 'td' ,
450 :content => 'jsmith' ,
451 :attributes => { :class => 'author' },
452 }
453 assert_tag :tag => 'th',
454 :content => '1',
455 :attributes => { :class => 'line-num' },
456 :sibling => { :tag => 'td',
457 :content => /Mercurial is a distributed version control system/ }
458
435 assert_select "th.line-num", :text => '1' do
436 assert_select "+ td.revision" do
437 assert_select "a", :text => '20:709858aafd1b'
438 assert_select "+ td.author", :text => "jsmith" do
439 assert_select "+ td",
440 :text => "Mercurial is a distributed version control system."
441 end
442 end
443 end
459 444 end
460 445 end
461 446
462 447 def test_annotate_latin_1_contents
463 448 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
464 449 [27, '7bbf4c738e71'].each do |r1|
465 450 get :annotate, :id => PRJ_ID,
466 451 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
467 452 :rev => r1
468 453 assert_tag :tag => 'th',
469 454 :content => '1',
470 455 :attributes => { :class => 'line-num' },
471 456 :sibling => { :tag => 'td',
472 457 :content => /test-#{@char_1}.txt/ }
473 458 end
474 459 end
475 460 end
476 461
477 462 def test_empty_revision
478 463 assert_equal 0, @repository.changesets.count
479 464 @repository.fetch_changesets
480 465 @project.reload
481 466 assert_equal NUM_REV, @repository.changesets.count
482 467 ['', ' ', nil].each do |r|
483 468 get :revision, :id => PRJ_ID, :rev => r
484 469 assert_response 404
485 470 assert_error_tag :content => /was not found/
486 471 end
487 472 end
488 473
489 474 def test_destroy_valid_repository
490 475 @request.session[:user_id] = 1 # admin
491 476 assert_equal 0, @repository.changesets.count
492 477 @repository.fetch_changesets
493 478 assert_equal NUM_REV, @repository.changesets.count
494 479
495 480 assert_difference 'Repository.count', -1 do
496 481 delete :destroy, :id => @repository.id
497 482 end
498 483 assert_response 302
499 484 @project.reload
500 485 assert_nil @project.repository
501 486 end
502 487
503 488 def test_destroy_invalid_repository
504 489 @request.session[:user_id] = 1 # admin
505 490 @project.repository.destroy
506 491 @repository = Repository::Mercurial.create!(
507 492 :project => Project.find(PRJ_ID),
508 493 :url => "/invalid",
509 494 :path_encoding => 'ISO-8859-1'
510 495 )
511 496 @repository.fetch_changesets
512 497 assert_equal 0, @repository.changesets.count
513 498
514 499 assert_difference 'Repository.count', -1 do
515 500 delete :destroy, :id => @repository.id
516 501 end
517 502 assert_response 302
518 503 @project.reload
519 504 assert_nil @project.repository
520 505 end
521 506 else
522 507 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
523 508 def test_fake; assert true end
524 509 end
525 510 end
General Comments 0
You need to be logged in to leave comments. Login now