##// END OF EJS Templates
Fix: Unable to run unit and functional tests if git binary is not available....
Jean-Philippe Lang -
r9678:2311f80c5dd1
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,567 +1,567
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_entries
100 def test_entries
101 entries = @repository.entries
101 entries = @repository.entries
102 assert_kind_of Redmine::Scm::Adapters::Entries, entries
102 assert_kind_of Redmine::Scm::Adapters::Entries, entries
103 end
103 end
104
104
105 def test_fetch_changesets_from_scratch
105 def test_fetch_changesets_from_scratch
106 assert_nil @repository.extra_info
106 assert_nil @repository.extra_info
107
107
108 assert_equal 0, @repository.changesets.count
108 assert_equal 0, @repository.changesets.count
109 @repository.fetch_changesets
109 @repository.fetch_changesets
110 @project.reload
110 @project.reload
111
111
112 assert_equal NUM_REV, @repository.changesets.count
112 assert_equal NUM_REV, @repository.changesets.count
113 assert_equal 39, @repository.filechanges.count
113 assert_equal 39, @repository.filechanges.count
114
114
115 commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
115 commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
116 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
116 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
117 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
117 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
118 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
118 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
119 assert_equal User.find_by_login('jsmith'), commit.user
119 assert_equal User.find_by_login('jsmith'), commit.user
120 # TODO: add a commit with commit time <> author time to the test repository
120 # TODO: add a commit with commit time <> author time to the test repository
121 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
121 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
122 assert_equal "2007-12-14".to_date, commit.commit_date
122 assert_equal "2007-12-14".to_date, commit.commit_date
123 assert_equal 3, commit.filechanges.count
123 assert_equal 3, commit.filechanges.count
124 change = commit.filechanges.sort_by(&:path).first
124 change = commit.filechanges.sort_by(&:path).first
125 assert_equal "README", change.path
125 assert_equal "README", change.path
126 assert_equal nil, change.from_path
126 assert_equal nil, change.from_path
127 assert_equal "A", change.action
127 assert_equal "A", change.action
128
128
129 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
129 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
130 end
130 end
131
131
132 def test_fetch_changesets_incremental
132 def test_fetch_changesets_incremental
133 assert_equal 0, @repository.changesets.count
133 assert_equal 0, @repository.changesets.count
134 @repository.fetch_changesets
134 @repository.fetch_changesets
135 @project.reload
135 @project.reload
136 assert_equal NUM_REV, @repository.changesets.count
136 assert_equal NUM_REV, @repository.changesets.count
137 extra_info_heads = @repository.extra_info["heads"].dup
137 extra_info_heads = @repository.extra_info["heads"].dup
138 assert_equal NUM_HEAD, extra_info_heads.size
138 assert_equal NUM_HEAD, extra_info_heads.size
139 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
139 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
140 assert_equal 4, extra_info_heads.size
140 assert_equal 4, extra_info_heads.size
141
141
142 del_revs = [
142 del_revs = [
143 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
143 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
144 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
144 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
145 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
145 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
146 "deff712f05a90d96edbd70facc47d944be5897e3",
146 "deff712f05a90d96edbd70facc47d944be5897e3",
147 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
147 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
148 "7e61ac704deecde634b51e59daa8110435dcb3da",
148 "7e61ac704deecde634b51e59daa8110435dcb3da",
149 ]
149 ]
150 @repository.changesets.each do |rev|
150 @repository.changesets.each do |rev|
151 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
151 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
152 end
152 end
153 @project.reload
153 @project.reload
154 cs1 = @repository.changesets
154 cs1 = @repository.changesets
155 assert_equal NUM_REV - 6, cs1.count
155 assert_equal NUM_REV - 6, cs1.count
156 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
156 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
157 h = {}
157 h = {}
158 h["heads"] = extra_info_heads
158 h["heads"] = extra_info_heads
159 @repository.merge_extra_info(h)
159 @repository.merge_extra_info(h)
160 @repository.save
160 @repository.save
161 @project.reload
161 @project.reload
162 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
162 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
163 @repository.fetch_changesets
163 @repository.fetch_changesets
164 @project.reload
164 @project.reload
165 assert_equal NUM_REV, @repository.changesets.count
165 assert_equal NUM_REV, @repository.changesets.count
166 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
166 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
167 assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c")
167 assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c")
168 end
168 end
169
169
170 def test_fetch_changesets_history_editing
170 def test_fetch_changesets_history_editing
171 assert_equal 0, @repository.changesets.count
171 assert_equal 0, @repository.changesets.count
172 @repository.fetch_changesets
172 @repository.fetch_changesets
173 @project.reload
173 @project.reload
174 assert_equal NUM_REV, @repository.changesets.count
174 assert_equal NUM_REV, @repository.changesets.count
175 extra_info_heads = @repository.extra_info["heads"].dup
175 extra_info_heads = @repository.extra_info["heads"].dup
176 assert_equal NUM_HEAD, extra_info_heads.size
176 assert_equal NUM_HEAD, extra_info_heads.size
177 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
177 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
178 assert_equal 4, extra_info_heads.size
178 assert_equal 4, extra_info_heads.size
179
179
180 del_revs = [
180 del_revs = [
181 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
181 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
182 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
182 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
183 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
183 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
184 "deff712f05a90d96edbd70facc47d944be5897e3",
184 "deff712f05a90d96edbd70facc47d944be5897e3",
185 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
185 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
186 "7e61ac704deecde634b51e59daa8110435dcb3da",
186 "7e61ac704deecde634b51e59daa8110435dcb3da",
187 ]
187 ]
188 @repository.changesets.each do |rev|
188 @repository.changesets.each do |rev|
189 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
189 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
190 end
190 end
191 @project.reload
191 @project.reload
192 assert_equal NUM_REV - 6, @repository.changesets.count
192 assert_equal NUM_REV - 6, @repository.changesets.count
193
193
194 c = Changeset.new(:repository => @repository,
194 c = Changeset.new(:repository => @repository,
195 :committed_on => Time.now,
195 :committed_on => Time.now,
196 :revision => "abcd1234efgh",
196 :revision => "abcd1234efgh",
197 :scmid => "abcd1234efgh",
197 :scmid => "abcd1234efgh",
198 :comments => 'test')
198 :comments => 'test')
199 assert c.save
199 assert c.save
200 @project.reload
200 @project.reload
201 assert_equal NUM_REV - 5, @repository.changesets.count
201 assert_equal NUM_REV - 5, @repository.changesets.count
202
202
203 extra_info_heads << "1234abcd5678"
203 extra_info_heads << "1234abcd5678"
204 h = {}
204 h = {}
205 h["heads"] = extra_info_heads
205 h["heads"] = extra_info_heads
206 @repository.merge_extra_info(h)
206 @repository.merge_extra_info(h)
207 @repository.save
207 @repository.save
208 @project.reload
208 @project.reload
209 h1 = @repository.extra_info["heads"].dup
209 h1 = @repository.extra_info["heads"].dup
210 assert h1.index("1234abcd5678")
210 assert h1.index("1234abcd5678")
211 assert_equal 5, h1.size
211 assert_equal 5, h1.size
212
212
213 @repository.fetch_changesets
213 @repository.fetch_changesets
214 @project.reload
214 @project.reload
215 assert_equal NUM_REV - 5, @repository.changesets.count
215 assert_equal NUM_REV - 5, @repository.changesets.count
216 h2 = @repository.extra_info["heads"].dup
216 h2 = @repository.extra_info["heads"].dup
217 assert_equal h1, h2
217 assert_equal h1, h2
218 end
218 end
219
219
220 def test_parents
220 def test_parents
221 assert_equal 0, @repository.changesets.count
221 assert_equal 0, @repository.changesets.count
222 @repository.fetch_changesets
222 @repository.fetch_changesets
223 @project.reload
223 @project.reload
224 assert_equal NUM_REV, @repository.changesets.count
224 assert_equal NUM_REV, @repository.changesets.count
225 r1 = @repository.find_changeset_by_name("7234cb2750b63")
225 r1 = @repository.find_changeset_by_name("7234cb2750b63")
226 assert_equal [], r1.parents
226 assert_equal [], r1.parents
227 r2 = @repository.find_changeset_by_name("899a15dba03a3")
227 r2 = @repository.find_changeset_by_name("899a15dba03a3")
228 assert_equal 1, r2.parents.length
228 assert_equal 1, r2.parents.length
229 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
229 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
230 r2.parents[0].identifier
230 r2.parents[0].identifier
231 r3 = @repository.find_changeset_by_name("32ae898b720c2")
231 r3 = @repository.find_changeset_by_name("32ae898b720c2")
232 assert_equal 2, r3.parents.length
232 assert_equal 2, r3.parents.length
233 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
233 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
234 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0]
234 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0]
235 assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1]
235 assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1]
236 end
236 end
237
237
238 def test_db_consistent_ordering_init
238 def test_db_consistent_ordering_init
239 assert_nil @repository.extra_info
239 assert_nil @repository.extra_info
240 assert_equal 0, @repository.changesets.count
240 assert_equal 0, @repository.changesets.count
241 @repository.fetch_changesets
241 @repository.fetch_changesets
242 @project.reload
242 @project.reload
243 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
243 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
244 end
244 end
245
245
246 def test_db_consistent_ordering_before_1_2
246 def test_db_consistent_ordering_before_1_2
247 assert_nil @repository.extra_info
247 assert_nil @repository.extra_info
248 assert_equal 0, @repository.changesets.count
248 assert_equal 0, @repository.changesets.count
249 @repository.fetch_changesets
249 @repository.fetch_changesets
250 @project.reload
250 @project.reload
251 assert_equal NUM_REV, @repository.changesets.count
251 assert_equal NUM_REV, @repository.changesets.count
252 assert_not_nil @repository.extra_info
252 assert_not_nil @repository.extra_info
253 h = {}
253 h = {}
254 h["heads"] = []
254 h["heads"] = []
255 h["branches"] = {}
255 h["branches"] = {}
256 h["db_consistent"] = {}
256 h["db_consistent"] = {}
257 @repository.merge_extra_info(h)
257 @repository.merge_extra_info(h)
258 @repository.save
258 @repository.save
259 assert_equal NUM_REV, @repository.changesets.count
259 assert_equal NUM_REV, @repository.changesets.count
260 @repository.fetch_changesets
260 @repository.fetch_changesets
261 @project.reload
261 @project.reload
262 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
262 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
263
263
264 extra_info_heads = @repository.extra_info["heads"].dup
264 extra_info_heads = @repository.extra_info["heads"].dup
265 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
265 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
266 del_revs = [
266 del_revs = [
267 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
267 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
268 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
268 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
269 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
269 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
270 "deff712f05a90d96edbd70facc47d944be5897e3",
270 "deff712f05a90d96edbd70facc47d944be5897e3",
271 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
271 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
272 "7e61ac704deecde634b51e59daa8110435dcb3da",
272 "7e61ac704deecde634b51e59daa8110435dcb3da",
273 ]
273 ]
274 @repository.changesets.each do |rev|
274 @repository.changesets.each do |rev|
275 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
275 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
276 end
276 end
277 @project.reload
277 @project.reload
278 cs1 = @repository.changesets
278 cs1 = @repository.changesets
279 assert_equal NUM_REV - 6, cs1.count
279 assert_equal NUM_REV - 6, cs1.count
280 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
280 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
281
281
282 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
282 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
283 h = {}
283 h = {}
284 h["heads"] = extra_info_heads
284 h["heads"] = extra_info_heads
285 @repository.merge_extra_info(h)
285 @repository.merge_extra_info(h)
286 @repository.save
286 @repository.save
287 @project.reload
287 @project.reload
288 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
288 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
289 @repository.fetch_changesets
289 @repository.fetch_changesets
290 @project.reload
290 @project.reload
291 assert_equal NUM_REV, @repository.changesets.count
291 assert_equal NUM_REV, @repository.changesets.count
292 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
292 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
293
293
294 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
294 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
295 end
295 end
296
296
297 def test_heads_from_branches_hash
297 def test_heads_from_branches_hash
298 assert_nil @repository.extra_info
298 assert_nil @repository.extra_info
299 assert_equal 0, @repository.changesets.count
299 assert_equal 0, @repository.changesets.count
300 assert_equal [], @repository.heads_from_branches_hash
300 assert_equal [], @repository.heads_from_branches_hash
301 h = {}
301 h = {}
302 h["branches"] = {}
302 h["branches"] = {}
303 h["branches"]["test1"] = {}
303 h["branches"]["test1"] = {}
304 h["branches"]["test1"]["last_scmid"] = "1234abcd"
304 h["branches"]["test1"]["last_scmid"] = "1234abcd"
305 h["branches"]["test2"] = {}
305 h["branches"]["test2"] = {}
306 h["branches"]["test2"]["last_scmid"] = "abcd1234"
306 h["branches"]["test2"]["last_scmid"] = "abcd1234"
307 @repository.merge_extra_info(h)
307 @repository.merge_extra_info(h)
308 @repository.save
308 @repository.save
309 @project.reload
309 @project.reload
310 assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
310 assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
311 end
311 end
312
312
313 def test_latest_changesets
313 def test_latest_changesets
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 # with limit
318 # with limit
319 changesets = @repository.latest_changesets('', 'master', 2)
319 changesets = @repository.latest_changesets('', 'master', 2)
320 assert_equal 2, changesets.size
320 assert_equal 2, changesets.size
321
321
322 # with path
322 # with path
323 changesets = @repository.latest_changesets('images', 'master')
323 changesets = @repository.latest_changesets('images', 'master')
324 assert_equal [
324 assert_equal [
325 'deff712f05a90d96edbd70facc47d944be5897e3',
325 'deff712f05a90d96edbd70facc47d944be5897e3',
326 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
326 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
327 '7234cb2750b63f47bff735edc50a1c0a433c2518',
327 '7234cb2750b63f47bff735edc50a1c0a433c2518',
328 ], changesets.collect(&:revision)
328 ], changesets.collect(&:revision)
329
329
330 changesets = @repository.latest_changesets('README', nil)
330 changesets = @repository.latest_changesets('README', nil)
331 assert_equal [
331 assert_equal [
332 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
332 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
333 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
333 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
334 '713f4944648826f558cf548222f813dabe7cbb04',
334 '713f4944648826f558cf548222f813dabe7cbb04',
335 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
335 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
336 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
336 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
337 '7234cb2750b63f47bff735edc50a1c0a433c2518',
337 '7234cb2750b63f47bff735edc50a1c0a433c2518',
338 ], changesets.collect(&:revision)
338 ], changesets.collect(&:revision)
339
339
340 # with path, revision and limit
340 # with path, revision and limit
341 changesets = @repository.latest_changesets('images', '899a15dba')
341 changesets = @repository.latest_changesets('images', '899a15dba')
342 assert_equal [
342 assert_equal [
343 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
343 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
344 '7234cb2750b63f47bff735edc50a1c0a433c2518',
344 '7234cb2750b63f47bff735edc50a1c0a433c2518',
345 ], changesets.collect(&:revision)
345 ], changesets.collect(&:revision)
346
346
347 changesets = @repository.latest_changesets('images', '899a15dba', 1)
347 changesets = @repository.latest_changesets('images', '899a15dba', 1)
348 assert_equal [
348 assert_equal [
349 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
349 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
350 ], changesets.collect(&:revision)
350 ], changesets.collect(&:revision)
351
351
352 changesets = @repository.latest_changesets('README', '899a15dba')
352 changesets = @repository.latest_changesets('README', '899a15dba')
353 assert_equal [
353 assert_equal [
354 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
354 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
355 '7234cb2750b63f47bff735edc50a1c0a433c2518',
355 '7234cb2750b63f47bff735edc50a1c0a433c2518',
356 ], changesets.collect(&:revision)
356 ], changesets.collect(&:revision)
357
357
358 changesets = @repository.latest_changesets('README', '899a15dba', 1)
358 changesets = @repository.latest_changesets('README', '899a15dba', 1)
359 assert_equal [
359 assert_equal [
360 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
360 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
361 ], changesets.collect(&:revision)
361 ], changesets.collect(&:revision)
362
362
363 # with path, tag and limit
363 # with path, tag and limit
364 changesets = @repository.latest_changesets('images', 'tag01.annotated')
364 changesets = @repository.latest_changesets('images', 'tag01.annotated')
365 assert_equal [
365 assert_equal [
366 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
366 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
367 '7234cb2750b63f47bff735edc50a1c0a433c2518',
367 '7234cb2750b63f47bff735edc50a1c0a433c2518',
368 ], changesets.collect(&:revision)
368 ], changesets.collect(&:revision)
369
369
370 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
370 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
371 assert_equal [
371 assert_equal [
372 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
372 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
373 ], changesets.collect(&:revision)
373 ], changesets.collect(&:revision)
374
374
375 changesets = @repository.latest_changesets('README', 'tag01.annotated')
375 changesets = @repository.latest_changesets('README', 'tag01.annotated')
376 assert_equal [
376 assert_equal [
377 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
377 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
378 '7234cb2750b63f47bff735edc50a1c0a433c2518',
378 '7234cb2750b63f47bff735edc50a1c0a433c2518',
379 ], changesets.collect(&:revision)
379 ], changesets.collect(&:revision)
380
380
381 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
381 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
382 assert_equal [
382 assert_equal [
383 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
383 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
384 ], changesets.collect(&:revision)
384 ], changesets.collect(&:revision)
385
385
386 # with path, branch and limit
386 # with path, branch and limit
387 changesets = @repository.latest_changesets('images', 'test_branch')
387 changesets = @repository.latest_changesets('images', 'test_branch')
388 assert_equal [
388 assert_equal [
389 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
389 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
390 '7234cb2750b63f47bff735edc50a1c0a433c2518',
390 '7234cb2750b63f47bff735edc50a1c0a433c2518',
391 ], changesets.collect(&:revision)
391 ], changesets.collect(&:revision)
392
392
393 changesets = @repository.latest_changesets('images', 'test_branch', 1)
393 changesets = @repository.latest_changesets('images', 'test_branch', 1)
394 assert_equal [
394 assert_equal [
395 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
395 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
396 ], changesets.collect(&:revision)
396 ], changesets.collect(&:revision)
397
397
398 changesets = @repository.latest_changesets('README', 'test_branch')
398 changesets = @repository.latest_changesets('README', 'test_branch')
399 assert_equal [
399 assert_equal [
400 '713f4944648826f558cf548222f813dabe7cbb04',
400 '713f4944648826f558cf548222f813dabe7cbb04',
401 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
401 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
402 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
402 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
403 '7234cb2750b63f47bff735edc50a1c0a433c2518',
403 '7234cb2750b63f47bff735edc50a1c0a433c2518',
404 ], changesets.collect(&:revision)
404 ], changesets.collect(&:revision)
405
405
406 changesets = @repository.latest_changesets('README', 'test_branch', 2)
406 changesets = @repository.latest_changesets('README', 'test_branch', 2)
407 assert_equal [
407 assert_equal [
408 '713f4944648826f558cf548222f813dabe7cbb04',
408 '713f4944648826f558cf548222f813dabe7cbb04',
409 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
409 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
410 ], changesets.collect(&:revision)
410 ], changesets.collect(&:revision)
411
411
412 if WINDOWS_PASS
412 if WINDOWS_PASS
413 puts WINDOWS_SKIP_STR
413 puts WINDOWS_SKIP_STR
414 elsif JRUBY_SKIP
414 elsif JRUBY_SKIP
415 puts JRUBY_SKIP_STR
415 puts JRUBY_SKIP_STR
416 else
416 else
417 # latin-1 encoding path
417 # latin-1 encoding path
418 changesets = @repository.latest_changesets(
418 changesets = @repository.latest_changesets(
419 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
419 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
420 assert_equal [
420 assert_equal [
421 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
421 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
422 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
422 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
423 ], changesets.collect(&:revision)
423 ], changesets.collect(&:revision)
424
424
425 changesets = @repository.latest_changesets(
425 changesets = @repository.latest_changesets(
426 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
426 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
427 assert_equal [
427 assert_equal [
428 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
428 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
429 ], changesets.collect(&:revision)
429 ], changesets.collect(&:revision)
430 end
430 end
431 end
431 end
432
432
433 def test_latest_changesets_latin_1_dir
433 def test_latest_changesets_latin_1_dir
434 if WINDOWS_PASS
434 if WINDOWS_PASS
435 puts WINDOWS_SKIP_STR
435 puts WINDOWS_SKIP_STR
436 elsif JRUBY_SKIP
436 elsif JRUBY_SKIP
437 puts JRUBY_SKIP_STR
437 puts JRUBY_SKIP_STR
438 else
438 else
439 assert_equal 0, @repository.changesets.count
439 assert_equal 0, @repository.changesets.count
440 @repository.fetch_changesets
440 @repository.fetch_changesets
441 @project.reload
441 @project.reload
442 assert_equal NUM_REV, @repository.changesets.count
442 assert_equal NUM_REV, @repository.changesets.count
443 changesets = @repository.latest_changesets(
443 changesets = @repository.latest_changesets(
444 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
444 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
445 assert_equal [
445 assert_equal [
446 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
446 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
447 ], changesets.collect(&:revision)
447 ], changesets.collect(&:revision)
448 end
448 end
449 end
449 end
450
450
451 def test_find_changeset_by_name
451 def test_find_changeset_by_name
452 assert_equal 0, @repository.changesets.count
452 assert_equal 0, @repository.changesets.count
453 @repository.fetch_changesets
453 @repository.fetch_changesets
454 @project.reload
454 @project.reload
455 assert_equal NUM_REV, @repository.changesets.count
455 assert_equal NUM_REV, @repository.changesets.count
456 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
456 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
457 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
457 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
458 @repository.find_changeset_by_name(r).revision
458 @repository.find_changeset_by_name(r).revision
459 end
459 end
460 end
460 end
461
461
462 def test_find_changeset_by_empty_name
462 def test_find_changeset_by_empty_name
463 assert_equal 0, @repository.changesets.count
463 assert_equal 0, @repository.changesets.count
464 @repository.fetch_changesets
464 @repository.fetch_changesets
465 @project.reload
465 @project.reload
466 assert_equal NUM_REV, @repository.changesets.count
466 assert_equal NUM_REV, @repository.changesets.count
467 ['', ' ', nil].each do |r|
467 ['', ' ', nil].each do |r|
468 assert_nil @repository.find_changeset_by_name(r)
468 assert_nil @repository.find_changeset_by_name(r)
469 end
469 end
470 end
470 end
471
471
472 def test_identifier
472 def test_identifier
473 assert_equal 0, @repository.changesets.count
473 assert_equal 0, @repository.changesets.count
474 @repository.fetch_changesets
474 @repository.fetch_changesets
475 @project.reload
475 @project.reload
476 assert_equal NUM_REV, @repository.changesets.count
476 assert_equal NUM_REV, @repository.changesets.count
477 c = @repository.changesets.find_by_revision(
477 c = @repository.changesets.find_by_revision(
478 '7234cb2750b63f47bff735edc50a1c0a433c2518')
478 '7234cb2750b63f47bff735edc50a1c0a433c2518')
479 assert_equal c.scmid, c.identifier
479 assert_equal c.scmid, c.identifier
480 end
480 end
481
481
482 def test_format_identifier
482 def test_format_identifier
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 c = @repository.changesets.find_by_revision(
487 c = @repository.changesets.find_by_revision(
488 '7234cb2750b63f47bff735edc50a1c0a433c2518')
488 '7234cb2750b63f47bff735edc50a1c0a433c2518')
489 assert_equal '7234cb27', c.format_identifier
489 assert_equal '7234cb27', c.format_identifier
490 end
490 end
491
491
492 def test_activities
492 def test_activities
493 c = Changeset.new(:repository => @repository,
493 c = Changeset.new(:repository => @repository,
494 :committed_on => Time.now,
494 :committed_on => Time.now,
495 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
495 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
496 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
496 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
497 :comments => 'test')
497 :comments => 'test')
498 assert c.event_title.include?('abc7234c:')
498 assert c.event_title.include?('abc7234c:')
499 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
499 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
500 end
500 end
501
501
502 def test_log_utf8
502 def test_log_utf8
503 assert_equal 0, @repository.changesets.count
503 assert_equal 0, @repository.changesets.count
504 @repository.fetch_changesets
504 @repository.fetch_changesets
505 @project.reload
505 @project.reload
506 assert_equal NUM_REV, @repository.changesets.count
506 assert_equal NUM_REV, @repository.changesets.count
507 str_felix_hex = FELIX_HEX.dup
507 str_felix_hex = FELIX_HEX.dup
508 if str_felix_hex.respond_to?(:force_encoding)
508 if str_felix_hex.respond_to?(:force_encoding)
509 str_felix_hex.force_encoding('UTF-8')
509 str_felix_hex.force_encoding('UTF-8')
510 end
510 end
511 c = @repository.changesets.find_by_revision(
511 c = @repository.changesets.find_by_revision(
512 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
512 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
513 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
513 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
514 end
514 end
515
515
516 def test_previous
516 def test_previous
517 assert_equal 0, @repository.changesets.count
517 assert_equal 0, @repository.changesets.count
518 @repository.fetch_changesets
518 @repository.fetch_changesets
519 @project.reload
519 @project.reload
520 assert_equal NUM_REV, @repository.changesets.count
520 assert_equal NUM_REV, @repository.changesets.count
521 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
521 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
522 changeset = @repository.find_changeset_by_name(r1)
522 changeset = @repository.find_changeset_by_name(r1)
523 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
523 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
524 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
524 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
525 end
525 end
526 end
526 end
527 end
527 end
528
528
529 def test_previous_nil
529 def test_previous_nil
530 assert_equal 0, @repository.changesets.count
530 assert_equal 0, @repository.changesets.count
531 @repository.fetch_changesets
531 @repository.fetch_changesets
532 @project.reload
532 @project.reload
533 assert_equal NUM_REV, @repository.changesets.count
533 assert_equal NUM_REV, @repository.changesets.count
534 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1|
534 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1|
535 changeset = @repository.find_changeset_by_name(r1)
535 changeset = @repository.find_changeset_by_name(r1)
536 assert_nil changeset.previous
536 assert_nil changeset.previous
537 end
537 end
538 end
538 end
539
539
540 def test_next
540 def test_next
541 assert_equal 0, @repository.changesets.count
541 assert_equal 0, @repository.changesets.count
542 @repository.fetch_changesets
542 @repository.fetch_changesets
543 @project.reload
543 @project.reload
544 assert_equal NUM_REV, @repository.changesets.count
544 assert_equal NUM_REV, @repository.changesets.count
545 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
545 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
546 changeset = @repository.find_changeset_by_name(r2)
546 changeset = @repository.find_changeset_by_name(r2)
547 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
547 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
548 assert_equal @repository.find_changeset_by_name(r1), changeset.next
548 assert_equal @repository.find_changeset_by_name(r1), changeset.next
549 end
549 end
550 end
550 end
551 end
551 end
552
552
553 def test_next_nil
553 def test_next_nil
554 assert_equal 0, @repository.changesets.count
554 assert_equal 0, @repository.changesets.count
555 @repository.fetch_changesets
555 @repository.fetch_changesets
556 @project.reload
556 @project.reload
557 assert_equal NUM_REV, @repository.changesets.count
557 assert_equal NUM_REV, @repository.changesets.count
558 %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1|
558 %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1|
559 changeset = @repository.find_changeset_by_name(r1)
559 changeset = @repository.find_changeset_by_name(r1)
560 assert_nil changeset.next
560 assert_nil changeset.next
561 end
561 end
562 end
562 end
563 else
563 else
564 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
564 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
565 def test_fake; assert true end
565 def test_fake; assert true end
566 end
566 end
567 end
567 end
General Comments 0
You need to be logged in to leave comments. Login now