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