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