##// END OF EJS Templates
Rails3: test: scm: git: use "repository_path_hash" for path param...
Toshi MARUYAMA -
r8804:08811bd259b0
parent child
Show More
@@ -1,493 +1,505
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
19
20 class RepositoriesGitControllerTest < ActionController::TestCase
20 class RepositoriesGitControllerTest < ActionController::TestCase
21 tests RepositoriesController
21 tests RepositoriesController
22
22
23 fixtures :projects, :users, :roles, :members, :member_roles,
23 fixtures :projects, :users, :roles, :members, :member_roles,
24 :repositories, :enabled_modules
24 :repositories, :enabled_modules
25
25
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 PRJ_ID = 3
28 PRJ_ID = 3
29 CHAR_1_HEX = "\xc3\x9c"
29 CHAR_1_HEX = "\xc3\x9c"
30 NUM_REV = 28
30 NUM_REV = 28
31
31
32 ## Git, Mercurial and CVS path encodings are binary.
32 ## Git, Mercurial and CVS path encodings are binary.
33 ## Subversion supports URL encoding for path.
33 ## Subversion supports URL encoding for path.
34 ## Redmine Mercurial adapter and extension use URL encoding.
34 ## Redmine Mercurial adapter and extension use URL encoding.
35 ## Git accepts only binary path in command line parameter.
35 ## Git accepts only binary path in command line parameter.
36 ## So, there is no way to use binary command line parameter in JRuby.
36 ## So, there is no way to use binary command line parameter in JRuby.
37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
39
39
40 def setup
40 def setup
41 @ruby19_non_utf8_pass =
41 @ruby19_non_utf8_pass =
42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
43
43
44 User.current = nil
44 User.current = nil
45 @project = Project.find(PRJ_ID)
45 @project = Project.find(PRJ_ID)
46 @repository = Repository::Git.create(
46 @repository = Repository::Git.create(
47 :project => @project,
47 :project => @project,
48 :url => REPOSITORY_PATH,
48 :url => REPOSITORY_PATH,
49 :path_encoding => 'ISO-8859-1'
49 :path_encoding => 'ISO-8859-1'
50 )
50 )
51 assert @repository
51 assert @repository
52 @char_1 = CHAR_1_HEX.dup
52 @char_1 = CHAR_1_HEX.dup
53 if @char_1.respond_to?(:force_encoding)
53 if @char_1.respond_to?(:force_encoding)
54 @char_1.force_encoding('UTF-8')
54 @char_1.force_encoding('UTF-8')
55 end
55 end
56
56
57 Setting.default_language = 'en'
57 Setting.default_language = 'en'
58 end
58 end
59
59
60 if File.directory?(REPOSITORY_PATH)
60 if File.directory?(REPOSITORY_PATH)
61 def test_get_new
61 def test_get_new
62 @request.session[:user_id] = 1
62 @request.session[:user_id] = 1
63 @project.repository.destroy
63 @project.repository.destroy
64 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
64 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
65 assert_response :success
65 assert_response :success
66 assert_template 'new'
66 assert_template 'new'
67 assert_kind_of Repository::Git, assigns(:repository)
67 assert_kind_of Repository::Git, assigns(:repository)
68 assert assigns(:repository).new_record?
68 assert assigns(:repository).new_record?
69 end
69 end
70
70
71 def test_browse_root
71 def test_browse_root
72 assert_equal 0, @repository.changesets.count
72 assert_equal 0, @repository.changesets.count
73 @repository.fetch_changesets
73 @repository.fetch_changesets
74 @project.reload
74 @project.reload
75 assert_equal NUM_REV, @repository.changesets.count
75 assert_equal NUM_REV, @repository.changesets.count
76
76
77 get :show, :id => PRJ_ID
77 get :show, :id => PRJ_ID
78 assert_response :success
78 assert_response :success
79 assert_template 'show'
79 assert_template 'show'
80 assert_not_nil assigns(:entries)
80 assert_not_nil assigns(:entries)
81 assert_equal 9, assigns(:entries).size
81 assert_equal 9, assigns(:entries).size
82 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
82 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
83 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
83 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
86 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
86 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
87 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
87 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
88 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
88 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
89 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
89 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
90 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
90 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
91 assert_not_nil assigns(:changesets)
91 assert_not_nil assigns(:changesets)
92 assert assigns(:changesets).size > 0
92 assert assigns(:changesets).size > 0
93 end
93 end
94
94
95 def test_browse_branch
95 def test_browse_branch
96 assert_equal 0, @repository.changesets.count
96 assert_equal 0, @repository.changesets.count
97 @repository.fetch_changesets
97 @repository.fetch_changesets
98 @project.reload
98 @project.reload
99 assert_equal NUM_REV, @repository.changesets.count
99 assert_equal NUM_REV, @repository.changesets.count
100 get :show, :id => PRJ_ID, :rev => 'test_branch'
100 get :show, :id => PRJ_ID, :rev => 'test_branch'
101 assert_response :success
101 assert_response :success
102 assert_template 'show'
102 assert_template 'show'
103 assert_not_nil assigns(:entries)
103 assert_not_nil assigns(:entries)
104 assert_equal 4, assigns(:entries).size
104 assert_equal 4, assigns(:entries).size
105 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
105 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
106 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
106 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
107 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
107 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
108 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
108 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
109 assert_not_nil assigns(:changesets)
109 assert_not_nil assigns(:changesets)
110 assert assigns(:changesets).size > 0
110 assert assigns(:changesets).size > 0
111 end
111 end
112
112
113 def test_browse_tag
113 def test_browse_tag
114 assert_equal 0, @repository.changesets.count
114 assert_equal 0, @repository.changesets.count
115 @repository.fetch_changesets
115 @repository.fetch_changesets
116 @project.reload
116 @project.reload
117 assert_equal NUM_REV, @repository.changesets.count
117 assert_equal NUM_REV, @repository.changesets.count
118 [
118 [
119 "tag00.lightweight",
119 "tag00.lightweight",
120 "tag01.annotated",
120 "tag01.annotated",
121 ].each do |t1|
121 ].each do |t1|
122 get :show, :id => PRJ_ID, :rev => t1
122 get :show, :id => PRJ_ID, :rev => t1
123 assert_response :success
123 assert_response :success
124 assert_template 'show'
124 assert_template 'show'
125 assert_not_nil assigns(:entries)
125 assert_not_nil assigns(:entries)
126 assert assigns(:entries).size > 0
126 assert assigns(:entries).size > 0
127 assert_not_nil assigns(:changesets)
127 assert_not_nil assigns(:changesets)
128 assert assigns(:changesets).size > 0
128 assert assigns(:changesets).size > 0
129 end
129 end
130 end
130 end
131
131
132 def test_browse_directory
132 def test_browse_directory
133 assert_equal 0, @repository.changesets.count
133 assert_equal 0, @repository.changesets.count
134 @repository.fetch_changesets
134 @repository.fetch_changesets
135 @project.reload
135 @project.reload
136 assert_equal NUM_REV, @repository.changesets.count
136 assert_equal NUM_REV, @repository.changesets.count
137 get :show, :id => PRJ_ID, :path => ['images']
137 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
138 assert_response :success
138 assert_response :success
139 assert_template 'show'
139 assert_template 'show'
140 assert_not_nil assigns(:entries)
140 assert_not_nil assigns(:entries)
141 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
141 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
142 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
142 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
143 assert_not_nil entry
143 assert_not_nil entry
144 assert_equal 'file', entry.kind
144 assert_equal 'file', entry.kind
145 assert_equal 'images/edit.png', entry.path
145 assert_equal 'images/edit.png', entry.path
146 assert_not_nil assigns(:changesets)
146 assert_not_nil assigns(:changesets)
147 assert assigns(:changesets).size > 0
147 assert assigns(:changesets).size > 0
148 end
148 end
149
149
150 def test_browse_at_given_revision
150 def test_browse_at_given_revision
151 assert_equal 0, @repository.changesets.count
151 assert_equal 0, @repository.changesets.count
152 @repository.fetch_changesets
152 @repository.fetch_changesets
153 @project.reload
153 @project.reload
154 assert_equal NUM_REV, @repository.changesets.count
154 assert_equal NUM_REV, @repository.changesets.count
155 get :show, :id => PRJ_ID, :path => ['images'],
155 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
156 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
156 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
157 assert_response :success
157 assert_response :success
158 assert_template 'show'
158 assert_template 'show'
159 assert_not_nil assigns(:entries)
159 assert_not_nil assigns(:entries)
160 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
160 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
161 assert_not_nil assigns(:changesets)
161 assert_not_nil assigns(:changesets)
162 assert assigns(:changesets).size > 0
162 assert assigns(:changesets).size > 0
163 end
163 end
164
164
165 def test_changes
165 def test_changes
166 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
166 get :changes, :id => PRJ_ID,
167 :path => repository_path_hash(['images', 'edit.png'])[:param]
167 assert_response :success
168 assert_response :success
168 assert_template 'changes'
169 assert_template 'changes'
169 assert_tag :tag => 'h2', :content => 'edit.png'
170 assert_tag :tag => 'h2', :content => 'edit.png'
170 end
171 end
171
172
172 def test_entry_show
173 def test_entry_show
173 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
174 get :entry, :id => PRJ_ID,
175 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
174 assert_response :success
176 assert_response :success
175 assert_template 'entry'
177 assert_template 'entry'
176 # Line 19
178 # Line 19
177 assert_tag :tag => 'th',
179 assert_tag :tag => 'th',
178 :content => '11',
180 :content => '11',
179 :attributes => { :class => 'line-num' },
181 :attributes => { :class => 'line-num' },
180 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
182 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
181 end
183 end
182
184
183 def test_entry_show_latin_1
185 def test_entry_show_latin_1
184 if @ruby19_non_utf8_pass
186 if @ruby19_non_utf8_pass
185 puts_ruby19_non_utf8_pass()
187 puts_ruby19_non_utf8_pass()
186 elsif JRUBY_SKIP
188 elsif JRUBY_SKIP
187 puts JRUBY_SKIP_STR
189 puts JRUBY_SKIP_STR
188 else
190 else
189 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
191 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
190 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
192 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
191 get :entry, :id => PRJ_ID,
193 get :entry, :id => PRJ_ID,
192 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
194 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
195 :rev => r1
193 assert_response :success
196 assert_response :success
194 assert_template 'entry'
197 assert_template 'entry'
195 assert_tag :tag => 'th',
198 assert_tag :tag => 'th',
196 :content => '1',
199 :content => '1',
197 :attributes => { :class => 'line-num' },
200 :attributes => { :class => 'line-num' },
198 :sibling => { :tag => 'td',
201 :sibling => { :tag => 'td',
199 :content => /test-#{@char_1}.txt/ }
202 :content => /test-#{@char_1}.txt/ }
200 end
203 end
201 end
204 end
202 end
205 end
203 end
206 end
204
207
205 def test_entry_download
208 def test_entry_download
206 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
209 get :entry, :id => PRJ_ID,
210 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
207 :format => 'raw'
211 :format => 'raw'
208 assert_response :success
212 assert_response :success
209 # File content
213 # File content
210 assert @response.body.include?('WITHOUT ANY WARRANTY')
214 assert @response.body.include?('WITHOUT ANY WARRANTY')
211 end
215 end
212
216
213 def test_directory_entry
217 def test_directory_entry
214 get :entry, :id => PRJ_ID, :path => ['sources']
218 get :entry, :id => PRJ_ID,
219 :path => repository_path_hash(['sources'])[:param]
215 assert_response :success
220 assert_response :success
216 assert_template 'show'
221 assert_template 'show'
217 assert_not_nil assigns(:entry)
222 assert_not_nil assigns(:entry)
218 assert_equal 'sources', assigns(:entry).name
223 assert_equal 'sources', assigns(:entry).name
219 end
224 end
220
225
221 def test_diff
226 def test_diff
222 assert_equal 0, @repository.changesets.count
227 assert_equal 0, @repository.changesets.count
223 @repository.fetch_changesets
228 @repository.fetch_changesets
224 @project.reload
229 @project.reload
225 assert_equal NUM_REV, @repository.changesets.count
230 assert_equal NUM_REV, @repository.changesets.count
226 # Full diff of changeset 2f9c0091
231 # Full diff of changeset 2f9c0091
227 ['inline', 'sbs'].each do |dt|
232 ['inline', 'sbs'].each do |dt|
228 get :diff,
233 get :diff,
229 :id => PRJ_ID,
234 :id => PRJ_ID,
230 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
235 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
231 :type => dt
236 :type => dt
232 assert_response :success
237 assert_response :success
233 assert_template 'diff'
238 assert_template 'diff'
234 # Line 22 removed
239 # Line 22 removed
235 assert_tag :tag => 'th',
240 assert_tag :tag => 'th',
236 :content => /22/,
241 :content => /22/,
237 :sibling => { :tag => 'td',
242 :sibling => { :tag => 'td',
238 :attributes => { :class => /diff_out/ },
243 :attributes => { :class => /diff_out/ },
239 :content => /def remove/ }
244 :content => /def remove/ }
240 assert_tag :tag => 'h2', :content => /2f9c0091/
245 assert_tag :tag => 'h2', :content => /2f9c0091/
241 end
246 end
242 end
247 end
243
248
244 def test_diff_truncated
249 def test_diff_truncated
245 assert_equal 0, @repository.changesets.count
250 assert_equal 0, @repository.changesets.count
246 @repository.fetch_changesets
251 @repository.fetch_changesets
247 @project.reload
252 @project.reload
248 assert_equal NUM_REV, @repository.changesets.count
253 assert_equal NUM_REV, @repository.changesets.count
249 Setting.diff_max_lines_displayed = 5
254 Setting.diff_max_lines_displayed = 5
250
255
251 # Truncated diff of changeset 2f9c0091
256 # Truncated diff of changeset 2f9c0091
252 with_cache do
257 with_cache do
253 get :diff, :id => PRJ_ID, :type => 'inline',
258 get :diff, :id => PRJ_ID, :type => 'inline',
254 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
259 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
255 assert_response :success
260 assert_response :success
256 assert @response.body.include?("... This diff was truncated")
261 assert @response.body.include?("... This diff was truncated")
257
262
258 Setting.default_language = 'fr'
263 Setting.default_language = 'fr'
259 get :diff, :id => PRJ_ID, :type => 'inline',
264 get :diff, :id => PRJ_ID, :type => 'inline',
260 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
265 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
261 assert_response :success
266 assert_response :success
262 assert ! @response.body.include?("... This diff was truncated")
267 assert ! @response.body.include?("... This diff was truncated")
263 assert @response.body.include?("... Ce diff")
268 assert @response.body.include?("... Ce diff")
264 end
269 end
265 end
270 end
266
271
267 def test_diff_two_revs
272 def test_diff_two_revs
268 assert_equal 0, @repository.changesets.count
273 assert_equal 0, @repository.changesets.count
269 @repository.fetch_changesets
274 @repository.fetch_changesets
270 @project.reload
275 @project.reload
271 assert_equal NUM_REV, @repository.changesets.count
276 assert_equal NUM_REV, @repository.changesets.count
272 ['inline', 'sbs'].each do |dt|
277 ['inline', 'sbs'].each do |dt|
273 get :diff,
278 get :diff,
274 :id => PRJ_ID,
279 :id => PRJ_ID,
275 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
280 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
276 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
281 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
277 :type => dt
282 :type => dt
278 assert_response :success
283 assert_response :success
279 assert_template 'diff'
284 assert_template 'diff'
280 diff = assigns(:diff)
285 diff = assigns(:diff)
281 assert_not_nil diff
286 assert_not_nil diff
282 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
287 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
283 end
288 end
284 end
289 end
285
290
286 def test_diff_latin_1
291 def test_diff_latin_1
287 if @ruby19_non_utf8_pass
292 if @ruby19_non_utf8_pass
288 puts_ruby19_non_utf8_pass()
293 puts_ruby19_non_utf8_pass()
289 else
294 else
290 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
295 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
291 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
296 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
292 ['inline', 'sbs'].each do |dt|
297 ['inline', 'sbs'].each do |dt|
293 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
298 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
294 assert_response :success
299 assert_response :success
295 assert_template 'diff'
300 assert_template 'diff'
296 assert_tag :tag => 'thead',
301 assert_tag :tag => 'thead',
297 :descendant => {
302 :descendant => {
298 :tag => 'th',
303 :tag => 'th',
299 :attributes => { :class => 'filename' } ,
304 :attributes => { :class => 'filename' } ,
300 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
305 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
301 },
306 },
302 :sibling => {
307 :sibling => {
303 :tag => 'tbody',
308 :tag => 'tbody',
304 :descendant => {
309 :descendant => {
305 :tag => 'td',
310 :tag => 'td',
306 :attributes => { :class => /diff_in/ },
311 :attributes => { :class => /diff_in/ },
307 :content => /test-#{@char_1}.txt/
312 :content => /test-#{@char_1}.txt/
308 }
313 }
309 }
314 }
310 end
315 end
311 end
316 end
312 end
317 end
313 end
318 end
314 end
319 end
315
320
316 def test_save_diff_type
321 def test_save_diff_type
317 @request.session[:user_id] = 1 # admin
322 @request.session[:user_id] = 1 # admin
318 user = User.find(1)
323 user = User.find(1)
319 get :diff,
324 get :diff,
320 :id => PRJ_ID,
325 :id => PRJ_ID,
321 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
326 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
322 assert_response :success
327 assert_response :success
323 assert_template 'diff'
328 assert_template 'diff'
324 user.reload
329 user.reload
325 assert_equal "inline", user.pref[:diff_type]
330 assert_equal "inline", user.pref[:diff_type]
326 get :diff,
331 get :diff,
327 :id => PRJ_ID,
332 :id => PRJ_ID,
328 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
333 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
329 :type => 'sbs'
334 :type => 'sbs'
330 assert_response :success
335 assert_response :success
331 assert_template 'diff'
336 assert_template 'diff'
332 user.reload
337 user.reload
333 assert_equal "sbs", user.pref[:diff_type]
338 assert_equal "sbs", user.pref[:diff_type]
334 end
339 end
335
340
336 def test_annotate
341 def test_annotate
337 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
342 get :annotate, :id => PRJ_ID,
343 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
338 assert_response :success
344 assert_response :success
339 assert_template 'annotate'
345 assert_template 'annotate'
340 # Line 24, changeset 2f9c0091
346 # Line 24, changeset 2f9c0091
341 assert_tag :tag => 'th', :content => '24',
347 assert_tag :tag => 'th', :content => '24',
342 :sibling => {
348 :sibling => {
343 :tag => 'td',
349 :tag => 'td',
344 :child => {
350 :child => {
345 :tag => 'a',
351 :tag => 'a',
346 :content => /2f9c0091/
352 :content => /2f9c0091/
347 }
353 }
348 }
354 }
349 assert_tag :tag => 'th', :content => '24',
355 assert_tag :tag => 'th', :content => '24',
350 :sibling => { :tag => 'td', :content => /jsmith/ }
356 :sibling => { :tag => 'td', :content => /jsmith/ }
351 assert_tag :tag => 'th', :content => '24',
357 assert_tag :tag => 'th', :content => '24',
352 :sibling => {
358 :sibling => {
353 :tag => 'td',
359 :tag => 'td',
354 :child => {
360 :child => {
355 :tag => 'a',
361 :tag => 'a',
356 :content => /2f9c0091/
362 :content => /2f9c0091/
357 }
363 }
358 }
364 }
359 assert_tag :tag => 'th', :content => '24',
365 assert_tag :tag => 'th', :content => '24',
360 :sibling => { :tag => 'td', :content => /watcher =/ }
366 :sibling => { :tag => 'td', :content => /watcher =/ }
361 end
367 end
362
368
363 def test_annotate_at_given_revision
369 def test_annotate_at_given_revision
364 assert_equal 0, @repository.changesets.count
370 assert_equal 0, @repository.changesets.count
365 @repository.fetch_changesets
371 @repository.fetch_changesets
366 @project.reload
372 @project.reload
367 assert_equal NUM_REV, @repository.changesets.count
373 assert_equal NUM_REV, @repository.changesets.count
368 get :annotate, :id => PRJ_ID, :rev => 'deff7',
374 get :annotate, :id => PRJ_ID, :rev => 'deff7',
369 :path => ['sources', 'watchers_controller.rb']
375 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
370 assert_response :success
376 assert_response :success
371 assert_template 'annotate'
377 assert_template 'annotate'
372 assert_tag :tag => 'h2', :content => /@ deff712f/
378 assert_tag :tag => 'h2', :content => /@ deff712f/
373 end
379 end
374
380
375 def test_annotate_binary_file
381 def test_annotate_binary_file
376 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
382 get :annotate, :id => PRJ_ID,
383 :path => repository_path_hash(['images', 'edit.png'])[:param]
377 assert_response 500
384 assert_response 500
378 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
385 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
379 :content => /cannot be annotated/
386 :content => /cannot be annotated/
380 end
387 end
381
388
382 def test_annotate_error_when_too_big
389 def test_annotate_error_when_too_big
383 with_settings :file_max_size_displayed => 1 do
390 with_settings :file_max_size_displayed => 1 do
384 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 'deff712f'
391 get :annotate, :id => PRJ_ID,
392 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
393 :rev => 'deff712f'
385 assert_response 500
394 assert_response 500
386 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
395 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
387 :content => /exceeds the maximum text file size/
396 :content => /exceeds the maximum text file size/
388
397
389 get :annotate, :id => PRJ_ID, :path => ['README'], :rev => '7234cb2'
398 get :annotate, :id => PRJ_ID,
399 :path => repository_path_hash(['README'])[:param],
400 :rev => '7234cb2'
390 assert_response :success
401 assert_response :success
391 assert_template 'annotate'
402 assert_template 'annotate'
392 end
403 end
393 end
404 end
394
405
395 def test_annotate_latin_1
406 def test_annotate_latin_1
396 if @ruby19_non_utf8_pass
407 if @ruby19_non_utf8_pass
397 puts_ruby19_non_utf8_pass()
408 puts_ruby19_non_utf8_pass()
398 elsif JRUBY_SKIP
409 elsif JRUBY_SKIP
399 puts JRUBY_SKIP_STR
410 puts JRUBY_SKIP_STR
400 else
411 else
401 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
412 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
402 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
413 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
403 get :annotate, :id => PRJ_ID,
414 get :annotate, :id => PRJ_ID,
404 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
415 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
416 :rev => r1
405 assert_tag :tag => 'th',
417 assert_tag :tag => 'th',
406 :content => '1',
418 :content => '1',
407 :attributes => { :class => 'line-num' },
419 :attributes => { :class => 'line-num' },
408 :sibling => { :tag => 'td',
420 :sibling => { :tag => 'td',
409 :content => /test-#{@char_1}.txt/ }
421 :content => /test-#{@char_1}.txt/ }
410 end
422 end
411 end
423 end
412 end
424 end
413 end
425 end
414
426
415 def test_revision
427 def test_revision
416 assert_equal 0, @repository.changesets.count
428 assert_equal 0, @repository.changesets.count
417 @repository.fetch_changesets
429 @repository.fetch_changesets
418 @project.reload
430 @project.reload
419 assert_equal NUM_REV, @repository.changesets.count
431 assert_equal NUM_REV, @repository.changesets.count
420 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
432 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
421 get :revision, :id => PRJ_ID, :rev => r
433 get :revision, :id => PRJ_ID, :rev => r
422 assert_response :success
434 assert_response :success
423 assert_template 'revision'
435 assert_template 'revision'
424 end
436 end
425 end
437 end
426
438
427 def test_empty_revision
439 def test_empty_revision
428 assert_equal 0, @repository.changesets.count
440 assert_equal 0, @repository.changesets.count
429 @repository.fetch_changesets
441 @repository.fetch_changesets
430 @project.reload
442 @project.reload
431 assert_equal NUM_REV, @repository.changesets.count
443 assert_equal NUM_REV, @repository.changesets.count
432 ['', ' ', nil].each do |r|
444 ['', ' ', nil].each do |r|
433 get :revision, :id => PRJ_ID, :rev => r
445 get :revision, :id => PRJ_ID, :rev => r
434 assert_response 404
446 assert_response 404
435 assert_error_tag :content => /was not found/
447 assert_error_tag :content => /was not found/
436 end
448 end
437 end
449 end
438
450
439 def test_destroy_valid_repository
451 def test_destroy_valid_repository
440 @request.session[:user_id] = 1 # admin
452 @request.session[:user_id] = 1 # admin
441 assert_equal 0, @repository.changesets.count
453 assert_equal 0, @repository.changesets.count
442 @repository.fetch_changesets
454 @repository.fetch_changesets
443 @project.reload
455 @project.reload
444 assert_equal NUM_REV, @repository.changesets.count
456 assert_equal NUM_REV, @repository.changesets.count
445
457
446 assert_difference 'Repository.count', -1 do
458 assert_difference 'Repository.count', -1 do
447 delete :destroy, :id => @repository.id
459 delete :destroy, :id => @repository.id
448 end
460 end
449 assert_response 302
461 assert_response 302
450 @project.reload
462 @project.reload
451 assert_nil @project.repository
463 assert_nil @project.repository
452 end
464 end
453
465
454 def test_destroy_invalid_repository
466 def test_destroy_invalid_repository
455 @request.session[:user_id] = 1 # admin
467 @request.session[:user_id] = 1 # admin
456 @project.repository.destroy
468 @project.repository.destroy
457 @repository = Repository::Git.create!(
469 @repository = Repository::Git.create!(
458 :project => @project,
470 :project => @project,
459 :url => "/invalid",
471 :url => "/invalid",
460 :path_encoding => 'ISO-8859-1'
472 :path_encoding => 'ISO-8859-1'
461 )
473 )
462 @repository.fetch_changesets
474 @repository.fetch_changesets
463 @repository.reload
475 @repository.reload
464 assert_equal 0, @repository.changesets.count
476 assert_equal 0, @repository.changesets.count
465
477
466 assert_difference 'Repository.count', -1 do
478 assert_difference 'Repository.count', -1 do
467 delete :destroy, :id => @repository.id
479 delete :destroy, :id => @repository.id
468 end
480 end
469 assert_response 302
481 assert_response 302
470 @project.reload
482 @project.reload
471 assert_nil @project.repository
483 assert_nil @project.repository
472 end
484 end
473
485
474 private
486 private
475
487
476 def puts_ruby19_non_utf8_pass
488 def puts_ruby19_non_utf8_pass
477 puts "TODO: This test fails in Ruby 1.9 " +
489 puts "TODO: This test fails in Ruby 1.9 " +
478 "and Encoding.default_external is not UTF-8. " +
490 "and Encoding.default_external is not UTF-8. " +
479 "Current value is '#{Encoding.default_external.to_s}'"
491 "Current value is '#{Encoding.default_external.to_s}'"
480 end
492 end
481 else
493 else
482 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
494 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
483 def test_fake; assert true end
495 def test_fake; assert true end
484 end
496 end
485
497
486 private
498 private
487 def with_cache(&block)
499 def with_cache(&block)
488 before = ActionController::Base.perform_caching
500 before = ActionController::Base.perform_caching
489 ActionController::Base.perform_caching = true
501 ActionController::Base.perform_caching = true
490 block.call
502 block.call
491 ActionController::Base.perform_caching = before
503 ActionController::Base.perform_caching = before
492 end
504 end
493 end
505 end
General Comments 0
You need to be logged in to leave comments. Login now