1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -1,505 +1,505 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 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 | require 'repositories_controller' |
|
19 | require 'repositories_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class RepositoriesController; def rescue_action(e) raise e end; end |
|
22 | class RepositoriesController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class RepositoriesMercurialControllerTest < ActionController::TestCase |
|
24 | class RepositoriesMercurialControllerTest < ActionController::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
25 | fixtures :projects, :users, :roles, :members, :member_roles, | |
26 | :repositories, :enabled_modules |
|
26 | :repositories, :enabled_modules | |
27 |
|
27 | |||
28 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
|
28 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s | |
29 | CHAR_1_HEX = "\xc3\x9c" |
|
29 | CHAR_1_HEX = "\xc3\x9c" | |
30 | PRJ_ID = 3 |
|
30 | PRJ_ID = 3 | |
31 |
NUM_REV = 2 |
|
31 | NUM_REV = 32 | |
32 |
|
32 | |||
33 | ruby19_non_utf8_pass = |
|
33 | ruby19_non_utf8_pass = | |
34 | (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') |
|
34 | (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') | |
35 |
|
35 | |||
36 | def setup |
|
36 | def setup | |
37 | @controller = RepositoriesController.new |
|
37 | @controller = RepositoriesController.new | |
38 | @request = ActionController::TestRequest.new |
|
38 | @request = ActionController::TestRequest.new | |
39 | @response = ActionController::TestResponse.new |
|
39 | @response = ActionController::TestResponse.new | |
40 | User.current = nil |
|
40 | User.current = nil | |
41 | @project = Project.find(PRJ_ID) |
|
41 | @project = Project.find(PRJ_ID) | |
42 | @repository = Repository::Mercurial.create( |
|
42 | @repository = Repository::Mercurial.create( | |
43 | :project => @project, |
|
43 | :project => @project, | |
44 | :url => REPOSITORY_PATH, |
|
44 | :url => REPOSITORY_PATH, | |
45 | :path_encoding => 'ISO-8859-1' |
|
45 | :path_encoding => 'ISO-8859-1' | |
46 | ) |
|
46 | ) | |
47 | assert @repository |
|
47 | assert @repository | |
48 | @diff_c_support = true |
|
48 | @diff_c_support = true | |
49 | @char_1 = CHAR_1_HEX.dup |
|
49 | @char_1 = CHAR_1_HEX.dup | |
50 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
50 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" | |
51 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
51 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" | |
52 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
52 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" | |
53 | if @char_1.respond_to?(:force_encoding) |
|
53 | if @char_1.respond_to?(:force_encoding) | |
54 | @char_1.force_encoding('UTF-8') |
|
54 | @char_1.force_encoding('UTF-8') | |
55 | @tag_char_1.force_encoding('UTF-8') |
|
55 | @tag_char_1.force_encoding('UTF-8') | |
56 | @branch_char_0.force_encoding('UTF-8') |
|
56 | @branch_char_0.force_encoding('UTF-8') | |
57 | @branch_char_1.force_encoding('UTF-8') |
|
57 | @branch_char_1.force_encoding('UTF-8') | |
58 | end |
|
58 | end | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | if ruby19_non_utf8_pass |
|
61 | if ruby19_non_utf8_pass | |
62 | puts "TODO: Mercurial functional test fails in Ruby 1.9 " + |
|
62 | puts "TODO: Mercurial functional test fails in Ruby 1.9 " + | |
63 | "and Encoding.default_external is not UTF-8. " + |
|
63 | "and Encoding.default_external is not UTF-8. " + | |
64 | "Current value is '#{Encoding.default_external.to_s}'" |
|
64 | "Current value is '#{Encoding.default_external.to_s}'" | |
65 | def test_fake; assert true end |
|
65 | def test_fake; assert true end | |
66 | elsif File.directory?(REPOSITORY_PATH) |
|
66 | elsif File.directory?(REPOSITORY_PATH) | |
67 | def test_show_root |
|
67 | def test_show_root | |
68 | assert_equal 0, @repository.changesets.count |
|
68 | assert_equal 0, @repository.changesets.count | |
69 | @repository.fetch_changesets |
|
69 | @repository.fetch_changesets | |
70 | @project.reload |
|
70 | @project.reload | |
71 | assert_equal NUM_REV, @repository.changesets.count |
|
71 | assert_equal NUM_REV, @repository.changesets.count | |
72 | get :show, :id => PRJ_ID |
|
72 | get :show, :id => PRJ_ID | |
73 | assert_response :success |
|
73 | assert_response :success | |
74 | assert_template 'show' |
|
74 | assert_template 'show' | |
75 | assert_not_nil assigns(:entries) |
|
75 | assert_not_nil assigns(:entries) | |
76 | assert_equal 4, assigns(:entries).size |
|
76 | assert_equal 4, assigns(:entries).size | |
77 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
77 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
78 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
78 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
79 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
79 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
80 | assert_not_nil assigns(:changesets) |
|
80 | assert_not_nil assigns(:changesets) | |
81 | assert assigns(:changesets).size > 0 |
|
81 | assert assigns(:changesets).size > 0 | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_show_directory |
|
84 | def test_show_directory | |
85 | assert_equal 0, @repository.changesets.count |
|
85 | assert_equal 0, @repository.changesets.count | |
86 | @repository.fetch_changesets |
|
86 | @repository.fetch_changesets | |
87 | @project.reload |
|
87 | @project.reload | |
88 | assert_equal NUM_REV, @repository.changesets.count |
|
88 | assert_equal NUM_REV, @repository.changesets.count | |
89 | get :show, :id => PRJ_ID, :path => ['images'] |
|
89 | get :show, :id => PRJ_ID, :path => ['images'] | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_template 'show' |
|
91 | assert_template 'show' | |
92 | assert_not_nil assigns(:entries) |
|
92 | assert_not_nil assigns(:entries) | |
93 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
93 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
94 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
94 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
95 | assert_not_nil entry |
|
95 | assert_not_nil entry | |
96 | assert_equal 'file', entry.kind |
|
96 | assert_equal 'file', entry.kind | |
97 | assert_equal 'images/edit.png', entry.path |
|
97 | assert_equal 'images/edit.png', entry.path | |
98 | assert_not_nil assigns(:changesets) |
|
98 | assert_not_nil assigns(:changesets) | |
99 | assert assigns(:changesets).size > 0 |
|
99 | assert assigns(:changesets).size > 0 | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | def test_show_at_given_revision |
|
102 | def test_show_at_given_revision | |
103 | assert_equal 0, @repository.changesets.count |
|
103 | assert_equal 0, @repository.changesets.count | |
104 | @repository.fetch_changesets |
|
104 | @repository.fetch_changesets | |
105 | @project.reload |
|
105 | @project.reload | |
106 | assert_equal NUM_REV, @repository.changesets.count |
|
106 | assert_equal NUM_REV, @repository.changesets.count | |
107 | [0, '0', '0885933ad4f6'].each do |r1| |
|
107 | [0, '0', '0885933ad4f6'].each do |r1| | |
108 | get :show, :id => PRJ_ID, :path => ['images'], :rev => r1 |
|
108 | get :show, :id => PRJ_ID, :path => ['images'], :rev => r1 | |
109 | assert_response :success |
|
109 | assert_response :success | |
110 | assert_template 'show' |
|
110 | assert_template 'show' | |
111 | assert_not_nil assigns(:entries) |
|
111 | assert_not_nil assigns(:entries) | |
112 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
112 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |
113 | assert_not_nil assigns(:changesets) |
|
113 | assert_not_nil assigns(:changesets) | |
114 | assert assigns(:changesets).size > 0 |
|
114 | assert assigns(:changesets).size > 0 | |
115 | end |
|
115 | end | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | def test_show_directory_sql_escape_percent |
|
118 | def test_show_directory_sql_escape_percent | |
119 | assert_equal 0, @repository.changesets.count |
|
119 | assert_equal 0, @repository.changesets.count | |
120 | @repository.fetch_changesets |
|
120 | @repository.fetch_changesets | |
121 | @project.reload |
|
121 | @project.reload | |
122 | assert_equal NUM_REV, @repository.changesets.count |
|
122 | assert_equal NUM_REV, @repository.changesets.count | |
123 | [13, '13', '3a330eb32958'].each do |r1| |
|
123 | [13, '13', '3a330eb32958'].each do |r1| | |
124 | get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'], |
|
124 | get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'], | |
125 | :rev => r1 |
|
125 | :rev => r1 | |
126 | assert_response :success |
|
126 | assert_response :success | |
127 | assert_template 'show' |
|
127 | assert_template 'show' | |
128 |
|
128 | |||
129 | assert_not_nil assigns(:entries) |
|
129 | assert_not_nil assigns(:entries) | |
130 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], |
|
130 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], | |
131 | assigns(:entries).collect(&:name) |
|
131 | assigns(:entries).collect(&:name) | |
132 | changesets = assigns(:changesets) |
|
132 | changesets = assigns(:changesets) | |
133 | assert_not_nil changesets |
|
133 | assert_not_nil changesets | |
134 | assert assigns(:changesets).size > 0 |
|
134 | assert assigns(:changesets).size > 0 | |
135 | assert_equal %w(13 11 10 9), changesets.collect(&:revision) |
|
135 | assert_equal %w(13 11 10 9), changesets.collect(&:revision) | |
136 | end |
|
136 | end | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | def test_show_directory_latin_1_path |
|
139 | def test_show_directory_latin_1_path | |
140 | assert_equal 0, @repository.changesets.count |
|
140 | assert_equal 0, @repository.changesets.count | |
141 | @repository.fetch_changesets |
|
141 | @repository.fetch_changesets | |
142 | @project.reload |
|
142 | @project.reload | |
143 | assert_equal NUM_REV, @repository.changesets.count |
|
143 | assert_equal NUM_REV, @repository.changesets.count | |
144 | [21, '21', 'adf805632193'].each do |r1| |
|
144 | [21, '21', 'adf805632193'].each do |r1| | |
145 | get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1 |
|
145 | get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1 | |
146 | assert_response :success |
|
146 | assert_response :success | |
147 | assert_template 'show' |
|
147 | assert_template 'show' | |
148 |
|
148 | |||
149 | assert_not_nil assigns(:entries) |
|
149 | assert_not_nil assigns(:entries) | |
150 | assert_equal ["make-latin-1-file.rb", |
|
150 | assert_equal ["make-latin-1-file.rb", | |
151 | "test-#{@char_1}-1.txt", |
|
151 | "test-#{@char_1}-1.txt", | |
152 | "test-#{@char_1}-2.txt", |
|
152 | "test-#{@char_1}-2.txt", | |
153 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) |
|
153 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) | |
154 | changesets = assigns(:changesets) |
|
154 | changesets = assigns(:changesets) | |
155 | assert_not_nil changesets |
|
155 | assert_not_nil changesets | |
156 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) |
|
156 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) | |
157 | end |
|
157 | end | |
158 | end |
|
158 | end | |
159 |
|
159 | |||
160 | def test_show_branch |
|
160 | def test_show_branch | |
161 | assert_equal 0, @repository.changesets.count |
|
161 | assert_equal 0, @repository.changesets.count | |
162 | @repository.fetch_changesets |
|
162 | @repository.fetch_changesets | |
163 | @project.reload |
|
163 | @project.reload | |
164 | assert_equal NUM_REV, @repository.changesets.count |
|
164 | assert_equal NUM_REV, @repository.changesets.count | |
165 | [ |
|
165 | [ | |
166 | 'default', |
|
166 | 'default', | |
167 | @branch_char_1, |
|
167 | @branch_char_1, | |
168 | 'branch (1)[2]&,%.-3_4', |
|
168 | 'branch (1)[2]&,%.-3_4', | |
169 | @branch_char_0, |
|
169 | @branch_char_0, | |
170 | 'test_branch.latin-1', |
|
170 | 'test_branch.latin-1', | |
171 | 'test-branch-00', |
|
171 | 'test-branch-00', | |
172 | ].each do |bra| |
|
172 | ].each do |bra| | |
173 | get :show, :id => PRJ_ID, :rev => bra |
|
173 | get :show, :id => PRJ_ID, :rev => bra | |
174 | assert_response :success |
|
174 | assert_response :success | |
175 | assert_template 'show' |
|
175 | assert_template 'show' | |
176 | assert_not_nil assigns(:entries) |
|
176 | assert_not_nil assigns(:entries) | |
177 | assert assigns(:entries).size > 0 |
|
177 | assert assigns(:entries).size > 0 | |
178 | assert_not_nil assigns(:changesets) |
|
178 | assert_not_nil assigns(:changesets) | |
179 | assert assigns(:changesets).size > 0 |
|
179 | assert assigns(:changesets).size > 0 | |
180 | end |
|
180 | end | |
181 | end |
|
181 | end | |
182 |
|
182 | |||
183 | def test_show_tag |
|
183 | def test_show_tag | |
184 | assert_equal 0, @repository.changesets.count |
|
184 | assert_equal 0, @repository.changesets.count | |
185 | @repository.fetch_changesets |
|
185 | @repository.fetch_changesets | |
186 | @project.reload |
|
186 | @project.reload | |
187 | assert_equal NUM_REV, @repository.changesets.count |
|
187 | assert_equal NUM_REV, @repository.changesets.count | |
188 | [ |
|
188 | [ | |
189 | @tag_char_1, |
|
189 | @tag_char_1, | |
190 | 'tag_test.00', |
|
190 | 'tag_test.00', | |
191 | 'tag-init-revision' |
|
191 | 'tag-init-revision' | |
192 | ].each do |tag| |
|
192 | ].each do |tag| | |
193 | get :show, :id => PRJ_ID, :rev => tag |
|
193 | get :show, :id => PRJ_ID, :rev => tag | |
194 | assert_response :success |
|
194 | assert_response :success | |
195 | assert_template 'show' |
|
195 | assert_template 'show' | |
196 | assert_not_nil assigns(:entries) |
|
196 | assert_not_nil assigns(:entries) | |
197 | assert assigns(:entries).size > 0 |
|
197 | assert assigns(:entries).size > 0 | |
198 | assert_not_nil assigns(:changesets) |
|
198 | assert_not_nil assigns(:changesets) | |
199 | assert assigns(:changesets).size > 0 |
|
199 | assert assigns(:changesets).size > 0 | |
200 | end |
|
200 | end | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | def test_changes |
|
203 | def test_changes | |
204 | get :changes, :id => PRJ_ID, :path => ['images', 'edit.png'] |
|
204 | get :changes, :id => PRJ_ID, :path => ['images', 'edit.png'] | |
205 | assert_response :success |
|
205 | assert_response :success | |
206 | assert_template 'changes' |
|
206 | assert_template 'changes' | |
207 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
207 | assert_tag :tag => 'h2', :content => 'edit.png' | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | def test_entry_show |
|
210 | def test_entry_show | |
211 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
211 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] | |
212 | assert_response :success |
|
212 | assert_response :success | |
213 | assert_template 'entry' |
|
213 | assert_template 'entry' | |
214 | # Line 10 |
|
214 | # Line 10 | |
215 | assert_tag :tag => 'th', |
|
215 | assert_tag :tag => 'th', | |
216 | :content => '10', |
|
216 | :content => '10', | |
217 | :attributes => { :class => 'line-num' }, |
|
217 | :attributes => { :class => 'line-num' }, | |
218 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
218 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | def test_entry_show_latin_1_path |
|
221 | def test_entry_show_latin_1_path | |
222 | [21, '21', 'adf805632193'].each do |r1| |
|
222 | [21, '21', 'adf805632193'].each do |r1| | |
223 | get :entry, :id => PRJ_ID, |
|
223 | get :entry, :id => PRJ_ID, | |
224 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 |
|
224 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 | |
225 | assert_response :success |
|
225 | assert_response :success | |
226 | assert_template 'entry' |
|
226 | assert_template 'entry' | |
227 | assert_tag :tag => 'th', |
|
227 | assert_tag :tag => 'th', | |
228 | :content => '1', |
|
228 | :content => '1', | |
229 | :attributes => { :class => 'line-num' }, |
|
229 | :attributes => { :class => 'line-num' }, | |
230 | :sibling => { :tag => 'td', |
|
230 | :sibling => { :tag => 'td', | |
231 | :content => /Mercurial is a distributed version control system/ } |
|
231 | :content => /Mercurial is a distributed version control system/ } | |
232 | end |
|
232 | end | |
233 | end |
|
233 | end | |
234 |
|
234 | |||
235 | def test_entry_show_latin_1_contents |
|
235 | def test_entry_show_latin_1_contents | |
236 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
236 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
237 | [27, '27', '7bbf4c738e71'].each do |r1| |
|
237 | [27, '27', '7bbf4c738e71'].each do |r1| | |
238 | get :entry, :id => PRJ_ID, |
|
238 | get :entry, :id => PRJ_ID, | |
239 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 |
|
239 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 | |
240 | assert_response :success |
|
240 | assert_response :success | |
241 | assert_template 'entry' |
|
241 | assert_template 'entry' | |
242 | assert_tag :tag => 'th', |
|
242 | assert_tag :tag => 'th', | |
243 | :content => '1', |
|
243 | :content => '1', | |
244 | :attributes => { :class => 'line-num' }, |
|
244 | :attributes => { :class => 'line-num' }, | |
245 | :sibling => { :tag => 'td', |
|
245 | :sibling => { :tag => 'td', | |
246 | :content => /test-#{@char_1}.txt/ } |
|
246 | :content => /test-#{@char_1}.txt/ } | |
247 | end |
|
247 | end | |
248 | end |
|
248 | end | |
249 | end |
|
249 | end | |
250 |
|
250 | |||
251 | def test_entry_download |
|
251 | def test_entry_download | |
252 | get :entry, :id => PRJ_ID, |
|
252 | get :entry, :id => PRJ_ID, | |
253 | :path => ['sources', 'watchers_controller.rb'], :format => 'raw' |
|
253 | :path => ['sources', 'watchers_controller.rb'], :format => 'raw' | |
254 | assert_response :success |
|
254 | assert_response :success | |
255 | # File content |
|
255 | # File content | |
256 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
256 | assert @response.body.include?('WITHOUT ANY WARRANTY') | |
257 | end |
|
257 | end | |
258 |
|
258 | |||
259 | def test_entry_binary_force_download |
|
259 | def test_entry_binary_force_download | |
260 | get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png'] |
|
260 | get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png'] | |
261 | assert_response :success |
|
261 | assert_response :success | |
262 | assert_equal 'image/png', @response.content_type |
|
262 | assert_equal 'image/png', @response.content_type | |
263 | end |
|
263 | end | |
264 |
|
264 | |||
265 | def test_directory_entry |
|
265 | def test_directory_entry | |
266 | get :entry, :id => PRJ_ID, :path => ['sources'] |
|
266 | get :entry, :id => PRJ_ID, :path => ['sources'] | |
267 | assert_response :success |
|
267 | assert_response :success | |
268 | assert_template 'show' |
|
268 | assert_template 'show' | |
269 | assert_not_nil assigns(:entry) |
|
269 | assert_not_nil assigns(:entry) | |
270 | assert_equal 'sources', assigns(:entry).name |
|
270 | assert_equal 'sources', assigns(:entry).name | |
271 | end |
|
271 | end | |
272 |
|
272 | |||
273 | def test_diff |
|
273 | def test_diff | |
274 | assert_equal 0, @repository.changesets.count |
|
274 | assert_equal 0, @repository.changesets.count | |
275 | @repository.fetch_changesets |
|
275 | @repository.fetch_changesets | |
276 | @project.reload |
|
276 | @project.reload | |
277 | assert_equal NUM_REV, @repository.changesets.count |
|
277 | assert_equal NUM_REV, @repository.changesets.count | |
278 | [4, '4', 'def6d2f1254a'].each do |r1| |
|
278 | [4, '4', 'def6d2f1254a'].each do |r1| | |
279 | # Full diff of changeset 4 |
|
279 | # Full diff of changeset 4 | |
280 | ['inline', 'sbs'].each do |dt| |
|
280 | ['inline', 'sbs'].each do |dt| | |
281 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
281 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt | |
282 | assert_response :success |
|
282 | assert_response :success | |
283 | assert_template 'diff' |
|
283 | assert_template 'diff' | |
284 | if @diff_c_support |
|
284 | if @diff_c_support | |
285 | # Line 22 removed |
|
285 | # Line 22 removed | |
286 | assert_tag :tag => 'th', |
|
286 | assert_tag :tag => 'th', | |
287 | :content => '22', |
|
287 | :content => '22', | |
288 | :sibling => { :tag => 'td', |
|
288 | :sibling => { :tag => 'td', | |
289 | :attributes => { :class => /diff_out/ }, |
|
289 | :attributes => { :class => /diff_out/ }, | |
290 | :content => /def remove/ } |
|
290 | :content => /def remove/ } | |
291 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ |
|
291 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ | |
292 | end |
|
292 | end | |
293 | end |
|
293 | end | |
294 | end |
|
294 | end | |
295 | end |
|
295 | end | |
296 |
|
296 | |||
297 | def test_diff_two_revs |
|
297 | def test_diff_two_revs | |
298 | assert_equal 0, @repository.changesets.count |
|
298 | assert_equal 0, @repository.changesets.count | |
299 | @repository.fetch_changesets |
|
299 | @repository.fetch_changesets | |
300 | @project.reload |
|
300 | @project.reload | |
301 | assert_equal NUM_REV, @repository.changesets.count |
|
301 | assert_equal NUM_REV, @repository.changesets.count | |
302 | [2, '400bb8672109', '400', 400].each do |r1| |
|
302 | [2, '400bb8672109', '400', 400].each do |r1| | |
303 | [4, 'def6d2f1254a'].each do |r2| |
|
303 | [4, 'def6d2f1254a'].each do |r2| | |
304 | ['inline', 'sbs'].each do |dt| |
|
304 | ['inline', 'sbs'].each do |dt| | |
305 | get :diff, |
|
305 | get :diff, | |
306 | :id => PRJ_ID, |
|
306 | :id => PRJ_ID, | |
307 | :rev => r1, |
|
307 | :rev => r1, | |
308 | :rev_to => r2, |
|
308 | :rev_to => r2, | |
309 | :type => dt |
|
309 | :type => dt | |
310 | assert_response :success |
|
310 | assert_response :success | |
311 | assert_template 'diff' |
|
311 | assert_template 'diff' | |
312 | diff = assigns(:diff) |
|
312 | diff = assigns(:diff) | |
313 | assert_not_nil diff |
|
313 | assert_not_nil diff | |
314 | assert_tag :tag => 'h2', |
|
314 | assert_tag :tag => 'h2', | |
315 | :content => /4:def6d2f1254a 2:400bb8672109/ |
|
315 | :content => /4:def6d2f1254a 2:400bb8672109/ | |
316 | end |
|
316 | end | |
317 | end |
|
317 | end | |
318 | end |
|
318 | end | |
319 | end |
|
319 | end | |
320 |
|
320 | |||
321 | def test_diff_latin_1_path |
|
321 | def test_diff_latin_1_path | |
322 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
322 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
323 | [21, 'adf805632193'].each do |r1| |
|
323 | [21, 'adf805632193'].each do |r1| | |
324 | ['inline', 'sbs'].each do |dt| |
|
324 | ['inline', 'sbs'].each do |dt| | |
325 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
325 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt | |
326 | assert_response :success |
|
326 | assert_response :success | |
327 | assert_template 'diff' |
|
327 | assert_template 'diff' | |
328 | assert_tag :tag => 'thead', |
|
328 | assert_tag :tag => 'thead', | |
329 | :descendant => { |
|
329 | :descendant => { | |
330 | :tag => 'th', |
|
330 | :tag => 'th', | |
331 | :attributes => { :class => 'filename' } , |
|
331 | :attributes => { :class => 'filename' } , | |
332 | :content => /latin-1-dir\/test-#{@char_1}-2.txt/ , |
|
332 | :content => /latin-1-dir\/test-#{@char_1}-2.txt/ , | |
333 | }, |
|
333 | }, | |
334 | :sibling => { |
|
334 | :sibling => { | |
335 | :tag => 'tbody', |
|
335 | :tag => 'tbody', | |
336 | :descendant => { |
|
336 | :descendant => { | |
337 | :tag => 'td', |
|
337 | :tag => 'td', | |
338 | :attributes => { :class => /diff_in/ }, |
|
338 | :attributes => { :class => /diff_in/ }, | |
339 | :content => /It is written in Python/ |
|
339 | :content => /It is written in Python/ | |
340 | } |
|
340 | } | |
341 | } |
|
341 | } | |
342 | end |
|
342 | end | |
343 | end |
|
343 | end | |
344 | end |
|
344 | end | |
345 | end |
|
345 | end | |
346 |
|
346 | |||
347 | def test_annotate |
|
347 | def test_annotate | |
348 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
348 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] | |
349 | assert_response :success |
|
349 | assert_response :success | |
350 | assert_template 'annotate' |
|
350 | assert_template 'annotate' | |
351 | # Line 23, revision 4:def6d2f1254a |
|
351 | # Line 23, revision 4:def6d2f1254a | |
352 | assert_tag :tag => 'th', |
|
352 | assert_tag :tag => 'th', | |
353 | :content => '23', |
|
353 | :content => '23', | |
354 | :attributes => { :class => 'line-num' }, |
|
354 | :attributes => { :class => 'line-num' }, | |
355 | :sibling => |
|
355 | :sibling => | |
356 | { |
|
356 | { | |
357 | :tag => 'td', |
|
357 | :tag => 'td', | |
358 | :attributes => { :class => 'revision' }, |
|
358 | :attributes => { :class => 'revision' }, | |
359 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } |
|
359 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } | |
360 | } |
|
360 | } | |
361 | assert_tag :tag => 'th', |
|
361 | assert_tag :tag => 'th', | |
362 | :content => '23', |
|
362 | :content => '23', | |
363 | :attributes => { :class => 'line-num' }, |
|
363 | :attributes => { :class => 'line-num' }, | |
364 | :sibling => |
|
364 | :sibling => | |
365 | { |
|
365 | { | |
366 | :tag => 'td' , |
|
366 | :tag => 'td' , | |
367 | :content => 'jsmith' , |
|
367 | :content => 'jsmith' , | |
368 | :attributes => { :class => 'author' }, |
|
368 | :attributes => { :class => 'author' }, | |
369 | } |
|
369 | } | |
370 | assert_tag :tag => 'th', |
|
370 | assert_tag :tag => 'th', | |
371 | :content => '23', |
|
371 | :content => '23', | |
372 | :attributes => { :class => 'line-num' }, |
|
372 | :attributes => { :class => 'line-num' }, | |
373 | :sibling => { :tag => 'td', :content => /watcher =/ } |
|
373 | :sibling => { :tag => 'td', :content => /watcher =/ } | |
374 | end |
|
374 | end | |
375 |
|
375 | |||
376 | def test_annotate_not_in_tip |
|
376 | def test_annotate_not_in_tip | |
377 | assert_equal 0, @repository.changesets.count |
|
377 | assert_equal 0, @repository.changesets.count | |
378 | @repository.fetch_changesets |
|
378 | @repository.fetch_changesets | |
379 | @project.reload |
|
379 | @project.reload | |
380 | assert_equal NUM_REV, @repository.changesets.count |
|
380 | assert_equal NUM_REV, @repository.changesets.count | |
381 |
|
381 | |||
382 | get :annotate, :id => PRJ_ID, |
|
382 | get :annotate, :id => PRJ_ID, | |
383 | :path => ['sources', 'welcome_controller.rb'] |
|
383 | :path => ['sources', 'welcome_controller.rb'] | |
384 | assert_response 404 |
|
384 | assert_response 404 | |
385 | assert_error_tag :content => /was not found/ |
|
385 | assert_error_tag :content => /was not found/ | |
386 | end |
|
386 | end | |
387 |
|
387 | |||
388 | def test_annotate_at_given_revision |
|
388 | def test_annotate_at_given_revision | |
389 | assert_equal 0, @repository.changesets.count |
|
389 | assert_equal 0, @repository.changesets.count | |
390 | @repository.fetch_changesets |
|
390 | @repository.fetch_changesets | |
391 | @project.reload |
|
391 | @project.reload | |
392 | assert_equal NUM_REV, @repository.changesets.count |
|
392 | assert_equal NUM_REV, @repository.changesets.count | |
393 | [2, '400bb8672109', '400', 400].each do |r1| |
|
393 | [2, '400bb8672109', '400', 400].each do |r1| | |
394 | get :annotate, :id => PRJ_ID, :rev => r1, |
|
394 | get :annotate, :id => PRJ_ID, :rev => r1, | |
395 | :path => ['sources', 'watchers_controller.rb'] |
|
395 | :path => ['sources', 'watchers_controller.rb'] | |
396 | assert_response :success |
|
396 | assert_response :success | |
397 | assert_template 'annotate' |
|
397 | assert_template 'annotate' | |
398 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ |
|
398 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ | |
399 | end |
|
399 | end | |
400 | end |
|
400 | end | |
401 |
|
401 | |||
402 | def test_annotate_latin_1_path |
|
402 | def test_annotate_latin_1_path | |
403 | [21, '21', 'adf805632193'].each do |r1| |
|
403 | [21, '21', 'adf805632193'].each do |r1| | |
404 | get :annotate, :id => PRJ_ID, |
|
404 | get :annotate, :id => PRJ_ID, | |
405 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 |
|
405 | :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1 | |
406 | assert_response :success |
|
406 | assert_response :success | |
407 | assert_template 'annotate' |
|
407 | assert_template 'annotate' | |
408 | assert_tag :tag => 'th', |
|
408 | assert_tag :tag => 'th', | |
409 | :content => '1', |
|
409 | :content => '1', | |
410 | :attributes => { :class => 'line-num' }, |
|
410 | :attributes => { :class => 'line-num' }, | |
411 | :sibling => |
|
411 | :sibling => | |
412 | { |
|
412 | { | |
413 | :tag => 'td', |
|
413 | :tag => 'td', | |
414 | :attributes => { :class => 'revision' }, |
|
414 | :attributes => { :class => 'revision' }, | |
415 | :child => { :tag => 'a', :content => '20:709858aafd1b' } |
|
415 | :child => { :tag => 'a', :content => '20:709858aafd1b' } | |
416 | } |
|
416 | } | |
417 | assert_tag :tag => 'th', |
|
417 | assert_tag :tag => 'th', | |
418 | :content => '1', |
|
418 | :content => '1', | |
419 | :attributes => { :class => 'line-num' }, |
|
419 | :attributes => { :class => 'line-num' }, | |
420 | :sibling => |
|
420 | :sibling => | |
421 | { |
|
421 | { | |
422 | :tag => 'td' , |
|
422 | :tag => 'td' , | |
423 | :content => 'jsmith' , |
|
423 | :content => 'jsmith' , | |
424 | :attributes => { :class => 'author' }, |
|
424 | :attributes => { :class => 'author' }, | |
425 | } |
|
425 | } | |
426 | assert_tag :tag => 'th', |
|
426 | assert_tag :tag => 'th', | |
427 | :content => '1', |
|
427 | :content => '1', | |
428 | :attributes => { :class => 'line-num' }, |
|
428 | :attributes => { :class => 'line-num' }, | |
429 | :sibling => { :tag => 'td', |
|
429 | :sibling => { :tag => 'td', | |
430 | :content => /Mercurial is a distributed version control system/ } |
|
430 | :content => /Mercurial is a distributed version control system/ } | |
431 |
|
431 | |||
432 | end |
|
432 | end | |
433 | end |
|
433 | end | |
434 |
|
434 | |||
435 | def test_annotate_latin_1_contents |
|
435 | def test_annotate_latin_1_contents | |
436 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
436 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do | |
437 | [27, '7bbf4c738e71'].each do |r1| |
|
437 | [27, '7bbf4c738e71'].each do |r1| | |
438 | get :annotate, :id => PRJ_ID, |
|
438 | get :annotate, :id => PRJ_ID, | |
439 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 |
|
439 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 | |
440 | assert_tag :tag => 'th', |
|
440 | assert_tag :tag => 'th', | |
441 | :content => '1', |
|
441 | :content => '1', | |
442 | :attributes => { :class => 'line-num' }, |
|
442 | :attributes => { :class => 'line-num' }, | |
443 | :sibling => { :tag => 'td', |
|
443 | :sibling => { :tag => 'td', | |
444 | :content => /test-#{@char_1}.txt/ } |
|
444 | :content => /test-#{@char_1}.txt/ } | |
445 | end |
|
445 | end | |
446 | end |
|
446 | end | |
447 | end |
|
447 | end | |
448 |
|
448 | |||
449 | def test_empty_revision |
|
449 | def test_empty_revision | |
450 | assert_equal 0, @repository.changesets.count |
|
450 | assert_equal 0, @repository.changesets.count | |
451 | @repository.fetch_changesets |
|
451 | @repository.fetch_changesets | |
452 | @project.reload |
|
452 | @project.reload | |
453 | assert_equal NUM_REV, @repository.changesets.count |
|
453 | assert_equal NUM_REV, @repository.changesets.count | |
454 | ['', ' ', nil].each do |r| |
|
454 | ['', ' ', nil].each do |r| | |
455 | get :revision, :id => PRJ_ID, :rev => r |
|
455 | get :revision, :id => PRJ_ID, :rev => r | |
456 | assert_response 404 |
|
456 | assert_response 404 | |
457 | assert_error_tag :content => /was not found/ |
|
457 | assert_error_tag :content => /was not found/ | |
458 | end |
|
458 | end | |
459 | end |
|
459 | end | |
460 |
|
460 | |||
461 | def test_destroy_valid_repository |
|
461 | def test_destroy_valid_repository | |
462 | @request.session[:user_id] = 1 # admin |
|
462 | @request.session[:user_id] = 1 # admin | |
463 | assert_equal 0, @repository.changesets.count |
|
463 | assert_equal 0, @repository.changesets.count | |
464 | @repository.fetch_changesets |
|
464 | @repository.fetch_changesets | |
465 | @project.reload |
|
465 | @project.reload | |
466 | assert_equal NUM_REV, @repository.changesets.count |
|
466 | assert_equal NUM_REV, @repository.changesets.count | |
467 |
|
467 | |||
468 | get :destroy, :id => PRJ_ID |
|
468 | get :destroy, :id => PRJ_ID | |
469 | assert_response 302 |
|
469 | assert_response 302 | |
470 | @project.reload |
|
470 | @project.reload | |
471 | assert_nil @project.repository |
|
471 | assert_nil @project.repository | |
472 | end |
|
472 | end | |
473 |
|
473 | |||
474 | def test_destroy_invalid_repository |
|
474 | def test_destroy_invalid_repository | |
475 | @request.session[:user_id] = 1 # admin |
|
475 | @request.session[:user_id] = 1 # admin | |
476 | assert_equal 0, @repository.changesets.count |
|
476 | assert_equal 0, @repository.changesets.count | |
477 | @repository.fetch_changesets |
|
477 | @repository.fetch_changesets | |
478 | @project.reload |
|
478 | @project.reload | |
479 | assert_equal NUM_REV, @repository.changesets.count |
|
479 | assert_equal NUM_REV, @repository.changesets.count | |
480 |
|
480 | |||
481 | get :destroy, :id => PRJ_ID |
|
481 | get :destroy, :id => PRJ_ID | |
482 | assert_response 302 |
|
482 | assert_response 302 | |
483 | @project.reload |
|
483 | @project.reload | |
484 | assert_nil @project.repository |
|
484 | assert_nil @project.repository | |
485 |
|
485 | |||
486 | @repository = Repository::Mercurial.create( |
|
486 | @repository = Repository::Mercurial.create( | |
487 | :project => Project.find(PRJ_ID), |
|
487 | :project => Project.find(PRJ_ID), | |
488 | :url => "/invalid", |
|
488 | :url => "/invalid", | |
489 | :path_encoding => 'ISO-8859-1' |
|
489 | :path_encoding => 'ISO-8859-1' | |
490 | ) |
|
490 | ) | |
491 | assert @repository |
|
491 | assert @repository | |
492 | @repository.fetch_changesets |
|
492 | @repository.fetch_changesets | |
493 | @project.reload |
|
493 | @project.reload | |
494 | assert_equal 0, @repository.changesets.count |
|
494 | assert_equal 0, @repository.changesets.count | |
495 |
|
495 | |||
496 | get :destroy, :id => PRJ_ID |
|
496 | get :destroy, :id => PRJ_ID | |
497 | assert_response 302 |
|
497 | assert_response 302 | |
498 | @project.reload |
|
498 | @project.reload | |
499 | assert_nil @project.repository |
|
499 | assert_nil @project.repository | |
500 | end |
|
500 | end | |
501 | else |
|
501 | else | |
502 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" |
|
502 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" | |
503 | def test_fake; assert true end |
|
503 | def test_fake; assert true end | |
504 | end |
|
504 | end | |
505 | end |
|
505 | end |
@@ -1,374 +1,376 | |||||
1 | require File.expand_path('../../../../../../test_helper', __FILE__) |
|
1 | require File.expand_path('../../../../../../test_helper', __FILE__) | |
2 | begin |
|
2 | begin | |
3 | require 'mocha' |
|
3 | require 'mocha' | |
4 |
|
4 | |||
5 | class MercurialAdapterTest < ActiveSupport::TestCase |
|
5 | class MercurialAdapterTest < ActiveSupport::TestCase | |
6 | HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR |
|
6 | HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR | |
7 | TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME |
|
7 | TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME | |
8 | TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION |
|
8 | TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION | |
9 |
|
9 | |||
10 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
|
10 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s | |
11 | CHAR_1_HEX = "\xc3\x9c" |
|
11 | CHAR_1_HEX = "\xc3\x9c" | |
12 |
|
12 | |||
13 | if File.directory?(REPOSITORY_PATH) |
|
13 | if File.directory?(REPOSITORY_PATH) | |
14 | def setup |
|
14 | def setup | |
15 | adapter_class = Redmine::Scm::Adapters::MercurialAdapter |
|
15 | adapter_class = Redmine::Scm::Adapters::MercurialAdapter | |
16 | assert adapter_class |
|
16 | assert adapter_class | |
17 | assert adapter_class.client_command |
|
17 | assert adapter_class.client_command | |
18 | assert_equal true, adapter_class.client_available |
|
18 | assert_equal true, adapter_class.client_available | |
19 | assert_equal true, adapter_class.client_version_above?([0, 9, 5]) |
|
19 | assert_equal true, adapter_class.client_version_above?([0, 9, 5]) | |
20 |
|
20 | |||
21 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new( |
|
21 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new( | |
22 | REPOSITORY_PATH, |
|
22 | REPOSITORY_PATH, | |
23 | nil, |
|
23 | nil, | |
24 | nil, |
|
24 | nil, | |
25 | nil, |
|
25 | nil, | |
26 | 'ISO-8859-1') |
|
26 | 'ISO-8859-1') | |
27 | @diff_c_support = true |
|
27 | @diff_c_support = true | |
28 | @char_1 = CHAR_1_HEX.dup |
|
28 | @char_1 = CHAR_1_HEX.dup | |
29 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
29 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" | |
30 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
30 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" | |
31 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
31 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" | |
32 | if @tag_char_1.respond_to?(:force_encoding) |
|
32 | if @tag_char_1.respond_to?(:force_encoding) | |
33 | @char_1.force_encoding('UTF-8') |
|
33 | @char_1.force_encoding('UTF-8') | |
34 | @tag_char_1.force_encoding('UTF-8') |
|
34 | @tag_char_1.force_encoding('UTF-8') | |
35 | @branch_char_0.force_encoding('UTF-8') |
|
35 | @branch_char_0.force_encoding('UTF-8') | |
36 | @branch_char_1.force_encoding('UTF-8') |
|
36 | @branch_char_1.force_encoding('UTF-8') | |
37 | end |
|
37 | end | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | def test_hgversion |
|
40 | def test_hgversion | |
41 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], |
|
41 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], | |
42 | "Mercurial Distributed SCM (1.0)\n" => [1,0], |
|
42 | "Mercurial Distributed SCM (1.0)\n" => [1,0], | |
43 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, |
|
43 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, | |
44 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], |
|
44 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], | |
45 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, |
|
45 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, | |
46 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], |
|
46 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], | |
47 | "(1.6)\n(1.7)\n(1.8)" => [1,6], |
|
47 | "(1.6)\n(1.7)\n(1.8)" => [1,6], | |
48 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} |
|
48 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} | |
49 |
|
49 | |||
50 | to_test.each do |s, v| |
|
50 | to_test.each do |s, v| | |
51 | test_hgversion_for(s, v) |
|
51 | test_hgversion_for(s, v) | |
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def test_template_path |
|
55 | def test_template_path | |
56 | to_test = { |
|
56 | to_test = { | |
57 | [1,2] => "1.0", |
|
57 | [1,2] => "1.0", | |
58 | [] => "1.0", |
|
58 | [] => "1.0", | |
59 | [1,2,1] => "1.0", |
|
59 | [1,2,1] => "1.0", | |
60 | [1,7] => "1.0", |
|
60 | [1,7] => "1.0", | |
61 | [1,7,1] => "1.0", |
|
61 | [1,7,1] => "1.0", | |
62 | [2,0] => "1.0", |
|
62 | [2,0] => "1.0", | |
63 | } |
|
63 | } | |
64 | to_test.each do |v, template| |
|
64 | to_test.each do |v, template| | |
65 | test_template_path_for(v, template) |
|
65 | test_template_path_for(v, template) | |
66 | end |
|
66 | end | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def test_info |
|
69 | def test_info | |
70 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", |
|
70 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", | |
71 | REPOSITORY_PATH + "//"].each do |repo| |
|
71 | REPOSITORY_PATH + "//"].each do |repo| | |
72 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) |
|
72 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) | |
73 | repo_path = adp.info.root_url.gsub(/\\/, "/") |
|
73 | repo_path = adp.info.root_url.gsub(/\\/, "/") | |
74 | assert_equal REPOSITORY_PATH, repo_path |
|
74 | assert_equal REPOSITORY_PATH, repo_path | |
75 |
assert_equal ' |
|
75 | assert_equal '31', adp.info.lastrev.revision | |
76 |
assert_equal '3 |
|
76 | assert_equal '31eeee7395c8',adp.info.lastrev.scmid | |
77 | end |
|
77 | end | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def test_revisions |
|
80 | def test_revisions | |
81 | revisions = @adapter.revisions(nil, 2, 4) |
|
81 | revisions = @adapter.revisions(nil, 2, 4) | |
82 | assert_equal 3, revisions.size |
|
82 | assert_equal 3, revisions.size | |
83 | assert_equal '2', revisions[0].revision |
|
83 | assert_equal '2', revisions[0].revision | |
84 | assert_equal '400bb8672109', revisions[0].scmid |
|
84 | assert_equal '400bb8672109', revisions[0].scmid | |
85 | assert_equal '4', revisions[2].revision |
|
85 | assert_equal '4', revisions[2].revision | |
86 | assert_equal 'def6d2f1254a', revisions[2].scmid |
|
86 | assert_equal 'def6d2f1254a', revisions[2].scmid | |
87 |
|
87 | |||
88 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) |
|
88 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) | |
89 | assert_equal 2, revisions.size |
|
89 | assert_equal 2, revisions.size | |
90 | assert_equal '2', revisions[0].revision |
|
90 | assert_equal '2', revisions[0].revision | |
91 | assert_equal '400bb8672109', revisions[0].scmid |
|
91 | assert_equal '400bb8672109', revisions[0].scmid | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | def test_diff |
|
94 | def test_diff | |
95 | if @adapter.class.client_version_above?([1, 2]) |
|
95 | if @adapter.class.client_version_above?([1, 2]) | |
96 | assert_nil @adapter.diff(nil, '100000') |
|
96 | assert_nil @adapter.diff(nil, '100000') | |
97 | end |
|
97 | end | |
98 | assert_nil @adapter.diff(nil, '100000', '200000') |
|
98 | assert_nil @adapter.diff(nil, '100000', '200000') | |
99 | [2, '400bb8672109', '400', 400].each do |r1| |
|
99 | [2, '400bb8672109', '400', 400].each do |r1| | |
100 | diff1 = @adapter.diff(nil, r1) |
|
100 | diff1 = @adapter.diff(nil, r1) | |
101 | if @diff_c_support |
|
101 | if @diff_c_support | |
102 | assert_equal 28, diff1.size |
|
102 | assert_equal 28, diff1.size | |
103 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") |
|
103 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") | |
104 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf |
|
104 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf | |
105 | else |
|
105 | else | |
106 | assert_equal 0, diff1.size |
|
106 | assert_equal 0, diff1.size | |
107 | end |
|
107 | end | |
108 | [4, 'def6d2f1254a'].each do |r2| |
|
108 | [4, 'def6d2f1254a'].each do |r2| | |
109 | diff2 = @adapter.diff(nil,r1,r2) |
|
109 | diff2 = @adapter.diff(nil,r1,r2) | |
110 | assert_equal 49, diff2.size |
|
110 | assert_equal 49, diff2.size | |
111 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") |
|
111 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") | |
112 | assert_equal "+class WelcomeController < ApplicationController", buf |
|
112 | assert_equal "+class WelcomeController < ApplicationController", buf | |
113 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) |
|
113 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) | |
114 | assert_equal 20, diff3.size |
|
114 | assert_equal 20, diff3.size | |
115 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") |
|
115 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") | |
116 | assert_equal "+ @watched.remove_watcher(user)", buf |
|
116 | assert_equal "+ @watched.remove_watcher(user)", buf | |
117 | end |
|
117 | end | |
118 | end |
|
118 | end | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def test_diff_made_by_revision |
|
121 | def test_diff_made_by_revision | |
122 | if @diff_c_support |
|
122 | if @diff_c_support | |
123 | [24, '24', '4cddb4e45f52'].each do |r1| |
|
123 | [24, '24', '4cddb4e45f52'].each do |r1| | |
124 | diff1 = @adapter.diff(nil, r1) |
|
124 | diff1 = @adapter.diff(nil, r1) | |
125 | assert_equal 5, diff1.size |
|
125 | assert_equal 5, diff1.size | |
126 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") |
|
126 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") | |
127 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf |
|
127 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf | |
128 | end |
|
128 | end | |
129 | end |
|
129 | end | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | def test_cat |
|
132 | def test_cat | |
133 | [2, '400bb8672109', '400', 400].each do |r| |
|
133 | [2, '400bb8672109', '400', 400].each do |r| | |
134 | buf = @adapter.cat('sources/welcome_controller.rb', r) |
|
134 | buf = @adapter.cat('sources/welcome_controller.rb', r) | |
135 | assert buf |
|
135 | assert buf | |
136 | lines = buf.split("\r\n") |
|
136 | lines = buf.split("\r\n") | |
137 | assert_equal 25, lines.length |
|
137 | assert_equal 25, lines.length | |
138 | assert_equal 'class WelcomeController < ApplicationController', lines[17] |
|
138 | assert_equal 'class WelcomeController < ApplicationController', lines[17] | |
139 | end |
|
139 | end | |
140 | assert_nil @adapter.cat('sources/welcome_controller.rb') |
|
140 | assert_nil @adapter.cat('sources/welcome_controller.rb') | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | def test_annotate |
|
143 | def test_annotate | |
144 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines |
|
144 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines | |
145 | [2, '400bb8672109', '400', 400].each do |r| |
|
145 | [2, '400bb8672109', '400', 400].each do |r| | |
146 | ann = @adapter.annotate('sources/welcome_controller.rb', r) |
|
146 | ann = @adapter.annotate('sources/welcome_controller.rb', r) | |
147 | assert ann |
|
147 | assert ann | |
148 | assert_equal '1', ann.revisions[17].revision |
|
148 | assert_equal '1', ann.revisions[17].revision | |
149 | assert_equal '9d5b5b004199', ann.revisions[17].identifier |
|
149 | assert_equal '9d5b5b004199', ann.revisions[17].identifier | |
150 | assert_equal 'jsmith', ann.revisions[0].author |
|
150 | assert_equal 'jsmith', ann.revisions[0].author | |
151 | assert_equal 25, ann.lines.length |
|
151 | assert_equal 25, ann.lines.length | |
152 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] |
|
152 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] | |
153 | end |
|
153 | end | |
154 | end |
|
154 | end | |
155 |
|
155 | |||
156 | def test_entries |
|
156 | def test_entries | |
157 | assert_nil @adapter.entries(nil, '100000') |
|
157 | assert_nil @adapter.entries(nil, '100000') | |
158 |
|
158 | |||
159 | assert_equal 1, @adapter.entries("sources", 3).size |
|
159 | assert_equal 1, @adapter.entries("sources", 3).size | |
160 | assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size |
|
160 | assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size | |
161 |
|
161 | |||
162 | [2, '400bb8672109', '400', 400].each do |r| |
|
162 | [2, '400bb8672109', '400', 400].each do |r| | |
163 | entries1 = @adapter.entries(nil, r) |
|
163 | entries1 = @adapter.entries(nil, r) | |
164 | assert entries1 |
|
164 | assert entries1 | |
165 | assert_equal 3, entries1.size |
|
165 | assert_equal 3, entries1.size | |
166 | assert_equal 'sources', entries1[1].name |
|
166 | assert_equal 'sources', entries1[1].name | |
167 | assert_equal 'sources', entries1[1].path |
|
167 | assert_equal 'sources', entries1[1].path | |
168 | assert_equal 'dir', entries1[1].kind |
|
168 | assert_equal 'dir', entries1[1].kind | |
169 | readme = entries1[2] |
|
169 | readme = entries1[2] | |
170 | assert_equal 'README', readme.name |
|
170 | assert_equal 'README', readme.name | |
171 | assert_equal 'README', readme.path |
|
171 | assert_equal 'README', readme.path | |
172 | assert_equal 'file', readme.kind |
|
172 | assert_equal 'file', readme.kind | |
173 | assert_equal 27, readme.size |
|
173 | assert_equal 27, readme.size | |
174 | assert_equal '1', readme.lastrev.revision |
|
174 | assert_equal '1', readme.lastrev.revision | |
175 | assert_equal '9d5b5b004199', readme.lastrev.identifier |
|
175 | assert_equal '9d5b5b004199', readme.lastrev.identifier | |
176 | # 2007-12-14 10:24:01 +0100 |
|
176 | # 2007-12-14 10:24:01 +0100 | |
177 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time |
|
177 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time | |
178 |
|
178 | |||
179 | entries2 = @adapter.entries('sources', r) |
|
179 | entries2 = @adapter.entries('sources', r) | |
180 | assert entries2 |
|
180 | assert entries2 | |
181 | assert_equal 2, entries2.size |
|
181 | assert_equal 2, entries2.size | |
182 | assert_equal 'watchers_controller.rb', entries2[0].name |
|
182 | assert_equal 'watchers_controller.rb', entries2[0].name | |
183 | assert_equal 'sources/watchers_controller.rb', entries2[0].path |
|
183 | assert_equal 'sources/watchers_controller.rb', entries2[0].path | |
184 | assert_equal 'file', entries2[0].kind |
|
184 | assert_equal 'file', entries2[0].kind | |
185 | assert_equal 'welcome_controller.rb', entries2[1].name |
|
185 | assert_equal 'welcome_controller.rb', entries2[1].name | |
186 | assert_equal 'sources/welcome_controller.rb', entries2[1].path |
|
186 | assert_equal 'sources/welcome_controller.rb', entries2[1].path | |
187 | assert_equal 'file', entries2[1].kind |
|
187 | assert_equal 'file', entries2[1].kind | |
188 | end |
|
188 | end | |
189 | end |
|
189 | end | |
190 |
|
190 | |||
191 | def test_entries_tag |
|
191 | def test_entries_tag | |
192 | entries1 = @adapter.entries(nil, 'tag_test.00') |
|
192 | entries1 = @adapter.entries(nil, 'tag_test.00') | |
193 | assert entries1 |
|
193 | assert entries1 | |
194 | assert_equal 3, entries1.size |
|
194 | assert_equal 3, entries1.size | |
195 | assert_equal 'sources', entries1[1].name |
|
195 | assert_equal 'sources', entries1[1].name | |
196 | assert_equal 'sources', entries1[1].path |
|
196 | assert_equal 'sources', entries1[1].path | |
197 | assert_equal 'dir', entries1[1].kind |
|
197 | assert_equal 'dir', entries1[1].kind | |
198 | readme = entries1[2] |
|
198 | readme = entries1[2] | |
199 | assert_equal 'README', readme.name |
|
199 | assert_equal 'README', readme.name | |
200 | assert_equal 'README', readme.path |
|
200 | assert_equal 'README', readme.path | |
201 | assert_equal 'file', readme.kind |
|
201 | assert_equal 'file', readme.kind | |
202 | assert_equal 21, readme.size |
|
202 | assert_equal 21, readme.size | |
203 | assert_equal '0', readme.lastrev.revision |
|
203 | assert_equal '0', readme.lastrev.revision | |
204 | assert_equal '0885933ad4f6', readme.lastrev.identifier |
|
204 | assert_equal '0885933ad4f6', readme.lastrev.identifier | |
205 | # 2007-12-14 10:22:52 +0100 |
|
205 | # 2007-12-14 10:22:52 +0100 | |
206 | assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time |
|
206 | assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time | |
207 | end |
|
207 | end | |
208 |
|
208 | |||
209 | def test_entries_branch |
|
209 | def test_entries_branch | |
210 | entries1 = @adapter.entries(nil, 'test-branch-00') |
|
210 | entries1 = @adapter.entries(nil, 'test-branch-00') | |
211 | assert entries1 |
|
211 | assert entries1 | |
212 | assert_equal 5, entries1.size |
|
212 | assert_equal 5, entries1.size | |
213 | assert_equal 'sql_escape', entries1[2].name |
|
213 | assert_equal 'sql_escape', entries1[2].name | |
214 | assert_equal 'sql_escape', entries1[2].path |
|
214 | assert_equal 'sql_escape', entries1[2].path | |
215 | assert_equal 'dir', entries1[2].kind |
|
215 | assert_equal 'dir', entries1[2].kind | |
216 | readme = entries1[4] |
|
216 | readme = entries1[4] | |
217 | assert_equal 'README', readme.name |
|
217 | assert_equal 'README', readme.name | |
218 | assert_equal 'README', readme.path |
|
218 | assert_equal 'README', readme.path | |
219 | assert_equal 'file', readme.kind |
|
219 | assert_equal 'file', readme.kind | |
220 | assert_equal 365, readme.size |
|
220 | assert_equal 365, readme.size | |
221 | assert_equal '8', readme.lastrev.revision |
|
221 | assert_equal '8', readme.lastrev.revision | |
222 | assert_equal 'c51f5bb613cd', readme.lastrev.identifier |
|
222 | assert_equal 'c51f5bb613cd', readme.lastrev.identifier | |
223 | # 2001-02-01 00:00:00 -0900 |
|
223 | # 2001-02-01 00:00:00 -0900 | |
224 | assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time |
|
224 | assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time | |
225 | end |
|
225 | end | |
226 |
|
226 | |||
227 | def test_locate_on_outdated_repository |
|
227 | def test_locate_on_outdated_repository | |
228 | assert_equal 1, @adapter.entries("images", 0).size |
|
228 | assert_equal 1, @adapter.entries("images", 0).size | |
229 | assert_equal 2, @adapter.entries("images").size |
|
229 | assert_equal 2, @adapter.entries("images").size | |
230 | assert_equal 2, @adapter.entries("images", 2).size |
|
230 | assert_equal 2, @adapter.entries("images", 2).size | |
231 | end |
|
231 | end | |
232 |
|
232 | |||
233 | def test_access_by_nodeid |
|
233 | def test_access_by_nodeid | |
234 | path = 'sources/welcome_controller.rb' |
|
234 | path = 'sources/welcome_controller.rb' | |
235 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') |
|
235 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') | |
236 | end |
|
236 | end | |
237 |
|
237 | |||
238 | def test_access_by_fuzzy_nodeid |
|
238 | def test_access_by_fuzzy_nodeid | |
239 | path = 'sources/welcome_controller.rb' |
|
239 | path = 'sources/welcome_controller.rb' | |
240 | # falls back to nodeid |
|
240 | # falls back to nodeid | |
241 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') |
|
241 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') | |
242 | end |
|
242 | end | |
243 |
|
243 | |||
244 | def test_tags |
|
244 | def test_tags | |
245 | assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags |
|
245 | assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags | |
246 | end |
|
246 | end | |
247 |
|
247 | |||
248 | def test_tagmap |
|
248 | def test_tagmap | |
249 | tm = { |
|
249 | tm = { | |
250 | @tag_char_1 => 'adf805632193', |
|
250 | @tag_char_1 => 'adf805632193', | |
251 | 'tag_test.00' => '6987191f453a', |
|
251 | 'tag_test.00' => '6987191f453a', | |
252 | 'tag-init-revision' => '0885933ad4f6', |
|
252 | 'tag-init-revision' => '0885933ad4f6', | |
253 | } |
|
253 | } | |
254 | assert_equal tm, @adapter.tagmap |
|
254 | assert_equal tm, @adapter.tagmap | |
255 | end |
|
255 | end | |
256 |
|
256 | |||
257 | def test_branches |
|
257 | def test_branches | |
258 | assert_equal [ |
|
258 | assert_equal [ | |
259 | 'default', |
|
259 | 'default', | |
|
260 | 'test-branch-01', | |||
260 | @branch_char_1, |
|
261 | @branch_char_1, | |
261 | 'branch (1)[2]&,%.-3_4', |
|
262 | 'branch (1)[2]&,%.-3_4', | |
262 | @branch_char_0, |
|
263 | @branch_char_0, | |
263 | 'test_branch.latin-1', |
|
264 | 'test_branch.latin-1', | |
264 | 'test-branch-00', |
|
265 | 'test-branch-00', | |
265 | ], @adapter.branches |
|
266 | ], @adapter.branches | |
266 | end |
|
267 | end | |
267 |
|
268 | |||
268 | def test_branchmap |
|
269 | def test_branchmap | |
269 | bm = { |
|
270 | bm = { | |
270 |
'default' => '3 |
|
271 | 'default' => '31eeee7395c8', | |
271 | 'test_branch.latin-1' => 'c2ffe7da686a', |
|
272 | 'test_branch.latin-1' => 'c2ffe7da686a', | |
272 | 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7', |
|
273 | 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7', | |
273 | 'test-branch-00' => '3a330eb32958', |
|
274 | 'test-branch-00' => '3a330eb32958', | |
|
275 | "test-branch-01" => 'ad4dc4f80284', | |||
274 | @branch_char_0 => 'c8d3e4887474', |
|
276 | @branch_char_0 => 'c8d3e4887474', | |
275 | @branch_char_1 => '7bbf4c738e71', |
|
277 | @branch_char_1 => '7bbf4c738e71', | |
276 | } |
|
278 | } | |
277 | assert_equal bm, @adapter.branchmap |
|
279 | assert_equal bm, @adapter.branchmap | |
278 | end |
|
280 | end | |
279 |
|
281 | |||
280 | def test_path_space |
|
282 | def test_path_space | |
281 | p = 'README (1)[2]&,%.-3_4' |
|
283 | p = 'README (1)[2]&,%.-3_4' | |
282 | [15, '933ca60293d7'].each do |r1| |
|
284 | [15, '933ca60293d7'].each do |r1| | |
283 | assert @adapter.diff(p, r1) |
|
285 | assert @adapter.diff(p, r1) | |
284 | assert @adapter.cat(p, r1) |
|
286 | assert @adapter.cat(p, r1) | |
285 | assert_equal 1, @adapter.annotate(p, r1).lines.length |
|
287 | assert_equal 1, @adapter.annotate(p, r1).lines.length | |
286 | [25, 'afc61e85bde7'].each do |r2| |
|
288 | [25, 'afc61e85bde7'].each do |r2| | |
287 | assert @adapter.diff(p, r1, r2) |
|
289 | assert @adapter.diff(p, r1, r2) | |
288 | end |
|
290 | end | |
289 | end |
|
291 | end | |
290 | end |
|
292 | end | |
291 |
|
293 | |||
292 | def test_tag_non_ascii |
|
294 | def test_tag_non_ascii | |
293 | p = "latin-1-dir/test-#{@char_1}-1.txt" |
|
295 | p = "latin-1-dir/test-#{@char_1}-1.txt" | |
294 | assert @adapter.cat(p, @tag_char_1) |
|
296 | assert @adapter.cat(p, @tag_char_1) | |
295 | assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length |
|
297 | assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length | |
296 | end |
|
298 | end | |
297 |
|
299 | |||
298 | def test_branch_non_ascii |
|
300 | def test_branch_non_ascii | |
299 | p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt" |
|
301 | p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt" | |
300 | assert @adapter.cat(p, @branch_char_1) |
|
302 | assert @adapter.cat(p, @branch_char_1) | |
301 | assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length |
|
303 | assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length | |
302 | end |
|
304 | end | |
303 |
|
305 | |||
304 | def test_nodes_in_branch |
|
306 | def test_nodes_in_branch | |
305 | [ |
|
307 | [ | |
306 | 'default', |
|
308 | 'default', | |
307 | @branch_char_1, |
|
309 | @branch_char_1, | |
308 | 'branch (1)[2]&,%.-3_4', |
|
310 | 'branch (1)[2]&,%.-3_4', | |
309 | @branch_char_0, |
|
311 | @branch_char_0, | |
310 | 'test_branch.latin-1', |
|
312 | 'test_branch.latin-1', | |
311 | 'test-branch-00', |
|
313 | 'test-branch-00', | |
312 | ].each do |bra| |
|
314 | ].each do |bra| | |
313 | nib0 = @adapter.nodes_in_branch(bra) |
|
315 | nib0 = @adapter.nodes_in_branch(bra) | |
314 | assert nib0 |
|
316 | assert nib0 | |
315 | nib1 = @adapter.nodes_in_branch(bra, :limit => 1) |
|
317 | nib1 = @adapter.nodes_in_branch(bra, :limit => 1) | |
316 | assert_equal 1, nib1.size |
|
318 | assert_equal 1, nib1.size | |
317 | case bra |
|
319 | case bra | |
318 | when 'branch (1)[2]&,%.-3_4' |
|
320 | when 'branch (1)[2]&,%.-3_4' | |
319 | if @adapter.class.client_version_above?([1, 6]) |
|
321 | if @adapter.class.client_version_above?([1, 6]) | |
320 | assert_equal 3, nib0.size |
|
322 | assert_equal 3, nib0.size | |
321 | assert_equal nib0[0], 'afc61e85bde7' |
|
323 | assert_equal nib0[0], 'afc61e85bde7' | |
322 | nib2 = @adapter.nodes_in_branch(bra, :limit => 2) |
|
324 | nib2 = @adapter.nodes_in_branch(bra, :limit => 2) | |
323 | assert_equal 2, nib2.size |
|
325 | assert_equal 2, nib2.size | |
324 | assert_equal nib2[1], '933ca60293d7' |
|
326 | assert_equal nib2[1], '933ca60293d7' | |
325 | end |
|
327 | end | |
326 | when @branch_char_1 |
|
328 | when @branch_char_1 | |
327 | if @adapter.class.client_version_above?([1, 6]) |
|
329 | if @adapter.class.client_version_above?([1, 6]) | |
328 | assert_equal 2, nib0.size |
|
330 | assert_equal 2, nib0.size | |
329 | assert_equal nib0[1], '08ff3227303e' |
|
331 | assert_equal nib0[1], '08ff3227303e' | |
330 | nib2 = @adapter.nodes_in_branch(bra, :limit => 1) |
|
332 | nib2 = @adapter.nodes_in_branch(bra, :limit => 1) | |
331 | assert_equal 1, nib2.size |
|
333 | assert_equal 1, nib2.size | |
332 | assert_equal nib2[0], '7bbf4c738e71' |
|
334 | assert_equal nib2[0], '7bbf4c738e71' | |
333 | end |
|
335 | end | |
334 | end |
|
336 | end | |
335 | end |
|
337 | end | |
336 | end |
|
338 | end | |
337 |
|
339 | |||
338 | def test_path_encoding_default_utf8 |
|
340 | def test_path_encoding_default_utf8 | |
339 | adpt1 = Redmine::Scm::Adapters::MercurialAdapter.new( |
|
341 | adpt1 = Redmine::Scm::Adapters::MercurialAdapter.new( | |
340 | REPOSITORY_PATH |
|
342 | REPOSITORY_PATH | |
341 | ) |
|
343 | ) | |
342 | assert_equal "UTF-8", adpt1.path_encoding |
|
344 | assert_equal "UTF-8", adpt1.path_encoding | |
343 | adpt2 = Redmine::Scm::Adapters::MercurialAdapter.new( |
|
345 | adpt2 = Redmine::Scm::Adapters::MercurialAdapter.new( | |
344 | REPOSITORY_PATH, |
|
346 | REPOSITORY_PATH, | |
345 | nil, |
|
347 | nil, | |
346 | nil, |
|
348 | nil, | |
347 | nil, |
|
349 | nil, | |
348 | "" |
|
350 | "" | |
349 | ) |
|
351 | ) | |
350 | assert_equal "UTF-8", adpt2.path_encoding |
|
352 | assert_equal "UTF-8", adpt2.path_encoding | |
351 | end |
|
353 | end | |
352 |
|
354 | |||
353 | private |
|
355 | private | |
354 |
|
356 | |||
355 | def test_hgversion_for(hgversion, version) |
|
357 | def test_hgversion_for(hgversion, version) | |
356 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) |
|
358 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) | |
357 | assert_equal version, @adapter.class.hgversion |
|
359 | assert_equal version, @adapter.class.hgversion | |
358 | end |
|
360 | end | |
359 |
|
361 | |||
360 | def test_template_path_for(version, template) |
|
362 | def test_template_path_for(version, template) | |
361 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", |
|
363 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", | |
362 | @adapter.class.template_path_for(version) |
|
364 | @adapter.class.template_path_for(version) | |
363 | assert File.exist?(@adapter.class.template_path_for(version)) |
|
365 | assert File.exist?(@adapter.class.template_path_for(version)) | |
364 | end |
|
366 | end | |
365 | else |
|
367 | else | |
366 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
368 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
367 | def test_fake; assert true end |
|
369 | def test_fake; assert true end | |
368 | end |
|
370 | end | |
369 | end |
|
371 | end | |
370 | rescue LoadError |
|
372 | rescue LoadError | |
371 | class MercurialMochaFake < ActiveSupport::TestCase |
|
373 | class MercurialMochaFake < ActiveSupport::TestCase | |
372 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
374 | def test_fake; assert(false, "Requires mocha to run those tests") end | |
373 | end |
|
375 | end | |
374 | end |
|
376 | end |
@@ -1,324 +1,324 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 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 RepositoryMercurialTest < ActiveSupport::TestCase |
|
20 | class RepositoryMercurialTest < ActiveSupport::TestCase | |
21 | fixtures :projects |
|
21 | fixtures :projects | |
22 |
|
22 | |||
23 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
|
23 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s | |
24 |
NUM_REV = 2 |
|
24 | NUM_REV = 32 | |
25 | CHAR_1_HEX = "\xc3\x9c" |
|
25 | CHAR_1_HEX = "\xc3\x9c" | |
26 |
|
26 | |||
27 | if File.directory?(REPOSITORY_PATH) |
|
27 | if File.directory?(REPOSITORY_PATH) | |
28 | def setup |
|
28 | def setup | |
29 | klass = Repository::Mercurial |
|
29 | klass = Repository::Mercurial | |
30 | assert_equal "Mercurial", klass.scm_name |
|
30 | assert_equal "Mercurial", klass.scm_name | |
31 | assert klass.scm_adapter_class |
|
31 | assert klass.scm_adapter_class | |
32 | assert_not_equal "", klass.scm_command |
|
32 | assert_not_equal "", klass.scm_command | |
33 | assert_equal true, klass.scm_available |
|
33 | assert_equal true, klass.scm_available | |
34 |
|
34 | |||
35 | @project = Project.find(3) |
|
35 | @project = Project.find(3) | |
36 | @repository = Repository::Mercurial.create( |
|
36 | @repository = Repository::Mercurial.create( | |
37 | :project => @project, |
|
37 | :project => @project, | |
38 | :url => REPOSITORY_PATH, |
|
38 | :url => REPOSITORY_PATH, | |
39 | :path_encoding => 'ISO-8859-1' |
|
39 | :path_encoding => 'ISO-8859-1' | |
40 | ) |
|
40 | ) | |
41 | assert @repository |
|
41 | assert @repository | |
42 | @char_1 = CHAR_1_HEX.dup |
|
42 | @char_1 = CHAR_1_HEX.dup | |
43 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
43 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" | |
44 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
44 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" | |
45 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
45 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" | |
46 | if @char_1.respond_to?(:force_encoding) |
|
46 | if @char_1.respond_to?(:force_encoding) | |
47 | @char_1.force_encoding('UTF-8') |
|
47 | @char_1.force_encoding('UTF-8') | |
48 | @tag_char_1.force_encoding('UTF-8') |
|
48 | @tag_char_1.force_encoding('UTF-8') | |
49 | @branch_char_0.force_encoding('UTF-8') |
|
49 | @branch_char_0.force_encoding('UTF-8') | |
50 | @branch_char_1.force_encoding('UTF-8') |
|
50 | @branch_char_1.force_encoding('UTF-8') | |
51 | end |
|
51 | end | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def test_fetch_changesets_from_scratch |
|
54 | def test_fetch_changesets_from_scratch | |
55 | assert_equal 0, @repository.changesets.count |
|
55 | assert_equal 0, @repository.changesets.count | |
56 | @repository.fetch_changesets |
|
56 | @repository.fetch_changesets | |
57 | @project.reload |
|
57 | @project.reload | |
58 | assert_equal NUM_REV, @repository.changesets.count |
|
58 | assert_equal NUM_REV, @repository.changesets.count | |
59 |
assert_equal |
|
59 | assert_equal 46, @repository.changes.count | |
60 | assert_equal "Initial import.\nThe repository contains 3 files.", |
|
60 | assert_equal "Initial import.\nThe repository contains 3 files.", | |
61 | @repository.changesets.find_by_revision('0').comments |
|
61 | @repository.changesets.find_by_revision('0').comments | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_fetch_changesets_incremental |
|
64 | def test_fetch_changesets_incremental | |
65 | assert_equal 0, @repository.changesets.count |
|
65 | assert_equal 0, @repository.changesets.count | |
66 | @repository.fetch_changesets |
|
66 | @repository.fetch_changesets | |
67 | @project.reload |
|
67 | @project.reload | |
68 | assert_equal NUM_REV, @repository.changesets.count |
|
68 | assert_equal NUM_REV, @repository.changesets.count | |
69 | # Remove changesets with revision > 2 |
|
69 | # Remove changesets with revision > 2 | |
70 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} |
|
70 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} | |
71 | @project.reload |
|
71 | @project.reload | |
72 | assert_equal 3, @repository.changesets.count |
|
72 | assert_equal 3, @repository.changesets.count | |
73 |
|
73 | |||
74 | @repository.fetch_changesets |
|
74 | @repository.fetch_changesets | |
75 | @project.reload |
|
75 | @project.reload | |
76 | assert_equal NUM_REV, @repository.changesets.count |
|
76 | assert_equal NUM_REV, @repository.changesets.count | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | def test_isodatesec |
|
79 | def test_isodatesec | |
80 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
|
80 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher | |
81 | if @repository.scm.class.client_version_above?([1, 0]) |
|
81 | if @repository.scm.class.client_version_above?([1, 0]) | |
82 | assert_equal 0, @repository.changesets.count |
|
82 | assert_equal 0, @repository.changesets.count | |
83 | @repository.fetch_changesets |
|
83 | @repository.fetch_changesets | |
84 | @project.reload |
|
84 | @project.reload | |
85 | assert_equal NUM_REV, @repository.changesets.count |
|
85 | assert_equal NUM_REV, @repository.changesets.count | |
86 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) |
|
86 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) | |
87 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on |
|
87 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on | |
88 | end |
|
88 | end | |
89 | end |
|
89 | end | |
90 |
|
90 | |||
91 | def test_changeset_order_by_revision |
|
91 | def test_changeset_order_by_revision | |
92 | assert_equal 0, @repository.changesets.count |
|
92 | assert_equal 0, @repository.changesets.count | |
93 | @repository.fetch_changesets |
|
93 | @repository.fetch_changesets | |
94 | @project.reload |
|
94 | @project.reload | |
95 | assert_equal NUM_REV, @repository.changesets.count |
|
95 | assert_equal NUM_REV, @repository.changesets.count | |
96 |
|
96 | |||
97 | c0 = @repository.latest_changeset |
|
97 | c0 = @repository.latest_changeset | |
98 | c1 = @repository.changesets.find_by_revision('0') |
|
98 | c1 = @repository.changesets.find_by_revision('0') | |
99 | # sorted by revision (id), not by date |
|
99 | # sorted by revision (id), not by date | |
100 | assert c0.revision.to_i > c1.revision.to_i |
|
100 | assert c0.revision.to_i > c1.revision.to_i | |
101 | assert c0.committed_on < c1.committed_on |
|
101 | assert c0.committed_on < c1.committed_on | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | def test_latest_changesets |
|
104 | def test_latest_changesets | |
105 | assert_equal 0, @repository.changesets.count |
|
105 | assert_equal 0, @repository.changesets.count | |
106 | @repository.fetch_changesets |
|
106 | @repository.fetch_changesets | |
107 | @project.reload |
|
107 | @project.reload | |
108 | assert_equal NUM_REV, @repository.changesets.count |
|
108 | assert_equal NUM_REV, @repository.changesets.count | |
109 |
|
109 | |||
110 | # with_limit |
|
110 | # with_limit | |
111 | changesets = @repository.latest_changesets('', nil, 2) |
|
111 | changesets = @repository.latest_changesets('', nil, 2) | |
112 |
assert_equal %w| |
|
112 | assert_equal %w|31 30|, changesets.collect(&:revision) | |
113 |
|
113 | |||
114 | # with_filepath |
|
114 | # with_filepath | |
115 | changesets = @repository.latest_changesets( |
|
115 | changesets = @repository.latest_changesets( | |
116 | '/sql_escape/percent%dir/percent%file1.txt', nil) |
|
116 | '/sql_escape/percent%dir/percent%file1.txt', nil) | |
117 | assert_equal %w|11 10 9|, changesets.collect(&:revision) |
|
117 | assert_equal %w|30 11 10 9|, changesets.collect(&:revision) | |
118 |
|
118 | |||
119 | changesets = @repository.latest_changesets( |
|
119 | changesets = @repository.latest_changesets( | |
120 | '/sql_escape/underscore_dir/understrike_file.txt', nil) |
|
120 | '/sql_escape/underscore_dir/understrike_file.txt', nil) | |
121 | assert_equal %w|12 9|, changesets.collect(&:revision) |
|
121 | assert_equal %w|30 12 9|, changesets.collect(&:revision) | |
122 |
|
122 | |||
123 | changesets = @repository.latest_changesets('README', nil) |
|
123 | changesets = @repository.latest_changesets('README', nil) | |
124 | assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision) |
|
124 | assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision) | |
125 |
|
125 | |||
126 | changesets = @repository.latest_changesets('README','8') |
|
126 | changesets = @repository.latest_changesets('README','8') | |
127 | assert_equal %w|8 6 1 0|, changesets.collect(&:revision) |
|
127 | assert_equal %w|8 6 1 0|, changesets.collect(&:revision) | |
128 |
|
128 | |||
129 | changesets = @repository.latest_changesets('README','8', 2) |
|
129 | changesets = @repository.latest_changesets('README','8', 2) | |
130 | assert_equal %w|8 6|, changesets.collect(&:revision) |
|
130 | assert_equal %w|8 6|, changesets.collect(&:revision) | |
131 |
|
131 | |||
132 | # with_dirpath |
|
132 | # with_dirpath | |
133 | changesets = @repository.latest_changesets('images', nil) |
|
133 | changesets = @repository.latest_changesets('images', nil) | |
134 | assert_equal %w|1 0|, changesets.collect(&:revision) |
|
134 | assert_equal %w|1 0|, changesets.collect(&:revision) | |
135 |
|
135 | |||
136 | path = 'sql_escape/percent%dir' |
|
136 | path = 'sql_escape/percent%dir' | |
137 | changesets = @repository.latest_changesets(path, nil) |
|
137 | changesets = @repository.latest_changesets(path, nil) | |
138 | assert_equal %w|13 11 10 9|, changesets.collect(&:revision) |
|
138 | assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision) | |
139 |
|
139 | |||
140 | changesets = @repository.latest_changesets(path, '11') |
|
140 | changesets = @repository.latest_changesets(path, '11') | |
141 | assert_equal %w|11 10 9|, changesets.collect(&:revision) |
|
141 | assert_equal %w|11 10 9|, changesets.collect(&:revision) | |
142 |
|
142 | |||
143 | changesets = @repository.latest_changesets(path, '11', 2) |
|
143 | changesets = @repository.latest_changesets(path, '11', 2) | |
144 | assert_equal %w|11 10|, changesets.collect(&:revision) |
|
144 | assert_equal %w|11 10|, changesets.collect(&:revision) | |
145 |
|
145 | |||
146 | path = 'sql_escape/underscore_dir' |
|
146 | path = 'sql_escape/underscore_dir' | |
147 | changesets = @repository.latest_changesets(path, nil) |
|
147 | changesets = @repository.latest_changesets(path, nil) | |
148 | assert_equal %w|13 12 9|, changesets.collect(&:revision) |
|
148 | assert_equal %w|30 13 12 9|, changesets.collect(&:revision) | |
149 |
|
149 | |||
150 | changesets = @repository.latest_changesets(path, '12') |
|
150 | changesets = @repository.latest_changesets(path, '12') | |
151 | assert_equal %w|12 9|, changesets.collect(&:revision) |
|
151 | assert_equal %w|12 9|, changesets.collect(&:revision) | |
152 |
|
152 | |||
153 | changesets = @repository.latest_changesets(path, '12', 1) |
|
153 | changesets = @repository.latest_changesets(path, '12', 1) | |
154 | assert_equal %w|12|, changesets.collect(&:revision) |
|
154 | assert_equal %w|12|, changesets.collect(&:revision) | |
155 |
|
155 | |||
156 | # tag |
|
156 | # tag | |
157 | changesets = @repository.latest_changesets('', 'tag_test.00') |
|
157 | changesets = @repository.latest_changesets('', 'tag_test.00') | |
158 | assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision) |
|
158 | assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision) | |
159 |
|
159 | |||
160 | changesets = @repository.latest_changesets('', 'tag_test.00', 2) |
|
160 | changesets = @repository.latest_changesets('', 'tag_test.00', 2) | |
161 | assert_equal %w|5 4|, changesets.collect(&:revision) |
|
161 | assert_equal %w|5 4|, changesets.collect(&:revision) | |
162 |
|
162 | |||
163 | changesets = @repository.latest_changesets('sources', 'tag_test.00') |
|
163 | changesets = @repository.latest_changesets('sources', 'tag_test.00') | |
164 | assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision) |
|
164 | assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision) | |
165 |
|
165 | |||
166 | changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) |
|
166 | changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) | |
167 | assert_equal %w|4 3|, changesets.collect(&:revision) |
|
167 | assert_equal %w|4 3|, changesets.collect(&:revision) | |
168 |
|
168 | |||
169 | # named branch |
|
169 | # named branch | |
170 | if @repository.scm.class.client_version_above?([1, 6]) |
|
170 | if @repository.scm.class.client_version_above?([1, 6]) | |
171 | changesets = @repository.latest_changesets('', @branch_char_1) |
|
171 | changesets = @repository.latest_changesets('', @branch_char_1) | |
172 | assert_equal %w|27 26|, changesets.collect(&:revision) |
|
172 | assert_equal %w|27 26|, changesets.collect(&:revision) | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) |
|
175 | changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) | |
176 | assert_equal %w|27|, changesets.collect(&:revision) |
|
176 | assert_equal %w|27|, changesets.collect(&:revision) | |
177 | end |
|
177 | end | |
178 |
|
178 | |||
179 | def test_copied_files |
|
179 | def test_copied_files | |
180 | assert_equal 0, @repository.changesets.count |
|
180 | assert_equal 0, @repository.changesets.count | |
181 | @repository.fetch_changesets |
|
181 | @repository.fetch_changesets | |
182 | @project.reload |
|
182 | @project.reload | |
183 | assert_equal NUM_REV, @repository.changesets.count |
|
183 | assert_equal NUM_REV, @repository.changesets.count | |
184 |
|
184 | |||
185 | cs1 = @repository.changesets.find_by_revision('13') |
|
185 | cs1 = @repository.changesets.find_by_revision('13') | |
186 | assert_not_nil cs1 |
|
186 | assert_not_nil cs1 | |
187 | c1 = cs1.changes.sort_by(&:path) |
|
187 | c1 = cs1.changes.sort_by(&:path) | |
188 | assert_equal 2, c1.size |
|
188 | assert_equal 2, c1.size | |
189 |
|
189 | |||
190 | assert_equal 'A', c1[0].action |
|
190 | assert_equal 'A', c1[0].action | |
191 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path |
|
191 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path | |
192 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path |
|
192 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path | |
193 | assert_equal '3a330eb32958', c1[0].from_revision |
|
193 | assert_equal '3a330eb32958', c1[0].from_revision | |
194 |
|
194 | |||
195 | assert_equal 'A', c1[1].action |
|
195 | assert_equal 'A', c1[1].action | |
196 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path |
|
196 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path | |
197 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path |
|
197 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path | |
198 |
|
198 | |||
199 | cs2 = @repository.changesets.find_by_revision('15') |
|
199 | cs2 = @repository.changesets.find_by_revision('15') | |
200 | c2 = cs2.changes |
|
200 | c2 = cs2.changes | |
201 | assert_equal 1, c2.size |
|
201 | assert_equal 1, c2.size | |
202 |
|
202 | |||
203 | assert_equal 'A', c2[0].action |
|
203 | assert_equal 'A', c2[0].action | |
204 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
|
204 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path | |
205 | assert_equal '/README', c2[0].from_path |
|
205 | assert_equal '/README', c2[0].from_path | |
206 | assert_equal '933ca60293d7', c2[0].from_revision |
|
206 | assert_equal '933ca60293d7', c2[0].from_revision | |
207 |
|
207 | |||
208 | cs3 = @repository.changesets.find_by_revision('19') |
|
208 | cs3 = @repository.changesets.find_by_revision('19') | |
209 | c3 = cs3.changes |
|
209 | c3 = cs3.changes | |
210 | assert_equal 1, c3.size |
|
210 | assert_equal 1, c3.size | |
211 | assert_equal 'A', c3[0].action |
|
211 | assert_equal 'A', c3[0].action | |
212 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path |
|
212 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path | |
213 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path |
|
213 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path | |
214 | assert_equal '5d9891a1b425', c3[0].from_revision |
|
214 | assert_equal '5d9891a1b425', c3[0].from_revision | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | def test_find_changeset_by_name |
|
217 | def test_find_changeset_by_name | |
218 | assert_equal 0, @repository.changesets.count |
|
218 | assert_equal 0, @repository.changesets.count | |
219 | @repository.fetch_changesets |
|
219 | @repository.fetch_changesets | |
220 | @project.reload |
|
220 | @project.reload | |
221 | assert_equal NUM_REV, @repository.changesets.count |
|
221 | assert_equal NUM_REV, @repository.changesets.count | |
222 | %w|2 400bb8672109 400|.each do |r| |
|
222 | %w|2 400bb8672109 400|.each do |r| | |
223 | assert_equal '2', @repository.find_changeset_by_name(r).revision |
|
223 | assert_equal '2', @repository.find_changeset_by_name(r).revision | |
224 | end |
|
224 | end | |
225 | end |
|
225 | end | |
226 |
|
226 | |||
227 | def test_find_changeset_by_invalid_name |
|
227 | def test_find_changeset_by_invalid_name | |
228 | assert_equal 0, @repository.changesets.count |
|
228 | assert_equal 0, @repository.changesets.count | |
229 | @repository.fetch_changesets |
|
229 | @repository.fetch_changesets | |
230 | @project.reload |
|
230 | @project.reload | |
231 | assert_equal NUM_REV, @repository.changesets.count |
|
231 | assert_equal NUM_REV, @repository.changesets.count | |
232 | assert_nil @repository.find_changeset_by_name('100000') |
|
232 | assert_nil @repository.find_changeset_by_name('100000') | |
233 | end |
|
233 | end | |
234 |
|
234 | |||
235 | def test_identifier |
|
235 | def test_identifier | |
236 | assert_equal 0, @repository.changesets.count |
|
236 | assert_equal 0, @repository.changesets.count | |
237 | @repository.fetch_changesets |
|
237 | @repository.fetch_changesets | |
238 | @project.reload |
|
238 | @project.reload | |
239 | assert_equal NUM_REV, @repository.changesets.count |
|
239 | assert_equal NUM_REV, @repository.changesets.count | |
240 | c = @repository.changesets.find_by_revision('2') |
|
240 | c = @repository.changesets.find_by_revision('2') | |
241 | assert_equal c.scmid, c.identifier |
|
241 | assert_equal c.scmid, c.identifier | |
242 | end |
|
242 | end | |
243 |
|
243 | |||
244 | def test_format_identifier |
|
244 | def test_format_identifier | |
245 | assert_equal 0, @repository.changesets.count |
|
245 | assert_equal 0, @repository.changesets.count | |
246 | @repository.fetch_changesets |
|
246 | @repository.fetch_changesets | |
247 | @project.reload |
|
247 | @project.reload | |
248 | assert_equal NUM_REV, @repository.changesets.count |
|
248 | assert_equal NUM_REV, @repository.changesets.count | |
249 | c = @repository.changesets.find_by_revision('2') |
|
249 | c = @repository.changesets.find_by_revision('2') | |
250 | assert_equal '2:400bb8672109', c.format_identifier |
|
250 | assert_equal '2:400bb8672109', c.format_identifier | |
251 | end |
|
251 | end | |
252 |
|
252 | |||
253 | def test_find_changeset_by_empty_name |
|
253 | def test_find_changeset_by_empty_name | |
254 | assert_equal 0, @repository.changesets.count |
|
254 | assert_equal 0, @repository.changesets.count | |
255 | @repository.fetch_changesets |
|
255 | @repository.fetch_changesets | |
256 | @project.reload |
|
256 | @project.reload | |
257 | assert_equal NUM_REV, @repository.changesets.count |
|
257 | assert_equal NUM_REV, @repository.changesets.count | |
258 | ['', ' ', nil].each do |r| |
|
258 | ['', ' ', nil].each do |r| | |
259 | assert_nil @repository.find_changeset_by_name(r) |
|
259 | assert_nil @repository.find_changeset_by_name(r) | |
260 | end |
|
260 | end | |
261 | end |
|
261 | end | |
262 |
|
262 | |||
263 | def test_activities |
|
263 | def test_activities | |
264 | c = Changeset.new(:repository => @repository, |
|
264 | c = Changeset.new(:repository => @repository, | |
265 | :committed_on => Time.now, |
|
265 | :committed_on => Time.now, | |
266 | :revision => '123', |
|
266 | :revision => '123', | |
267 | :scmid => 'abc400bb8672', |
|
267 | :scmid => 'abc400bb8672', | |
268 | :comments => 'test') |
|
268 | :comments => 'test') | |
269 | assert c.event_title.include?('123:abc400bb8672:') |
|
269 | assert c.event_title.include?('123:abc400bb8672:') | |
270 | assert_equal 'abc400bb8672', c.event_url[:rev] |
|
270 | assert_equal 'abc400bb8672', c.event_url[:rev] | |
271 | end |
|
271 | end | |
272 |
|
272 | |||
273 | def test_previous |
|
273 | def test_previous | |
274 | assert_equal 0, @repository.changesets.count |
|
274 | assert_equal 0, @repository.changesets.count | |
275 | @repository.fetch_changesets |
|
275 | @repository.fetch_changesets | |
276 | @project.reload |
|
276 | @project.reload | |
277 | assert_equal NUM_REV, @repository.changesets.count |
|
277 | assert_equal NUM_REV, @repository.changesets.count | |
278 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
278 | %w|28 3ae45e2d177d 3ae45|.each do |r1| | |
279 | changeset = @repository.find_changeset_by_name(r1) |
|
279 | changeset = @repository.find_changeset_by_name(r1) | |
280 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
280 | %w|27 7bbf4c738e71 7bbf|.each do |r2| | |
281 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
281 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous | |
282 | end |
|
282 | end | |
283 | end |
|
283 | end | |
284 | end |
|
284 | end | |
285 |
|
285 | |||
286 | def test_previous_nil |
|
286 | def test_previous_nil | |
287 | assert_equal 0, @repository.changesets.count |
|
287 | assert_equal 0, @repository.changesets.count | |
288 | @repository.fetch_changesets |
|
288 | @repository.fetch_changesets | |
289 | @project.reload |
|
289 | @project.reload | |
290 | assert_equal NUM_REV, @repository.changesets.count |
|
290 | assert_equal NUM_REV, @repository.changesets.count | |
291 | %w|0 0885933ad4f6 0885|.each do |r1| |
|
291 | %w|0 0885933ad4f6 0885|.each do |r1| | |
292 | changeset = @repository.find_changeset_by_name(r1) |
|
292 | changeset = @repository.find_changeset_by_name(r1) | |
293 | assert_nil changeset.previous |
|
293 | assert_nil changeset.previous | |
294 | end |
|
294 | end | |
295 | end |
|
295 | end | |
296 |
|
296 | |||
297 | def test_next |
|
297 | def test_next | |
298 | assert_equal 0, @repository.changesets.count |
|
298 | assert_equal 0, @repository.changesets.count | |
299 | @repository.fetch_changesets |
|
299 | @repository.fetch_changesets | |
300 | @project.reload |
|
300 | @project.reload | |
301 | assert_equal NUM_REV, @repository.changesets.count |
|
301 | assert_equal NUM_REV, @repository.changesets.count | |
302 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
302 | %w|27 7bbf4c738e71 7bbf|.each do |r2| | |
303 | changeset = @repository.find_changeset_by_name(r2) |
|
303 | changeset = @repository.find_changeset_by_name(r2) | |
304 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
304 | %w|28 3ae45e2d177d 3ae45|.each do |r1| | |
305 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
305 | assert_equal @repository.find_changeset_by_name(r1), changeset.next | |
306 | end |
|
306 | end | |
307 | end |
|
307 | end | |
308 | end |
|
308 | end | |
309 |
|
309 | |||
310 | def test_next_nil |
|
310 | def test_next_nil | |
311 | assert_equal 0, @repository.changesets.count |
|
311 | assert_equal 0, @repository.changesets.count | |
312 | @repository.fetch_changesets |
|
312 | @repository.fetch_changesets | |
313 | @project.reload |
|
313 | @project.reload | |
314 | assert_equal NUM_REV, @repository.changesets.count |
|
314 | assert_equal NUM_REV, @repository.changesets.count | |
315 |
%w| |
|
315 | %w|31 31eeee7395c8 31eee|.each do |r1| | |
316 | changeset = @repository.find_changeset_by_name(r1) |
|
316 | changeset = @repository.find_changeset_by_name(r1) | |
317 | assert_nil changeset.next |
|
317 | assert_nil changeset.next | |
318 | end |
|
318 | end | |
319 | end |
|
319 | end | |
320 | else |
|
320 | else | |
321 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
321 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
322 | def test_fake; assert true end |
|
322 | def test_fake; assert true end | |
323 | end |
|
323 | end | |
324 | end |
|
324 | end |
General Comments 0
You need to be logged in to leave comments.
Login now