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