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