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