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