@@ -1,373 +1,372 | |||||
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 | include Redmine::I18n |
|
23 | include Redmine::I18n | |
24 |
|
24 | |||
25 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
|
25 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s | |
26 | NUM_REV = 32 |
|
26 | NUM_REV = 32 | |
27 | CHAR_1_HEX = "\xc3\x9c" |
|
27 | CHAR_1_HEX = "\xc3\x9c" | |
28 |
|
28 | |||
29 | def setup |
|
29 | def setup | |
30 | @project = Project.find(3) |
|
30 | @project = Project.find(3) | |
31 | @repository = Repository::Mercurial.create( |
|
31 | @repository = Repository::Mercurial.create( | |
32 | :project => @project, |
|
32 | :project => @project, | |
33 | :url => REPOSITORY_PATH, |
|
33 | :url => REPOSITORY_PATH, | |
34 | :path_encoding => 'ISO-8859-1' |
|
34 | :path_encoding => 'ISO-8859-1' | |
35 | ) |
|
35 | ) | |
36 | assert @repository |
|
36 | assert @repository | |
37 | @char_1 = CHAR_1_HEX.dup |
|
37 | @char_1 = CHAR_1_HEX.dup | |
38 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
38 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" | |
39 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
39 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" | |
40 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
40 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" | |
41 | if @char_1.respond_to?(:force_encoding) |
|
41 | if @char_1.respond_to?(:force_encoding) | |
42 | @char_1.force_encoding('UTF-8') |
|
42 | @char_1.force_encoding('UTF-8') | |
43 | @tag_char_1.force_encoding('UTF-8') |
|
43 | @tag_char_1.force_encoding('UTF-8') | |
44 | @branch_char_0.force_encoding('UTF-8') |
|
44 | @branch_char_0.force_encoding('UTF-8') | |
45 | @branch_char_1.force_encoding('UTF-8') |
|
45 | @branch_char_1.force_encoding('UTF-8') | |
46 | end |
|
46 | end | |
47 | end |
|
47 | end | |
48 |
|
48 | |||
49 |
|
49 | |||
50 | def test_blank_path_to_repository_error_message |
|
50 | def test_blank_path_to_repository_error_message | |
51 | set_language_if_valid 'en' |
|
51 | set_language_if_valid 'en' | |
52 | repo = Repository::Mercurial.new( |
|
52 | repo = Repository::Mercurial.new( | |
53 | :project => @project, |
|
53 | :project => @project, | |
54 |
:identifier => 'test' |
|
54 | :identifier => 'test' | |
55 | :log_encoding => 'UTF-8' |
|
|||
56 | ) |
|
55 | ) | |
57 | assert !repo.save |
|
56 | assert !repo.save | |
58 | assert_include "Path to repository can't be blank", |
|
57 | assert_include "Path to repository can't be blank", | |
59 | repo.errors.full_messages |
|
58 | repo.errors.full_messages | |
60 | end |
|
59 | end | |
61 |
|
60 | |||
62 | def test_blank_path_to_repository_error_message_fr |
|
61 | def test_blank_path_to_repository_error_message_fr | |
63 | set_language_if_valid 'fr' |
|
62 | set_language_if_valid 'fr' | |
64 | str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)" |
|
63 | str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)" | |
65 | str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) |
|
64 | str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) | |
66 | repo = Repository::Mercurial.new( |
|
65 | repo = Repository::Mercurial.new( | |
67 | :project => @project, |
|
66 | :project => @project, | |
68 | :url => "", |
|
67 | :url => "", | |
69 | :identifier => 'test', |
|
68 | :identifier => 'test', | |
70 |
: |
|
69 | :path_encoding => '' | |
71 | ) |
|
70 | ) | |
72 | assert !repo.save |
|
71 | assert !repo.save | |
73 | assert_include str, repo.errors.full_messages |
|
72 | assert_include str, repo.errors.full_messages | |
74 | end |
|
73 | end | |
75 |
|
74 | |||
76 | if File.directory?(REPOSITORY_PATH) |
|
75 | if File.directory?(REPOSITORY_PATH) | |
77 | def test_scm_available |
|
76 | def test_scm_available | |
78 | klass = Repository::Mercurial |
|
77 | klass = Repository::Mercurial | |
79 | assert_equal "Mercurial", klass.scm_name |
|
78 | assert_equal "Mercurial", klass.scm_name | |
80 | assert klass.scm_adapter_class |
|
79 | assert klass.scm_adapter_class | |
81 | assert_not_equal "", klass.scm_command |
|
80 | assert_not_equal "", klass.scm_command | |
82 | assert_equal true, klass.scm_available |
|
81 | assert_equal true, klass.scm_available | |
83 | end |
|
82 | end | |
84 |
|
83 | |||
85 | def test_fetch_changesets_from_scratch |
|
84 | def test_fetch_changesets_from_scratch | |
86 | assert_equal 0, @repository.changesets.count |
|
85 | assert_equal 0, @repository.changesets.count | |
87 | @repository.fetch_changesets |
|
86 | @repository.fetch_changesets | |
88 | @project.reload |
|
87 | @project.reload | |
89 | assert_equal NUM_REV, @repository.changesets.count |
|
88 | assert_equal NUM_REV, @repository.changesets.count | |
90 | assert_equal 46, @repository.changes.count |
|
89 | assert_equal 46, @repository.changes.count | |
91 | assert_equal "Initial import.\nThe repository contains 3 files.", |
|
90 | assert_equal "Initial import.\nThe repository contains 3 files.", | |
92 | @repository.changesets.find_by_revision('0').comments |
|
91 | @repository.changesets.find_by_revision('0').comments | |
93 | end |
|
92 | end | |
94 |
|
93 | |||
95 | def test_fetch_changesets_incremental |
|
94 | def test_fetch_changesets_incremental | |
96 | assert_equal 0, @repository.changesets.count |
|
95 | assert_equal 0, @repository.changesets.count | |
97 | @repository.fetch_changesets |
|
96 | @repository.fetch_changesets | |
98 | @project.reload |
|
97 | @project.reload | |
99 | assert_equal NUM_REV, @repository.changesets.count |
|
98 | assert_equal NUM_REV, @repository.changesets.count | |
100 | # Remove changesets with revision > 2 |
|
99 | # Remove changesets with revision > 2 | |
101 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} |
|
100 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} | |
102 | @project.reload |
|
101 | @project.reload | |
103 | assert_equal 3, @repository.changesets.count |
|
102 | assert_equal 3, @repository.changesets.count | |
104 |
|
103 | |||
105 | @repository.fetch_changesets |
|
104 | @repository.fetch_changesets | |
106 | @project.reload |
|
105 | @project.reload | |
107 | assert_equal NUM_REV, @repository.changesets.count |
|
106 | assert_equal NUM_REV, @repository.changesets.count | |
108 | end |
|
107 | end | |
109 |
|
108 | |||
110 | def test_isodatesec |
|
109 | def test_isodatesec | |
111 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
|
110 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher | |
112 | if @repository.scm.class.client_version_above?([1, 0]) |
|
111 | if @repository.scm.class.client_version_above?([1, 0]) | |
113 | assert_equal 0, @repository.changesets.count |
|
112 | assert_equal 0, @repository.changesets.count | |
114 | @repository.fetch_changesets |
|
113 | @repository.fetch_changesets | |
115 | @project.reload |
|
114 | @project.reload | |
116 | assert_equal NUM_REV, @repository.changesets.count |
|
115 | assert_equal NUM_REV, @repository.changesets.count | |
117 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) |
|
116 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) | |
118 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on |
|
117 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on | |
119 | end |
|
118 | end | |
120 | end |
|
119 | end | |
121 |
|
120 | |||
122 | def test_changeset_order_by_revision |
|
121 | def test_changeset_order_by_revision | |
123 | assert_equal 0, @repository.changesets.count |
|
122 | assert_equal 0, @repository.changesets.count | |
124 | @repository.fetch_changesets |
|
123 | @repository.fetch_changesets | |
125 | @project.reload |
|
124 | @project.reload | |
126 | assert_equal NUM_REV, @repository.changesets.count |
|
125 | assert_equal NUM_REV, @repository.changesets.count | |
127 |
|
126 | |||
128 | c0 = @repository.latest_changeset |
|
127 | c0 = @repository.latest_changeset | |
129 | c1 = @repository.changesets.find_by_revision('0') |
|
128 | c1 = @repository.changesets.find_by_revision('0') | |
130 | # sorted by revision (id), not by date |
|
129 | # sorted by revision (id), not by date | |
131 | assert c0.revision.to_i > c1.revision.to_i |
|
130 | assert c0.revision.to_i > c1.revision.to_i | |
132 | assert c0.committed_on < c1.committed_on |
|
131 | assert c0.committed_on < c1.committed_on | |
133 | end |
|
132 | end | |
134 |
|
133 | |||
135 | def test_latest_changesets |
|
134 | def test_latest_changesets | |
136 | assert_equal 0, @repository.changesets.count |
|
135 | assert_equal 0, @repository.changesets.count | |
137 | @repository.fetch_changesets |
|
136 | @repository.fetch_changesets | |
138 | @project.reload |
|
137 | @project.reload | |
139 | assert_equal NUM_REV, @repository.changesets.count |
|
138 | assert_equal NUM_REV, @repository.changesets.count | |
140 |
|
139 | |||
141 | # with_limit |
|
140 | # with_limit | |
142 | changesets = @repository.latest_changesets('', nil, 2) |
|
141 | changesets = @repository.latest_changesets('', nil, 2) | |
143 | assert_equal %w|31 30|, changesets.collect(&:revision) |
|
142 | assert_equal %w|31 30|, changesets.collect(&:revision) | |
144 |
|
143 | |||
145 | # with_filepath |
|
144 | # with_filepath | |
146 | changesets = @repository.latest_changesets( |
|
145 | changesets = @repository.latest_changesets( | |
147 | '/sql_escape/percent%dir/percent%file1.txt', nil) |
|
146 | '/sql_escape/percent%dir/percent%file1.txt', nil) | |
148 | assert_equal %w|30 11 10 9|, changesets.collect(&:revision) |
|
147 | assert_equal %w|30 11 10 9|, changesets.collect(&:revision) | |
149 |
|
148 | |||
150 | changesets = @repository.latest_changesets( |
|
149 | changesets = @repository.latest_changesets( | |
151 | '/sql_escape/underscore_dir/understrike_file.txt', nil) |
|
150 | '/sql_escape/underscore_dir/understrike_file.txt', nil) | |
152 | assert_equal %w|30 12 9|, changesets.collect(&:revision) |
|
151 | assert_equal %w|30 12 9|, changesets.collect(&:revision) | |
153 |
|
152 | |||
154 | changesets = @repository.latest_changesets('README', nil) |
|
153 | changesets = @repository.latest_changesets('README', nil) | |
155 | assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision) |
|
154 | assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision) | |
156 |
|
155 | |||
157 | changesets = @repository.latest_changesets('README','8') |
|
156 | changesets = @repository.latest_changesets('README','8') | |
158 | assert_equal %w|8 6 1 0|, changesets.collect(&:revision) |
|
157 | assert_equal %w|8 6 1 0|, changesets.collect(&:revision) | |
159 |
|
158 | |||
160 | changesets = @repository.latest_changesets('README','8', 2) |
|
159 | changesets = @repository.latest_changesets('README','8', 2) | |
161 | assert_equal %w|8 6|, changesets.collect(&:revision) |
|
160 | assert_equal %w|8 6|, changesets.collect(&:revision) | |
162 |
|
161 | |||
163 | # with_dirpath |
|
162 | # with_dirpath | |
164 | changesets = @repository.latest_changesets('images', nil) |
|
163 | changesets = @repository.latest_changesets('images', nil) | |
165 | assert_equal %w|1 0|, changesets.collect(&:revision) |
|
164 | assert_equal %w|1 0|, changesets.collect(&:revision) | |
166 |
|
165 | |||
167 | path = 'sql_escape/percent%dir' |
|
166 | path = 'sql_escape/percent%dir' | |
168 | changesets = @repository.latest_changesets(path, nil) |
|
167 | changesets = @repository.latest_changesets(path, nil) | |
169 | assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision) |
|
168 | assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision) | |
170 |
|
169 | |||
171 | changesets = @repository.latest_changesets(path, '11') |
|
170 | changesets = @repository.latest_changesets(path, '11') | |
172 | assert_equal %w|11 10 9|, changesets.collect(&:revision) |
|
171 | assert_equal %w|11 10 9|, changesets.collect(&:revision) | |
173 |
|
172 | |||
174 | changesets = @repository.latest_changesets(path, '11', 2) |
|
173 | changesets = @repository.latest_changesets(path, '11', 2) | |
175 | assert_equal %w|11 10|, changesets.collect(&:revision) |
|
174 | assert_equal %w|11 10|, changesets.collect(&:revision) | |
176 |
|
175 | |||
177 | path = 'sql_escape/underscore_dir' |
|
176 | path = 'sql_escape/underscore_dir' | |
178 | changesets = @repository.latest_changesets(path, nil) |
|
177 | changesets = @repository.latest_changesets(path, nil) | |
179 | assert_equal %w|30 13 12 9|, changesets.collect(&:revision) |
|
178 | assert_equal %w|30 13 12 9|, changesets.collect(&:revision) | |
180 |
|
179 | |||
181 | changesets = @repository.latest_changesets(path, '12') |
|
180 | changesets = @repository.latest_changesets(path, '12') | |
182 | assert_equal %w|12 9|, changesets.collect(&:revision) |
|
181 | assert_equal %w|12 9|, changesets.collect(&:revision) | |
183 |
|
182 | |||
184 | changesets = @repository.latest_changesets(path, '12', 1) |
|
183 | changesets = @repository.latest_changesets(path, '12', 1) | |
185 | assert_equal %w|12|, changesets.collect(&:revision) |
|
184 | assert_equal %w|12|, changesets.collect(&:revision) | |
186 |
|
185 | |||
187 | # tag |
|
186 | # tag | |
188 | changesets = @repository.latest_changesets('', 'tag_test.00') |
|
187 | changesets = @repository.latest_changesets('', 'tag_test.00') | |
189 | assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision) |
|
188 | assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision) | |
190 |
|
189 | |||
191 | changesets = @repository.latest_changesets('', 'tag_test.00', 2) |
|
190 | changesets = @repository.latest_changesets('', 'tag_test.00', 2) | |
192 | assert_equal %w|5 4|, changesets.collect(&:revision) |
|
191 | assert_equal %w|5 4|, changesets.collect(&:revision) | |
193 |
|
192 | |||
194 | changesets = @repository.latest_changesets('sources', 'tag_test.00') |
|
193 | changesets = @repository.latest_changesets('sources', 'tag_test.00') | |
195 | assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision) |
|
194 | assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision) | |
196 |
|
195 | |||
197 | changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) |
|
196 | changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) | |
198 | assert_equal %w|4 3|, changesets.collect(&:revision) |
|
197 | assert_equal %w|4 3|, changesets.collect(&:revision) | |
199 |
|
198 | |||
200 | # named branch |
|
199 | # named branch | |
201 | if @repository.scm.class.client_version_above?([1, 6]) |
|
200 | if @repository.scm.class.client_version_above?([1, 6]) | |
202 | changesets = @repository.latest_changesets('', @branch_char_1) |
|
201 | changesets = @repository.latest_changesets('', @branch_char_1) | |
203 | assert_equal %w|27 26|, changesets.collect(&:revision) |
|
202 | assert_equal %w|27 26|, changesets.collect(&:revision) | |
204 | end |
|
203 | end | |
205 |
|
204 | |||
206 | changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) |
|
205 | changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) | |
207 | assert_equal %w|27|, changesets.collect(&:revision) |
|
206 | assert_equal %w|27|, changesets.collect(&:revision) | |
208 | end |
|
207 | end | |
209 |
|
208 | |||
210 | def test_copied_files |
|
209 | def test_copied_files | |
211 | assert_equal 0, @repository.changesets.count |
|
210 | assert_equal 0, @repository.changesets.count | |
212 | @repository.fetch_changesets |
|
211 | @repository.fetch_changesets | |
213 | @project.reload |
|
212 | @project.reload | |
214 | assert_equal NUM_REV, @repository.changesets.count |
|
213 | assert_equal NUM_REV, @repository.changesets.count | |
215 |
|
214 | |||
216 | cs1 = @repository.changesets.find_by_revision('13') |
|
215 | cs1 = @repository.changesets.find_by_revision('13') | |
217 | assert_not_nil cs1 |
|
216 | assert_not_nil cs1 | |
218 | c1 = cs1.changes.sort_by(&:path) |
|
217 | c1 = cs1.changes.sort_by(&:path) | |
219 | assert_equal 2, c1.size |
|
218 | assert_equal 2, c1.size | |
220 |
|
219 | |||
221 | assert_equal 'A', c1[0].action |
|
220 | assert_equal 'A', c1[0].action | |
222 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path |
|
221 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path | |
223 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path |
|
222 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path | |
224 | assert_equal '3a330eb32958', c1[0].from_revision |
|
223 | assert_equal '3a330eb32958', c1[0].from_revision | |
225 |
|
224 | |||
226 | assert_equal 'A', c1[1].action |
|
225 | assert_equal 'A', c1[1].action | |
227 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path |
|
226 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path | |
228 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path |
|
227 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path | |
229 |
|
228 | |||
230 | cs2 = @repository.changesets.find_by_revision('15') |
|
229 | cs2 = @repository.changesets.find_by_revision('15') | |
231 | c2 = cs2.changes |
|
230 | c2 = cs2.changes | |
232 | assert_equal 1, c2.size |
|
231 | assert_equal 1, c2.size | |
233 |
|
232 | |||
234 | assert_equal 'A', c2[0].action |
|
233 | assert_equal 'A', c2[0].action | |
235 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
|
234 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path | |
236 | assert_equal '/README', c2[0].from_path |
|
235 | assert_equal '/README', c2[0].from_path | |
237 | assert_equal '933ca60293d7', c2[0].from_revision |
|
236 | assert_equal '933ca60293d7', c2[0].from_revision | |
238 |
|
237 | |||
239 | cs3 = @repository.changesets.find_by_revision('19') |
|
238 | cs3 = @repository.changesets.find_by_revision('19') | |
240 | c3 = cs3.changes |
|
239 | c3 = cs3.changes | |
241 | assert_equal 1, c3.size |
|
240 | assert_equal 1, c3.size | |
242 | assert_equal 'A', c3[0].action |
|
241 | assert_equal 'A', c3[0].action | |
243 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path |
|
242 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path | |
244 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path |
|
243 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path | |
245 | assert_equal '5d9891a1b425', c3[0].from_revision |
|
244 | assert_equal '5d9891a1b425', c3[0].from_revision | |
246 | end |
|
245 | end | |
247 |
|
246 | |||
248 | def test_find_changeset_by_name |
|
247 | def test_find_changeset_by_name | |
249 | assert_equal 0, @repository.changesets.count |
|
248 | assert_equal 0, @repository.changesets.count | |
250 | @repository.fetch_changesets |
|
249 | @repository.fetch_changesets | |
251 | @project.reload |
|
250 | @project.reload | |
252 | assert_equal NUM_REV, @repository.changesets.count |
|
251 | assert_equal NUM_REV, @repository.changesets.count | |
253 | %w|2 400bb8672109 400|.each do |r| |
|
252 | %w|2 400bb8672109 400|.each do |r| | |
254 | assert_equal '2', @repository.find_changeset_by_name(r).revision |
|
253 | assert_equal '2', @repository.find_changeset_by_name(r).revision | |
255 | end |
|
254 | end | |
256 | end |
|
255 | end | |
257 |
|
256 | |||
258 | def test_find_changeset_by_invalid_name |
|
257 | def test_find_changeset_by_invalid_name | |
259 | assert_equal 0, @repository.changesets.count |
|
258 | assert_equal 0, @repository.changesets.count | |
260 | @repository.fetch_changesets |
|
259 | @repository.fetch_changesets | |
261 | @project.reload |
|
260 | @project.reload | |
262 | assert_equal NUM_REV, @repository.changesets.count |
|
261 | assert_equal NUM_REV, @repository.changesets.count | |
263 | assert_nil @repository.find_changeset_by_name('100000') |
|
262 | assert_nil @repository.find_changeset_by_name('100000') | |
264 | end |
|
263 | end | |
265 |
|
264 | |||
266 | def test_identifier |
|
265 | def test_identifier | |
267 | assert_equal 0, @repository.changesets.count |
|
266 | assert_equal 0, @repository.changesets.count | |
268 | @repository.fetch_changesets |
|
267 | @repository.fetch_changesets | |
269 | @project.reload |
|
268 | @project.reload | |
270 | assert_equal NUM_REV, @repository.changesets.count |
|
269 | assert_equal NUM_REV, @repository.changesets.count | |
271 | c = @repository.changesets.find_by_revision('2') |
|
270 | c = @repository.changesets.find_by_revision('2') | |
272 | assert_equal c.scmid, c.identifier |
|
271 | assert_equal c.scmid, c.identifier | |
273 | end |
|
272 | end | |
274 |
|
273 | |||
275 | def test_format_identifier |
|
274 | def test_format_identifier | |
276 | assert_equal 0, @repository.changesets.count |
|
275 | assert_equal 0, @repository.changesets.count | |
277 | @repository.fetch_changesets |
|
276 | @repository.fetch_changesets | |
278 | @project.reload |
|
277 | @project.reload | |
279 | assert_equal NUM_REV, @repository.changesets.count |
|
278 | assert_equal NUM_REV, @repository.changesets.count | |
280 | c = @repository.changesets.find_by_revision('2') |
|
279 | c = @repository.changesets.find_by_revision('2') | |
281 | assert_equal '2:400bb8672109', c.format_identifier |
|
280 | assert_equal '2:400bb8672109', c.format_identifier | |
282 | end |
|
281 | end | |
283 |
|
282 | |||
284 | def test_find_changeset_by_empty_name |
|
283 | def test_find_changeset_by_empty_name | |
285 | assert_equal 0, @repository.changesets.count |
|
284 | assert_equal 0, @repository.changesets.count | |
286 | @repository.fetch_changesets |
|
285 | @repository.fetch_changesets | |
287 | @project.reload |
|
286 | @project.reload | |
288 | assert_equal NUM_REV, @repository.changesets.count |
|
287 | assert_equal NUM_REV, @repository.changesets.count | |
289 | ['', ' ', nil].each do |r| |
|
288 | ['', ' ', nil].each do |r| | |
290 | assert_nil @repository.find_changeset_by_name(r) |
|
289 | assert_nil @repository.find_changeset_by_name(r) | |
291 | end |
|
290 | end | |
292 | end |
|
291 | end | |
293 |
|
292 | |||
294 | def test_parents |
|
293 | def test_parents | |
295 | assert_equal 0, @repository.changesets.count |
|
294 | assert_equal 0, @repository.changesets.count | |
296 | @repository.fetch_changesets |
|
295 | @repository.fetch_changesets | |
297 | @project.reload |
|
296 | @project.reload | |
298 | assert_equal NUM_REV, @repository.changesets.count |
|
297 | assert_equal NUM_REV, @repository.changesets.count | |
299 | r1 = @repository.changesets.find_by_revision('0') |
|
298 | r1 = @repository.changesets.find_by_revision('0') | |
300 | assert_equal [], r1.parents |
|
299 | assert_equal [], r1.parents | |
301 | r2 = @repository.changesets.find_by_revision('1') |
|
300 | r2 = @repository.changesets.find_by_revision('1') | |
302 | assert_equal 1, r2.parents.length |
|
301 | assert_equal 1, r2.parents.length | |
303 | assert_equal "0885933ad4f6", |
|
302 | assert_equal "0885933ad4f6", | |
304 | r2.parents[0].identifier |
|
303 | r2.parents[0].identifier | |
305 | r3 = @repository.changesets.find_by_revision('30') |
|
304 | r3 = @repository.changesets.find_by_revision('30') | |
306 | assert_equal 2, r3.parents.length |
|
305 | assert_equal 2, r3.parents.length | |
307 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort |
|
306 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort | |
308 | assert_equal "3a330eb32958", r4[0] |
|
307 | assert_equal "3a330eb32958", r4[0] | |
309 | assert_equal "a94b0528f24f", r4[1] |
|
308 | assert_equal "a94b0528f24f", r4[1] | |
310 | end |
|
309 | end | |
311 |
|
310 | |||
312 | def test_activities |
|
311 | def test_activities | |
313 | c = Changeset.new(:repository => @repository, |
|
312 | c = Changeset.new(:repository => @repository, | |
314 | :committed_on => Time.now, |
|
313 | :committed_on => Time.now, | |
315 | :revision => '123', |
|
314 | :revision => '123', | |
316 | :scmid => 'abc400bb8672', |
|
315 | :scmid => 'abc400bb8672', | |
317 | :comments => 'test') |
|
316 | :comments => 'test') | |
318 | assert c.event_title.include?('123:abc400bb8672:') |
|
317 | assert c.event_title.include?('123:abc400bb8672:') | |
319 | assert_equal 'abc400bb8672', c.event_url[:rev] |
|
318 | assert_equal 'abc400bb8672', c.event_url[:rev] | |
320 | end |
|
319 | end | |
321 |
|
320 | |||
322 | def test_previous |
|
321 | def test_previous | |
323 | assert_equal 0, @repository.changesets.count |
|
322 | assert_equal 0, @repository.changesets.count | |
324 | @repository.fetch_changesets |
|
323 | @repository.fetch_changesets | |
325 | @project.reload |
|
324 | @project.reload | |
326 | assert_equal NUM_REV, @repository.changesets.count |
|
325 | assert_equal NUM_REV, @repository.changesets.count | |
327 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
326 | %w|28 3ae45e2d177d 3ae45|.each do |r1| | |
328 | changeset = @repository.find_changeset_by_name(r1) |
|
327 | changeset = @repository.find_changeset_by_name(r1) | |
329 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
328 | %w|27 7bbf4c738e71 7bbf|.each do |r2| | |
330 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
329 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous | |
331 | end |
|
330 | end | |
332 | end |
|
331 | end | |
333 | end |
|
332 | end | |
334 |
|
333 | |||
335 | def test_previous_nil |
|
334 | def test_previous_nil | |
336 | assert_equal 0, @repository.changesets.count |
|
335 | assert_equal 0, @repository.changesets.count | |
337 | @repository.fetch_changesets |
|
336 | @repository.fetch_changesets | |
338 | @project.reload |
|
337 | @project.reload | |
339 | assert_equal NUM_REV, @repository.changesets.count |
|
338 | assert_equal NUM_REV, @repository.changesets.count | |
340 | %w|0 0885933ad4f6 0885|.each do |r1| |
|
339 | %w|0 0885933ad4f6 0885|.each do |r1| | |
341 | changeset = @repository.find_changeset_by_name(r1) |
|
340 | changeset = @repository.find_changeset_by_name(r1) | |
342 | assert_nil changeset.previous |
|
341 | assert_nil changeset.previous | |
343 | end |
|
342 | end | |
344 | end |
|
343 | end | |
345 |
|
344 | |||
346 | def test_next |
|
345 | def test_next | |
347 | assert_equal 0, @repository.changesets.count |
|
346 | assert_equal 0, @repository.changesets.count | |
348 | @repository.fetch_changesets |
|
347 | @repository.fetch_changesets | |
349 | @project.reload |
|
348 | @project.reload | |
350 | assert_equal NUM_REV, @repository.changesets.count |
|
349 | assert_equal NUM_REV, @repository.changesets.count | |
351 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
350 | %w|27 7bbf4c738e71 7bbf|.each do |r2| | |
352 | changeset = @repository.find_changeset_by_name(r2) |
|
351 | changeset = @repository.find_changeset_by_name(r2) | |
353 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
352 | %w|28 3ae45e2d177d 3ae45|.each do |r1| | |
354 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
353 | assert_equal @repository.find_changeset_by_name(r1), changeset.next | |
355 | end |
|
354 | end | |
356 | end |
|
355 | end | |
357 | end |
|
356 | end | |
358 |
|
357 | |||
359 | def test_next_nil |
|
358 | def test_next_nil | |
360 | assert_equal 0, @repository.changesets.count |
|
359 | assert_equal 0, @repository.changesets.count | |
361 | @repository.fetch_changesets |
|
360 | @repository.fetch_changesets | |
362 | @project.reload |
|
361 | @project.reload | |
363 | assert_equal NUM_REV, @repository.changesets.count |
|
362 | assert_equal NUM_REV, @repository.changesets.count | |
364 | %w|31 31eeee7395c8 31eee|.each do |r1| |
|
363 | %w|31 31eeee7395c8 31eee|.each do |r1| | |
365 | changeset = @repository.find_changeset_by_name(r1) |
|
364 | changeset = @repository.find_changeset_by_name(r1) | |
366 | assert_nil changeset.next |
|
365 | assert_nil changeset.next | |
367 | end |
|
366 | end | |
368 | end |
|
367 | end | |
369 | else |
|
368 | else | |
370 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
369 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
371 | def test_fake; assert true end |
|
370 | def test_fake; assert true end | |
372 | end |
|
371 | end | |
373 | end |
|
372 | end |
General Comments 0
You need to be logged in to leave comments.
Login now