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