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