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