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