##// END OF EJS Templates
Rails3: scm: git: fix error of test_destroy_invalid_repository at functional test...
Toshi MARUYAMA -
r7026:5bf47d1eb83d
parent child
Show More
@@ -1,460 +1,461
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 assert_equal 0, @repository.changesets.count
241 @repository.fetch_changesets
241 @repository.fetch_changesets
242 @project.reload
242 @project.reload
243 assert_equal NUM_REV, @repository.changesets.count
243 assert_equal NUM_REV, @repository.changesets.count
244 Setting.diff_max_lines_displayed = 5
244 Setting.diff_max_lines_displayed = 5
245
245
246 # Truncated diff of changeset 2f9c0091
246 # Truncated diff of changeset 2f9c0091
247 with_cache do
247 with_cache do
248 get :diff, :id => PRJ_ID, :type => 'inline',
248 get :diff, :id => PRJ_ID, :type => 'inline',
249 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
249 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
250 assert_response :success
250 assert_response :success
251 assert @response.body.include?("... This diff was truncated")
251 assert @response.body.include?("... This diff was truncated")
252
252
253 Setting.default_language = 'fr'
253 Setting.default_language = 'fr'
254 get :diff, :id => PRJ_ID, :type => 'inline',
254 get :diff, :id => PRJ_ID, :type => 'inline',
255 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
255 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
256 assert_response :success
256 assert_response :success
257 assert ! @response.body.include?("... This diff was truncated")
257 assert ! @response.body.include?("... This diff was truncated")
258 assert @response.body.include?("... Ce diff")
258 assert @response.body.include?("... Ce diff")
259 end
259 end
260 end
260 end
261
261
262 def test_diff_two_revs
262 def test_diff_two_revs
263 assert_equal 0, @repository.changesets.count
263 assert_equal 0, @repository.changesets.count
264 @repository.fetch_changesets
264 @repository.fetch_changesets
265 @project.reload
265 @project.reload
266 assert_equal NUM_REV, @repository.changesets.count
266 assert_equal NUM_REV, @repository.changesets.count
267 ['inline', 'sbs'].each do |dt|
267 ['inline', 'sbs'].each do |dt|
268 get :diff,
268 get :diff,
269 :id => PRJ_ID,
269 :id => PRJ_ID,
270 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
270 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
271 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
271 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
272 :type => dt
272 :type => dt
273 assert_response :success
273 assert_response :success
274 assert_template 'diff'
274 assert_template 'diff'
275 diff = assigns(:diff)
275 diff = assigns(:diff)
276 assert_not_nil diff
276 assert_not_nil diff
277 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
277 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
278 end
278 end
279 end
279 end
280
280
281 def test_diff_latin_1
281 def test_diff_latin_1
282 if @ruby19_non_utf8_pass
282 if @ruby19_non_utf8_pass
283 puts_ruby19_non_utf8_pass()
283 puts_ruby19_non_utf8_pass()
284 else
284 else
285 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
285 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
286 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
286 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
287 ['inline', 'sbs'].each do |dt|
287 ['inline', 'sbs'].each do |dt|
288 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
288 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
289 assert_response :success
289 assert_response :success
290 assert_template 'diff'
290 assert_template 'diff'
291 assert_tag :tag => 'thead',
291 assert_tag :tag => 'thead',
292 :descendant => {
292 :descendant => {
293 :tag => 'th',
293 :tag => 'th',
294 :attributes => { :class => 'filename' } ,
294 :attributes => { :class => 'filename' } ,
295 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
295 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
296 },
296 },
297 :sibling => {
297 :sibling => {
298 :tag => 'tbody',
298 :tag => 'tbody',
299 :descendant => {
299 :descendant => {
300 :tag => 'td',
300 :tag => 'td',
301 :attributes => { :class => /diff_in/ },
301 :attributes => { :class => /diff_in/ },
302 :content => /test-#{@char_1}.txt/
302 :content => /test-#{@char_1}.txt/
303 }
303 }
304 }
304 }
305 end
305 end
306 end
306 end
307 end
307 end
308 end
308 end
309 end
309 end
310
310
311 def test_annotate
311 def test_annotate
312 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
312 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
313 assert_response :success
313 assert_response :success
314 assert_template 'annotate'
314 assert_template 'annotate'
315 # Line 24, changeset 2f9c0091
315 # Line 24, changeset 2f9c0091
316 assert_tag :tag => 'th', :content => '24',
316 assert_tag :tag => 'th', :content => '24',
317 :sibling => {
317 :sibling => {
318 :tag => 'td',
318 :tag => 'td',
319 :child => {
319 :child => {
320 :tag => 'a',
320 :tag => 'a',
321 :content => /2f9c0091/
321 :content => /2f9c0091/
322 }
322 }
323 }
323 }
324 assert_tag :tag => 'th', :content => '24',
324 assert_tag :tag => 'th', :content => '24',
325 :sibling => { :tag => 'td', :content => /jsmith/ }
325 :sibling => { :tag => 'td', :content => /jsmith/ }
326 assert_tag :tag => 'th', :content => '24',
326 assert_tag :tag => 'th', :content => '24',
327 :sibling => {
327 :sibling => {
328 :tag => 'td',
328 :tag => 'td',
329 :child => {
329 :child => {
330 :tag => 'a',
330 :tag => 'a',
331 :content => /2f9c0091/
331 :content => /2f9c0091/
332 }
332 }
333 }
333 }
334 assert_tag :tag => 'th', :content => '24',
334 assert_tag :tag => 'th', :content => '24',
335 :sibling => { :tag => 'td', :content => /watcher =/ }
335 :sibling => { :tag => 'td', :content => /watcher =/ }
336 end
336 end
337
337
338 def test_annotate_at_given_revision
338 def test_annotate_at_given_revision
339 assert_equal 0, @repository.changesets.count
339 assert_equal 0, @repository.changesets.count
340 @repository.fetch_changesets
340 @repository.fetch_changesets
341 @project.reload
341 @project.reload
342 assert_equal NUM_REV, @repository.changesets.count
342 assert_equal NUM_REV, @repository.changesets.count
343 get :annotate, :id => PRJ_ID, :rev => 'deff7',
343 get :annotate, :id => PRJ_ID, :rev => 'deff7',
344 :path => ['sources', 'watchers_controller.rb']
344 :path => ['sources', 'watchers_controller.rb']
345 assert_response :success
345 assert_response :success
346 assert_template 'annotate'
346 assert_template 'annotate'
347 assert_tag :tag => 'h2', :content => /@ deff712f/
347 assert_tag :tag => 'h2', :content => /@ deff712f/
348 end
348 end
349
349
350 def test_annotate_binary_file
350 def test_annotate_binary_file
351 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
351 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
352 assert_response 500
352 assert_response 500
353 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
353 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
354 :content => /cannot be annotated/
354 :content => /cannot be annotated/
355 end
355 end
356
356
357 def test_annotate_latin_1
357 def test_annotate_latin_1
358 if @ruby19_non_utf8_pass
358 if @ruby19_non_utf8_pass
359 puts_ruby19_non_utf8_pass()
359 puts_ruby19_non_utf8_pass()
360 elsif JRUBY_SKIP
360 elsif JRUBY_SKIP
361 puts JRUBY_SKIP_STR
361 puts JRUBY_SKIP_STR
362 else
362 else
363 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
363 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
364 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
364 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
365 get :annotate, :id => PRJ_ID,
365 get :annotate, :id => PRJ_ID,
366 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
366 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
367 assert_tag :tag => 'th',
367 assert_tag :tag => 'th',
368 :content => '1',
368 :content => '1',
369 :attributes => { :class => 'line-num' },
369 :attributes => { :class => 'line-num' },
370 :sibling => { :tag => 'td',
370 :sibling => { :tag => 'td',
371 :content => /test-#{@char_1}.txt/ }
371 :content => /test-#{@char_1}.txt/ }
372 end
372 end
373 end
373 end
374 end
374 end
375 end
375 end
376
376
377 def test_revision
377 def test_revision
378 assert_equal 0, @repository.changesets.count
378 assert_equal 0, @repository.changesets.count
379 @repository.fetch_changesets
379 @repository.fetch_changesets
380 @project.reload
380 @project.reload
381 assert_equal NUM_REV, @repository.changesets.count
381 assert_equal NUM_REV, @repository.changesets.count
382 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
382 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
383 get :revision, :id => PRJ_ID, :rev => r
383 get :revision, :id => PRJ_ID, :rev => r
384 assert_response :success
384 assert_response :success
385 assert_template 'revision'
385 assert_template 'revision'
386 end
386 end
387 end
387 end
388
388
389 def test_empty_revision
389 def test_empty_revision
390 assert_equal 0, @repository.changesets.count
390 assert_equal 0, @repository.changesets.count
391 @repository.fetch_changesets
391 @repository.fetch_changesets
392 @project.reload
392 @project.reload
393 assert_equal NUM_REV, @repository.changesets.count
393 assert_equal NUM_REV, @repository.changesets.count
394 ['', ' ', nil].each do |r|
394 ['', ' ', nil].each do |r|
395 get :revision, :id => PRJ_ID, :rev => r
395 get :revision, :id => PRJ_ID, :rev => r
396 assert_response 404
396 assert_response 404
397 assert_error_tag :content => /was not found/
397 assert_error_tag :content => /was not found/
398 end
398 end
399 end
399 end
400
400
401 def test_destroy_valid_repository
401 def test_destroy_valid_repository
402 @request.session[:user_id] = 1 # admin
402 @request.session[:user_id] = 1 # admin
403 assert_equal 0, @repository.changesets.count
403 assert_equal 0, @repository.changesets.count
404 @repository.fetch_changesets
404 @repository.fetch_changesets
405 @project.reload
405 @project.reload
406 assert_equal NUM_REV, @repository.changesets.count
406 assert_equal NUM_REV, @repository.changesets.count
407
407
408 get :destroy, :id => PRJ_ID
408 get :destroy, :id => PRJ_ID
409 assert_response 302
409 assert_response 302
410 @project.reload
410 @project.reload
411 assert_nil @project.repository
411 assert_nil @project.repository
412 end
412 end
413
413
414 def test_destroy_invalid_repository
414 def test_destroy_invalid_repository
415 @request.session[:user_id] = 1 # admin
415 @request.session[:user_id] = 1 # admin
416 assert_equal 0, @repository.changesets.count
416 @repository.fetch_changesets
417 @repository.fetch_changesets
417 @repository.reload
418 @project.reload
418 assert @repository.changesets.count > 0
419 assert_equal NUM_REV, @repository.changesets.count
419
420
420 get :destroy, :id => PRJ_ID
421 get :destroy, :id => PRJ_ID
421 assert_response 302
422 assert_response 302
422 @project.reload
423 @project.reload
423 assert_nil @project.repository
424 assert_nil @project.repository
424
425
425 @repository = Repository::Git.create(
426 @repository = Repository::Git.create(
426 :project => @project,
427 :project => @project,
427 :url => "/invalid",
428 :url => "/invalid",
428 :path_encoding => 'ISO-8859-1'
429 :path_encoding => 'ISO-8859-1'
429 )
430 )
430 assert @repository
431 assert @repository
431 @repository.fetch_changesets
432 @repository.fetch_changesets
432 @repository.reload
433 @repository.reload
433 assert_equal 0, @repository.changesets.count
434 assert_equal 0, @repository.changesets.count
434
435
435 get :destroy, :id => PRJ_ID
436 get :destroy, :id => PRJ_ID
436 assert_response 302
437 assert_response 302
437 @project.reload
438 @project.reload
438 assert_nil @project.repository
439 assert_nil @project.repository
439 end
440 end
440
441
441 private
442 private
442
443
443 def puts_ruby19_non_utf8_pass
444 def puts_ruby19_non_utf8_pass
444 puts "TODO: This test fails in Ruby 1.9 " +
445 puts "TODO: This test fails in Ruby 1.9 " +
445 "and Encoding.default_external is not UTF-8. " +
446 "and Encoding.default_external is not UTF-8. " +
446 "Current value is '#{Encoding.default_external.to_s}'"
447 "Current value is '#{Encoding.default_external.to_s}'"
447 end
448 end
448 else
449 else
449 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
450 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
450 def test_fake; assert true end
451 def test_fake; assert true end
451 end
452 end
452
453
453 private
454 private
454 def with_cache(&block)
455 def with_cache(&block)
455 before = ActionController::Base.perform_caching
456 before = ActionController::Base.perform_caching
456 ActionController::Base.perform_caching = true
457 ActionController::Base.perform_caching = true
457 block.call
458 block.call
458 ActionController::Base.perform_caching = before
459 ActionController::Base.perform_caching = before
459 end
460 end
460 end
461 end
General Comments 0
You need to be logged in to leave comments. Login now