##// END OF EJS Templates
scm: git: define NUM_REV as the number of test repository revisions at functional test...
Toshi MARUYAMA -
r6989:7c579d13af6e
parent child
Show More
@@ -1,435 +1,436
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 require 'repositories_controller'
19 require 'repositories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
23
24 class RepositoriesGitControllerTest < ActionController::TestCase
24 class RepositoriesGitControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles,
25 fixtures :projects, :users, :roles, :members, :member_roles,
26 :repositories, :enabled_modules
26 :repositories, :enabled_modules
27
27
28 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
28 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 PRJ_ID = 3
30 PRJ_ID = 3
31 CHAR_1_HEX = "\xc3\x9c"
31 CHAR_1_HEX = "\xc3\x9c"
32 NUM_REV = 21
32
33
33 ## Git, Mercurial and CVS path encodings are binary.
34 ## Git, Mercurial and CVS path encodings are binary.
34 ## Subversion supports URL encoding for path.
35 ## Subversion supports URL encoding for path.
35 ## Redmine Mercurial adapter and extension use URL encoding.
36 ## Redmine Mercurial adapter and extension use URL encoding.
36 ## Git accepts only binary path in command line parameter.
37 ## Git accepts only binary path in command line parameter.
37 ## So, there is no way to use binary command line parameter in JRuby.
38 ## So, there is no way to use binary command line parameter in JRuby.
38 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
39 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
39 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
40 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
40
41
41 def setup
42 def setup
42 @ruby19_non_utf8_pass =
43 @ruby19_non_utf8_pass =
43 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
44 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
44
45
45 @controller = RepositoriesController.new
46 @controller = RepositoriesController.new
46 @request = ActionController::TestRequest.new
47 @request = ActionController::TestRequest.new
47 @response = ActionController::TestResponse.new
48 @response = ActionController::TestResponse.new
48 User.current = nil
49 User.current = nil
49 @project = Project.find(PRJ_ID)
50 @project = Project.find(PRJ_ID)
50 @repository = Repository::Git.create(
51 @repository = Repository::Git.create(
51 :project => @project,
52 :project => @project,
52 :url => REPOSITORY_PATH,
53 :url => REPOSITORY_PATH,
53 :path_encoding => 'ISO-8859-1'
54 :path_encoding => 'ISO-8859-1'
54 )
55 )
55 assert @repository
56 assert @repository
56 @char_1 = CHAR_1_HEX.dup
57 @char_1 = CHAR_1_HEX.dup
57 if @char_1.respond_to?(:force_encoding)
58 if @char_1.respond_to?(:force_encoding)
58 @char_1.force_encoding('UTF-8')
59 @char_1.force_encoding('UTF-8')
59 end
60 end
60
61
61 Setting.default_language = 'en'
62 Setting.default_language = 'en'
62 end
63 end
63
64
64 if File.directory?(REPOSITORY_PATH)
65 if File.directory?(REPOSITORY_PATH)
65 def test_browse_root
66 def test_browse_root
66 @repository.fetch_changesets
67 @repository.fetch_changesets
67 @repository.reload
68 @repository.reload
68 get :show, :id => PRJ_ID
69 get :show, :id => PRJ_ID
69 assert_response :success
70 assert_response :success
70 assert_template 'show'
71 assert_template 'show'
71 assert_not_nil assigns(:entries)
72 assert_not_nil assigns(:entries)
72 assert_equal 9, assigns(:entries).size
73 assert_equal 9, assigns(:entries).size
73 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
74 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
74 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
75 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
75 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
76 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
76 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
77 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
77 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
78 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
78 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
79 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
79 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
80 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
80 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
81 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
81 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
82 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
82 assert_not_nil assigns(:changesets)
83 assert_not_nil assigns(:changesets)
83 assert assigns(:changesets).size > 0
84 assert assigns(:changesets).size > 0
84 end
85 end
85
86
86 def test_browse_branch
87 def test_browse_branch
87 @repository.fetch_changesets
88 @repository.fetch_changesets
88 @repository.reload
89 @repository.reload
89 get :show, :id => PRJ_ID, :rev => 'test_branch'
90 get :show, :id => PRJ_ID, :rev => 'test_branch'
90 assert_response :success
91 assert_response :success
91 assert_template 'show'
92 assert_template 'show'
92 assert_not_nil assigns(:entries)
93 assert_not_nil assigns(:entries)
93 assert_equal 4, assigns(:entries).size
94 assert_equal 4, assigns(:entries).size
94 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
95 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
95 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
96 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
96 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
97 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
97 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
98 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
98 assert_not_nil assigns(:changesets)
99 assert_not_nil assigns(:changesets)
99 assert assigns(:changesets).size > 0
100 assert assigns(:changesets).size > 0
100 end
101 end
101
102
102 def test_browse_tag
103 def test_browse_tag
103 @repository.fetch_changesets
104 @repository.fetch_changesets
104 @repository.reload
105 @repository.reload
105 [
106 [
106 "tag00.lightweight",
107 "tag00.lightweight",
107 "tag01.annotated",
108 "tag01.annotated",
108 ].each do |t1|
109 ].each do |t1|
109 get :show, :id => PRJ_ID, :rev => t1
110 get :show, :id => PRJ_ID, :rev => t1
110 assert_response :success
111 assert_response :success
111 assert_template 'show'
112 assert_template 'show'
112 assert_not_nil assigns(:entries)
113 assert_not_nil assigns(:entries)
113 assert assigns(:entries).size > 0
114 assert assigns(:entries).size > 0
114 assert_not_nil assigns(:changesets)
115 assert_not_nil assigns(:changesets)
115 assert assigns(:changesets).size > 0
116 assert assigns(:changesets).size > 0
116 end
117 end
117 end
118 end
118
119
119 def test_browse_directory
120 def test_browse_directory
120 @repository.fetch_changesets
121 @repository.fetch_changesets
121 @repository.reload
122 @repository.reload
122 get :show, :id => PRJ_ID, :path => ['images']
123 get :show, :id => PRJ_ID, :path => ['images']
123 assert_response :success
124 assert_response :success
124 assert_template 'show'
125 assert_template 'show'
125 assert_not_nil assigns(:entries)
126 assert_not_nil assigns(:entries)
126 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
127 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
127 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
128 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
128 assert_not_nil entry
129 assert_not_nil entry
129 assert_equal 'file', entry.kind
130 assert_equal 'file', entry.kind
130 assert_equal 'images/edit.png', entry.path
131 assert_equal 'images/edit.png', entry.path
131 assert_not_nil assigns(:changesets)
132 assert_not_nil assigns(:changesets)
132 assert assigns(:changesets).size > 0
133 assert assigns(:changesets).size > 0
133 end
134 end
134
135
135 def test_browse_at_given_revision
136 def test_browse_at_given_revision
136 @repository.fetch_changesets
137 @repository.fetch_changesets
137 @repository.reload
138 @repository.reload
138 get :show, :id => PRJ_ID, :path => ['images'],
139 get :show, :id => PRJ_ID, :path => ['images'],
139 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
140 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
140 assert_response :success
141 assert_response :success
141 assert_template 'show'
142 assert_template 'show'
142 assert_not_nil assigns(:entries)
143 assert_not_nil assigns(:entries)
143 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
144 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
144 assert_not_nil assigns(:changesets)
145 assert_not_nil assigns(:changesets)
145 assert assigns(:changesets).size > 0
146 assert assigns(:changesets).size > 0
146 end
147 end
147
148
148 def test_changes
149 def test_changes
149 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
150 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
150 assert_response :success
151 assert_response :success
151 assert_template 'changes'
152 assert_template 'changes'
152 assert_tag :tag => 'h2', :content => 'edit.png'
153 assert_tag :tag => 'h2', :content => 'edit.png'
153 end
154 end
154
155
155 def test_entry_show
156 def test_entry_show
156 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
157 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
157 assert_response :success
158 assert_response :success
158 assert_template 'entry'
159 assert_template 'entry'
159 # Line 19
160 # Line 19
160 assert_tag :tag => 'th',
161 assert_tag :tag => 'th',
161 :content => '11',
162 :content => '11',
162 :attributes => { :class => 'line-num' },
163 :attributes => { :class => 'line-num' },
163 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
164 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
164 end
165 end
165
166
166 def test_entry_show_latin_1
167 def test_entry_show_latin_1
167 if @ruby19_non_utf8_pass
168 if @ruby19_non_utf8_pass
168 puts_ruby19_non_utf8_pass()
169 puts_ruby19_non_utf8_pass()
169 elsif JRUBY_SKIP
170 elsif JRUBY_SKIP
170 puts JRUBY_SKIP_STR
171 puts JRUBY_SKIP_STR
171 else
172 else
172 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
173 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
173 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
174 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
174 get :entry, :id => PRJ_ID,
175 get :entry, :id => PRJ_ID,
175 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
176 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
176 assert_response :success
177 assert_response :success
177 assert_template 'entry'
178 assert_template 'entry'
178 assert_tag :tag => 'th',
179 assert_tag :tag => 'th',
179 :content => '1',
180 :content => '1',
180 :attributes => { :class => 'line-num' },
181 :attributes => { :class => 'line-num' },
181 :sibling => { :tag => 'td',
182 :sibling => { :tag => 'td',
182 :content => /test-#{@char_1}.txt/ }
183 :content => /test-#{@char_1}.txt/ }
183 end
184 end
184 end
185 end
185 end
186 end
186 end
187 end
187
188
188 def test_entry_download
189 def test_entry_download
189 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
190 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
190 :format => 'raw'
191 :format => 'raw'
191 assert_response :success
192 assert_response :success
192 # File content
193 # File content
193 assert @response.body.include?('WITHOUT ANY WARRANTY')
194 assert @response.body.include?('WITHOUT ANY WARRANTY')
194 end
195 end
195
196
196 def test_directory_entry
197 def test_directory_entry
197 get :entry, :id => PRJ_ID, :path => ['sources']
198 get :entry, :id => PRJ_ID, :path => ['sources']
198 assert_response :success
199 assert_response :success
199 assert_template 'show'
200 assert_template 'show'
200 assert_not_nil assigns(:entry)
201 assert_not_nil assigns(:entry)
201 assert_equal 'sources', assigns(:entry).name
202 assert_equal 'sources', assigns(:entry).name
202 end
203 end
203
204
204 def test_diff
205 def test_diff
205 @repository.fetch_changesets
206 @repository.fetch_changesets
206 @repository.reload
207 @repository.reload
207 # Full diff of changeset 2f9c0091
208 # Full diff of changeset 2f9c0091
208 ['inline', 'sbs'].each do |dt|
209 ['inline', 'sbs'].each do |dt|
209 get :diff,
210 get :diff,
210 :id => PRJ_ID,
211 :id => PRJ_ID,
211 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
212 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
212 :type => dt
213 :type => dt
213 assert_response :success
214 assert_response :success
214 assert_template 'diff'
215 assert_template 'diff'
215 # Line 22 removed
216 # Line 22 removed
216 assert_tag :tag => 'th',
217 assert_tag :tag => 'th',
217 :content => /22/,
218 :content => /22/,
218 :sibling => { :tag => 'td',
219 :sibling => { :tag => 'td',
219 :attributes => { :class => /diff_out/ },
220 :attributes => { :class => /diff_out/ },
220 :content => /def remove/ }
221 :content => /def remove/ }
221 assert_tag :tag => 'h2', :content => /2f9c0091/
222 assert_tag :tag => 'h2', :content => /2f9c0091/
222 end
223 end
223 end
224 end
224
225
225 def test_diff_truncated
226 def test_diff_truncated
226 @repository.fetch_changesets
227 @repository.fetch_changesets
227 @repository.reload
228 @repository.reload
228 Setting.diff_max_lines_displayed = 5
229 Setting.diff_max_lines_displayed = 5
229
230
230 # Truncated diff of changeset 2f9c0091
231 # Truncated diff of changeset 2f9c0091
231 with_cache do
232 with_cache do
232 get :diff, :id => PRJ_ID, :type => 'inline',
233 get :diff, :id => PRJ_ID, :type => 'inline',
233 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
234 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
234 assert_response :success
235 assert_response :success
235 assert @response.body.include?("... This diff was truncated")
236 assert @response.body.include?("... This diff was truncated")
236
237
237 Setting.default_language = 'fr'
238 Setting.default_language = 'fr'
238 get :diff, :id => PRJ_ID, :type => 'inline',
239 get :diff, :id => PRJ_ID, :type => 'inline',
239 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
240 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
240 assert_response :success
241 assert_response :success
241 assert ! @response.body.include?("... This diff was truncated")
242 assert ! @response.body.include?("... This diff was truncated")
242 assert @response.body.include?("... Ce diff")
243 assert @response.body.include?("... Ce diff")
243 end
244 end
244 end
245 end
245
246
246 def test_diff_two_revs
247 def test_diff_two_revs
247 @repository.fetch_changesets
248 @repository.fetch_changesets
248 @repository.reload
249 @repository.reload
249 ['inline', 'sbs'].each do |dt|
250 ['inline', 'sbs'].each do |dt|
250 get :diff,
251 get :diff,
251 :id => PRJ_ID,
252 :id => PRJ_ID,
252 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
253 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
253 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
254 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
254 :type => dt
255 :type => dt
255 assert_response :success
256 assert_response :success
256 assert_template 'diff'
257 assert_template 'diff'
257 diff = assigns(:diff)
258 diff = assigns(:diff)
258 assert_not_nil diff
259 assert_not_nil diff
259 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
260 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
260 end
261 end
261 end
262 end
262
263
263 def test_diff_latin_1
264 def test_diff_latin_1
264 if @ruby19_non_utf8_pass
265 if @ruby19_non_utf8_pass
265 puts_ruby19_non_utf8_pass()
266 puts_ruby19_non_utf8_pass()
266 else
267 else
267 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
268 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
268 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
269 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
269 ['inline', 'sbs'].each do |dt|
270 ['inline', 'sbs'].each do |dt|
270 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
271 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
271 assert_response :success
272 assert_response :success
272 assert_template 'diff'
273 assert_template 'diff'
273 assert_tag :tag => 'thead',
274 assert_tag :tag => 'thead',
274 :descendant => {
275 :descendant => {
275 :tag => 'th',
276 :tag => 'th',
276 :attributes => { :class => 'filename' } ,
277 :attributes => { :class => 'filename' } ,
277 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
278 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
278 },
279 },
279 :sibling => {
280 :sibling => {
280 :tag => 'tbody',
281 :tag => 'tbody',
281 :descendant => {
282 :descendant => {
282 :tag => 'td',
283 :tag => 'td',
283 :attributes => { :class => /diff_in/ },
284 :attributes => { :class => /diff_in/ },
284 :content => /test-#{@char_1}.txt/
285 :content => /test-#{@char_1}.txt/
285 }
286 }
286 }
287 }
287 end
288 end
288 end
289 end
289 end
290 end
290 end
291 end
291 end
292 end
292
293
293 def test_annotate
294 def test_annotate
294 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
295 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
295 assert_response :success
296 assert_response :success
296 assert_template 'annotate'
297 assert_template 'annotate'
297 # Line 24, changeset 2f9c0091
298 # Line 24, changeset 2f9c0091
298 assert_tag :tag => 'th', :content => '24',
299 assert_tag :tag => 'th', :content => '24',
299 :sibling => {
300 :sibling => {
300 :tag => 'td',
301 :tag => 'td',
301 :child => {
302 :child => {
302 :tag => 'a',
303 :tag => 'a',
303 :content => /2f9c0091/
304 :content => /2f9c0091/
304 }
305 }
305 }
306 }
306 assert_tag :tag => 'th', :content => '24',
307 assert_tag :tag => 'th', :content => '24',
307 :sibling => { :tag => 'td', :content => /jsmith/ }
308 :sibling => { :tag => 'td', :content => /jsmith/ }
308 assert_tag :tag => 'th', :content => '24',
309 assert_tag :tag => 'th', :content => '24',
309 :sibling => {
310 :sibling => {
310 :tag => 'td',
311 :tag => 'td',
311 :child => {
312 :child => {
312 :tag => 'a',
313 :tag => 'a',
313 :content => /2f9c0091/
314 :content => /2f9c0091/
314 }
315 }
315 }
316 }
316 assert_tag :tag => 'th', :content => '24',
317 assert_tag :tag => 'th', :content => '24',
317 :sibling => { :tag => 'td', :content => /watcher =/ }
318 :sibling => { :tag => 'td', :content => /watcher =/ }
318 end
319 end
319
320
320 def test_annotate_at_given_revision
321 def test_annotate_at_given_revision
321 @repository.fetch_changesets
322 @repository.fetch_changesets
322 @repository.reload
323 @repository.reload
323 get :annotate, :id => PRJ_ID, :rev => 'deff7',
324 get :annotate, :id => PRJ_ID, :rev => 'deff7',
324 :path => ['sources', 'watchers_controller.rb']
325 :path => ['sources', 'watchers_controller.rb']
325 assert_response :success
326 assert_response :success
326 assert_template 'annotate'
327 assert_template 'annotate'
327 assert_tag :tag => 'h2', :content => /@ deff712f/
328 assert_tag :tag => 'h2', :content => /@ deff712f/
328 end
329 end
329
330
330 def test_annotate_binary_file
331 def test_annotate_binary_file
331 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
332 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
332 assert_response 500
333 assert_response 500
333 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
334 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
334 :content => /cannot be annotated/
335 :content => /cannot be annotated/
335 end
336 end
336
337
337 def test_annotate_latin_1
338 def test_annotate_latin_1
338 if @ruby19_non_utf8_pass
339 if @ruby19_non_utf8_pass
339 puts_ruby19_non_utf8_pass()
340 puts_ruby19_non_utf8_pass()
340 elsif JRUBY_SKIP
341 elsif JRUBY_SKIP
341 puts JRUBY_SKIP_STR
342 puts JRUBY_SKIP_STR
342 else
343 else
343 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
344 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
344 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
345 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
345 get :annotate, :id => PRJ_ID,
346 get :annotate, :id => PRJ_ID,
346 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
347 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
347 assert_tag :tag => 'th',
348 assert_tag :tag => 'th',
348 :content => '1',
349 :content => '1',
349 :attributes => { :class => 'line-num' },
350 :attributes => { :class => 'line-num' },
350 :sibling => { :tag => 'td',
351 :sibling => { :tag => 'td',
351 :content => /test-#{@char_1}.txt/ }
352 :content => /test-#{@char_1}.txt/ }
352 end
353 end
353 end
354 end
354 end
355 end
355 end
356 end
356
357
357 def test_revision
358 def test_revision
358 @repository.fetch_changesets
359 @repository.fetch_changesets
359 @repository.reload
360 @repository.reload
360 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
361 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
361 get :revision, :id => PRJ_ID, :rev => r
362 get :revision, :id => PRJ_ID, :rev => r
362 assert_response :success
363 assert_response :success
363 assert_template 'revision'
364 assert_template 'revision'
364 end
365 end
365 end
366 end
366
367
367 def test_empty_revision
368 def test_empty_revision
368 @repository.fetch_changesets
369 @repository.fetch_changesets
369 @repository.reload
370 @repository.reload
370 ['', ' ', nil].each do |r|
371 ['', ' ', nil].each do |r|
371 get :revision, :id => PRJ_ID, :rev => r
372 get :revision, :id => PRJ_ID, :rev => r
372 assert_response 404
373 assert_response 404
373 assert_error_tag :content => /was not found/
374 assert_error_tag :content => /was not found/
374 end
375 end
375 end
376 end
376
377
377 def test_destroy_valid_repository
378 def test_destroy_valid_repository
378 @request.session[:user_id] = 1 # admin
379 @request.session[:user_id] = 1 # admin
379 @repository.fetch_changesets
380 @repository.fetch_changesets
380 @repository.reload
381 @repository.reload
381 assert @repository.changesets.count > 0
382 assert @repository.changesets.count > 0
382
383
383 get :destroy, :id => PRJ_ID
384 get :destroy, :id => PRJ_ID
384 assert_response 302
385 assert_response 302
385 @project.reload
386 @project.reload
386 assert_nil @project.repository
387 assert_nil @project.repository
387 end
388 end
388
389
389 def test_destroy_invalid_repository
390 def test_destroy_invalid_repository
390 @request.session[:user_id] = 1 # admin
391 @request.session[:user_id] = 1 # admin
391 @repository.fetch_changesets
392 @repository.fetch_changesets
392 @repository.reload
393 @repository.reload
393 assert @repository.changesets.count > 0
394 assert @repository.changesets.count > 0
394
395
395 get :destroy, :id => PRJ_ID
396 get :destroy, :id => PRJ_ID
396 assert_response 302
397 assert_response 302
397 @project.reload
398 @project.reload
398 assert_nil @project.repository
399 assert_nil @project.repository
399
400
400 @repository = Repository::Git.create(
401 @repository = Repository::Git.create(
401 :project => @project,
402 :project => @project,
402 :url => "/invalid",
403 :url => "/invalid",
403 :path_encoding => 'ISO-8859-1'
404 :path_encoding => 'ISO-8859-1'
404 )
405 )
405 assert @repository
406 assert @repository
406 @repository.fetch_changesets
407 @repository.fetch_changesets
407 @repository.reload
408 @repository.reload
408 assert_equal 0, @repository.changesets.count
409 assert_equal 0, @repository.changesets.count
409
410
410 get :destroy, :id => PRJ_ID
411 get :destroy, :id => PRJ_ID
411 assert_response 302
412 assert_response 302
412 @project.reload
413 @project.reload
413 assert_nil @project.repository
414 assert_nil @project.repository
414 end
415 end
415
416
416 private
417 private
417
418
418 def puts_ruby19_non_utf8_pass
419 def puts_ruby19_non_utf8_pass
419 puts "TODO: This test fails in Ruby 1.9 " +
420 puts "TODO: This test fails in Ruby 1.9 " +
420 "and Encoding.default_external is not UTF-8. " +
421 "and Encoding.default_external is not UTF-8. " +
421 "Current value is '#{Encoding.default_external.to_s}'"
422 "Current value is '#{Encoding.default_external.to_s}'"
422 end
423 end
423 else
424 else
424 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
425 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
425 def test_fake; assert true end
426 def test_fake; assert true end
426 end
427 end
427
428
428 private
429 private
429 def with_cache(&block)
430 def with_cache(&block)
430 before = ActionController::Base.perform_caching
431 before = ActionController::Base.perform_caching
431 ActionController::Base.perform_caching = true
432 ActionController::Base.perform_caching = true
432 block.call
433 block.call
433 ActionController::Base.perform_caching = before
434 ActionController::Base.perform_caching = before
434 end
435 end
435 end
436 end
General Comments 0
You need to be logged in to leave comments. Login now