##// END OF EJS Templates
Test for repository edit and cleanup....
Jean-Philippe Lang -
r7930:4eb14ab85cf4
parent child
Show More
@@ -1,474 +1,480
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 require 'repositories_controller'
20
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
19
24 class RepositoriesGitControllerTest < ActionController::TestCase
20 class RepositoriesGitControllerTest < ActionController::TestCase
21 tests RepositoriesController
22
25 fixtures :projects, :users, :roles, :members, :member_roles,
23 fixtures :projects, :users, :roles, :members, :member_roles,
26 :repositories, :enabled_modules
24 :repositories, :enabled_modules
27
25
28 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 PRJ_ID = 3
28 PRJ_ID = 3
31 CHAR_1_HEX = "\xc3\x9c"
29 CHAR_1_HEX = "\xc3\x9c"
32 NUM_REV = 21
30 NUM_REV = 21
33
31
34 ## Git, Mercurial and CVS path encodings are binary.
32 ## Git, Mercurial and CVS path encodings are binary.
35 ## Subversion supports URL encoding for path.
33 ## Subversion supports URL encoding for path.
36 ## Redmine Mercurial adapter and extension use URL encoding.
34 ## Redmine Mercurial adapter and extension use URL encoding.
37 ## Git accepts only binary path in command line parameter.
35 ## Git accepts only binary path in command line parameter.
38 ## 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.
39 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
40 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
41
39
42 def setup
40 def setup
43 @ruby19_non_utf8_pass =
41 @ruby19_non_utf8_pass =
44 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
45
43
46 @controller = RepositoriesController.new
47 @request = ActionController::TestRequest.new
48 @response = ActionController::TestResponse.new
49 User.current = nil
44 User.current = nil
50 @project = Project.find(PRJ_ID)
45 @project = Project.find(PRJ_ID)
51 @repository = Repository::Git.create(
46 @repository = Repository::Git.create(
52 :project => @project,
47 :project => @project,
53 :url => REPOSITORY_PATH,
48 :url => REPOSITORY_PATH,
54 :path_encoding => 'ISO-8859-1'
49 :path_encoding => 'ISO-8859-1'
55 )
50 )
56 assert @repository
51 assert @repository
57 @char_1 = CHAR_1_HEX.dup
52 @char_1 = CHAR_1_HEX.dup
58 if @char_1.respond_to?(:force_encoding)
53 if @char_1.respond_to?(:force_encoding)
59 @char_1.force_encoding('UTF-8')
54 @char_1.force_encoding('UTF-8')
60 end
55 end
61
56
62 Setting.default_language = 'en'
57 Setting.default_language = 'en'
63 end
58 end
64
59
65 if File.directory?(REPOSITORY_PATH)
60 if File.directory?(REPOSITORY_PATH)
61 def test_get_edit
62 @request.session[:user_id] = 1
63 @project.repository.destroy
64 xhr :get, :edit, :id => 'subproject1', :repository_scm => 'Git'
65 assert_response :success
66 assert_equal 'text/javascript', @response.content_type
67 assert_kind_of Repository::Git, assigns(:repository)
68 assert assigns(:repository).new_record?
69 assert_select_rjs :replace_html, 'tab-content-repository'
70 end
71
66 def test_browse_root
72 def test_browse_root
67 assert_equal 0, @repository.changesets.count
73 assert_equal 0, @repository.changesets.count
68 @repository.fetch_changesets
74 @repository.fetch_changesets
69 @project.reload
75 @project.reload
70 assert_equal NUM_REV, @repository.changesets.count
76 assert_equal NUM_REV, @repository.changesets.count
71
77
72 get :show, :id => PRJ_ID
78 get :show, :id => PRJ_ID
73 assert_response :success
79 assert_response :success
74 assert_template 'show'
80 assert_template 'show'
75 assert_not_nil assigns(:entries)
81 assert_not_nil assigns(:entries)
76 assert_equal 9, assigns(:entries).size
82 assert_equal 9, assigns(:entries).size
77 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
83 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
78 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 == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
79 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
85 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
80 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
86 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
81 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
87 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
82 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
88 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
83 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
89 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
84 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
90 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
85 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
91 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
86 assert_not_nil assigns(:changesets)
92 assert_not_nil assigns(:changesets)
87 assert assigns(:changesets).size > 0
93 assert assigns(:changesets).size > 0
88 end
94 end
89
95
90 def test_browse_branch
96 def test_browse_branch
91 assert_equal 0, @repository.changesets.count
97 assert_equal 0, @repository.changesets.count
92 @repository.fetch_changesets
98 @repository.fetch_changesets
93 @project.reload
99 @project.reload
94 assert_equal NUM_REV, @repository.changesets.count
100 assert_equal NUM_REV, @repository.changesets.count
95 get :show, :id => PRJ_ID, :rev => 'test_branch'
101 get :show, :id => PRJ_ID, :rev => 'test_branch'
96 assert_response :success
102 assert_response :success
97 assert_template 'show'
103 assert_template 'show'
98 assert_not_nil assigns(:entries)
104 assert_not_nil assigns(:entries)
99 assert_equal 4, assigns(:entries).size
105 assert_equal 4, assigns(:entries).size
100 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
106 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
101 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
107 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
102 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
108 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
103 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
109 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
104 assert_not_nil assigns(:changesets)
110 assert_not_nil assigns(:changesets)
105 assert assigns(:changesets).size > 0
111 assert assigns(:changesets).size > 0
106 end
112 end
107
113
108 def test_browse_tag
114 def test_browse_tag
109 assert_equal 0, @repository.changesets.count
115 assert_equal 0, @repository.changesets.count
110 @repository.fetch_changesets
116 @repository.fetch_changesets
111 @project.reload
117 @project.reload
112 assert_equal NUM_REV, @repository.changesets.count
118 assert_equal NUM_REV, @repository.changesets.count
113 [
119 [
114 "tag00.lightweight",
120 "tag00.lightweight",
115 "tag01.annotated",
121 "tag01.annotated",
116 ].each do |t1|
122 ].each do |t1|
117 get :show, :id => PRJ_ID, :rev => t1
123 get :show, :id => PRJ_ID, :rev => t1
118 assert_response :success
124 assert_response :success
119 assert_template 'show'
125 assert_template 'show'
120 assert_not_nil assigns(:entries)
126 assert_not_nil assigns(:entries)
121 assert assigns(:entries).size > 0
127 assert assigns(:entries).size > 0
122 assert_not_nil assigns(:changesets)
128 assert_not_nil assigns(:changesets)
123 assert assigns(:changesets).size > 0
129 assert assigns(:changesets).size > 0
124 end
130 end
125 end
131 end
126
132
127 def test_browse_directory
133 def test_browse_directory
128 assert_equal 0, @repository.changesets.count
134 assert_equal 0, @repository.changesets.count
129 @repository.fetch_changesets
135 @repository.fetch_changesets
130 @project.reload
136 @project.reload
131 assert_equal NUM_REV, @repository.changesets.count
137 assert_equal NUM_REV, @repository.changesets.count
132 get :show, :id => PRJ_ID, :path => ['images']
138 get :show, :id => PRJ_ID, :path => ['images']
133 assert_response :success
139 assert_response :success
134 assert_template 'show'
140 assert_template 'show'
135 assert_not_nil assigns(:entries)
141 assert_not_nil assigns(:entries)
136 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
142 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
137 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
143 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
138 assert_not_nil entry
144 assert_not_nil entry
139 assert_equal 'file', entry.kind
145 assert_equal 'file', entry.kind
140 assert_equal 'images/edit.png', entry.path
146 assert_equal 'images/edit.png', entry.path
141 assert_not_nil assigns(:changesets)
147 assert_not_nil assigns(:changesets)
142 assert assigns(:changesets).size > 0
148 assert assigns(:changesets).size > 0
143 end
149 end
144
150
145 def test_browse_at_given_revision
151 def test_browse_at_given_revision
146 assert_equal 0, @repository.changesets.count
152 assert_equal 0, @repository.changesets.count
147 @repository.fetch_changesets
153 @repository.fetch_changesets
148 @project.reload
154 @project.reload
149 assert_equal NUM_REV, @repository.changesets.count
155 assert_equal NUM_REV, @repository.changesets.count
150 get :show, :id => PRJ_ID, :path => ['images'],
156 get :show, :id => PRJ_ID, :path => ['images'],
151 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
157 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
152 assert_response :success
158 assert_response :success
153 assert_template 'show'
159 assert_template 'show'
154 assert_not_nil assigns(:entries)
160 assert_not_nil assigns(:entries)
155 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
161 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
156 assert_not_nil assigns(:changesets)
162 assert_not_nil assigns(:changesets)
157 assert assigns(:changesets).size > 0
163 assert assigns(:changesets).size > 0
158 end
164 end
159
165
160 def test_changes
166 def test_changes
161 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
167 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
162 assert_response :success
168 assert_response :success
163 assert_template 'changes'
169 assert_template 'changes'
164 assert_tag :tag => 'h2', :content => 'edit.png'
170 assert_tag :tag => 'h2', :content => 'edit.png'
165 end
171 end
166
172
167 def test_entry_show
173 def test_entry_show
168 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
174 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
169 assert_response :success
175 assert_response :success
170 assert_template 'entry'
176 assert_template 'entry'
171 # Line 19
177 # Line 19
172 assert_tag :tag => 'th',
178 assert_tag :tag => 'th',
173 :content => '11',
179 :content => '11',
174 :attributes => { :class => 'line-num' },
180 :attributes => { :class => 'line-num' },
175 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
181 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
176 end
182 end
177
183
178 def test_entry_show_latin_1
184 def test_entry_show_latin_1
179 if @ruby19_non_utf8_pass
185 if @ruby19_non_utf8_pass
180 puts_ruby19_non_utf8_pass()
186 puts_ruby19_non_utf8_pass()
181 elsif JRUBY_SKIP
187 elsif JRUBY_SKIP
182 puts JRUBY_SKIP_STR
188 puts JRUBY_SKIP_STR
183 else
189 else
184 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
190 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
185 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
191 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
186 get :entry, :id => PRJ_ID,
192 get :entry, :id => PRJ_ID,
187 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
193 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
188 assert_response :success
194 assert_response :success
189 assert_template 'entry'
195 assert_template 'entry'
190 assert_tag :tag => 'th',
196 assert_tag :tag => 'th',
191 :content => '1',
197 :content => '1',
192 :attributes => { :class => 'line-num' },
198 :attributes => { :class => 'line-num' },
193 :sibling => { :tag => 'td',
199 :sibling => { :tag => 'td',
194 :content => /test-#{@char_1}.txt/ }
200 :content => /test-#{@char_1}.txt/ }
195 end
201 end
196 end
202 end
197 end
203 end
198 end
204 end
199
205
200 def test_entry_download
206 def test_entry_download
201 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
207 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
202 :format => 'raw'
208 :format => 'raw'
203 assert_response :success
209 assert_response :success
204 # File content
210 # File content
205 assert @response.body.include?('WITHOUT ANY WARRANTY')
211 assert @response.body.include?('WITHOUT ANY WARRANTY')
206 end
212 end
207
213
208 def test_directory_entry
214 def test_directory_entry
209 get :entry, :id => PRJ_ID, :path => ['sources']
215 get :entry, :id => PRJ_ID, :path => ['sources']
210 assert_response :success
216 assert_response :success
211 assert_template 'show'
217 assert_template 'show'
212 assert_not_nil assigns(:entry)
218 assert_not_nil assigns(:entry)
213 assert_equal 'sources', assigns(:entry).name
219 assert_equal 'sources', assigns(:entry).name
214 end
220 end
215
221
216 def test_diff
222 def test_diff
217 assert_equal 0, @repository.changesets.count
223 assert_equal 0, @repository.changesets.count
218 @repository.fetch_changesets
224 @repository.fetch_changesets
219 @project.reload
225 @project.reload
220 assert_equal NUM_REV, @repository.changesets.count
226 assert_equal NUM_REV, @repository.changesets.count
221 # Full diff of changeset 2f9c0091
227 # Full diff of changeset 2f9c0091
222 ['inline', 'sbs'].each do |dt|
228 ['inline', 'sbs'].each do |dt|
223 get :diff,
229 get :diff,
224 :id => PRJ_ID,
230 :id => PRJ_ID,
225 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
231 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
226 :type => dt
232 :type => dt
227 assert_response :success
233 assert_response :success
228 assert_template 'diff'
234 assert_template 'diff'
229 # Line 22 removed
235 # Line 22 removed
230 assert_tag :tag => 'th',
236 assert_tag :tag => 'th',
231 :content => /22/,
237 :content => /22/,
232 :sibling => { :tag => 'td',
238 :sibling => { :tag => 'td',
233 :attributes => { :class => /diff_out/ },
239 :attributes => { :class => /diff_out/ },
234 :content => /def remove/ }
240 :content => /def remove/ }
235 assert_tag :tag => 'h2', :content => /2f9c0091/
241 assert_tag :tag => 'h2', :content => /2f9c0091/
236 end
242 end
237 end
243 end
238
244
239 def test_diff_truncated
245 def test_diff_truncated
240 assert_equal 0, @repository.changesets.count
246 assert_equal 0, @repository.changesets.count
241 @repository.fetch_changesets
247 @repository.fetch_changesets
242 @project.reload
248 @project.reload
243 assert_equal NUM_REV, @repository.changesets.count
249 assert_equal NUM_REV, @repository.changesets.count
244 Setting.diff_max_lines_displayed = 5
250 Setting.diff_max_lines_displayed = 5
245
251
246 # Truncated diff of changeset 2f9c0091
252 # Truncated diff of changeset 2f9c0091
247 with_cache do
253 with_cache do
248 get :diff, :id => PRJ_ID, :type => 'inline',
254 get :diff, :id => PRJ_ID, :type => 'inline',
249 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
255 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
250 assert_response :success
256 assert_response :success
251 assert @response.body.include?("... This diff was truncated")
257 assert @response.body.include?("... This diff was truncated")
252
258
253 Setting.default_language = 'fr'
259 Setting.default_language = 'fr'
254 get :diff, :id => PRJ_ID, :type => 'inline',
260 get :diff, :id => PRJ_ID, :type => 'inline',
255 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
261 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
256 assert_response :success
262 assert_response :success
257 assert ! @response.body.include?("... This diff was truncated")
263 assert ! @response.body.include?("... This diff was truncated")
258 assert @response.body.include?("... Ce diff")
264 assert @response.body.include?("... Ce diff")
259 end
265 end
260 end
266 end
261
267
262 def test_diff_two_revs
268 def test_diff_two_revs
263 assert_equal 0, @repository.changesets.count
269 assert_equal 0, @repository.changesets.count
264 @repository.fetch_changesets
270 @repository.fetch_changesets
265 @project.reload
271 @project.reload
266 assert_equal NUM_REV, @repository.changesets.count
272 assert_equal NUM_REV, @repository.changesets.count
267 ['inline', 'sbs'].each do |dt|
273 ['inline', 'sbs'].each do |dt|
268 get :diff,
274 get :diff,
269 :id => PRJ_ID,
275 :id => PRJ_ID,
270 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
276 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
271 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
277 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
272 :type => dt
278 :type => dt
273 assert_response :success
279 assert_response :success
274 assert_template 'diff'
280 assert_template 'diff'
275 diff = assigns(:diff)
281 diff = assigns(:diff)
276 assert_not_nil diff
282 assert_not_nil diff
277 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
283 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
278 end
284 end
279 end
285 end
280
286
281 def test_diff_latin_1
287 def test_diff_latin_1
282 if @ruby19_non_utf8_pass
288 if @ruby19_non_utf8_pass
283 puts_ruby19_non_utf8_pass()
289 puts_ruby19_non_utf8_pass()
284 else
290 else
285 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
291 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
286 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
292 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
287 ['inline', 'sbs'].each do |dt|
293 ['inline', 'sbs'].each do |dt|
288 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
294 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
289 assert_response :success
295 assert_response :success
290 assert_template 'diff'
296 assert_template 'diff'
291 assert_tag :tag => 'thead',
297 assert_tag :tag => 'thead',
292 :descendant => {
298 :descendant => {
293 :tag => 'th',
299 :tag => 'th',
294 :attributes => { :class => 'filename' } ,
300 :attributes => { :class => 'filename' } ,
295 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
301 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
296 },
302 },
297 :sibling => {
303 :sibling => {
298 :tag => 'tbody',
304 :tag => 'tbody',
299 :descendant => {
305 :descendant => {
300 :tag => 'td',
306 :tag => 'td',
301 :attributes => { :class => /diff_in/ },
307 :attributes => { :class => /diff_in/ },
302 :content => /test-#{@char_1}.txt/
308 :content => /test-#{@char_1}.txt/
303 }
309 }
304 }
310 }
305 end
311 end
306 end
312 end
307 end
313 end
308 end
314 end
309 end
315 end
310
316
311 def test_annotate
317 def test_annotate
312 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
318 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
313 assert_response :success
319 assert_response :success
314 assert_template 'annotate'
320 assert_template 'annotate'
315 # Line 24, changeset 2f9c0091
321 # Line 24, changeset 2f9c0091
316 assert_tag :tag => 'th', :content => '24',
322 assert_tag :tag => 'th', :content => '24',
317 :sibling => {
323 :sibling => {
318 :tag => 'td',
324 :tag => 'td',
319 :child => {
325 :child => {
320 :tag => 'a',
326 :tag => 'a',
321 :content => /2f9c0091/
327 :content => /2f9c0091/
322 }
328 }
323 }
329 }
324 assert_tag :tag => 'th', :content => '24',
330 assert_tag :tag => 'th', :content => '24',
325 :sibling => { :tag => 'td', :content => /jsmith/ }
331 :sibling => { :tag => 'td', :content => /jsmith/ }
326 assert_tag :tag => 'th', :content => '24',
332 assert_tag :tag => 'th', :content => '24',
327 :sibling => {
333 :sibling => {
328 :tag => 'td',
334 :tag => 'td',
329 :child => {
335 :child => {
330 :tag => 'a',
336 :tag => 'a',
331 :content => /2f9c0091/
337 :content => /2f9c0091/
332 }
338 }
333 }
339 }
334 assert_tag :tag => 'th', :content => '24',
340 assert_tag :tag => 'th', :content => '24',
335 :sibling => { :tag => 'td', :content => /watcher =/ }
341 :sibling => { :tag => 'td', :content => /watcher =/ }
336 end
342 end
337
343
338 def test_annotate_at_given_revision
344 def test_annotate_at_given_revision
339 assert_equal 0, @repository.changesets.count
345 assert_equal 0, @repository.changesets.count
340 @repository.fetch_changesets
346 @repository.fetch_changesets
341 @project.reload
347 @project.reload
342 assert_equal NUM_REV, @repository.changesets.count
348 assert_equal NUM_REV, @repository.changesets.count
343 get :annotate, :id => PRJ_ID, :rev => 'deff7',
349 get :annotate, :id => PRJ_ID, :rev => 'deff7',
344 :path => ['sources', 'watchers_controller.rb']
350 :path => ['sources', 'watchers_controller.rb']
345 assert_response :success
351 assert_response :success
346 assert_template 'annotate'
352 assert_template 'annotate'
347 assert_tag :tag => 'h2', :content => /@ deff712f/
353 assert_tag :tag => 'h2', :content => /@ deff712f/
348 end
354 end
349
355
350 def test_annotate_binary_file
356 def test_annotate_binary_file
351 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
357 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
352 assert_response 500
358 assert_response 500
353 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
359 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
354 :content => /cannot be annotated/
360 :content => /cannot be annotated/
355 end
361 end
356
362
357 def test_annotate_error_when_too_big
363 def test_annotate_error_when_too_big
358 with_settings :file_max_size_displayed => 1 do
364 with_settings :file_max_size_displayed => 1 do
359 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 'deff712f'
365 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 'deff712f'
360 assert_response 500
366 assert_response 500
361 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
367 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
362 :content => /exceeds the maximum text file size/
368 :content => /exceeds the maximum text file size/
363
369
364 get :annotate, :id => PRJ_ID, :path => ['README'], :rev => '7234cb2'
370 get :annotate, :id => PRJ_ID, :path => ['README'], :rev => '7234cb2'
365 assert_response :success
371 assert_response :success
366 assert_template 'annotate'
372 assert_template 'annotate'
367 end
373 end
368 end
374 end
369
375
370 def test_annotate_latin_1
376 def test_annotate_latin_1
371 if @ruby19_non_utf8_pass
377 if @ruby19_non_utf8_pass
372 puts_ruby19_non_utf8_pass()
378 puts_ruby19_non_utf8_pass()
373 elsif JRUBY_SKIP
379 elsif JRUBY_SKIP
374 puts JRUBY_SKIP_STR
380 puts JRUBY_SKIP_STR
375 else
381 else
376 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
382 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
377 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
383 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
378 get :annotate, :id => PRJ_ID,
384 get :annotate, :id => PRJ_ID,
379 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
385 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
380 assert_tag :tag => 'th',
386 assert_tag :tag => 'th',
381 :content => '1',
387 :content => '1',
382 :attributes => { :class => 'line-num' },
388 :attributes => { :class => 'line-num' },
383 :sibling => { :tag => 'td',
389 :sibling => { :tag => 'td',
384 :content => /test-#{@char_1}.txt/ }
390 :content => /test-#{@char_1}.txt/ }
385 end
391 end
386 end
392 end
387 end
393 end
388 end
394 end
389
395
390 def test_revision
396 def test_revision
391 assert_equal 0, @repository.changesets.count
397 assert_equal 0, @repository.changesets.count
392 @repository.fetch_changesets
398 @repository.fetch_changesets
393 @project.reload
399 @project.reload
394 assert_equal NUM_REV, @repository.changesets.count
400 assert_equal NUM_REV, @repository.changesets.count
395 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
401 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
396 get :revision, :id => PRJ_ID, :rev => r
402 get :revision, :id => PRJ_ID, :rev => r
397 assert_response :success
403 assert_response :success
398 assert_template 'revision'
404 assert_template 'revision'
399 end
405 end
400 end
406 end
401
407
402 def test_empty_revision
408 def test_empty_revision
403 assert_equal 0, @repository.changesets.count
409 assert_equal 0, @repository.changesets.count
404 @repository.fetch_changesets
410 @repository.fetch_changesets
405 @project.reload
411 @project.reload
406 assert_equal NUM_REV, @repository.changesets.count
412 assert_equal NUM_REV, @repository.changesets.count
407 ['', ' ', nil].each do |r|
413 ['', ' ', nil].each do |r|
408 get :revision, :id => PRJ_ID, :rev => r
414 get :revision, :id => PRJ_ID, :rev => r
409 assert_response 404
415 assert_response 404
410 assert_error_tag :content => /was not found/
416 assert_error_tag :content => /was not found/
411 end
417 end
412 end
418 end
413
419
414 def test_destroy_valid_repository
420 def test_destroy_valid_repository
415 @request.session[:user_id] = 1 # admin
421 @request.session[:user_id] = 1 # admin
416 assert_equal 0, @repository.changesets.count
422 assert_equal 0, @repository.changesets.count
417 @repository.fetch_changesets
423 @repository.fetch_changesets
418 @project.reload
424 @project.reload
419 assert_equal NUM_REV, @repository.changesets.count
425 assert_equal NUM_REV, @repository.changesets.count
420
426
421 get :destroy, :id => PRJ_ID
427 get :destroy, :id => PRJ_ID
422 assert_response 302
428 assert_response 302
423 @project.reload
429 @project.reload
424 assert_nil @project.repository
430 assert_nil @project.repository
425 end
431 end
426
432
427 def test_destroy_invalid_repository
433 def test_destroy_invalid_repository
428 @request.session[:user_id] = 1 # admin
434 @request.session[:user_id] = 1 # admin
429 assert_equal 0, @repository.changesets.count
435 assert_equal 0, @repository.changesets.count
430 @repository.fetch_changesets
436 @repository.fetch_changesets
431 @project.reload
437 @project.reload
432 assert_equal NUM_REV, @repository.changesets.count
438 assert_equal NUM_REV, @repository.changesets.count
433
439
434 get :destroy, :id => PRJ_ID
440 get :destroy, :id => PRJ_ID
435 assert_response 302
441 assert_response 302
436 @project.reload
442 @project.reload
437 assert_nil @project.repository
443 assert_nil @project.repository
438
444
439 @repository = Repository::Git.create(
445 @repository = Repository::Git.create(
440 :project => @project,
446 :project => @project,
441 :url => "/invalid",
447 :url => "/invalid",
442 :path_encoding => 'ISO-8859-1'
448 :path_encoding => 'ISO-8859-1'
443 )
449 )
444 assert @repository
450 assert @repository
445 @repository.fetch_changesets
451 @repository.fetch_changesets
446 @repository.reload
452 @repository.reload
447 assert_equal 0, @repository.changesets.count
453 assert_equal 0, @repository.changesets.count
448
454
449 get :destroy, :id => PRJ_ID
455 get :destroy, :id => PRJ_ID
450 assert_response 302
456 assert_response 302
451 @project.reload
457 @project.reload
452 assert_nil @project.repository
458 assert_nil @project.repository
453 end
459 end
454
460
455 private
461 private
456
462
457 def puts_ruby19_non_utf8_pass
463 def puts_ruby19_non_utf8_pass
458 puts "TODO: This test fails in Ruby 1.9 " +
464 puts "TODO: This test fails in Ruby 1.9 " +
459 "and Encoding.default_external is not UTF-8. " +
465 "and Encoding.default_external is not UTF-8. " +
460 "Current value is '#{Encoding.default_external.to_s}'"
466 "Current value is '#{Encoding.default_external.to_s}'"
461 end
467 end
462 else
468 else
463 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
469 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
464 def test_fake; assert true end
470 def test_fake; assert true end
465 end
471 end
466
472
467 private
473 private
468 def with_cache(&block)
474 def with_cache(&block)
469 before = ActionController::Base.perform_caching
475 before = ActionController::Base.perform_caching
470 ActionController::Base.perform_caching = true
476 ActionController::Base.perform_caching = true
471 block.call
477 block.call
472 ActionController::Base.perform_caching = before
478 ActionController::Base.perform_caching = before
473 end
479 end
474 end
480 end
General Comments 0
You need to be logged in to leave comments. Login now