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