##// END OF EJS Templates
scm: git: add test of showing non ASCII contents of non ASCII path in functional test....
Toshi MARUYAMA -
r5577:6eb8b5fb4a4a
parent child
Show More
@@ -1,257 +1,293
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesGitControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
29 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 30 PRJ_ID = 3
31 CHAR_1_HEX = "\xc3\x9c"
31 32
32 33 def setup
34 @ruby19_non_utf8_pass =
35 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
36
33 37 @controller = RepositoriesController.new
34 38 @request = ActionController::TestRequest.new
35 39 @response = ActionController::TestResponse.new
36 40 User.current = nil
37 41 @repository = Repository::Git.create(
38 42 :project => Project.find(3),
39 43 :url => REPOSITORY_PATH,
40 44 :path_encoding => 'ISO-8859-1'
41 45 )
42 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
43 51 end
44 52
45 53 if File.directory?(REPOSITORY_PATH)
46 54 def test_browse_root
47 55 @repository.fetch_changesets
48 56 @repository.reload
49 57 get :show, :id => PRJ_ID
50 58 assert_response :success
51 59 assert_template 'show'
52 60 assert_not_nil assigns(:entries)
53 61 assert_equal 9, assigns(:entries).size
54 62 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
55 63 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
56 64 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
57 65 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
58 66 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
59 67 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
60 68 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
61 69 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
62 70 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
63 71 assert_not_nil assigns(:changesets)
64 72 assigns(:changesets).size > 0
65 73 end
66 74
67 75 def test_browse_branch
68 76 @repository.fetch_changesets
69 77 @repository.reload
70 78 get :show, :id => PRJ_ID, :rev => 'test_branch'
71 79 assert_response :success
72 80 assert_template 'show'
73 81 assert_not_nil assigns(:entries)
74 82 assert_equal 4, assigns(:entries).size
75 83 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
76 84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
77 85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
78 86 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
79 87 assert_not_nil assigns(:changesets)
80 88 assigns(:changesets).size > 0
81 89 end
82 90
83 91 def test_browse_tag
84 92 @repository.fetch_changesets
85 93 @repository.reload
86 94 [
87 95 "tag00.lightweight",
88 96 "tag01.annotated",
89 97 ].each do |t1|
90 98 get :show, :id => PRJ_ID, :rev => t1
91 99 assert_response :success
92 100 assert_template 'show'
93 101 assert_not_nil assigns(:entries)
94 102 assigns(:entries).size > 0
95 103 assert_not_nil assigns(:changesets)
96 104 assigns(:changesets).size > 0
97 105 end
98 106 end
99 107
100 108 def test_browse_directory
101 109 @repository.fetch_changesets
102 110 @repository.reload
103 111 get :show, :id => PRJ_ID, :path => ['images']
104 112 assert_response :success
105 113 assert_template 'show'
106 114 assert_not_nil assigns(:entries)
107 115 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
108 116 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
109 117 assert_not_nil entry
110 118 assert_equal 'file', entry.kind
111 119 assert_equal 'images/edit.png', entry.path
112 120 assert_not_nil assigns(:changesets)
113 121 assigns(:changesets).size > 0
114 122 end
115 123
116 124 def test_browse_at_given_revision
117 125 @repository.fetch_changesets
118 126 @repository.reload
119 127 get :show, :id => PRJ_ID, :path => ['images'],
120 128 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
121 129 assert_response :success
122 130 assert_template 'show'
123 131 assert_not_nil assigns(:entries)
124 132 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
125 133 assert_not_nil assigns(:changesets)
126 134 assigns(:changesets).size > 0
127 135 end
128 136
129 137 def test_changes
130 138 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
131 139 assert_response :success
132 140 assert_template 'changes'
133 141 assert_tag :tag => 'h2', :content => 'edit.png'
134 142 end
135 143
136 144 def test_entry_show
137 145 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
138 146 assert_response :success
139 147 assert_template 'entry'
140 148 # Line 19
141 149 assert_tag :tag => 'th',
142 150 :content => '11',
143 151 :attributes => { :class => 'line-num' },
144 152 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
145 153 end
146 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
147 175 def test_entry_download
148 176 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
149 177 :format => 'raw'
150 178 assert_response :success
151 179 # File content
152 180 assert @response.body.include?('WITHOUT ANY WARRANTY')
153 181 end
154 182
155 183 def test_directory_entry
156 184 get :entry, :id => PRJ_ID, :path => ['sources']
157 185 assert_response :success
158 186 assert_template 'show'
159 187 assert_not_nil assigns(:entry)
160 188 assert_equal 'sources', assigns(:entry).name
161 189 end
162 190
163 191 def test_diff
164 192 @repository.fetch_changesets
165 193 @repository.reload
166 194 # Full diff of changeset 2f9c0091
167 195 get :diff, :id => PRJ_ID, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
168 196 assert_response :success
169 197 assert_template 'diff'
170 198 # Line 22 removed
171 199 assert_tag :tag => 'th',
172 200 :content => /22/,
173 201 :sibling => { :tag => 'td',
174 202 :attributes => { :class => /diff_out/ },
175 203 :content => /def remove/ }
176 204 assert_tag :tag => 'h2', :content => /2f9c0091/
177 205 end
178 206
179 207 def test_diff_two_revs
180 208 @repository.fetch_changesets
181 209 @repository.reload
182 210 get :diff, :id => PRJ_ID,
183 211 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
184 212 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
185 213 assert_response :success
186 214 assert_template 'diff'
187 215 diff = assigns(:diff)
188 216 assert_not_nil diff
189 217 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
190 218 end
191 219
192 220 def test_annotate
193 221 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
194 222 assert_response :success
195 223 assert_template 'annotate'
196 224 # Line 23, changeset 2f9c0091
197 225 assert_tag :tag => 'th', :content => '24',
198 226 :sibling => {
199 227 :tag => 'td',
200 228 :child => {
201 229 :tag => 'a',
202 230 :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/
203 231 }
204 232 },
205 233 :sibling => { :tag => 'td', :content => /jsmith/ }
206 234 assert_tag :tag => 'th', :content => '24',
207 235 :sibling => {
208 236 :tag => 'td',
209 237 :child => {
210 238 :tag => 'a',
211 239 :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/
212 240 }
213 241 },
214 242 :sibling => { :tag => 'td', :content => /watcher =/ }
215 243 end
216 244
217 245 def test_annotate_at_given_revision
218 246 @repository.fetch_changesets
219 247 @repository.reload
220 248 get :annotate, :id => PRJ_ID, :rev => 'deff7',
221 249 :path => ['sources', 'watchers_controller.rb']
222 250 assert_response :success
223 251 assert_template 'annotate'
224 252 assert_tag :tag => 'h2', :content => /@ deff712f/
225 253 end
226 254
227 255 def test_annotate_binary_file
228 256 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
229 257 assert_response 500
230 258 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
231 259 :content => /cannot be annotated/
232 260 end
233 261
234 262 def test_revision
235 263 @repository.fetch_changesets
236 264 @repository.reload
237 265 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
238 266 get :revision, :id => PRJ_ID, :rev => r
239 267 assert_response :success
240 268 assert_template 'revision'
241 269 end
242 270 end
243 271
244 272 def test_empty_revision
245 273 @repository.fetch_changesets
246 274 @repository.reload
247 275 ['', ' ', nil].each do |r|
248 276 get :revision, :id => PRJ_ID, :rev => r
249 277 assert_response 404
250 278 assert_error_tag :content => /was not found/
251 279 end
252 280 end
281
282 private
283
284 def puts_ruby19_non_utf8_pass
285 puts "TODO: This test fails in Ruby 1.9 " +
286 "and Encoding.default_external is not UTF-8. " +
287 "Current value is '#{Encoding.default_external.to_s}'"
288 end
253 289 else
254 290 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
255 291 def test_fake; assert true end
256 292 end
257 293 end
General Comments 0
You need to be logged in to leave comments. Login now