comparison test/functional/.svn/text-base/repositories_git_controller_test.rb.svn-base @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 0579821a129a
children 0c939c159af4
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2008 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__)
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 # No '..' in the repository path 27 # No '..' in the repository path
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 PRJ_ID = 3
31 CHAR_1_HEX = "\xc3\x9c"
30 32
31 def setup 33 def setup
34 @ruby19_non_utf8_pass =
35 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
36
32 @controller = RepositoriesController.new 37 @controller = RepositoriesController.new
33 @request = ActionController::TestRequest.new 38 @request = ActionController::TestRequest.new
34 @response = ActionController::TestResponse.new 39 @response = ActionController::TestResponse.new
35 User.current = nil 40 User.current = nil
36 @repository = Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH) 41 @repository = Repository::Git.create(
42 :project => Project.find(3),
43 :url => REPOSITORY_PATH,
44 :path_encoding => 'ISO-8859-1'
45 )
37 assert @repository 46 assert @repository
47 @char_1 = CHAR_1_HEX.dup
48 if @char_1.respond_to?(:force_encoding)
49 @char_1.force_encoding('UTF-8')
50 end
38 end 51 end
39 52
40 if File.directory?(REPOSITORY_PATH) 53 if File.directory?(REPOSITORY_PATH)
41 def test_show
42 get :show, :id => 3
43 assert_response :success
44 assert_template 'show'
45 assert_not_nil assigns(:entries)
46 assert_not_nil assigns(:changesets)
47 end
48
49 def test_browse_root 54 def test_browse_root
50 get :show, :id => 3 55 @repository.fetch_changesets
56 @repository.reload
57 get :show, :id => PRJ_ID
51 assert_response :success 58 assert_response :success
52 assert_template 'show' 59 assert_template 'show'
53 assert_not_nil assigns(:entries) 60 assert_not_nil assigns(:entries)
54 assert_equal 9, assigns(:entries).size 61 assert_equal 9, assigns(:entries).size
55 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} 62 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
59 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} 66 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
60 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} 67 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
61 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} 68 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
62 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'} 69 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
63 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'} 70 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
71 assert_not_nil assigns(:changesets)
72 assigns(:changesets).size > 0
64 end 73 end
65 74
66 def test_browse_branch 75 def test_browse_branch
67 get :show, :id => 3, :rev => 'test_branch' 76 @repository.fetch_changesets
77 @repository.reload
78 get :show, :id => PRJ_ID, :rev => 'test_branch'
68 assert_response :success 79 assert_response :success
69 assert_template 'show' 80 assert_template 'show'
70 assert_not_nil assigns(:entries) 81 assert_not_nil assigns(:entries)
71 assert_equal 4, assigns(:entries).size 82 assert_equal 4, assigns(:entries).size
72 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} 83 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
73 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} 84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
74 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} 85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
75 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} 86 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
87 assert_not_nil assigns(:changesets)
88 assigns(:changesets).size > 0
89 end
90
91 def test_browse_tag
92 @repository.fetch_changesets
93 @repository.reload
94 [
95 "tag00.lightweight",
96 "tag01.annotated",
97 ].each do |t1|
98 get :show, :id => PRJ_ID, :rev => t1
99 assert_response :success
100 assert_template 'show'
101 assert_not_nil assigns(:entries)
102 assigns(:entries).size > 0
103 assert_not_nil assigns(:changesets)
104 assigns(:changesets).size > 0
105 end
76 end 106 end
77 107
78 def test_browse_directory 108 def test_browse_directory
79 get :show, :id => 3, :path => ['images'] 109 @repository.fetch_changesets
110 @repository.reload
111 get :show, :id => PRJ_ID, :path => ['images']
80 assert_response :success 112 assert_response :success
81 assert_template 'show' 113 assert_template 'show'
82 assert_not_nil assigns(:entries) 114 assert_not_nil assigns(:entries)
83 assert_equal ['edit.png'], assigns(:entries).collect(&:name) 115 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
84 entry = assigns(:entries).detect {|e| e.name == 'edit.png'} 116 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
85 assert_not_nil entry 117 assert_not_nil entry
86 assert_equal 'file', entry.kind 118 assert_equal 'file', entry.kind
87 assert_equal 'images/edit.png', entry.path 119 assert_equal 'images/edit.png', entry.path
88 end 120 assert_not_nil assigns(:changesets)
89 121 assigns(:changesets).size > 0
122 end
123
90 def test_browse_at_given_revision 124 def test_browse_at_given_revision
91 get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' 125 @repository.fetch_changesets
126 @repository.reload
127 get :show, :id => PRJ_ID, :path => ['images'],
128 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
92 assert_response :success 129 assert_response :success
93 assert_template 'show' 130 assert_template 'show'
94 assert_not_nil assigns(:entries) 131 assert_not_nil assigns(:entries)
95 assert_equal ['delete.png'], assigns(:entries).collect(&:name) 132 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
133 assert_not_nil assigns(:changesets)
134 assigns(:changesets).size > 0
96 end 135 end
97 136
98 def test_changes 137 def test_changes
99 get :changes, :id => 3, :path => ['images', 'edit.png'] 138 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
100 assert_response :success 139 assert_response :success
101 assert_template 'changes' 140 assert_template 'changes'
102 assert_tag :tag => 'h2', :content => 'edit.png' 141 assert_tag :tag => 'h2', :content => 'edit.png'
103 end 142 end
104 143
105 def test_entry_show 144 def test_entry_show
106 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] 145 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
107 assert_response :success 146 assert_response :success
108 assert_template 'entry' 147 assert_template 'entry'
109 # Line 19 148 # Line 19
110 assert_tag :tag => 'th', 149 assert_tag :tag => 'th',
111 :content => /11/, 150 :content => '11',
112 :attributes => { :class => /line-num/ }, 151 :attributes => { :class => 'line-num' },
113 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } 152 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
114 end 153 end
115 154
155 def test_entry_show_latin_1
156 if @ruby19_non_utf8_pass
157 puts_ruby19_non_utf8_pass()
158 else
159 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
160 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
161 get :entry, :id => PRJ_ID,
162 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
163 assert_response :success
164 assert_template 'entry'
165 assert_tag :tag => 'th',
166 :content => '1',
167 :attributes => { :class => 'line-num' },
168 :sibling => { :tag => 'td',
169 :content => /test-#{@char_1}.txt/ }
170 end
171 end
172 end
173 end
174
116 def test_entry_download 175 def test_entry_download
117 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' 176 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
177 :format => 'raw'
118 assert_response :success 178 assert_response :success
119 # File content 179 # File content
120 assert @response.body.include?('WITHOUT ANY WARRANTY') 180 assert @response.body.include?('WITHOUT ANY WARRANTY')
121 end 181 end
122 182
123 def test_directory_entry 183 def test_directory_entry
124 get :entry, :id => 3, :path => ['sources'] 184 get :entry, :id => PRJ_ID, :path => ['sources']
125 assert_response :success 185 assert_response :success
126 assert_template 'show' 186 assert_template 'show'
127 assert_not_nil assigns(:entry) 187 assert_not_nil assigns(:entry)
128 assert_equal 'sources', assigns(:entry).name 188 assert_equal 'sources', assigns(:entry).name
129 end 189 end
130 190
131 def test_diff 191 def test_diff
132 @repository.fetch_changesets 192 @repository.fetch_changesets
133 @repository.reload 193 @repository.reload
134
135 # Full diff of changeset 2f9c0091 194 # Full diff of changeset 2f9c0091
136 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' 195 get :diff, :id => PRJ_ID, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
137 assert_response :success 196 assert_response :success
138 assert_template 'diff' 197 assert_template 'diff'
139 # Line 22 removed 198 # Line 22 removed
140 assert_tag :tag => 'th', 199 assert_tag :tag => 'th',
141 :content => /22/, 200 :content => /22/,
142 :sibling => { :tag => 'td', 201 :sibling => { :tag => 'td',
143 :attributes => { :class => /diff_out/ }, 202 :attributes => { :class => /diff_out/ },
144 :content => /def remove/ } 203 :content => /def remove/ }
145 assert_tag :tag => 'h2', :content => /2f9c0091/ 204 assert_tag :tag => 'h2', :content => /2f9c0091/
146 end 205 end
147 206
148 def test_diff_two_revs 207 def test_diff_two_revs
149 @repository.fetch_changesets 208 @repository.fetch_changesets
150 @repository.reload 209 @repository.reload
151 210 get :diff, :id => PRJ_ID,
152 get :diff, :id => 3, :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', 211 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
153 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' 212 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
154 assert_response :success 213 assert_response :success
155 assert_template 'diff' 214 assert_template 'diff'
156
157 diff = assigns(:diff) 215 diff = assigns(:diff)
158 assert_not_nil diff 216 assert_not_nil diff
159 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/ 217 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
160 end 218 end
161 219
220 def test_diff_latin_1
221 if @ruby19_non_utf8_pass
222 puts_ruby19_non_utf8_pass()
223 else
224 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
225 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
226 get :diff, :id => PRJ_ID, :rev => r1
227 assert_response :success
228 assert_template 'diff'
229 assert_tag :tag => 'thead',
230 :descendant => {
231 :tag => 'th',
232 :attributes => { :class => 'filename' } ,
233 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
234 },
235 :sibling => {
236 :tag => 'tbody',
237 :descendant => {
238 :tag => 'td',
239 :attributes => { :class => /diff_in/ },
240 :content => /test-#{@char_1}.txt/
241 }
242 }
243 end
244 end
245 end
246 end
247
162 def test_annotate 248 def test_annotate
163 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] 249 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
164 assert_response :success 250 assert_response :success
165 assert_template 'annotate' 251 assert_template 'annotate'
166 # Line 23, changeset 2f9c0091 252 # Line 23, changeset 2f9c0091
167 assert_tag :tag => 'th', :content => /24/, 253 assert_tag :tag => 'th', :content => '24',
168 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } }, 254 :sibling => {
169 :sibling => { :tag => 'td', :content => /jsmith/ }, 255 :tag => 'td',
256 :child => {
257 :tag => 'a',
258 :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/
259 }
260 },
261 :sibling => { :tag => 'td', :content => /jsmith/ }
262 assert_tag :tag => 'th', :content => '24',
263 :sibling => {
264 :tag => 'td',
265 :child => {
266 :tag => 'a',
267 :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/
268 }
269 },
170 :sibling => { :tag => 'td', :content => /watcher =/ } 270 :sibling => { :tag => 'td', :content => /watcher =/ }
171 end 271 end
172 272
173 def test_annotate_at_given_revision 273 def test_annotate_at_given_revision
174 @repository.fetch_changesets 274 @repository.fetch_changesets
175 @repository.reload 275 @repository.reload
176 get :annotate, :id => 3, :rev => 'deff7', :path => ['sources', 'watchers_controller.rb'] 276 get :annotate, :id => PRJ_ID, :rev => 'deff7',
277 :path => ['sources', 'watchers_controller.rb']
177 assert_response :success 278 assert_response :success
178 assert_template 'annotate' 279 assert_template 'annotate'
179 assert_tag :tag => 'h2', :content => /@ deff712f/ 280 assert_tag :tag => 'h2', :content => /@ deff712f/
180 end 281 end
181 282
182 def test_annotate_binary_file 283 def test_annotate_binary_file
183 get :annotate, :id => 3, :path => ['images', 'edit.png'] 284 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
184 assert_response 500 285 assert_response 500
185 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, 286 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
186 :content => /can not be annotated/ 287 :content => /cannot be annotated/
288 end
289
290 def test_annotate_latin_1
291 if @ruby19_non_utf8_pass
292 puts_ruby19_non_utf8_pass()
293 else
294 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
295 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
296 get :annotate, :id => PRJ_ID,
297 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
298 assert_tag :tag => 'th',
299 :content => '1',
300 :attributes => { :class => 'line-num' },
301 :sibling => { :tag => 'td',
302 :content => /test-#{@char_1}.txt/ }
303 end
304 end
305 end
187 end 306 end
188 307
189 def test_revision 308 def test_revision
190 @repository.fetch_changesets 309 @repository.fetch_changesets
191 @repository.reload 310 @repository.reload
192 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| 311 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
193 get :revision, :id => 3, :rev => r 312 get :revision, :id => PRJ_ID, :rev => r
194 assert_response :success 313 assert_response :success
195 assert_template 'revision' 314 assert_template 'revision'
196 end 315 end
197 end 316 end
198 317
199 def test_empty_revision 318 def test_empty_revision
200 @repository.fetch_changesets 319 @repository.fetch_changesets
201 @repository.reload 320 @repository.reload
202 ['', ' ', nil].each do |r| 321 ['', ' ', nil].each do |r|
203 get :revision, :id => 3, :rev => r 322 get :revision, :id => PRJ_ID, :rev => r
204 assert_response 404 323 assert_response 404
205 assert_error_tag :content => /was not found/ 324 assert_error_tag :content => /was not found/
206 end 325 end
326 end
327
328 private
329
330 def puts_ruby19_non_utf8_pass
331 puts "TODO: This test fails in Ruby 1.9 " +
332 "and Encoding.default_external is not UTF-8. " +
333 "Current value is '#{Encoding.default_external.to_s}'"
207 end 334 end
208 else 335 else
209 puts "Git test repository NOT FOUND. Skipping functional tests !!!" 336 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
210 def test_fake; assert true end 337 def test_fake; assert true end
211 end 338 end