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