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