##// END OF EJS Templates
scm: git: add test that diff type is saved in user preference (#10152)...
Toshi MARUYAMA -
r8640:af50c1e13e67
parent child
Show More
@@ -1,473 +1,493
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositoriesGitControllerTest < ActionController::TestCase
20 class RepositoriesGitControllerTest < ActionController::TestCase
21 tests RepositoriesController
21 tests RepositoriesController
22
22
23 fixtures :projects, :users, :roles, :members, :member_roles,
23 fixtures :projects, :users, :roles, :members, :member_roles,
24 :repositories, :enabled_modules
24 :repositories, :enabled_modules
25
25
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 PRJ_ID = 3
28 PRJ_ID = 3
29 CHAR_1_HEX = "\xc3\x9c"
29 CHAR_1_HEX = "\xc3\x9c"
30 NUM_REV = 21
30 NUM_REV = 21
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 if File.directory?(REPOSITORY_PATH)
60 if File.directory?(REPOSITORY_PATH)
61 def test_get_new
61 def test_get_new
62 @request.session[:user_id] = 1
62 @request.session[:user_id] = 1
63 @project.repository.destroy
63 @project.repository.destroy
64 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
64 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
65 assert_response :success
65 assert_response :success
66 assert_template 'new'
66 assert_template 'new'
67 assert_kind_of Repository::Git, assigns(:repository)
67 assert_kind_of Repository::Git, assigns(:repository)
68 assert assigns(:repository).new_record?
68 assert assigns(:repository).new_record?
69 end
69 end
70
70
71 def test_browse_root
71 def test_browse_root
72 assert_equal 0, @repository.changesets.count
72 assert_equal 0, @repository.changesets.count
73 @repository.fetch_changesets
73 @repository.fetch_changesets
74 @project.reload
74 @project.reload
75 assert_equal NUM_REV, @repository.changesets.count
75 assert_equal NUM_REV, @repository.changesets.count
76
76
77 get :show, :id => PRJ_ID
77 get :show, :id => PRJ_ID
78 assert_response :success
78 assert_response :success
79 assert_template 'show'
79 assert_template 'show'
80 assert_not_nil assigns(:entries)
80 assert_not_nil assigns(:entries)
81 assert_equal 9, assigns(:entries).size
81 assert_equal 9, assigns(:entries).size
82 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
82 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
83 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
83 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
86 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
86 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
87 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
87 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
88 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
88 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
89 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
89 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
90 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
90 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
91 assert_not_nil assigns(:changesets)
91 assert_not_nil assigns(:changesets)
92 assert assigns(:changesets).size > 0
92 assert assigns(:changesets).size > 0
93 end
93 end
94
94
95 def test_browse_branch
95 def test_browse_branch
96 assert_equal 0, @repository.changesets.count
96 assert_equal 0, @repository.changesets.count
97 @repository.fetch_changesets
97 @repository.fetch_changesets
98 @project.reload
98 @project.reload
99 assert_equal NUM_REV, @repository.changesets.count
99 assert_equal NUM_REV, @repository.changesets.count
100 get :show, :id => PRJ_ID, :rev => 'test_branch'
100 get :show, :id => PRJ_ID, :rev => 'test_branch'
101 assert_response :success
101 assert_response :success
102 assert_template 'show'
102 assert_template 'show'
103 assert_not_nil assigns(:entries)
103 assert_not_nil assigns(:entries)
104 assert_equal 4, assigns(:entries).size
104 assert_equal 4, assigns(:entries).size
105 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
105 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
106 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
106 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
107 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
107 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
108 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
108 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
109 assert_not_nil assigns(:changesets)
109 assert_not_nil assigns(:changesets)
110 assert assigns(:changesets).size > 0
110 assert assigns(:changesets).size > 0
111 end
111 end
112
112
113 def test_browse_tag
113 def test_browse_tag
114 assert_equal 0, @repository.changesets.count
114 assert_equal 0, @repository.changesets.count
115 @repository.fetch_changesets
115 @repository.fetch_changesets
116 @project.reload
116 @project.reload
117 assert_equal NUM_REV, @repository.changesets.count
117 assert_equal NUM_REV, @repository.changesets.count
118 [
118 [
119 "tag00.lightweight",
119 "tag00.lightweight",
120 "tag01.annotated",
120 "tag01.annotated",
121 ].each do |t1|
121 ].each do |t1|
122 get :show, :id => PRJ_ID, :rev => t1
122 get :show, :id => PRJ_ID, :rev => t1
123 assert_response :success
123 assert_response :success
124 assert_template 'show'
124 assert_template 'show'
125 assert_not_nil assigns(:entries)
125 assert_not_nil assigns(:entries)
126 assert assigns(:entries).size > 0
126 assert assigns(:entries).size > 0
127 assert_not_nil assigns(:changesets)
127 assert_not_nil assigns(:changesets)
128 assert assigns(:changesets).size > 0
128 assert assigns(:changesets).size > 0
129 end
129 end
130 end
130 end
131
131
132 def test_browse_directory
132 def test_browse_directory
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, :path => ['images']
137 get :show, :id => PRJ_ID, :path => ['images']
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 ['edit.png'], assigns(:entries).collect(&:name)
141 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
142 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
142 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
143 assert_not_nil entry
143 assert_not_nil entry
144 assert_equal 'file', entry.kind
144 assert_equal 'file', entry.kind
145 assert_equal 'images/edit.png', entry.path
145 assert_equal 'images/edit.png', entry.path
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_at_given_revision
150 def test_browse_at_given_revision
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 get :show, :id => PRJ_ID, :path => ['images'],
155 get :show, :id => PRJ_ID, :path => ['images'],
156 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
156 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
157 assert_response :success
157 assert_response :success
158 assert_template 'show'
158 assert_template 'show'
159 assert_not_nil assigns(:entries)
159 assert_not_nil assigns(:entries)
160 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
160 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
161 assert_not_nil assigns(:changesets)
161 assert_not_nil assigns(:changesets)
162 assert assigns(:changesets).size > 0
162 assert assigns(:changesets).size > 0
163 end
163 end
164
164
165 def test_changes
165 def test_changes
166 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
166 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
167 assert_response :success
167 assert_response :success
168 assert_template 'changes'
168 assert_template 'changes'
169 assert_tag :tag => 'h2', :content => 'edit.png'
169 assert_tag :tag => 'h2', :content => 'edit.png'
170 end
170 end
171
171
172 def test_entry_show
172 def test_entry_show
173 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
173 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
174 assert_response :success
174 assert_response :success
175 assert_template 'entry'
175 assert_template 'entry'
176 # Line 19
176 # Line 19
177 assert_tag :tag => 'th',
177 assert_tag :tag => 'th',
178 :content => '11',
178 :content => '11',
179 :attributes => { :class => 'line-num' },
179 :attributes => { :class => 'line-num' },
180 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
180 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
181 end
181 end
182
182
183 def test_entry_show_latin_1
183 def test_entry_show_latin_1
184 if @ruby19_non_utf8_pass
184 if @ruby19_non_utf8_pass
185 puts_ruby19_non_utf8_pass()
185 puts_ruby19_non_utf8_pass()
186 elsif JRUBY_SKIP
186 elsif JRUBY_SKIP
187 puts JRUBY_SKIP_STR
187 puts JRUBY_SKIP_STR
188 else
188 else
189 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
189 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
190 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
190 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
191 get :entry, :id => PRJ_ID,
191 get :entry, :id => PRJ_ID,
192 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
192 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
193 assert_response :success
193 assert_response :success
194 assert_template 'entry'
194 assert_template 'entry'
195 assert_tag :tag => 'th',
195 assert_tag :tag => 'th',
196 :content => '1',
196 :content => '1',
197 :attributes => { :class => 'line-num' },
197 :attributes => { :class => 'line-num' },
198 :sibling => { :tag => 'td',
198 :sibling => { :tag => 'td',
199 :content => /test-#{@char_1}.txt/ }
199 :content => /test-#{@char_1}.txt/ }
200 end
200 end
201 end
201 end
202 end
202 end
203 end
203 end
204
204
205 def test_entry_download
205 def test_entry_download
206 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
206 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
207 :format => 'raw'
207 :format => 'raw'
208 assert_response :success
208 assert_response :success
209 # File content
209 # File content
210 assert @response.body.include?('WITHOUT ANY WARRANTY')
210 assert @response.body.include?('WITHOUT ANY WARRANTY')
211 end
211 end
212
212
213 def test_directory_entry
213 def test_directory_entry
214 get :entry, :id => PRJ_ID, :path => ['sources']
214 get :entry, :id => PRJ_ID, :path => ['sources']
215 assert_response :success
215 assert_response :success
216 assert_template 'show'
216 assert_template 'show'
217 assert_not_nil assigns(:entry)
217 assert_not_nil assigns(:entry)
218 assert_equal 'sources', assigns(:entry).name
218 assert_equal 'sources', assigns(:entry).name
219 end
219 end
220
220
221 def test_diff
221 def test_diff
222 assert_equal 0, @repository.changesets.count
222 assert_equal 0, @repository.changesets.count
223 @repository.fetch_changesets
223 @repository.fetch_changesets
224 @project.reload
224 @project.reload
225 assert_equal NUM_REV, @repository.changesets.count
225 assert_equal NUM_REV, @repository.changesets.count
226 # Full diff of changeset 2f9c0091
226 # Full diff of changeset 2f9c0091
227 ['inline', 'sbs'].each do |dt|
227 ['inline', 'sbs'].each do |dt|
228 get :diff,
228 get :diff,
229 :id => PRJ_ID,
229 :id => PRJ_ID,
230 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
230 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
231 :type => dt
231 :type => dt
232 assert_response :success
232 assert_response :success
233 assert_template 'diff'
233 assert_template 'diff'
234 # Line 22 removed
234 # Line 22 removed
235 assert_tag :tag => 'th',
235 assert_tag :tag => 'th',
236 :content => /22/,
236 :content => /22/,
237 :sibling => { :tag => 'td',
237 :sibling => { :tag => 'td',
238 :attributes => { :class => /diff_out/ },
238 :attributes => { :class => /diff_out/ },
239 :content => /def remove/ }
239 :content => /def remove/ }
240 assert_tag :tag => 'h2', :content => /2f9c0091/
240 assert_tag :tag => 'h2', :content => /2f9c0091/
241 end
241 end
242 end
242 end
243
243
244 def test_diff_truncated
244 def test_diff_truncated
245 assert_equal 0, @repository.changesets.count
245 assert_equal 0, @repository.changesets.count
246 @repository.fetch_changesets
246 @repository.fetch_changesets
247 @project.reload
247 @project.reload
248 assert_equal NUM_REV, @repository.changesets.count
248 assert_equal NUM_REV, @repository.changesets.count
249 Setting.diff_max_lines_displayed = 5
249 Setting.diff_max_lines_displayed = 5
250
250
251 # Truncated diff of changeset 2f9c0091
251 # Truncated diff of changeset 2f9c0091
252 with_cache do
252 with_cache do
253 get :diff, :id => PRJ_ID, :type => 'inline',
253 get :diff, :id => PRJ_ID, :type => 'inline',
254 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
254 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
255 assert_response :success
255 assert_response :success
256 assert @response.body.include?("... This diff was truncated")
256 assert @response.body.include?("... This diff was truncated")
257
257
258 Setting.default_language = 'fr'
258 Setting.default_language = 'fr'
259 get :diff, :id => PRJ_ID, :type => 'inline',
259 get :diff, :id => PRJ_ID, :type => 'inline',
260 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
260 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
261 assert_response :success
261 assert_response :success
262 assert ! @response.body.include?("... This diff was truncated")
262 assert ! @response.body.include?("... This diff was truncated")
263 assert @response.body.include?("... Ce diff")
263 assert @response.body.include?("... Ce diff")
264 end
264 end
265 end
265 end
266
266
267 def test_diff_two_revs
267 def test_diff_two_revs
268 assert_equal 0, @repository.changesets.count
268 assert_equal 0, @repository.changesets.count
269 @repository.fetch_changesets
269 @repository.fetch_changesets
270 @project.reload
270 @project.reload
271 assert_equal NUM_REV, @repository.changesets.count
271 assert_equal NUM_REV, @repository.changesets.count
272 ['inline', 'sbs'].each do |dt|
272 ['inline', 'sbs'].each do |dt|
273 get :diff,
273 get :diff,
274 :id => PRJ_ID,
274 :id => PRJ_ID,
275 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
275 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
276 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
276 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
277 :type => dt
277 :type => dt
278 assert_response :success
278 assert_response :success
279 assert_template 'diff'
279 assert_template 'diff'
280 diff = assigns(:diff)
280 diff = assigns(:diff)
281 assert_not_nil diff
281 assert_not_nil diff
282 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
282 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
283 end
283 end
284 end
284 end
285
285
286 def test_diff_latin_1
286 def test_diff_latin_1
287 if @ruby19_non_utf8_pass
287 if @ruby19_non_utf8_pass
288 puts_ruby19_non_utf8_pass()
288 puts_ruby19_non_utf8_pass()
289 else
289 else
290 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
290 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
291 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
291 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
292 ['inline', 'sbs'].each do |dt|
292 ['inline', 'sbs'].each do |dt|
293 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
293 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
294 assert_response :success
294 assert_response :success
295 assert_template 'diff'
295 assert_template 'diff'
296 assert_tag :tag => 'thead',
296 assert_tag :tag => 'thead',
297 :descendant => {
297 :descendant => {
298 :tag => 'th',
298 :tag => 'th',
299 :attributes => { :class => 'filename' } ,
299 :attributes => { :class => 'filename' } ,
300 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
300 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
301 },
301 },
302 :sibling => {
302 :sibling => {
303 :tag => 'tbody',
303 :tag => 'tbody',
304 :descendant => {
304 :descendant => {
305 :tag => 'td',
305 :tag => 'td',
306 :attributes => { :class => /diff_in/ },
306 :attributes => { :class => /diff_in/ },
307 :content => /test-#{@char_1}.txt/
307 :content => /test-#{@char_1}.txt/
308 }
308 }
309 }
309 }
310 end
310 end
311 end
311 end
312 end
312 end
313 end
313 end
314 end
314 end
315
315
316 def test_save_diff_type
317 @request.session[:user_id] = 1 # admin
318 user = User.find(1)
319 get :diff,
320 :id => PRJ_ID,
321 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
322 assert_response :success
323 assert_template 'diff'
324 user.reload
325 assert_equal "inline", user.pref[:diff_type]
326 get :diff,
327 :id => PRJ_ID,
328 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
329 :type => 'sbs'
330 assert_response :success
331 assert_template 'diff'
332 user.reload
333 assert_equal "sbs", user.pref[:diff_type]
334 end
335
316 def test_annotate
336 def test_annotate
317 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
337 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
318 assert_response :success
338 assert_response :success
319 assert_template 'annotate'
339 assert_template 'annotate'
320 # Line 24, changeset 2f9c0091
340 # Line 24, changeset 2f9c0091
321 assert_tag :tag => 'th', :content => '24',
341 assert_tag :tag => 'th', :content => '24',
322 :sibling => {
342 :sibling => {
323 :tag => 'td',
343 :tag => 'td',
324 :child => {
344 :child => {
325 :tag => 'a',
345 :tag => 'a',
326 :content => /2f9c0091/
346 :content => /2f9c0091/
327 }
347 }
328 }
348 }
329 assert_tag :tag => 'th', :content => '24',
349 assert_tag :tag => 'th', :content => '24',
330 :sibling => { :tag => 'td', :content => /jsmith/ }
350 :sibling => { :tag => 'td', :content => /jsmith/ }
331 assert_tag :tag => 'th', :content => '24',
351 assert_tag :tag => 'th', :content => '24',
332 :sibling => {
352 :sibling => {
333 :tag => 'td',
353 :tag => 'td',
334 :child => {
354 :child => {
335 :tag => 'a',
355 :tag => 'a',
336 :content => /2f9c0091/
356 :content => /2f9c0091/
337 }
357 }
338 }
358 }
339 assert_tag :tag => 'th', :content => '24',
359 assert_tag :tag => 'th', :content => '24',
340 :sibling => { :tag => 'td', :content => /watcher =/ }
360 :sibling => { :tag => 'td', :content => /watcher =/ }
341 end
361 end
342
362
343 def test_annotate_at_given_revision
363 def test_annotate_at_given_revision
344 assert_equal 0, @repository.changesets.count
364 assert_equal 0, @repository.changesets.count
345 @repository.fetch_changesets
365 @repository.fetch_changesets
346 @project.reload
366 @project.reload
347 assert_equal NUM_REV, @repository.changesets.count
367 assert_equal NUM_REV, @repository.changesets.count
348 get :annotate, :id => PRJ_ID, :rev => 'deff7',
368 get :annotate, :id => PRJ_ID, :rev => 'deff7',
349 :path => ['sources', 'watchers_controller.rb']
369 :path => ['sources', 'watchers_controller.rb']
350 assert_response :success
370 assert_response :success
351 assert_template 'annotate'
371 assert_template 'annotate'
352 assert_tag :tag => 'h2', :content => /@ deff712f/
372 assert_tag :tag => 'h2', :content => /@ deff712f/
353 end
373 end
354
374
355 def test_annotate_binary_file
375 def test_annotate_binary_file
356 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
376 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
357 assert_response 500
377 assert_response 500
358 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
378 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
359 :content => /cannot be annotated/
379 :content => /cannot be annotated/
360 end
380 end
361
381
362 def test_annotate_error_when_too_big
382 def test_annotate_error_when_too_big
363 with_settings :file_max_size_displayed => 1 do
383 with_settings :file_max_size_displayed => 1 do
364 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 'deff712f'
384 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 'deff712f'
365 assert_response 500
385 assert_response 500
366 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
386 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
367 :content => /exceeds the maximum text file size/
387 :content => /exceeds the maximum text file size/
368
388
369 get :annotate, :id => PRJ_ID, :path => ['README'], :rev => '7234cb2'
389 get :annotate, :id => PRJ_ID, :path => ['README'], :rev => '7234cb2'
370 assert_response :success
390 assert_response :success
371 assert_template 'annotate'
391 assert_template 'annotate'
372 end
392 end
373 end
393 end
374
394
375 def test_annotate_latin_1
395 def test_annotate_latin_1
376 if @ruby19_non_utf8_pass
396 if @ruby19_non_utf8_pass
377 puts_ruby19_non_utf8_pass()
397 puts_ruby19_non_utf8_pass()
378 elsif JRUBY_SKIP
398 elsif JRUBY_SKIP
379 puts JRUBY_SKIP_STR
399 puts JRUBY_SKIP_STR
380 else
400 else
381 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
401 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
382 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
402 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
383 get :annotate, :id => PRJ_ID,
403 get :annotate, :id => PRJ_ID,
384 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
404 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
385 assert_tag :tag => 'th',
405 assert_tag :tag => 'th',
386 :content => '1',
406 :content => '1',
387 :attributes => { :class => 'line-num' },
407 :attributes => { :class => 'line-num' },
388 :sibling => { :tag => 'td',
408 :sibling => { :tag => 'td',
389 :content => /test-#{@char_1}.txt/ }
409 :content => /test-#{@char_1}.txt/ }
390 end
410 end
391 end
411 end
392 end
412 end
393 end
413 end
394
414
395 def test_revision
415 def test_revision
396 assert_equal 0, @repository.changesets.count
416 assert_equal 0, @repository.changesets.count
397 @repository.fetch_changesets
417 @repository.fetch_changesets
398 @project.reload
418 @project.reload
399 assert_equal NUM_REV, @repository.changesets.count
419 assert_equal NUM_REV, @repository.changesets.count
400 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
420 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
401 get :revision, :id => PRJ_ID, :rev => r
421 get :revision, :id => PRJ_ID, :rev => r
402 assert_response :success
422 assert_response :success
403 assert_template 'revision'
423 assert_template 'revision'
404 end
424 end
405 end
425 end
406
426
407 def test_empty_revision
427 def test_empty_revision
408 assert_equal 0, @repository.changesets.count
428 assert_equal 0, @repository.changesets.count
409 @repository.fetch_changesets
429 @repository.fetch_changesets
410 @project.reload
430 @project.reload
411 assert_equal NUM_REV, @repository.changesets.count
431 assert_equal NUM_REV, @repository.changesets.count
412 ['', ' ', nil].each do |r|
432 ['', ' ', nil].each do |r|
413 get :revision, :id => PRJ_ID, :rev => r
433 get :revision, :id => PRJ_ID, :rev => r
414 assert_response 404
434 assert_response 404
415 assert_error_tag :content => /was not found/
435 assert_error_tag :content => /was not found/
416 end
436 end
417 end
437 end
418
438
419 def test_destroy_valid_repository
439 def test_destroy_valid_repository
420 @request.session[:user_id] = 1 # admin
440 @request.session[:user_id] = 1 # admin
421 assert_equal 0, @repository.changesets.count
441 assert_equal 0, @repository.changesets.count
422 @repository.fetch_changesets
442 @repository.fetch_changesets
423 @project.reload
443 @project.reload
424 assert_equal NUM_REV, @repository.changesets.count
444 assert_equal NUM_REV, @repository.changesets.count
425
445
426 assert_difference 'Repository.count', -1 do
446 assert_difference 'Repository.count', -1 do
427 delete :destroy, :id => @repository.id
447 delete :destroy, :id => @repository.id
428 end
448 end
429 assert_response 302
449 assert_response 302
430 @project.reload
450 @project.reload
431 assert_nil @project.repository
451 assert_nil @project.repository
432 end
452 end
433
453
434 def test_destroy_invalid_repository
454 def test_destroy_invalid_repository
435 @request.session[:user_id] = 1 # admin
455 @request.session[:user_id] = 1 # admin
436 @project.repository.destroy
456 @project.repository.destroy
437 @repository = Repository::Git.create!(
457 @repository = Repository::Git.create!(
438 :project => @project,
458 :project => @project,
439 :url => "/invalid",
459 :url => "/invalid",
440 :path_encoding => 'ISO-8859-1'
460 :path_encoding => 'ISO-8859-1'
441 )
461 )
442 @repository.fetch_changesets
462 @repository.fetch_changesets
443 @repository.reload
463 @repository.reload
444 assert_equal 0, @repository.changesets.count
464 assert_equal 0, @repository.changesets.count
445
465
446 assert_difference 'Repository.count', -1 do
466 assert_difference 'Repository.count', -1 do
447 delete :destroy, :id => @repository.id
467 delete :destroy, :id => @repository.id
448 end
468 end
449 assert_response 302
469 assert_response 302
450 @project.reload
470 @project.reload
451 assert_nil @project.repository
471 assert_nil @project.repository
452 end
472 end
453
473
454 private
474 private
455
475
456 def puts_ruby19_non_utf8_pass
476 def puts_ruby19_non_utf8_pass
457 puts "TODO: This test fails in Ruby 1.9 " +
477 puts "TODO: This test fails in Ruby 1.9 " +
458 "and Encoding.default_external is not UTF-8. " +
478 "and Encoding.default_external is not UTF-8. " +
459 "Current value is '#{Encoding.default_external.to_s}'"
479 "Current value is '#{Encoding.default_external.to_s}'"
460 end
480 end
461 else
481 else
462 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
482 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
463 def test_fake; assert true end
483 def test_fake; assert true end
464 end
484 end
465
485
466 private
486 private
467 def with_cache(&block)
487 def with_cache(&block)
468 before = ActionController::Base.perform_caching
488 before = ActionController::Base.perform_caching
469 ActionController::Base.perform_caching = true
489 ActionController::Base.perform_caching = true
470 block.call
490 block.call
471 ActionController::Base.perform_caching = before
491 ActionController::Base.perform_caching = before
472 end
492 end
473 end
493 end
General Comments 0
You need to be logged in to leave comments. Login now