##// END OF EJS Templates
Merged r9861 from trunk....
Jean-Philippe Lang -
r9679:32e3d6e1b11a
parent child
Show More
@@ -1,548 +1,548
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 ## Ruby uses ANSI api to fork a process on Windows.
33 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
34 ## and these are incompatible with ASCII.
35 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
36 ## http://code.google.com/p/msysgit/issues/detail?id=80
37 ## So, Latin-1 path tests fail on Japanese Windows
38 WINDOWS_PASS = (Redmine::Platform.mswin? &&
39 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
40 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
41
42 ## Git, Mercurial and CVS path encodings are binary.
32 ## Git, Mercurial and CVS path encodings are binary.
43 ## Subversion supports URL encoding for path.
33 ## Subversion supports URL encoding for path.
44 ## Redmine Mercurial adapter and extension use URL encoding.
34 ## Redmine Mercurial adapter and extension use URL encoding.
45 ## Git accepts only binary path in command line parameter.
35 ## Git accepts only binary path in command line parameter.
46 ## 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.
47 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
48 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
49
39
50 def setup
40 def setup
51 @ruby19_non_utf8_pass =
41 @ruby19_non_utf8_pass =
52 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
53
43
54 User.current = nil
44 User.current = nil
55 @project = Project.find(PRJ_ID)
45 @project = Project.find(PRJ_ID)
56 @repository = Repository::Git.create(
46 @repository = Repository::Git.create(
57 :project => @project,
47 :project => @project,
58 :url => REPOSITORY_PATH,
48 :url => REPOSITORY_PATH,
59 :path_encoding => 'ISO-8859-1'
49 :path_encoding => 'ISO-8859-1'
60 )
50 )
61 assert @repository
51 assert @repository
62 @char_1 = CHAR_1_HEX.dup
52 @char_1 = CHAR_1_HEX.dup
63 if @char_1.respond_to?(:force_encoding)
53 if @char_1.respond_to?(:force_encoding)
64 @char_1.force_encoding('UTF-8')
54 @char_1.force_encoding('UTF-8')
65 end
55 end
66
56
67 Setting.default_language = 'en'
57 Setting.default_language = 'en'
68 end
58 end
69
59
70 def test_create_and_update
60 def test_create_and_update
71 @request.session[:user_id] = 1
61 @request.session[:user_id] = 1
72 assert_difference 'Repository.count' do
62 assert_difference 'Repository.count' do
73 post :create, :project_id => 'subproject1',
63 post :create, :project_id => 'subproject1',
74 :repository_scm => 'Git',
64 :repository_scm => 'Git',
75 :repository => {
65 :repository => {
76 :url => '/test',
66 :url => '/test',
77 :is_default => '0',
67 :is_default => '0',
78 :identifier => 'test-create',
68 :identifier => 'test-create',
79 :extra_report_last_commit => '1',
69 :extra_report_last_commit => '1',
80 }
70 }
81 end
71 end
82 assert_response 302
72 assert_response 302
83 repository = Repository.first(:order => 'id DESC')
73 repository = Repository.first(:order => 'id DESC')
84 assert_kind_of Repository::Git, repository
74 assert_kind_of Repository::Git, repository
85 assert_equal '/test', repository.url
75 assert_equal '/test', repository.url
86 assert_equal true, repository.extra_report_last_commit
76 assert_equal true, repository.extra_report_last_commit
87
77
88 put :update, :id => repository.id,
78 put :update, :id => repository.id,
89 :repository => {
79 :repository => {
90 :extra_report_last_commit => '0',
80 :extra_report_last_commit => '0',
91 :identifier => 'test-update',
81 :identifier => 'test-update',
92 }
82 }
93 assert_response 302
83 assert_response 302
94 repo2 = Repository.find(repository.id)
84 repo2 = Repository.find(repository.id)
95 assert_equal 'test-update', repo2.identifier
85 assert_equal 'test-update', repo2.identifier
96 assert_equal false, repo2.extra_report_last_commit
86 assert_equal false, repo2.extra_report_last_commit
97 end
87 end
98
88
99 if File.directory?(REPOSITORY_PATH)
89 if File.directory?(REPOSITORY_PATH)
90 ## Ruby uses ANSI api to fork a process on Windows.
91 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
92 ## and these are incompatible with ASCII.
93 ## 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
95 ## So, Latin-1 path tests fail on Japanese Windows
96 WINDOWS_PASS = (Redmine::Platform.mswin? &&
97 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"
99
100 def test_get_new
100 def test_get_new
101 @request.session[:user_id] = 1
101 @request.session[:user_id] = 1
102 @project.repository.destroy
102 @project.repository.destroy
103 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
103 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
104 assert_response :success
104 assert_response :success
105 assert_template 'new'
105 assert_template 'new'
106 assert_kind_of Repository::Git, assigns(:repository)
106 assert_kind_of Repository::Git, assigns(:repository)
107 assert assigns(:repository).new_record?
107 assert assigns(:repository).new_record?
108 end
108 end
109
109
110 def test_browse_root
110 def test_browse_root
111 assert_equal 0, @repository.changesets.count
111 assert_equal 0, @repository.changesets.count
112 @repository.fetch_changesets
112 @repository.fetch_changesets
113 @project.reload
113 @project.reload
114 assert_equal NUM_REV, @repository.changesets.count
114 assert_equal NUM_REV, @repository.changesets.count
115
115
116 get :show, :id => PRJ_ID
116 get :show, :id => PRJ_ID
117 assert_response :success
117 assert_response :success
118 assert_template 'show'
118 assert_template 'show'
119 assert_not_nil assigns(:entries)
119 assert_not_nil assigns(:entries)
120 assert_equal 9, assigns(:entries).size
120 assert_equal 9, assigns(:entries).size
121 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
121 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'}
122 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'}
123 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
124 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
124 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
125 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
125 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'}
126 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'}
127 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'}
128 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'}
129 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
130 assert_not_nil assigns(:changesets)
130 assert_not_nil assigns(:changesets)
131 assert assigns(:changesets).size > 0
131 assert assigns(:changesets).size > 0
132 end
132 end
133
133
134 def test_browse_branch
134 def test_browse_branch
135 assert_equal 0, @repository.changesets.count
135 assert_equal 0, @repository.changesets.count
136 @repository.fetch_changesets
136 @repository.fetch_changesets
137 @project.reload
137 @project.reload
138 assert_equal NUM_REV, @repository.changesets.count
138 assert_equal NUM_REV, @repository.changesets.count
139 get :show, :id => PRJ_ID, :rev => 'test_branch'
139 get :show, :id => PRJ_ID, :rev => 'test_branch'
140 assert_response :success
140 assert_response :success
141 assert_template 'show'
141 assert_template 'show'
142 assert_not_nil assigns(:entries)
142 assert_not_nil assigns(:entries)
143 assert_equal 4, assigns(:entries).size
143 assert_equal 4, assigns(:entries).size
144 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
144 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
145 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
145 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
146 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
146 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
147 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
147 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
148 assert_not_nil assigns(:changesets)
148 assert_not_nil assigns(:changesets)
149 assert assigns(:changesets).size > 0
149 assert assigns(:changesets).size > 0
150 end
150 end
151
151
152 def test_browse_tag
152 def test_browse_tag
153 assert_equal 0, @repository.changesets.count
153 assert_equal 0, @repository.changesets.count
154 @repository.fetch_changesets
154 @repository.fetch_changesets
155 @project.reload
155 @project.reload
156 assert_equal NUM_REV, @repository.changesets.count
156 assert_equal NUM_REV, @repository.changesets.count
157 [
157 [
158 "tag00.lightweight",
158 "tag00.lightweight",
159 "tag01.annotated",
159 "tag01.annotated",
160 ].each do |t1|
160 ].each do |t1|
161 get :show, :id => PRJ_ID, :rev => t1
161 get :show, :id => PRJ_ID, :rev => t1
162 assert_response :success
162 assert_response :success
163 assert_template 'show'
163 assert_template 'show'
164 assert_not_nil assigns(:entries)
164 assert_not_nil assigns(:entries)
165 assert assigns(:entries).size > 0
165 assert assigns(:entries).size > 0
166 assert_not_nil assigns(:changesets)
166 assert_not_nil assigns(:changesets)
167 assert assigns(:changesets).size > 0
167 assert assigns(:changesets).size > 0
168 end
168 end
169 end
169 end
170
170
171 def test_browse_directory
171 def test_browse_directory
172 assert_equal 0, @repository.changesets.count
172 assert_equal 0, @repository.changesets.count
173 @repository.fetch_changesets
173 @repository.fetch_changesets
174 @project.reload
174 @project.reload
175 assert_equal NUM_REV, @repository.changesets.count
175 assert_equal NUM_REV, @repository.changesets.count
176 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
176 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
177 assert_response :success
177 assert_response :success
178 assert_template 'show'
178 assert_template 'show'
179 assert_not_nil assigns(:entries)
179 assert_not_nil assigns(:entries)
180 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
180 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
181 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
181 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
182 assert_not_nil entry
182 assert_not_nil entry
183 assert_equal 'file', entry.kind
183 assert_equal 'file', entry.kind
184 assert_equal 'images/edit.png', entry.path
184 assert_equal 'images/edit.png', entry.path
185 assert_not_nil assigns(:changesets)
185 assert_not_nil assigns(:changesets)
186 assert assigns(:changesets).size > 0
186 assert assigns(:changesets).size > 0
187 end
187 end
188
188
189 def test_browse_at_given_revision
189 def test_browse_at_given_revision
190 assert_equal 0, @repository.changesets.count
190 assert_equal 0, @repository.changesets.count
191 @repository.fetch_changesets
191 @repository.fetch_changesets
192 @project.reload
192 @project.reload
193 assert_equal NUM_REV, @repository.changesets.count
193 assert_equal NUM_REV, @repository.changesets.count
194 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
194 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
195 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
195 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
196 assert_response :success
196 assert_response :success
197 assert_template 'show'
197 assert_template 'show'
198 assert_not_nil assigns(:entries)
198 assert_not_nil assigns(:entries)
199 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
199 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
200 assert_not_nil assigns(:changesets)
200 assert_not_nil assigns(:changesets)
201 assert assigns(:changesets).size > 0
201 assert assigns(:changesets).size > 0
202 end
202 end
203
203
204 def test_changes
204 def test_changes
205 get :changes, :id => PRJ_ID,
205 get :changes, :id => PRJ_ID,
206 :path => repository_path_hash(['images', 'edit.png'])[:param]
206 :path => repository_path_hash(['images', 'edit.png'])[:param]
207 assert_response :success
207 assert_response :success
208 assert_template 'changes'
208 assert_template 'changes'
209 assert_tag :tag => 'h2', :content => 'edit.png'
209 assert_tag :tag => 'h2', :content => 'edit.png'
210 end
210 end
211
211
212 def test_entry_show
212 def test_entry_show
213 get :entry, :id => PRJ_ID,
213 get :entry, :id => PRJ_ID,
214 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
214 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
215 assert_response :success
215 assert_response :success
216 assert_template 'entry'
216 assert_template 'entry'
217 # Line 19
217 # Line 19
218 assert_tag :tag => 'th',
218 assert_tag :tag => 'th',
219 :content => '11',
219 :content => '11',
220 :attributes => { :class => 'line-num' },
220 :attributes => { :class => 'line-num' },
221 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
221 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
222 end
222 end
223
223
224 def test_entry_show_latin_1
224 def test_entry_show_latin_1
225 if @ruby19_non_utf8_pass
225 if @ruby19_non_utf8_pass
226 puts_ruby19_non_utf8_pass()
226 puts_ruby19_non_utf8_pass()
227 elsif WINDOWS_PASS
227 elsif WINDOWS_PASS
228 puts WINDOWS_SKIP_STR
228 puts WINDOWS_SKIP_STR
229 elsif JRUBY_SKIP
229 elsif JRUBY_SKIP
230 puts JRUBY_SKIP_STR
230 puts JRUBY_SKIP_STR
231 else
231 else
232 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
232 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
233 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
233 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
234 get :entry, :id => PRJ_ID,
234 get :entry, :id => PRJ_ID,
235 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
235 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
236 :rev => r1
236 :rev => r1
237 assert_response :success
237 assert_response :success
238 assert_template 'entry'
238 assert_template 'entry'
239 assert_tag :tag => 'th',
239 assert_tag :tag => 'th',
240 :content => '1',
240 :content => '1',
241 :attributes => { :class => 'line-num' },
241 :attributes => { :class => 'line-num' },
242 :sibling => { :tag => 'td',
242 :sibling => { :tag => 'td',
243 :content => /test-#{@char_1}.txt/ }
243 :content => /test-#{@char_1}.txt/ }
244 end
244 end
245 end
245 end
246 end
246 end
247 end
247 end
248
248
249 def test_entry_download
249 def test_entry_download
250 get :entry, :id => PRJ_ID,
250 get :entry, :id => PRJ_ID,
251 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
251 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
252 :format => 'raw'
252 :format => 'raw'
253 assert_response :success
253 assert_response :success
254 # File content
254 # File content
255 assert @response.body.include?('WITHOUT ANY WARRANTY')
255 assert @response.body.include?('WITHOUT ANY WARRANTY')
256 end
256 end
257
257
258 def test_directory_entry
258 def test_directory_entry
259 get :entry, :id => PRJ_ID,
259 get :entry, :id => PRJ_ID,
260 :path => repository_path_hash(['sources'])[:param]
260 :path => repository_path_hash(['sources'])[:param]
261 assert_response :success
261 assert_response :success
262 assert_template 'show'
262 assert_template 'show'
263 assert_not_nil assigns(:entry)
263 assert_not_nil assigns(:entry)
264 assert_equal 'sources', assigns(:entry).name
264 assert_equal 'sources', assigns(:entry).name
265 end
265 end
266
266
267 def test_diff
267 def test_diff
268 assert_equal 0, @repository.changesets.count
268 assert_equal 0, @repository.changesets.count
269 @repository.fetch_changesets
269 @repository.fetch_changesets
270 @project.reload
270 @project.reload
271 assert_equal NUM_REV, @repository.changesets.count
271 assert_equal NUM_REV, @repository.changesets.count
272 # Full diff of changeset 2f9c0091
272 # Full diff of changeset 2f9c0091
273 ['inline', 'sbs'].each do |dt|
273 ['inline', 'sbs'].each do |dt|
274 get :diff,
274 get :diff,
275 :id => PRJ_ID,
275 :id => PRJ_ID,
276 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
276 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
277 :type => dt
277 :type => dt
278 assert_response :success
278 assert_response :success
279 assert_template 'diff'
279 assert_template 'diff'
280 # Line 22 removed
280 # Line 22 removed
281 assert_tag :tag => 'th',
281 assert_tag :tag => 'th',
282 :content => /22/,
282 :content => /22/,
283 :sibling => { :tag => 'td',
283 :sibling => { :tag => 'td',
284 :attributes => { :class => /diff_out/ },
284 :attributes => { :class => /diff_out/ },
285 :content => /def remove/ }
285 :content => /def remove/ }
286 assert_tag :tag => 'h2', :content => /2f9c0091/
286 assert_tag :tag => 'h2', :content => /2f9c0091/
287 end
287 end
288 end
288 end
289
289
290 def test_diff_truncated
290 def test_diff_truncated
291 assert_equal 0, @repository.changesets.count
291 assert_equal 0, @repository.changesets.count
292 @repository.fetch_changesets
292 @repository.fetch_changesets
293 @project.reload
293 @project.reload
294 assert_equal NUM_REV, @repository.changesets.count
294 assert_equal NUM_REV, @repository.changesets.count
295 Setting.diff_max_lines_displayed = 5
295 Setting.diff_max_lines_displayed = 5
296
296
297 # Truncated diff of changeset 2f9c0091
297 # Truncated diff of changeset 2f9c0091
298 with_cache do
298 with_cache do
299 get :diff, :id => PRJ_ID, :type => 'inline',
299 get :diff, :id => PRJ_ID, :type => 'inline',
300 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
300 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
301 assert_response :success
301 assert_response :success
302 assert @response.body.include?("... This diff was truncated")
302 assert @response.body.include?("... This diff was truncated")
303
303
304 Setting.default_language = 'fr'
304 Setting.default_language = 'fr'
305 get :diff, :id => PRJ_ID, :type => 'inline',
305 get :diff, :id => PRJ_ID, :type => 'inline',
306 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
306 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
307 assert_response :success
307 assert_response :success
308 assert ! @response.body.include?("... This diff was truncated")
308 assert ! @response.body.include?("... This diff was truncated")
309 assert @response.body.include?("... Ce diff")
309 assert @response.body.include?("... Ce diff")
310 end
310 end
311 end
311 end
312
312
313 def test_diff_two_revs
313 def test_diff_two_revs
314 assert_equal 0, @repository.changesets.count
314 assert_equal 0, @repository.changesets.count
315 @repository.fetch_changesets
315 @repository.fetch_changesets
316 @project.reload
316 @project.reload
317 assert_equal NUM_REV, @repository.changesets.count
317 assert_equal NUM_REV, @repository.changesets.count
318 ['inline', 'sbs'].each do |dt|
318 ['inline', 'sbs'].each do |dt|
319 get :diff,
319 get :diff,
320 :id => PRJ_ID,
320 :id => PRJ_ID,
321 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
321 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
322 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
322 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
323 :type => dt
323 :type => dt
324 assert_response :success
324 assert_response :success
325 assert_template 'diff'
325 assert_template 'diff'
326 diff = assigns(:diff)
326 diff = assigns(:diff)
327 assert_not_nil diff
327 assert_not_nil diff
328 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
328 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
329 end
329 end
330 end
330 end
331
331
332 def test_diff_latin_1
332 def test_diff_latin_1
333 if @ruby19_non_utf8_pass
333 if @ruby19_non_utf8_pass
334 puts_ruby19_non_utf8_pass()
334 puts_ruby19_non_utf8_pass()
335 else
335 else
336 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
336 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
337 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
337 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
338 ['inline', 'sbs'].each do |dt|
338 ['inline', 'sbs'].each do |dt|
339 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
339 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
340 assert_response :success
340 assert_response :success
341 assert_template 'diff'
341 assert_template 'diff'
342 assert_tag :tag => 'thead',
342 assert_tag :tag => 'thead',
343 :descendant => {
343 :descendant => {
344 :tag => 'th',
344 :tag => 'th',
345 :attributes => { :class => 'filename' } ,
345 :attributes => { :class => 'filename' } ,
346 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
346 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
347 },
347 },
348 :sibling => {
348 :sibling => {
349 :tag => 'tbody',
349 :tag => 'tbody',
350 :descendant => {
350 :descendant => {
351 :tag => 'td',
351 :tag => 'td',
352 :attributes => { :class => /diff_in/ },
352 :attributes => { :class => /diff_in/ },
353 :content => /test-#{@char_1}.txt/
353 :content => /test-#{@char_1}.txt/
354 }
354 }
355 }
355 }
356 end
356 end
357 end
357 end
358 end
358 end
359 end
359 end
360 end
360 end
361
361
362 def test_save_diff_type
362 def test_save_diff_type
363 @request.session[:user_id] = 1 # admin
363 @request.session[:user_id] = 1 # admin
364 user = User.find(1)
364 user = User.find(1)
365 get :diff,
365 get :diff,
366 :id => PRJ_ID,
366 :id => PRJ_ID,
367 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
367 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
368 assert_response :success
368 assert_response :success
369 assert_template 'diff'
369 assert_template 'diff'
370 user.reload
370 user.reload
371 assert_equal "inline", user.pref[:diff_type]
371 assert_equal "inline", user.pref[:diff_type]
372 get :diff,
372 get :diff,
373 :id => PRJ_ID,
373 :id => PRJ_ID,
374 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
374 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
375 :type => 'sbs'
375 :type => 'sbs'
376 assert_response :success
376 assert_response :success
377 assert_template 'diff'
377 assert_template 'diff'
378 user.reload
378 user.reload
379 assert_equal "sbs", user.pref[:diff_type]
379 assert_equal "sbs", user.pref[:diff_type]
380 end
380 end
381
381
382 def test_annotate
382 def test_annotate
383 get :annotate, :id => PRJ_ID,
383 get :annotate, :id => PRJ_ID,
384 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
384 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
385 assert_response :success
385 assert_response :success
386 assert_template 'annotate'
386 assert_template 'annotate'
387 # Line 24, changeset 2f9c0091
387 # Line 24, changeset 2f9c0091
388 assert_tag :tag => 'th', :content => '24',
388 assert_tag :tag => 'th', :content => '24',
389 :sibling => {
389 :sibling => {
390 :tag => 'td',
390 :tag => 'td',
391 :child => {
391 :child => {
392 :tag => 'a',
392 :tag => 'a',
393 :content => /2f9c0091/
393 :content => /2f9c0091/
394 }
394 }
395 }
395 }
396 assert_tag :tag => 'th', :content => '24',
396 assert_tag :tag => 'th', :content => '24',
397 :sibling => { :tag => 'td', :content => /jsmith/ }
397 :sibling => { :tag => 'td', :content => /jsmith/ }
398 assert_tag :tag => 'th', :content => '24',
398 assert_tag :tag => 'th', :content => '24',
399 :sibling => {
399 :sibling => {
400 :tag => 'td',
400 :tag => 'td',
401 :child => {
401 :child => {
402 :tag => 'a',
402 :tag => 'a',
403 :content => /2f9c0091/
403 :content => /2f9c0091/
404 }
404 }
405 }
405 }
406 assert_tag :tag => 'th', :content => '24',
406 assert_tag :tag => 'th', :content => '24',
407 :sibling => { :tag => 'td', :content => /watcher =/ }
407 :sibling => { :tag => 'td', :content => /watcher =/ }
408 end
408 end
409
409
410 def test_annotate_at_given_revision
410 def test_annotate_at_given_revision
411 assert_equal 0, @repository.changesets.count
411 assert_equal 0, @repository.changesets.count
412 @repository.fetch_changesets
412 @repository.fetch_changesets
413 @project.reload
413 @project.reload
414 assert_equal NUM_REV, @repository.changesets.count
414 assert_equal NUM_REV, @repository.changesets.count
415 get :annotate, :id => PRJ_ID, :rev => 'deff7',
415 get :annotate, :id => PRJ_ID, :rev => 'deff7',
416 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
416 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
417 assert_response :success
417 assert_response :success
418 assert_template 'annotate'
418 assert_template 'annotate'
419 assert_tag :tag => 'h2', :content => /@ deff712f/
419 assert_tag :tag => 'h2', :content => /@ deff712f/
420 end
420 end
421
421
422 def test_annotate_binary_file
422 def test_annotate_binary_file
423 get :annotate, :id => PRJ_ID,
423 get :annotate, :id => PRJ_ID,
424 :path => repository_path_hash(['images', 'edit.png'])[:param]
424 :path => repository_path_hash(['images', 'edit.png'])[:param]
425 assert_response 500
425 assert_response 500
426 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
426 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
427 :content => /cannot be annotated/
427 :content => /cannot be annotated/
428 end
428 end
429
429
430 def test_annotate_error_when_too_big
430 def test_annotate_error_when_too_big
431 with_settings :file_max_size_displayed => 1 do
431 with_settings :file_max_size_displayed => 1 do
432 get :annotate, :id => PRJ_ID,
432 get :annotate, :id => PRJ_ID,
433 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
433 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
434 :rev => 'deff712f'
434 :rev => 'deff712f'
435 assert_response 500
435 assert_response 500
436 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
436 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
437 :content => /exceeds the maximum text file size/
437 :content => /exceeds the maximum text file size/
438
438
439 get :annotate, :id => PRJ_ID,
439 get :annotate, :id => PRJ_ID,
440 :path => repository_path_hash(['README'])[:param],
440 :path => repository_path_hash(['README'])[:param],
441 :rev => '7234cb2'
441 :rev => '7234cb2'
442 assert_response :success
442 assert_response :success
443 assert_template 'annotate'
443 assert_template 'annotate'
444 end
444 end
445 end
445 end
446
446
447 def test_annotate_latin_1
447 def test_annotate_latin_1
448 if @ruby19_non_utf8_pass
448 if @ruby19_non_utf8_pass
449 puts_ruby19_non_utf8_pass()
449 puts_ruby19_non_utf8_pass()
450 elsif WINDOWS_PASS
450 elsif WINDOWS_PASS
451 puts WINDOWS_SKIP_STR
451 puts WINDOWS_SKIP_STR
452 elsif JRUBY_SKIP
452 elsif JRUBY_SKIP
453 puts JRUBY_SKIP_STR
453 puts JRUBY_SKIP_STR
454 else
454 else
455 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
455 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
456 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
456 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
457 get :annotate, :id => PRJ_ID,
457 get :annotate, :id => PRJ_ID,
458 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
458 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
459 :rev => r1
459 :rev => r1
460 assert_tag :tag => 'th',
460 assert_tag :tag => 'th',
461 :content => '1',
461 :content => '1',
462 :attributes => { :class => 'line-num' },
462 :attributes => { :class => 'line-num' },
463 :sibling => { :tag => 'td',
463 :sibling => { :tag => 'td',
464 :content => /test-#{@char_1}.txt/ }
464 :content => /test-#{@char_1}.txt/ }
465 end
465 end
466 end
466 end
467 end
467 end
468 end
468 end
469
469
470 def test_revision
470 def test_revision
471 assert_equal 0, @repository.changesets.count
471 assert_equal 0, @repository.changesets.count
472 @repository.fetch_changesets
472 @repository.fetch_changesets
473 @project.reload
473 @project.reload
474 assert_equal NUM_REV, @repository.changesets.count
474 assert_equal NUM_REV, @repository.changesets.count
475 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
475 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
476 get :revision, :id => PRJ_ID, :rev => r
476 get :revision, :id => PRJ_ID, :rev => r
477 assert_response :success
477 assert_response :success
478 assert_template 'revision'
478 assert_template 'revision'
479 end
479 end
480 end
480 end
481
481
482 def test_empty_revision
482 def test_empty_revision
483 assert_equal 0, @repository.changesets.count
483 assert_equal 0, @repository.changesets.count
484 @repository.fetch_changesets
484 @repository.fetch_changesets
485 @project.reload
485 @project.reload
486 assert_equal NUM_REV, @repository.changesets.count
486 assert_equal NUM_REV, @repository.changesets.count
487 ['', ' ', nil].each do |r|
487 ['', ' ', nil].each do |r|
488 get :revision, :id => PRJ_ID, :rev => r
488 get :revision, :id => PRJ_ID, :rev => r
489 assert_response 404
489 assert_response 404
490 assert_error_tag :content => /was not found/
490 assert_error_tag :content => /was not found/
491 end
491 end
492 end
492 end
493
493
494 def test_destroy_valid_repository
494 def test_destroy_valid_repository
495 @request.session[:user_id] = 1 # admin
495 @request.session[:user_id] = 1 # admin
496 assert_equal 0, @repository.changesets.count
496 assert_equal 0, @repository.changesets.count
497 @repository.fetch_changesets
497 @repository.fetch_changesets
498 @project.reload
498 @project.reload
499 assert_equal NUM_REV, @repository.changesets.count
499 assert_equal NUM_REV, @repository.changesets.count
500
500
501 assert_difference 'Repository.count', -1 do
501 assert_difference 'Repository.count', -1 do
502 delete :destroy, :id => @repository.id
502 delete :destroy, :id => @repository.id
503 end
503 end
504 assert_response 302
504 assert_response 302
505 @project.reload
505 @project.reload
506 assert_nil @project.repository
506 assert_nil @project.repository
507 end
507 end
508
508
509 def test_destroy_invalid_repository
509 def test_destroy_invalid_repository
510 @request.session[:user_id] = 1 # admin
510 @request.session[:user_id] = 1 # admin
511 @project.repository.destroy
511 @project.repository.destroy
512 @repository = Repository::Git.create!(
512 @repository = Repository::Git.create!(
513 :project => @project,
513 :project => @project,
514 :url => "/invalid",
514 :url => "/invalid",
515 :path_encoding => 'ISO-8859-1'
515 :path_encoding => 'ISO-8859-1'
516 )
516 )
517 @repository.fetch_changesets
517 @repository.fetch_changesets
518 @repository.reload
518 @repository.reload
519 assert_equal 0, @repository.changesets.count
519 assert_equal 0, @repository.changesets.count
520
520
521 assert_difference 'Repository.count', -1 do
521 assert_difference 'Repository.count', -1 do
522 delete :destroy, :id => @repository.id
522 delete :destroy, :id => @repository.id
523 end
523 end
524 assert_response 302
524 assert_response 302
525 @project.reload
525 @project.reload
526 assert_nil @project.repository
526 assert_nil @project.repository
527 end
527 end
528
528
529 private
529 private
530
530
531 def puts_ruby19_non_utf8_pass
531 def puts_ruby19_non_utf8_pass
532 puts "TODO: This test fails in Ruby 1.9 " +
532 puts "TODO: This test fails in Ruby 1.9 " +
533 "and Encoding.default_external is not UTF-8. " +
533 "and Encoding.default_external is not UTF-8. " +
534 "Current value is '#{Encoding.default_external.to_s}'"
534 "Current value is '#{Encoding.default_external.to_s}'"
535 end
535 end
536 else
536 else
537 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
537 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
538 def test_fake; assert true end
538 def test_fake; assert true end
539 end
539 end
540
540
541 private
541 private
542 def with_cache(&block)
542 def with_cache(&block)
543 before = ActionController::Base.perform_caching
543 before = ActionController::Base.perform_caching
544 ActionController::Base.perform_caching = true
544 ActionController::Base.perform_caching = true
545 block.call
545 block.call
546 ActionController::Base.perform_caching = before
546 ActionController::Base.perform_caching = before
547 end
547 end
548 end
548 end
@@ -1,562 +1,562
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 RepositoryGitTest < ActiveSupport::TestCase
20 class RepositoryGitTest < ActiveSupport::TestCase
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22
22
23 include Redmine::I18n
23 include Redmine::I18n
24
24
25 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
25 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
26 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27
27
28 NUM_REV = 28
28 NUM_REV = 28
29 NUM_HEAD = 6
29 NUM_HEAD = 6
30
30
31 FELIX_HEX = "Felix Sch\xC3\xA4fer"
31 FELIX_HEX = "Felix Sch\xC3\xA4fer"
32 CHAR_1_HEX = "\xc3\x9c"
32 CHAR_1_HEX = "\xc3\x9c"
33
33
34 ## Ruby uses ANSI api to fork a process on Windows.
35 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
36 ## and these are incompatible with ASCII.
37 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
38 ## http://code.google.com/p/msysgit/issues/detail?id=80
39 ## So, Latin-1 path tests fail on Japanese Windows
40 WINDOWS_PASS = (Redmine::Platform.mswin? &&
41 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
42 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
43
44 ## Git, Mercurial and CVS path encodings are binary.
34 ## Git, Mercurial and CVS path encodings are binary.
45 ## Subversion supports URL encoding for path.
35 ## Subversion supports URL encoding for path.
46 ## Redmine Mercurial adapter and extension use URL encoding.
36 ## Redmine Mercurial adapter and extension use URL encoding.
47 ## Git accepts only binary path in command line parameter.
37 ## Git accepts only binary path in command line parameter.
48 ## So, there is no way to use binary command line parameter in JRuby.
38 ## So, there is no way to use binary command line parameter in JRuby.
49 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
39 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
50 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
40 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
51
41
52 def setup
42 def setup
53 @project = Project.find(3)
43 @project = Project.find(3)
54 @repository = Repository::Git.create(
44 @repository = Repository::Git.create(
55 :project => @project,
45 :project => @project,
56 :url => REPOSITORY_PATH,
46 :url => REPOSITORY_PATH,
57 :path_encoding => 'ISO-8859-1'
47 :path_encoding => 'ISO-8859-1'
58 )
48 )
59 assert @repository
49 assert @repository
60 @char_1 = CHAR_1_HEX.dup
50 @char_1 = CHAR_1_HEX.dup
61 if @char_1.respond_to?(:force_encoding)
51 if @char_1.respond_to?(:force_encoding)
62 @char_1.force_encoding('UTF-8')
52 @char_1.force_encoding('UTF-8')
63 end
53 end
64 end
54 end
65
55
66 def test_blank_path_to_repository_error_message
56 def test_blank_path_to_repository_error_message
67 set_language_if_valid 'en'
57 set_language_if_valid 'en'
68 repo = Repository::Git.new(
58 repo = Repository::Git.new(
69 :project => @project,
59 :project => @project,
70 :identifier => 'test'
60 :identifier => 'test'
71 )
61 )
72 assert !repo.save
62 assert !repo.save
73 assert_include "Path to repository can't be blank",
63 assert_include "Path to repository can't be blank",
74 repo.errors.full_messages
64 repo.errors.full_messages
75 end
65 end
76
66
77 def test_blank_path_to_repository_error_message_fr
67 def test_blank_path_to_repository_error_message_fr
78 set_language_if_valid 'fr'
68 set_language_if_valid 'fr'
79 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
69 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
80 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
70 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
81 repo = Repository::Git.new(
71 repo = Repository::Git.new(
82 :project => @project,
72 :project => @project,
83 :url => "",
73 :url => "",
84 :identifier => 'test',
74 :identifier => 'test',
85 :path_encoding => ''
75 :path_encoding => ''
86 )
76 )
87 assert !repo.save
77 assert !repo.save
88 assert_include str, repo.errors.full_messages
78 assert_include str, repo.errors.full_messages
89 end
79 end
90
80
91 if File.directory?(REPOSITORY_PATH)
81 if File.directory?(REPOSITORY_PATH)
82 ## Ruby uses ANSI api to fork a process on Windows.
83 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
84 ## and these are incompatible with ASCII.
85 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
86 ## http://code.google.com/p/msysgit/issues/detail?id=80
87 ## So, Latin-1 path tests fail on Japanese Windows
88 WINDOWS_PASS = (Redmine::Platform.mswin? &&
89 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
90 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
91
92 def test_scm_available
92 def test_scm_available
93 klass = Repository::Git
93 klass = Repository::Git
94 assert_equal "Git", klass.scm_name
94 assert_equal "Git", klass.scm_name
95 assert klass.scm_adapter_class
95 assert klass.scm_adapter_class
96 assert_not_equal "", klass.scm_command
96 assert_not_equal "", klass.scm_command
97 assert_equal true, klass.scm_available
97 assert_equal true, klass.scm_available
98 end
98 end
99
99
100 def test_fetch_changesets_from_scratch
100 def test_fetch_changesets_from_scratch
101 assert_nil @repository.extra_info
101 assert_nil @repository.extra_info
102
102
103 assert_equal 0, @repository.changesets.count
103 assert_equal 0, @repository.changesets.count
104 @repository.fetch_changesets
104 @repository.fetch_changesets
105 @project.reload
105 @project.reload
106
106
107 assert_equal NUM_REV, @repository.changesets.count
107 assert_equal NUM_REV, @repository.changesets.count
108 assert_equal 39, @repository.filechanges.count
108 assert_equal 39, @repository.filechanges.count
109
109
110 commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
110 commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
111 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
111 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
112 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
112 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
113 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
113 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
114 assert_equal User.find_by_login('jsmith'), commit.user
114 assert_equal User.find_by_login('jsmith'), commit.user
115 # TODO: add a commit with commit time <> author time to the test repository
115 # TODO: add a commit with commit time <> author time to the test repository
116 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
116 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
117 assert_equal "2007-12-14".to_date, commit.commit_date
117 assert_equal "2007-12-14".to_date, commit.commit_date
118 assert_equal 3, commit.filechanges.count
118 assert_equal 3, commit.filechanges.count
119 change = commit.filechanges.sort_by(&:path).first
119 change = commit.filechanges.sort_by(&:path).first
120 assert_equal "README", change.path
120 assert_equal "README", change.path
121 assert_equal nil, change.from_path
121 assert_equal nil, change.from_path
122 assert_equal "A", change.action
122 assert_equal "A", change.action
123
123
124 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
124 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
125 end
125 end
126
126
127 def test_fetch_changesets_incremental
127 def test_fetch_changesets_incremental
128 assert_equal 0, @repository.changesets.count
128 assert_equal 0, @repository.changesets.count
129 @repository.fetch_changesets
129 @repository.fetch_changesets
130 @project.reload
130 @project.reload
131 assert_equal NUM_REV, @repository.changesets.count
131 assert_equal NUM_REV, @repository.changesets.count
132 extra_info_heads = @repository.extra_info["heads"].dup
132 extra_info_heads = @repository.extra_info["heads"].dup
133 assert_equal NUM_HEAD, extra_info_heads.size
133 assert_equal NUM_HEAD, extra_info_heads.size
134 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
134 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
135 assert_equal 4, extra_info_heads.size
135 assert_equal 4, extra_info_heads.size
136
136
137 del_revs = [
137 del_revs = [
138 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
138 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
139 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
139 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
140 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
140 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
141 "deff712f05a90d96edbd70facc47d944be5897e3",
141 "deff712f05a90d96edbd70facc47d944be5897e3",
142 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
142 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
143 "7e61ac704deecde634b51e59daa8110435dcb3da",
143 "7e61ac704deecde634b51e59daa8110435dcb3da",
144 ]
144 ]
145 @repository.changesets.each do |rev|
145 @repository.changesets.each do |rev|
146 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
146 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
147 end
147 end
148 @project.reload
148 @project.reload
149 cs1 = @repository.changesets
149 cs1 = @repository.changesets
150 assert_equal NUM_REV - 6, cs1.count
150 assert_equal NUM_REV - 6, cs1.count
151 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
151 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
152 h = {}
152 h = {}
153 h["heads"] = extra_info_heads
153 h["heads"] = extra_info_heads
154 @repository.merge_extra_info(h)
154 @repository.merge_extra_info(h)
155 @repository.save
155 @repository.save
156 @project.reload
156 @project.reload
157 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
157 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
158 @repository.fetch_changesets
158 @repository.fetch_changesets
159 @project.reload
159 @project.reload
160 assert_equal NUM_REV, @repository.changesets.count
160 assert_equal NUM_REV, @repository.changesets.count
161 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
161 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
162 assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c")
162 assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c")
163 end
163 end
164
164
165 def test_fetch_changesets_history_editing
165 def test_fetch_changesets_history_editing
166 assert_equal 0, @repository.changesets.count
166 assert_equal 0, @repository.changesets.count
167 @repository.fetch_changesets
167 @repository.fetch_changesets
168 @project.reload
168 @project.reload
169 assert_equal NUM_REV, @repository.changesets.count
169 assert_equal NUM_REV, @repository.changesets.count
170 extra_info_heads = @repository.extra_info["heads"].dup
170 extra_info_heads = @repository.extra_info["heads"].dup
171 assert_equal NUM_HEAD, extra_info_heads.size
171 assert_equal NUM_HEAD, extra_info_heads.size
172 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
172 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
173 assert_equal 4, extra_info_heads.size
173 assert_equal 4, extra_info_heads.size
174
174
175 del_revs = [
175 del_revs = [
176 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
176 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
177 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
177 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
178 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
178 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
179 "deff712f05a90d96edbd70facc47d944be5897e3",
179 "deff712f05a90d96edbd70facc47d944be5897e3",
180 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
180 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
181 "7e61ac704deecde634b51e59daa8110435dcb3da",
181 "7e61ac704deecde634b51e59daa8110435dcb3da",
182 ]
182 ]
183 @repository.changesets.each do |rev|
183 @repository.changesets.each do |rev|
184 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
184 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
185 end
185 end
186 @project.reload
186 @project.reload
187 assert_equal NUM_REV - 6, @repository.changesets.count
187 assert_equal NUM_REV - 6, @repository.changesets.count
188
188
189 c = Changeset.new(:repository => @repository,
189 c = Changeset.new(:repository => @repository,
190 :committed_on => Time.now,
190 :committed_on => Time.now,
191 :revision => "abcd1234efgh",
191 :revision => "abcd1234efgh",
192 :scmid => "abcd1234efgh",
192 :scmid => "abcd1234efgh",
193 :comments => 'test')
193 :comments => 'test')
194 assert c.save
194 assert c.save
195 @project.reload
195 @project.reload
196 assert_equal NUM_REV - 5, @repository.changesets.count
196 assert_equal NUM_REV - 5, @repository.changesets.count
197
197
198 extra_info_heads << "1234abcd5678"
198 extra_info_heads << "1234abcd5678"
199 h = {}
199 h = {}
200 h["heads"] = extra_info_heads
200 h["heads"] = extra_info_heads
201 @repository.merge_extra_info(h)
201 @repository.merge_extra_info(h)
202 @repository.save
202 @repository.save
203 @project.reload
203 @project.reload
204 h1 = @repository.extra_info["heads"].dup
204 h1 = @repository.extra_info["heads"].dup
205 assert h1.index("1234abcd5678")
205 assert h1.index("1234abcd5678")
206 assert_equal 5, h1.size
206 assert_equal 5, h1.size
207
207
208 @repository.fetch_changesets
208 @repository.fetch_changesets
209 @project.reload
209 @project.reload
210 assert_equal NUM_REV - 5, @repository.changesets.count
210 assert_equal NUM_REV - 5, @repository.changesets.count
211 h2 = @repository.extra_info["heads"].dup
211 h2 = @repository.extra_info["heads"].dup
212 assert_equal h1, h2
212 assert_equal h1, h2
213 end
213 end
214
214
215 def test_parents
215 def test_parents
216 assert_equal 0, @repository.changesets.count
216 assert_equal 0, @repository.changesets.count
217 @repository.fetch_changesets
217 @repository.fetch_changesets
218 @project.reload
218 @project.reload
219 assert_equal NUM_REV, @repository.changesets.count
219 assert_equal NUM_REV, @repository.changesets.count
220 r1 = @repository.find_changeset_by_name("7234cb2750b63")
220 r1 = @repository.find_changeset_by_name("7234cb2750b63")
221 assert_equal [], r1.parents
221 assert_equal [], r1.parents
222 r2 = @repository.find_changeset_by_name("899a15dba03a3")
222 r2 = @repository.find_changeset_by_name("899a15dba03a3")
223 assert_equal 1, r2.parents.length
223 assert_equal 1, r2.parents.length
224 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
224 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
225 r2.parents[0].identifier
225 r2.parents[0].identifier
226 r3 = @repository.find_changeset_by_name("32ae898b720c2")
226 r3 = @repository.find_changeset_by_name("32ae898b720c2")
227 assert_equal 2, r3.parents.length
227 assert_equal 2, r3.parents.length
228 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
228 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
229 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0]
229 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0]
230 assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1]
230 assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1]
231 end
231 end
232
232
233 def test_db_consistent_ordering_init
233 def test_db_consistent_ordering_init
234 assert_nil @repository.extra_info
234 assert_nil @repository.extra_info
235 assert_equal 0, @repository.changesets.count
235 assert_equal 0, @repository.changesets.count
236 @repository.fetch_changesets
236 @repository.fetch_changesets
237 @project.reload
237 @project.reload
238 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
238 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
239 end
239 end
240
240
241 def test_db_consistent_ordering_before_1_2
241 def test_db_consistent_ordering_before_1_2
242 assert_nil @repository.extra_info
242 assert_nil @repository.extra_info
243 assert_equal 0, @repository.changesets.count
243 assert_equal 0, @repository.changesets.count
244 @repository.fetch_changesets
244 @repository.fetch_changesets
245 @project.reload
245 @project.reload
246 assert_equal NUM_REV, @repository.changesets.count
246 assert_equal NUM_REV, @repository.changesets.count
247 assert_not_nil @repository.extra_info
247 assert_not_nil @repository.extra_info
248 h = {}
248 h = {}
249 h["heads"] = []
249 h["heads"] = []
250 h["branches"] = {}
250 h["branches"] = {}
251 h["db_consistent"] = {}
251 h["db_consistent"] = {}
252 @repository.merge_extra_info(h)
252 @repository.merge_extra_info(h)
253 @repository.save
253 @repository.save
254 assert_equal NUM_REV, @repository.changesets.count
254 assert_equal NUM_REV, @repository.changesets.count
255 @repository.fetch_changesets
255 @repository.fetch_changesets
256 @project.reload
256 @project.reload
257 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
257 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
258
258
259 extra_info_heads = @repository.extra_info["heads"].dup
259 extra_info_heads = @repository.extra_info["heads"].dup
260 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
260 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
261 del_revs = [
261 del_revs = [
262 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
262 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
263 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
263 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
264 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
264 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
265 "deff712f05a90d96edbd70facc47d944be5897e3",
265 "deff712f05a90d96edbd70facc47d944be5897e3",
266 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
266 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
267 "7e61ac704deecde634b51e59daa8110435dcb3da",
267 "7e61ac704deecde634b51e59daa8110435dcb3da",
268 ]
268 ]
269 @repository.changesets.each do |rev|
269 @repository.changesets.each do |rev|
270 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
270 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
271 end
271 end
272 @project.reload
272 @project.reload
273 cs1 = @repository.changesets
273 cs1 = @repository.changesets
274 assert_equal NUM_REV - 6, cs1.count
274 assert_equal NUM_REV - 6, cs1.count
275 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
275 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
276
276
277 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
277 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
278 h = {}
278 h = {}
279 h["heads"] = extra_info_heads
279 h["heads"] = extra_info_heads
280 @repository.merge_extra_info(h)
280 @repository.merge_extra_info(h)
281 @repository.save
281 @repository.save
282 @project.reload
282 @project.reload
283 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
283 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
284 @repository.fetch_changesets
284 @repository.fetch_changesets
285 @project.reload
285 @project.reload
286 assert_equal NUM_REV, @repository.changesets.count
286 assert_equal NUM_REV, @repository.changesets.count
287 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
287 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
288
288
289 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
289 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
290 end
290 end
291
291
292 def test_heads_from_branches_hash
292 def test_heads_from_branches_hash
293 assert_nil @repository.extra_info
293 assert_nil @repository.extra_info
294 assert_equal 0, @repository.changesets.count
294 assert_equal 0, @repository.changesets.count
295 assert_equal [], @repository.heads_from_branches_hash
295 assert_equal [], @repository.heads_from_branches_hash
296 h = {}
296 h = {}
297 h["branches"] = {}
297 h["branches"] = {}
298 h["branches"]["test1"] = {}
298 h["branches"]["test1"] = {}
299 h["branches"]["test1"]["last_scmid"] = "1234abcd"
299 h["branches"]["test1"]["last_scmid"] = "1234abcd"
300 h["branches"]["test2"] = {}
300 h["branches"]["test2"] = {}
301 h["branches"]["test2"]["last_scmid"] = "abcd1234"
301 h["branches"]["test2"]["last_scmid"] = "abcd1234"
302 @repository.merge_extra_info(h)
302 @repository.merge_extra_info(h)
303 @repository.save
303 @repository.save
304 @project.reload
304 @project.reload
305 assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
305 assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
306 end
306 end
307
307
308 def test_latest_changesets
308 def test_latest_changesets
309 assert_equal 0, @repository.changesets.count
309 assert_equal 0, @repository.changesets.count
310 @repository.fetch_changesets
310 @repository.fetch_changesets
311 @project.reload
311 @project.reload
312 assert_equal NUM_REV, @repository.changesets.count
312 assert_equal NUM_REV, @repository.changesets.count
313 # with limit
313 # with limit
314 changesets = @repository.latest_changesets('', 'master', 2)
314 changesets = @repository.latest_changesets('', 'master', 2)
315 assert_equal 2, changesets.size
315 assert_equal 2, changesets.size
316
316
317 # with path
317 # with path
318 changesets = @repository.latest_changesets('images', 'master')
318 changesets = @repository.latest_changesets('images', 'master')
319 assert_equal [
319 assert_equal [
320 'deff712f05a90d96edbd70facc47d944be5897e3',
320 'deff712f05a90d96edbd70facc47d944be5897e3',
321 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
321 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
322 '7234cb2750b63f47bff735edc50a1c0a433c2518',
322 '7234cb2750b63f47bff735edc50a1c0a433c2518',
323 ], changesets.collect(&:revision)
323 ], changesets.collect(&:revision)
324
324
325 changesets = @repository.latest_changesets('README', nil)
325 changesets = @repository.latest_changesets('README', nil)
326 assert_equal [
326 assert_equal [
327 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
327 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
328 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
328 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
329 '713f4944648826f558cf548222f813dabe7cbb04',
329 '713f4944648826f558cf548222f813dabe7cbb04',
330 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
330 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
331 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
331 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
332 '7234cb2750b63f47bff735edc50a1c0a433c2518',
332 '7234cb2750b63f47bff735edc50a1c0a433c2518',
333 ], changesets.collect(&:revision)
333 ], changesets.collect(&:revision)
334
334
335 # with path, revision and limit
335 # with path, revision and limit
336 changesets = @repository.latest_changesets('images', '899a15dba')
336 changesets = @repository.latest_changesets('images', '899a15dba')
337 assert_equal [
337 assert_equal [
338 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
338 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
339 '7234cb2750b63f47bff735edc50a1c0a433c2518',
339 '7234cb2750b63f47bff735edc50a1c0a433c2518',
340 ], changesets.collect(&:revision)
340 ], changesets.collect(&:revision)
341
341
342 changesets = @repository.latest_changesets('images', '899a15dba', 1)
342 changesets = @repository.latest_changesets('images', '899a15dba', 1)
343 assert_equal [
343 assert_equal [
344 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
344 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
345 ], changesets.collect(&:revision)
345 ], changesets.collect(&:revision)
346
346
347 changesets = @repository.latest_changesets('README', '899a15dba')
347 changesets = @repository.latest_changesets('README', '899a15dba')
348 assert_equal [
348 assert_equal [
349 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
349 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
350 '7234cb2750b63f47bff735edc50a1c0a433c2518',
350 '7234cb2750b63f47bff735edc50a1c0a433c2518',
351 ], changesets.collect(&:revision)
351 ], changesets.collect(&:revision)
352
352
353 changesets = @repository.latest_changesets('README', '899a15dba', 1)
353 changesets = @repository.latest_changesets('README', '899a15dba', 1)
354 assert_equal [
354 assert_equal [
355 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
355 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
356 ], changesets.collect(&:revision)
356 ], changesets.collect(&:revision)
357
357
358 # with path, tag and limit
358 # with path, tag and limit
359 changesets = @repository.latest_changesets('images', 'tag01.annotated')
359 changesets = @repository.latest_changesets('images', 'tag01.annotated')
360 assert_equal [
360 assert_equal [
361 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
361 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
362 '7234cb2750b63f47bff735edc50a1c0a433c2518',
362 '7234cb2750b63f47bff735edc50a1c0a433c2518',
363 ], changesets.collect(&:revision)
363 ], changesets.collect(&:revision)
364
364
365 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
365 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
366 assert_equal [
366 assert_equal [
367 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
367 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
368 ], changesets.collect(&:revision)
368 ], changesets.collect(&:revision)
369
369
370 changesets = @repository.latest_changesets('README', 'tag01.annotated')
370 changesets = @repository.latest_changesets('README', 'tag01.annotated')
371 assert_equal [
371 assert_equal [
372 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
372 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
373 '7234cb2750b63f47bff735edc50a1c0a433c2518',
373 '7234cb2750b63f47bff735edc50a1c0a433c2518',
374 ], changesets.collect(&:revision)
374 ], changesets.collect(&:revision)
375
375
376 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
376 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
377 assert_equal [
377 assert_equal [
378 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
378 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
379 ], changesets.collect(&:revision)
379 ], changesets.collect(&:revision)
380
380
381 # with path, branch and limit
381 # with path, branch and limit
382 changesets = @repository.latest_changesets('images', 'test_branch')
382 changesets = @repository.latest_changesets('images', 'test_branch')
383 assert_equal [
383 assert_equal [
384 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
384 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
385 '7234cb2750b63f47bff735edc50a1c0a433c2518',
385 '7234cb2750b63f47bff735edc50a1c0a433c2518',
386 ], changesets.collect(&:revision)
386 ], changesets.collect(&:revision)
387
387
388 changesets = @repository.latest_changesets('images', 'test_branch', 1)
388 changesets = @repository.latest_changesets('images', 'test_branch', 1)
389 assert_equal [
389 assert_equal [
390 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
390 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
391 ], changesets.collect(&:revision)
391 ], changesets.collect(&:revision)
392
392
393 changesets = @repository.latest_changesets('README', 'test_branch')
393 changesets = @repository.latest_changesets('README', 'test_branch')
394 assert_equal [
394 assert_equal [
395 '713f4944648826f558cf548222f813dabe7cbb04',
395 '713f4944648826f558cf548222f813dabe7cbb04',
396 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
396 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
397 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
397 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
398 '7234cb2750b63f47bff735edc50a1c0a433c2518',
398 '7234cb2750b63f47bff735edc50a1c0a433c2518',
399 ], changesets.collect(&:revision)
399 ], changesets.collect(&:revision)
400
400
401 changesets = @repository.latest_changesets('README', 'test_branch', 2)
401 changesets = @repository.latest_changesets('README', 'test_branch', 2)
402 assert_equal [
402 assert_equal [
403 '713f4944648826f558cf548222f813dabe7cbb04',
403 '713f4944648826f558cf548222f813dabe7cbb04',
404 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
404 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
405 ], changesets.collect(&:revision)
405 ], changesets.collect(&:revision)
406
406
407 if WINDOWS_PASS
407 if WINDOWS_PASS
408 puts WINDOWS_SKIP_STR
408 puts WINDOWS_SKIP_STR
409 elsif JRUBY_SKIP
409 elsif JRUBY_SKIP
410 puts JRUBY_SKIP_STR
410 puts JRUBY_SKIP_STR
411 else
411 else
412 # latin-1 encoding path
412 # latin-1 encoding path
413 changesets = @repository.latest_changesets(
413 changesets = @repository.latest_changesets(
414 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
414 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
415 assert_equal [
415 assert_equal [
416 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
416 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
417 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
417 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
418 ], changesets.collect(&:revision)
418 ], changesets.collect(&:revision)
419
419
420 changesets = @repository.latest_changesets(
420 changesets = @repository.latest_changesets(
421 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
421 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
422 assert_equal [
422 assert_equal [
423 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
423 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
424 ], changesets.collect(&:revision)
424 ], changesets.collect(&:revision)
425 end
425 end
426 end
426 end
427
427
428 def test_latest_changesets_latin_1_dir
428 def test_latest_changesets_latin_1_dir
429 if WINDOWS_PASS
429 if WINDOWS_PASS
430 puts WINDOWS_SKIP_STR
430 puts WINDOWS_SKIP_STR
431 elsif JRUBY_SKIP
431 elsif JRUBY_SKIP
432 puts JRUBY_SKIP_STR
432 puts JRUBY_SKIP_STR
433 else
433 else
434 assert_equal 0, @repository.changesets.count
434 assert_equal 0, @repository.changesets.count
435 @repository.fetch_changesets
435 @repository.fetch_changesets
436 @project.reload
436 @project.reload
437 assert_equal NUM_REV, @repository.changesets.count
437 assert_equal NUM_REV, @repository.changesets.count
438 changesets = @repository.latest_changesets(
438 changesets = @repository.latest_changesets(
439 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
439 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
440 assert_equal [
440 assert_equal [
441 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
441 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
442 ], changesets.collect(&:revision)
442 ], changesets.collect(&:revision)
443 end
443 end
444 end
444 end
445
445
446 def test_find_changeset_by_name
446 def test_find_changeset_by_name
447 assert_equal 0, @repository.changesets.count
447 assert_equal 0, @repository.changesets.count
448 @repository.fetch_changesets
448 @repository.fetch_changesets
449 @project.reload
449 @project.reload
450 assert_equal NUM_REV, @repository.changesets.count
450 assert_equal NUM_REV, @repository.changesets.count
451 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
451 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
452 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
452 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
453 @repository.find_changeset_by_name(r).revision
453 @repository.find_changeset_by_name(r).revision
454 end
454 end
455 end
455 end
456
456
457 def test_find_changeset_by_empty_name
457 def test_find_changeset_by_empty_name
458 assert_equal 0, @repository.changesets.count
458 assert_equal 0, @repository.changesets.count
459 @repository.fetch_changesets
459 @repository.fetch_changesets
460 @project.reload
460 @project.reload
461 assert_equal NUM_REV, @repository.changesets.count
461 assert_equal NUM_REV, @repository.changesets.count
462 ['', ' ', nil].each do |r|
462 ['', ' ', nil].each do |r|
463 assert_nil @repository.find_changeset_by_name(r)
463 assert_nil @repository.find_changeset_by_name(r)
464 end
464 end
465 end
465 end
466
466
467 def test_identifier
467 def test_identifier
468 assert_equal 0, @repository.changesets.count
468 assert_equal 0, @repository.changesets.count
469 @repository.fetch_changesets
469 @repository.fetch_changesets
470 @project.reload
470 @project.reload
471 assert_equal NUM_REV, @repository.changesets.count
471 assert_equal NUM_REV, @repository.changesets.count
472 c = @repository.changesets.find_by_revision(
472 c = @repository.changesets.find_by_revision(
473 '7234cb2750b63f47bff735edc50a1c0a433c2518')
473 '7234cb2750b63f47bff735edc50a1c0a433c2518')
474 assert_equal c.scmid, c.identifier
474 assert_equal c.scmid, c.identifier
475 end
475 end
476
476
477 def test_format_identifier
477 def test_format_identifier
478 assert_equal 0, @repository.changesets.count
478 assert_equal 0, @repository.changesets.count
479 @repository.fetch_changesets
479 @repository.fetch_changesets
480 @project.reload
480 @project.reload
481 assert_equal NUM_REV, @repository.changesets.count
481 assert_equal NUM_REV, @repository.changesets.count
482 c = @repository.changesets.find_by_revision(
482 c = @repository.changesets.find_by_revision(
483 '7234cb2750b63f47bff735edc50a1c0a433c2518')
483 '7234cb2750b63f47bff735edc50a1c0a433c2518')
484 assert_equal '7234cb27', c.format_identifier
484 assert_equal '7234cb27', c.format_identifier
485 end
485 end
486
486
487 def test_activities
487 def test_activities
488 c = Changeset.new(:repository => @repository,
488 c = Changeset.new(:repository => @repository,
489 :committed_on => Time.now,
489 :committed_on => Time.now,
490 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
490 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
491 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
491 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
492 :comments => 'test')
492 :comments => 'test')
493 assert c.event_title.include?('abc7234c:')
493 assert c.event_title.include?('abc7234c:')
494 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
494 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
495 end
495 end
496
496
497 def test_log_utf8
497 def test_log_utf8
498 assert_equal 0, @repository.changesets.count
498 assert_equal 0, @repository.changesets.count
499 @repository.fetch_changesets
499 @repository.fetch_changesets
500 @project.reload
500 @project.reload
501 assert_equal NUM_REV, @repository.changesets.count
501 assert_equal NUM_REV, @repository.changesets.count
502 str_felix_hex = FELIX_HEX.dup
502 str_felix_hex = FELIX_HEX.dup
503 if str_felix_hex.respond_to?(:force_encoding)
503 if str_felix_hex.respond_to?(:force_encoding)
504 str_felix_hex.force_encoding('UTF-8')
504 str_felix_hex.force_encoding('UTF-8')
505 end
505 end
506 c = @repository.changesets.find_by_revision(
506 c = @repository.changesets.find_by_revision(
507 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
507 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
508 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
508 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
509 end
509 end
510
510
511 def test_previous
511 def test_previous
512 assert_equal 0, @repository.changesets.count
512 assert_equal 0, @repository.changesets.count
513 @repository.fetch_changesets
513 @repository.fetch_changesets
514 @project.reload
514 @project.reload
515 assert_equal NUM_REV, @repository.changesets.count
515 assert_equal NUM_REV, @repository.changesets.count
516 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
516 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
517 changeset = @repository.find_changeset_by_name(r1)
517 changeset = @repository.find_changeset_by_name(r1)
518 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
518 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
519 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
519 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
520 end
520 end
521 end
521 end
522 end
522 end
523
523
524 def test_previous_nil
524 def test_previous_nil
525 assert_equal 0, @repository.changesets.count
525 assert_equal 0, @repository.changesets.count
526 @repository.fetch_changesets
526 @repository.fetch_changesets
527 @project.reload
527 @project.reload
528 assert_equal NUM_REV, @repository.changesets.count
528 assert_equal NUM_REV, @repository.changesets.count
529 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1|
529 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1|
530 changeset = @repository.find_changeset_by_name(r1)
530 changeset = @repository.find_changeset_by_name(r1)
531 assert_nil changeset.previous
531 assert_nil changeset.previous
532 end
532 end
533 end
533 end
534
534
535 def test_next
535 def test_next
536 assert_equal 0, @repository.changesets.count
536 assert_equal 0, @repository.changesets.count
537 @repository.fetch_changesets
537 @repository.fetch_changesets
538 @project.reload
538 @project.reload
539 assert_equal NUM_REV, @repository.changesets.count
539 assert_equal NUM_REV, @repository.changesets.count
540 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
540 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
541 changeset = @repository.find_changeset_by_name(r2)
541 changeset = @repository.find_changeset_by_name(r2)
542 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
542 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
543 assert_equal @repository.find_changeset_by_name(r1), changeset.next
543 assert_equal @repository.find_changeset_by_name(r1), changeset.next
544 end
544 end
545 end
545 end
546 end
546 end
547
547
548 def test_next_nil
548 def test_next_nil
549 assert_equal 0, @repository.changesets.count
549 assert_equal 0, @repository.changesets.count
550 @repository.fetch_changesets
550 @repository.fetch_changesets
551 @project.reload
551 @project.reload
552 assert_equal NUM_REV, @repository.changesets.count
552 assert_equal NUM_REV, @repository.changesets.count
553 %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1|
553 %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1|
554 changeset = @repository.find_changeset_by_name(r1)
554 changeset = @repository.find_changeset_by_name(r1)
555 assert_nil changeset.next
555 assert_nil changeset.next
556 end
556 end
557 end
557 end
558 else
558 else
559 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
559 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
560 def test_fake; assert true end
560 def test_fake; assert true end
561 end
561 end
562 end
562 end
General Comments 0
You need to be logged in to leave comments. Login now