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