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