##// END OF EJS Templates
Merged r10502 from trunk to 1.4-stable (#11966)...
Toshi MARUYAMA -
r10298:8a8df72937c5
parent child
Show More
@@ -1,580 +1,594
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
267 assert_nil @repository.identifier
266 assert_equal 0, @repository.changesets.count
268 assert_equal 0, @repository.changesets.count
267 @repository.fetch_changesets
269 @repository.fetch_changesets
268 @project.reload
270 @project.reload
269 assert_equal NUM_REV, @repository.changesets.count
271 assert_equal NUM_REV, @repository.changesets.count
270 # Full diff of changeset 2f9c0091
272 # Full diff of changeset 2f9c0091
271 ['inline', 'sbs'].each do |dt|
273 ['inline', 'sbs'].each do |dt|
272 get :diff,
274 get :diff,
273 :id => PRJ_ID,
275 :id => PRJ_ID,
274 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
276 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
275 :type => dt
277 :type => dt
276 assert_response :success
278 assert_response :success
277 assert_template 'diff'
279 assert_template 'diff'
278 # Line 22 removed
280 # Line 22 removed
279 assert_tag :tag => 'th',
281 assert_tag :tag => 'th',
280 :content => /22/,
282 :content => /22/,
281 :sibling => { :tag => 'td',
283 :sibling => { :tag => 'td',
282 :attributes => { :class => /diff_out/ },
284 :attributes => { :class => /diff_out/ },
283 :content => /def remove/ }
285 :content => /def remove/ }
284 assert_tag :tag => 'h2', :content => /2f9c0091/
286 assert_tag :tag => 'h2', :content => /2f9c0091/
285 end
287 end
286 end
288 end
287
289
288 def test_diff_with_rev_and_path
290 def test_diff_with_rev_and_path
289 assert_equal 0, @repository.changesets.count
291 assert_equal 0, @repository.changesets.count
290 @repository.fetch_changesets
292 @repository.fetch_changesets
291 @project.reload
293 @project.reload
292 assert_equal NUM_REV, @repository.changesets.count
294 assert_equal NUM_REV, @repository.changesets.count
293 with_settings :diff_max_lines_displayed => 1000 do
295 with_settings :diff_max_lines_displayed => 1000 do
294 # Full diff of changeset 2f9c0091
296 # Full diff of changeset 2f9c0091
295 ['inline', 'sbs'].each do |dt|
297 ['inline', 'sbs'].each do |dt|
296 get :diff,
298 get :diff,
297 :id => PRJ_ID,
299 :id => PRJ_ID,
298 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
300 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
299 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
301 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
300 :type => dt
302 :type => dt
301 assert_response :success
303 assert_response :success
302 assert_template 'diff'
304 assert_template 'diff'
303 # Line 22 removed
305 # Line 22 removed
304 assert_tag :tag => 'th',
306 assert_tag :tag => 'th',
305 :content => '22',
307 :content => '22',
306 :sibling => { :tag => 'td',
308 :sibling => { :tag => 'td',
307 :attributes => { :class => /diff_out/ },
309 :attributes => { :class => /diff_out/ },
308 :content => /def remove/ }
310 :content => /def remove/ }
309 assert_tag :tag => 'h2', :content => /2f9c0091/
311 assert_tag :tag => 'h2', :content => /2f9c0091/
310 end
312 end
311 end
313 end
312 end
314 end
313
315
314 def test_diff_truncated
316 def test_diff_truncated
315 assert_equal 0, @repository.changesets.count
317 assert_equal 0, @repository.changesets.count
316 @repository.fetch_changesets
318 @repository.fetch_changesets
317 @project.reload
319 @project.reload
318 assert_equal NUM_REV, @repository.changesets.count
320 assert_equal NUM_REV, @repository.changesets.count
319
321
320 with_settings :diff_max_lines_displayed => 5 do
322 with_settings :diff_max_lines_displayed => 5 do
321 # Truncated diff of changeset 2f9c0091
323 # Truncated diff of changeset 2f9c0091
322 with_cache do
324 with_cache do
323 with_settings :default_language => 'en' do
325 with_settings :default_language => 'en' do
324 get :diff, :id => PRJ_ID, :type => 'inline',
326 get :diff, :id => PRJ_ID, :type => 'inline',
325 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
327 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
326 assert_response :success
328 assert_response :success
327 assert @response.body.include?("... This diff was truncated")
329 assert @response.body.include?("... This diff was truncated")
328 end
330 end
329 with_settings :default_language => 'fr' do
331 with_settings :default_language => 'fr' do
330 get :diff, :id => PRJ_ID, :type => 'inline',
332 get :diff, :id => PRJ_ID, :type => 'inline',
331 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
333 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
332 assert_response :success
334 assert_response :success
333 assert ! @response.body.include?("... This diff was truncated")
335 assert ! @response.body.include?("... This diff was truncated")
334 assert @response.body.include?("... Ce diff")
336 assert @response.body.include?("... Ce diff")
335 end
337 end
336 end
338 end
337 end
339 end
338 end
340 end
339
341
340 def test_diff_two_revs
342 def test_diff_two_revs
341 assert_equal 0, @repository.changesets.count
343 assert_equal 0, @repository.changesets.count
342 @repository.fetch_changesets
344 @repository.fetch_changesets
343 @project.reload
345 @project.reload
344 assert_equal NUM_REV, @repository.changesets.count
346 assert_equal NUM_REV, @repository.changesets.count
345 ['inline', 'sbs'].each do |dt|
347 ['inline', 'sbs'].each do |dt|
346 get :diff,
348 get :diff,
347 :id => PRJ_ID,
349 :id => PRJ_ID,
348 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
350 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
349 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
351 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
350 :type => dt
352 :type => dt
351 assert_response :success
353 assert_response :success
352 assert_template 'diff'
354 assert_template 'diff'
353 diff = assigns(:diff)
355 diff = assigns(:diff)
354 assert_not_nil diff
356 assert_not_nil diff
355 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
357 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
358 assert_tag :tag => "form",
359 :attributes => {
360 :action => "/projects/subproject1/repository/revisions/" +
361 "61b685fbe55ab05b5ac68402d5720c1a6ac973d1/diff"
362 }
363 assert_tag :tag => 'input',
364 :attributes => {
365 :id => "rev_to",
366 :name => "rev_to",
367 :type => "hidden",
368 :value => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
369 }
356 end
370 end
357 end
371 end
358
372
359 def test_diff_latin_1
373 def test_diff_latin_1
360 if @ruby19_non_utf8_pass
374 if @ruby19_non_utf8_pass
361 puts_ruby19_non_utf8_pass()
375 puts_ruby19_non_utf8_pass()
362 else
376 else
363 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
377 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
364 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
378 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
365 ['inline', 'sbs'].each do |dt|
379 ['inline', 'sbs'].each do |dt|
366 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
380 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
367 assert_response :success
381 assert_response :success
368 assert_template 'diff'
382 assert_template 'diff'
369 assert_tag :tag => 'thead',
383 assert_tag :tag => 'thead',
370 :descendant => {
384 :descendant => {
371 :tag => 'th',
385 :tag => 'th',
372 :attributes => { :class => 'filename' } ,
386 :attributes => { :class => 'filename' } ,
373 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
387 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
374 },
388 },
375 :sibling => {
389 :sibling => {
376 :tag => 'tbody',
390 :tag => 'tbody',
377 :descendant => {
391 :descendant => {
378 :tag => 'td',
392 :tag => 'td',
379 :attributes => { :class => /diff_in/ },
393 :attributes => { :class => /diff_in/ },
380 :content => /test-#{@char_1}.txt/
394 :content => /test-#{@char_1}.txt/
381 }
395 }
382 }
396 }
383 end
397 end
384 end
398 end
385 end
399 end
386 end
400 end
387 end
401 end
388
402
389 def test_save_diff_type
403 def test_save_diff_type
390 user1 = User.find(1)
404 user1 = User.find(1)
391 user1.pref[:diff_type] = nil
405 user1.pref[:diff_type] = nil
392 user1.preference.save
406 user1.preference.save
393 user = User.find(1)
407 user = User.find(1)
394 assert_nil user.pref[:diff_type]
408 assert_nil user.pref[:diff_type]
395
409
396 @request.session[:user_id] = 1 # admin
410 @request.session[:user_id] = 1 # admin
397 get :diff,
411 get :diff,
398 :id => PRJ_ID,
412 :id => PRJ_ID,
399 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
413 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
400 assert_response :success
414 assert_response :success
401 assert_template 'diff'
415 assert_template 'diff'
402 user.reload
416 user.reload
403 assert_equal "inline", user.pref[:diff_type]
417 assert_equal "inline", user.pref[:diff_type]
404 get :diff,
418 get :diff,
405 :id => PRJ_ID,
419 :id => PRJ_ID,
406 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
420 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
407 :type => 'sbs'
421 :type => 'sbs'
408 assert_response :success
422 assert_response :success
409 assert_template 'diff'
423 assert_template 'diff'
410 user.reload
424 user.reload
411 assert_equal "sbs", user.pref[:diff_type]
425 assert_equal "sbs", user.pref[:diff_type]
412 end
426 end
413
427
414 def test_annotate
428 def test_annotate
415 get :annotate, :id => PRJ_ID,
429 get :annotate, :id => PRJ_ID,
416 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
430 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
417 assert_response :success
431 assert_response :success
418 assert_template 'annotate'
432 assert_template 'annotate'
419 # Line 24, changeset 2f9c0091
433 # Line 24, changeset 2f9c0091
420 assert_tag :tag => 'th', :content => '24',
434 assert_tag :tag => 'th', :content => '24',
421 :sibling => {
435 :sibling => {
422 :tag => 'td',
436 :tag => 'td',
423 :child => {
437 :child => {
424 :tag => 'a',
438 :tag => 'a',
425 :content => /2f9c0091/
439 :content => /2f9c0091/
426 }
440 }
427 }
441 }
428 assert_tag :tag => 'th', :content => '24',
442 assert_tag :tag => 'th', :content => '24',
429 :sibling => { :tag => 'td', :content => /jsmith/ }
443 :sibling => { :tag => 'td', :content => /jsmith/ }
430 assert_tag :tag => 'th', :content => '24',
444 assert_tag :tag => 'th', :content => '24',
431 :sibling => {
445 :sibling => {
432 :tag => 'td',
446 :tag => 'td',
433 :child => {
447 :child => {
434 :tag => 'a',
448 :tag => 'a',
435 :content => /2f9c0091/
449 :content => /2f9c0091/
436 }
450 }
437 }
451 }
438 assert_tag :tag => 'th', :content => '24',
452 assert_tag :tag => 'th', :content => '24',
439 :sibling => { :tag => 'td', :content => /watcher =/ }
453 :sibling => { :tag => 'td', :content => /watcher =/ }
440 end
454 end
441
455
442 def test_annotate_at_given_revision
456 def test_annotate_at_given_revision
443 assert_equal 0, @repository.changesets.count
457 assert_equal 0, @repository.changesets.count
444 @repository.fetch_changesets
458 @repository.fetch_changesets
445 @project.reload
459 @project.reload
446 assert_equal NUM_REV, @repository.changesets.count
460 assert_equal NUM_REV, @repository.changesets.count
447 get :annotate, :id => PRJ_ID, :rev => 'deff7',
461 get :annotate, :id => PRJ_ID, :rev => 'deff7',
448 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
462 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
449 assert_response :success
463 assert_response :success
450 assert_template 'annotate'
464 assert_template 'annotate'
451 assert_tag :tag => 'h2', :content => /@ deff712f/
465 assert_tag :tag => 'h2', :content => /@ deff712f/
452 end
466 end
453
467
454 def test_annotate_binary_file
468 def test_annotate_binary_file
455 get :annotate, :id => PRJ_ID,
469 get :annotate, :id => PRJ_ID,
456 :path => repository_path_hash(['images', 'edit.png'])[:param]
470 :path => repository_path_hash(['images', 'edit.png'])[:param]
457 assert_response 500
471 assert_response 500
458 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
472 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
459 :content => /cannot be annotated/
473 :content => /cannot be annotated/
460 end
474 end
461
475
462 def test_annotate_error_when_too_big
476 def test_annotate_error_when_too_big
463 with_settings :file_max_size_displayed => 1 do
477 with_settings :file_max_size_displayed => 1 do
464 get :annotate, :id => PRJ_ID,
478 get :annotate, :id => PRJ_ID,
465 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
479 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
466 :rev => 'deff712f'
480 :rev => 'deff712f'
467 assert_response 500
481 assert_response 500
468 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
482 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
469 :content => /exceeds the maximum text file size/
483 :content => /exceeds the maximum text file size/
470
484
471 get :annotate, :id => PRJ_ID,
485 get :annotate, :id => PRJ_ID,
472 :path => repository_path_hash(['README'])[:param],
486 :path => repository_path_hash(['README'])[:param],
473 :rev => '7234cb2'
487 :rev => '7234cb2'
474 assert_response :success
488 assert_response :success
475 assert_template 'annotate'
489 assert_template 'annotate'
476 end
490 end
477 end
491 end
478
492
479 def test_annotate_latin_1
493 def test_annotate_latin_1
480 if @ruby19_non_utf8_pass
494 if @ruby19_non_utf8_pass
481 puts_ruby19_non_utf8_pass()
495 puts_ruby19_non_utf8_pass()
482 elsif WINDOWS_PASS
496 elsif WINDOWS_PASS
483 puts WINDOWS_SKIP_STR
497 puts WINDOWS_SKIP_STR
484 elsif JRUBY_SKIP
498 elsif JRUBY_SKIP
485 puts JRUBY_SKIP_STR
499 puts JRUBY_SKIP_STR
486 else
500 else
487 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
501 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
488 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
502 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
489 get :annotate, :id => PRJ_ID,
503 get :annotate, :id => PRJ_ID,
490 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
504 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
491 :rev => r1
505 :rev => r1
492 assert_tag :tag => 'th',
506 assert_tag :tag => 'th',
493 :content => '1',
507 :content => '1',
494 :attributes => { :class => 'line-num' },
508 :attributes => { :class => 'line-num' },
495 :sibling => { :tag => 'td',
509 :sibling => { :tag => 'td',
496 :content => /test-#{@char_1}.txt/ }
510 :content => /test-#{@char_1}.txt/ }
497 end
511 end
498 end
512 end
499 end
513 end
500 end
514 end
501
515
502 def test_revision
516 def test_revision
503 assert_equal 0, @repository.changesets.count
517 assert_equal 0, @repository.changesets.count
504 @repository.fetch_changesets
518 @repository.fetch_changesets
505 @project.reload
519 @project.reload
506 assert_equal NUM_REV, @repository.changesets.count
520 assert_equal NUM_REV, @repository.changesets.count
507 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
521 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
508 get :revision, :id => PRJ_ID, :rev => r
522 get :revision, :id => PRJ_ID, :rev => r
509 assert_response :success
523 assert_response :success
510 assert_template 'revision'
524 assert_template 'revision'
511 end
525 end
512 end
526 end
513
527
514 def test_empty_revision
528 def test_empty_revision
515 assert_equal 0, @repository.changesets.count
529 assert_equal 0, @repository.changesets.count
516 @repository.fetch_changesets
530 @repository.fetch_changesets
517 @project.reload
531 @project.reload
518 assert_equal NUM_REV, @repository.changesets.count
532 assert_equal NUM_REV, @repository.changesets.count
519 ['', ' ', nil].each do |r|
533 ['', ' ', nil].each do |r|
520 get :revision, :id => PRJ_ID, :rev => r
534 get :revision, :id => PRJ_ID, :rev => r
521 assert_response 404
535 assert_response 404
522 assert_error_tag :content => /was not found/
536 assert_error_tag :content => /was not found/
523 end
537 end
524 end
538 end
525
539
526 def test_destroy_valid_repository
540 def test_destroy_valid_repository
527 @request.session[:user_id] = 1 # admin
541 @request.session[:user_id] = 1 # admin
528 assert_equal 0, @repository.changesets.count
542 assert_equal 0, @repository.changesets.count
529 @repository.fetch_changesets
543 @repository.fetch_changesets
530 @project.reload
544 @project.reload
531 assert_equal NUM_REV, @repository.changesets.count
545 assert_equal NUM_REV, @repository.changesets.count
532
546
533 assert_difference 'Repository.count', -1 do
547 assert_difference 'Repository.count', -1 do
534 delete :destroy, :id => @repository.id
548 delete :destroy, :id => @repository.id
535 end
549 end
536 assert_response 302
550 assert_response 302
537 @project.reload
551 @project.reload
538 assert_nil @project.repository
552 assert_nil @project.repository
539 end
553 end
540
554
541 def test_destroy_invalid_repository
555 def test_destroy_invalid_repository
542 @request.session[:user_id] = 1 # admin
556 @request.session[:user_id] = 1 # admin
543 @project.repository.destroy
557 @project.repository.destroy
544 @repository = Repository::Git.create!(
558 @repository = Repository::Git.create!(
545 :project => @project,
559 :project => @project,
546 :url => "/invalid",
560 :url => "/invalid",
547 :path_encoding => 'ISO-8859-1'
561 :path_encoding => 'ISO-8859-1'
548 )
562 )
549 @repository.fetch_changesets
563 @repository.fetch_changesets
550 @repository.reload
564 @repository.reload
551 assert_equal 0, @repository.changesets.count
565 assert_equal 0, @repository.changesets.count
552
566
553 assert_difference 'Repository.count', -1 do
567 assert_difference 'Repository.count', -1 do
554 delete :destroy, :id => @repository.id
568 delete :destroy, :id => @repository.id
555 end
569 end
556 assert_response 302
570 assert_response 302
557 @project.reload
571 @project.reload
558 assert_nil @project.repository
572 assert_nil @project.repository
559 end
573 end
560
574
561 private
575 private
562
576
563 def puts_ruby19_non_utf8_pass
577 def puts_ruby19_non_utf8_pass
564 puts "TODO: This test fails in Ruby 1.9 " +
578 puts "TODO: This test fails in Ruby 1.9 " +
565 "and Encoding.default_external is not UTF-8. " +
579 "and Encoding.default_external is not UTF-8. " +
566 "Current value is '#{Encoding.default_external.to_s}'"
580 "Current value is '#{Encoding.default_external.to_s}'"
567 end
581 end
568 else
582 else
569 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
583 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
570 def test_fake; assert true end
584 def test_fake; assert true end
571 end
585 end
572
586
573 private
587 private
574 def with_cache(&block)
588 def with_cache(&block)
575 before = ActionController::Base.perform_caching
589 before = ActionController::Base.perform_caching
576 ActionController::Base.perform_caching = true
590 ActionController::Base.perform_caching = true
577 block.call
591 block.call
578 ActionController::Base.perform_caching = before
592 ActionController::Base.perform_caching = before
579 end
593 end
580 end
594 end
General Comments 0
You need to be logged in to leave comments. Login now