@@ -1,504 +1,509 | |||||
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_on_tip |
|
83 | def test_entries_on_tip | |
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 assert_entries |
|
88 | def assert_entries | |
89 | [2, '400bb8672109', '400', 400].each do |r| |
|
89 | [2, '400bb8672109', '400', 400].each do |r| | |
90 | entries1 = @repository.entries(nil, r) |
|
90 | entries1 = @repository.entries(nil, r) | |
91 | assert entries1 |
|
91 | assert entries1 | |
92 | assert_kind_of Redmine::Scm::Adapters::Entries, entries1 |
|
92 | assert_kind_of Redmine::Scm::Adapters::Entries, entries1 | |
93 | assert_equal 3, entries1.size |
|
93 | assert_equal 3, entries1.size | |
94 | readme = entries1[2] |
|
94 | readme = entries1[2] | |
95 | assert_equal '1', readme.lastrev.revision |
|
95 | assert_equal '1', readme.lastrev.revision | |
96 | assert_equal '9d5b5b004199', readme.lastrev.identifier |
|
96 | assert_equal '9d5b5b004199', readme.lastrev.identifier | |
97 | assert_equal '1', readme.changeset.revision |
|
97 | assert_equal '1', readme.changeset.revision | |
98 | assert_equal '9d5b5b004199', readme.changeset.scmid |
|
98 | assert_equal '9d5b5b004199', readme.changeset.scmid | |
99 | end |
|
99 | end | |
100 | end |
|
100 | end | |
101 | private :assert_entries |
|
101 | private :assert_entries | |
102 |
|
102 | |||
103 | def test_entries_short_id |
|
103 | def test_entries_short_id | |
104 | assert_equal 0, @repository.changesets.count |
|
104 | assert_equal 0, @repository.changesets.count | |
105 | @repository.fetch_changesets |
|
105 | @repository.fetch_changesets | |
106 | @project.reload |
|
106 | @project.reload | |
107 | assert_equal NUM_REV, @repository.changesets.count |
|
107 | assert_equal NUM_REV, @repository.changesets.count | |
108 | assert_entries |
|
108 | assert_entries | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | def test_entry_on_tip |
|
111 | def test_entry_on_tip | |
112 | entry = @repository.entry |
|
112 | entry = @repository.entry | |
113 | assert_kind_of Redmine::Scm::Adapters::Entry, entry |
|
113 | assert_kind_of Redmine::Scm::Adapters::Entry, entry | |
114 | assert_equal "", entry.path |
|
114 | assert_equal "", entry.path | |
115 | assert_equal 'dir', entry.kind |
|
115 | assert_equal 'dir', entry.kind | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | def assert_entry |
|
118 | def assert_entry | |
119 | ["README", "/README"].each do |path| |
|
119 | ["README", "/README"].each do |path| | |
120 | ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev| |
|
120 | ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev| | |
121 | entry = @repository.entry(path, rev) |
|
121 | entry = @repository.entry(path, rev) | |
122 | assert_kind_of Redmine::Scm::Adapters::Entry, entry |
|
122 | assert_kind_of Redmine::Scm::Adapters::Entry, entry | |
123 | assert_equal "README", entry.path |
|
123 | assert_equal "README", entry.path | |
124 | assert_equal "file", entry.kind |
|
124 | assert_equal "file", entry.kind | |
125 | assert_equal '0', entry.lastrev.revision |
|
125 | assert_equal '0', entry.lastrev.revision | |
126 | assert_equal '0885933ad4f6', entry.lastrev.identifier |
|
126 | assert_equal '0885933ad4f6', entry.lastrev.identifier | |
127 | end |
|
127 | end | |
128 | end |
|
128 | end | |
129 | ["sources", "/sources", "/sources/"].each do |path| |
|
129 | ["sources", "/sources", "/sources/"].each do |path| | |
130 | ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev| |
|
130 | ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev| | |
131 | entry = @repository.entry(path, rev) |
|
131 | entry = @repository.entry(path, rev) | |
132 | assert_kind_of Redmine::Scm::Adapters::Entry, entry |
|
132 | assert_kind_of Redmine::Scm::Adapters::Entry, entry | |
133 | assert_equal "sources", entry.path |
|
133 | assert_equal "sources", entry.path | |
134 | assert_equal "dir", entry.kind |
|
134 | assert_equal "dir", entry.kind | |
135 | end |
|
135 | end | |
136 | end |
|
136 | end | |
137 | ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path| |
|
137 | ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path| | |
138 | ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev| |
|
138 | ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev| | |
139 | entry = @repository.entry(path, rev) |
|
139 | entry = @repository.entry(path, rev) | |
140 | assert_kind_of Redmine::Scm::Adapters::Entry, entry |
|
140 | assert_kind_of Redmine::Scm::Adapters::Entry, entry | |
141 | assert_equal "sources/watchers_controller.rb", entry.path |
|
141 | assert_equal "sources/watchers_controller.rb", entry.path | |
142 | assert_equal "file", entry.kind |
|
142 | assert_equal "file", entry.kind | |
143 | assert_equal '0', entry.lastrev.revision |
|
143 | assert_equal '0', entry.lastrev.revision | |
144 | assert_equal '0885933ad4f6', entry.lastrev.identifier |
|
144 | assert_equal '0885933ad4f6', entry.lastrev.identifier | |
145 | end |
|
145 | end | |
146 | end |
|
146 | end | |
147 | end |
|
147 | end | |
148 | private :assert_entry |
|
148 | private :assert_entry | |
149 |
|
149 | |||
150 | def test_entry_short_id |
|
150 | def test_entry_short_id | |
151 | assert_entry |
|
151 | assert_entry | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | def test_fetch_changesets_from_scratch |
|
154 | def test_fetch_changesets_from_scratch | |
155 | assert_equal 0, @repository.changesets.count |
|
155 | assert_equal 0, @repository.changesets.count | |
156 | @repository.fetch_changesets |
|
156 | @repository.fetch_changesets | |
157 | @project.reload |
|
157 | @project.reload | |
158 | assert_equal NUM_REV, @repository.changesets.count |
|
158 | assert_equal NUM_REV, @repository.changesets.count | |
159 | assert_equal 46, @repository.filechanges.count |
|
159 | assert_equal 46, @repository.filechanges.count | |
160 | rev0 = @repository.changesets.find_by_revision('0') |
|
160 | rev0 = @repository.changesets.find_by_revision('0') | |
161 | assert_equal "Initial import.\nThe repository contains 3 files.", |
|
161 | assert_equal "Initial import.\nThe repository contains 3 files.", | |
162 | rev0.comments |
|
162 | rev0.comments | |
163 | assert_equal "0885933ad4f6", rev0.scmid |
|
163 | assert_equal "0885933ad4f6", rev0.scmid | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | def test_fetch_changesets_incremental |
|
166 | def test_fetch_changesets_incremental | |
167 | assert_equal 0, @repository.changesets.count |
|
167 | assert_equal 0, @repository.changesets.count | |
168 | @repository.fetch_changesets |
|
168 | @repository.fetch_changesets | |
169 | @project.reload |
|
169 | @project.reload | |
170 | assert_equal NUM_REV, @repository.changesets.count |
|
170 | assert_equal NUM_REV, @repository.changesets.count | |
171 | # Remove changesets with revision > 2 |
|
171 | # Remove changesets with revision > 2 | |
172 | @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2} |
|
172 | @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2} | |
173 | @project.reload |
|
173 | @project.reload | |
174 | @repository.reload |
|
174 | @repository.reload | |
175 | assert_equal 3, @repository.changesets.count |
|
175 | assert_equal 3, @repository.changesets.count | |
176 |
|
176 | |||
177 | @repository.fetch_changesets |
|
177 | @repository.fetch_changesets | |
178 | @project.reload |
|
178 | @project.reload | |
179 | assert_equal NUM_REV, @repository.changesets.count |
|
179 | assert_equal NUM_REV, @repository.changesets.count | |
180 | end |
|
180 | end | |
181 |
|
181 | |||
182 | def test_isodatesec |
|
182 | def test_isodatesec | |
183 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
|
183 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher | |
184 | if @repository.scm.class.client_version_above?([1, 0]) |
|
184 | if @repository.scm.class.client_version_above?([1, 0]) | |
185 | assert_equal 0, @repository.changesets.count |
|
185 | assert_equal 0, @repository.changesets.count | |
186 | @repository.fetch_changesets |
|
186 | @repository.fetch_changesets | |
187 | @project.reload |
|
187 | @project.reload | |
188 | assert_equal NUM_REV, @repository.changesets.count |
|
188 | assert_equal NUM_REV, @repository.changesets.count | |
189 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) |
|
189 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) | |
190 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on |
|
190 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on | |
191 | end |
|
191 | end | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
194 | def test_changeset_order_by_revision |
|
194 | def test_changeset_order_by_revision | |
195 | assert_equal 0, @repository.changesets.count |
|
195 | assert_equal 0, @repository.changesets.count | |
196 | @repository.fetch_changesets |
|
196 | @repository.fetch_changesets | |
197 | @project.reload |
|
197 | @project.reload | |
198 | assert_equal NUM_REV, @repository.changesets.count |
|
198 | assert_equal NUM_REV, @repository.changesets.count | |
199 |
|
199 | |||
200 | c0 = @repository.latest_changeset |
|
200 | c0 = @repository.latest_changeset | |
201 | c1 = @repository.changesets.find_by_revision('0') |
|
201 | c1 = @repository.changesets.find_by_revision('0') | |
202 | # sorted by revision (id), not by date |
|
202 | # sorted by revision (id), not by date | |
203 | assert c0.revision.to_i > c1.revision.to_i |
|
203 | assert c0.revision.to_i > c1.revision.to_i | |
204 | assert c0.committed_on < c1.committed_on |
|
204 | assert c0.committed_on < c1.committed_on | |
205 | end |
|
205 | end | |
206 |
|
206 | |||
207 | def test_latest_changesets |
|
207 | def test_latest_changesets | |
208 | assert_equal 0, @repository.changesets.count |
|
208 | assert_equal 0, @repository.changesets.count | |
209 | @repository.fetch_changesets |
|
209 | @repository.fetch_changesets | |
210 | @project.reload |
|
210 | @project.reload | |
211 | assert_equal NUM_REV, @repository.changesets.count |
|
211 | assert_equal NUM_REV, @repository.changesets.count | |
212 |
|
212 | |||
213 | # with_limit |
|
213 | # with_limit | |
214 | changesets = @repository.latest_changesets('', nil, 2) |
|
214 | changesets = @repository.latest_changesets('', nil, 2) | |
215 | assert_equal %w|31 30|, changesets.collect(&:revision) |
|
215 | assert_equal %w|31 30|, changesets.collect(&:revision) | |
216 |
|
216 | |||
217 | # with_filepath |
|
217 | # with_filepath | |
218 | changesets = @repository.latest_changesets( |
|
218 | changesets = @repository.latest_changesets( | |
219 | '/sql_escape/percent%dir/percent%file1.txt', nil) |
|
219 | '/sql_escape/percent%dir/percent%file1.txt', nil) | |
220 | assert_equal %w|30 11 10 9|, changesets.collect(&:revision) |
|
220 | assert_equal %w|30 11 10 9|, changesets.collect(&:revision) | |
221 |
|
221 | |||
222 | changesets = @repository.latest_changesets( |
|
222 | changesets = @repository.latest_changesets( | |
223 | '/sql_escape/underscore_dir/understrike_file.txt', nil) |
|
223 | '/sql_escape/underscore_dir/understrike_file.txt', nil) | |
224 | assert_equal %w|30 12 9|, changesets.collect(&:revision) |
|
224 | assert_equal %w|30 12 9|, changesets.collect(&:revision) | |
225 |
|
225 | |||
226 | changesets = @repository.latest_changesets('README', nil) |
|
226 | changesets = @repository.latest_changesets('README', nil) | |
227 | assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision) |
|
227 | assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision) | |
228 |
|
228 | |||
229 | changesets = @repository.latest_changesets('README','8') |
|
229 | changesets = @repository.latest_changesets('README','8') | |
230 | assert_equal %w|8 6 1 0|, changesets.collect(&:revision) |
|
230 | assert_equal %w|8 6 1 0|, changesets.collect(&:revision) | |
231 |
|
231 | |||
232 | changesets = @repository.latest_changesets('README','8', 2) |
|
232 | changesets = @repository.latest_changesets('README','8', 2) | |
233 | assert_equal %w|8 6|, changesets.collect(&:revision) |
|
233 | assert_equal %w|8 6|, changesets.collect(&:revision) | |
234 |
|
234 | |||
235 | # with_dirpath |
|
235 | # with_dirpath | |
236 | changesets = @repository.latest_changesets('images', nil) |
|
236 | changesets = @repository.latest_changesets('images', nil) | |
237 | assert_equal %w|1 0|, changesets.collect(&:revision) |
|
237 | assert_equal %w|1 0|, changesets.collect(&:revision) | |
238 |
|
238 | |||
239 | path = 'sql_escape/percent%dir' |
|
239 | path = 'sql_escape/percent%dir' | |
240 | changesets = @repository.latest_changesets(path, nil) |
|
240 | changesets = @repository.latest_changesets(path, nil) | |
241 | assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision) |
|
241 | assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision) | |
242 |
|
242 | |||
243 | changesets = @repository.latest_changesets(path, '11') |
|
243 | changesets = @repository.latest_changesets(path, '11') | |
244 | assert_equal %w|11 10 9|, changesets.collect(&:revision) |
|
244 | assert_equal %w|11 10 9|, changesets.collect(&:revision) | |
245 |
|
245 | |||
246 | changesets = @repository.latest_changesets(path, '11', 2) |
|
246 | changesets = @repository.latest_changesets(path, '11', 2) | |
247 | assert_equal %w|11 10|, changesets.collect(&:revision) |
|
247 | assert_equal %w|11 10|, changesets.collect(&:revision) | |
248 |
|
248 | |||
249 | path = 'sql_escape/underscore_dir' |
|
249 | path = 'sql_escape/underscore_dir' | |
250 | changesets = @repository.latest_changesets(path, nil) |
|
250 | changesets = @repository.latest_changesets(path, nil) | |
251 | assert_equal %w|30 13 12 9|, changesets.collect(&:revision) |
|
251 | assert_equal %w|30 13 12 9|, changesets.collect(&:revision) | |
252 |
|
252 | |||
253 | changesets = @repository.latest_changesets(path, '12') |
|
253 | changesets = @repository.latest_changesets(path, '12') | |
254 | assert_equal %w|12 9|, changesets.collect(&:revision) |
|
254 | assert_equal %w|12 9|, changesets.collect(&:revision) | |
255 |
|
255 | |||
256 | changesets = @repository.latest_changesets(path, '12', 1) |
|
256 | changesets = @repository.latest_changesets(path, '12', 1) | |
257 | assert_equal %w|12|, changesets.collect(&:revision) |
|
257 | assert_equal %w|12|, changesets.collect(&:revision) | |
258 | end |
|
258 | end | |
259 |
|
259 | |||
260 | def assert_latest_changesets_tag |
|
260 | def assert_latest_changesets_tag | |
261 | changesets = @repository.latest_changesets('', 'tag_test.00') |
|
261 | changesets = @repository.latest_changesets('', 'tag_test.00') | |
262 | assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision) |
|
262 | assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision) | |
263 | end |
|
263 | end | |
264 | private :assert_latest_changesets_tag |
|
264 | private :assert_latest_changesets_tag | |
265 |
|
265 | |||
266 | def test_latest_changesets_tag |
|
266 | def test_latest_changesets_tag | |
267 | assert_equal 0, @repository.changesets.count |
|
267 | assert_equal 0, @repository.changesets.count | |
268 | @repository.fetch_changesets |
|
268 | @repository.fetch_changesets | |
269 | @project.reload |
|
269 | @project.reload | |
270 | assert_equal NUM_REV, @repository.changesets.count |
|
270 | assert_equal NUM_REV, @repository.changesets.count | |
271 | assert_latest_changesets_tag |
|
271 | assert_latest_changesets_tag | |
272 | end |
|
272 | end | |
273 |
|
273 | |||
274 | def test_latest_changesets_tag_with_path |
|
274 | def test_latest_changesets_tag_with_path | |
275 | assert_equal 0, @repository.changesets.count |
|
275 | assert_equal 0, @repository.changesets.count | |
276 | @repository.fetch_changesets |
|
276 | @repository.fetch_changesets | |
277 | @project.reload |
|
277 | @project.reload | |
278 | assert_equal NUM_REV, @repository.changesets.count |
|
278 | assert_equal NUM_REV, @repository.changesets.count | |
279 |
|
279 | |||
280 | changesets = @repository.latest_changesets('sources', 'tag_test.00') |
|
280 | changesets = @repository.latest_changesets('sources', 'tag_test.00') | |
281 | assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision) |
|
281 | assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision) | |
282 | end |
|
282 | end | |
283 |
|
283 | |||
284 | def test_latest_changesets_tag_with_limit |
|
284 | def test_latest_changesets_tag_with_limit | |
285 | assert_equal 0, @repository.changesets.count |
|
285 | assert_equal 0, @repository.changesets.count | |
286 | @repository.fetch_changesets |
|
286 | @repository.fetch_changesets | |
287 | @project.reload |
|
287 | @project.reload | |
288 | assert_equal NUM_REV, @repository.changesets.count |
|
288 | assert_equal NUM_REV, @repository.changesets.count | |
289 |
|
289 | |||
290 | changesets = @repository.latest_changesets('', 'tag_test.00', 2) |
|
290 | changesets = @repository.latest_changesets('', 'tag_test.00', 2) | |
291 | assert_equal %w|5 4|, changesets.collect(&:revision) |
|
291 | assert_equal %w|5 4|, changesets.collect(&:revision) | |
292 |
|
292 | |||
293 | changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) |
|
293 | changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) | |
294 | assert_equal %w|4 3|, changesets.collect(&:revision) |
|
294 | assert_equal %w|4 3|, changesets.collect(&:revision) | |
295 | end |
|
295 | end | |
296 |
|
296 | |||
297 | def test_latest_changesets_branch |
|
297 | def test_latest_changesets_branch | |
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 |
|
302 | |||
303 | if @repository.scm.class.client_version_above?([1, 6]) |
|
303 | if @repository.scm.class.client_version_above?([1, 6]) | |
304 | changesets = @repository.latest_changesets('', @branch_char_1) |
|
304 | changesets = @repository.latest_changesets('', @branch_char_1) | |
305 | assert_equal %w|27 26|, changesets.collect(&:revision) |
|
305 | assert_equal %w|27 26|, changesets.collect(&:revision) | |
306 | end |
|
306 | end | |
307 |
|
307 | |||
308 | changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) |
|
308 | changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) | |
309 | assert_equal %w|27|, changesets.collect(&:revision) |
|
309 | assert_equal %w|27|, changesets.collect(&:revision) | |
310 | end |
|
310 | end | |
311 |
|
311 | |||
312 | def assert_latest_changesets_default_branch |
|
312 | def assert_latest_changesets_default_branch | |
313 | changesets = @repository.latest_changesets('', 'default') |
|
313 | changesets = @repository.latest_changesets('', 'default') | |
314 | assert_equal %w|31 28 24 6 4 3 2 1 0|, changesets.collect(&:revision) |
|
314 | assert_equal %w|31 28 24 6 4 3 2 1 0|, changesets.collect(&:revision) | |
315 | end |
|
315 | end | |
316 | private :assert_latest_changesets_default_branch |
|
316 | private :assert_latest_changesets_default_branch | |
317 |
|
317 | |||
318 | def test_latest_changesets_default_branch |
|
318 | def test_latest_changesets_default_branch | |
319 | assert_equal 0, @repository.changesets.count |
|
319 | assert_equal 0, @repository.changesets.count | |
320 | @repository.fetch_changesets |
|
320 | @repository.fetch_changesets | |
321 | @project.reload |
|
321 | @project.reload | |
322 | assert_equal NUM_REV, @repository.changesets.count |
|
322 | assert_equal NUM_REV, @repository.changesets.count | |
323 | assert_latest_changesets_default_branch |
|
323 | assert_latest_changesets_default_branch | |
324 | end |
|
324 | end | |
325 |
|
325 | |||
326 | def assert_copied_files |
|
326 | def assert_copied_files | |
327 | cs1 = @repository.changesets.find_by_revision('13') |
|
327 | cs1 = @repository.changesets.find_by_revision('13') | |
328 | assert_not_nil cs1 |
|
328 | assert_not_nil cs1 | |
329 | c1 = cs1.filechanges.sort_by(&:path) |
|
329 | c1 = cs1.filechanges.sort_by(&:path) | |
330 | assert_equal 2, c1.size |
|
330 | assert_equal 2, c1.size | |
331 |
|
331 | |||
332 | assert_equal 'A', c1[0].action |
|
332 | assert_equal 'A', c1[0].action | |
333 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path |
|
333 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path | |
334 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path |
|
334 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path | |
335 | assert_equal '3a330eb32958', c1[0].from_revision |
|
335 | assert_equal '3a330eb32958', c1[0].from_revision | |
336 |
|
336 | |||
337 | assert_equal 'A', c1[1].action |
|
337 | assert_equal 'A', c1[1].action | |
338 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path |
|
338 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path | |
339 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path |
|
339 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path | |
340 |
|
340 | |||
341 | cs2 = @repository.changesets.find_by_revision('15') |
|
341 | cs2 = @repository.changesets.find_by_revision('15') | |
342 | c2 = cs2.filechanges |
|
342 | c2 = cs2.filechanges | |
343 | assert_equal 1, c2.size |
|
343 | assert_equal 1, c2.size | |
344 |
|
344 | |||
345 | assert_equal 'A', c2[0].action |
|
345 | assert_equal 'A', c2[0].action | |
346 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
|
346 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path | |
347 | assert_equal '/README', c2[0].from_path |
|
347 | assert_equal '/README', c2[0].from_path | |
348 | assert_equal '933ca60293d7', c2[0].from_revision |
|
348 | assert_equal '933ca60293d7', c2[0].from_revision | |
349 |
|
349 | |||
350 | cs3 = @repository.changesets.find_by_revision('19') |
|
350 | cs3 = @repository.changesets.find_by_revision('19') | |
351 | c3 = cs3.filechanges |
|
351 | c3 = cs3.filechanges | |
352 | assert_equal 1, c3.size |
|
352 | assert_equal 1, c3.size | |
353 | assert_equal 'A', c3[0].action |
|
353 | assert_equal 'A', c3[0].action | |
354 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path |
|
354 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path | |
355 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path |
|
355 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path | |
356 | assert_equal '5d9891a1b425', c3[0].from_revision |
|
356 | assert_equal '5d9891a1b425', c3[0].from_revision | |
357 | end |
|
357 | end | |
358 | private :assert_copied_files |
|
358 | private :assert_copied_files | |
359 |
|
359 | |||
360 | def test_copied_files_short_id |
|
360 | def test_copied_files_short_id | |
361 | assert_equal 0, @repository.changesets.count |
|
361 | assert_equal 0, @repository.changesets.count | |
362 | @repository.fetch_changesets |
|
362 | @repository.fetch_changesets | |
363 | @project.reload |
|
363 | @project.reload | |
364 | assert_equal NUM_REV, @repository.changesets.count |
|
364 | assert_equal NUM_REV, @repository.changesets.count | |
365 | assert_copied_files |
|
365 | assert_copied_files | |
366 | end |
|
366 | end | |
367 |
|
367 | |||
368 | def test_find_changeset_by_name |
|
368 | def test_find_changeset_by_name | |
369 | assert_equal 0, @repository.changesets.count |
|
369 | assert_equal 0, @repository.changesets.count | |
370 | @repository.fetch_changesets |
|
370 | @repository.fetch_changesets | |
371 | @project.reload |
|
371 | @project.reload | |
372 | assert_equal NUM_REV, @repository.changesets.count |
|
372 | assert_equal NUM_REV, @repository.changesets.count | |
373 | %w|2 400bb8672109 400|.each do |r| |
|
373 | %w|2 400bb8672109 400|.each do |r| | |
374 | assert_equal '2', @repository.find_changeset_by_name(r).revision |
|
374 | assert_equal '2', @repository.find_changeset_by_name(r).revision | |
375 | end |
|
375 | end | |
376 | end |
|
376 | end | |
377 |
|
377 | |||
378 | def test_find_changeset_by_invalid_name |
|
378 | def test_find_changeset_by_invalid_name | |
379 | assert_equal 0, @repository.changesets.count |
|
379 | assert_equal 0, @repository.changesets.count | |
380 | @repository.fetch_changesets |
|
380 | @repository.fetch_changesets | |
381 | @project.reload |
|
381 | @project.reload | |
382 | assert_equal NUM_REV, @repository.changesets.count |
|
382 | assert_equal NUM_REV, @repository.changesets.count | |
383 | assert_nil @repository.find_changeset_by_name('100000') |
|
383 | assert_nil @repository.find_changeset_by_name('100000') | |
384 | end |
|
384 | end | |
385 |
|
385 | |||
386 | def test_identifier |
|
386 | def test_identifier | |
387 | assert_equal 0, @repository.changesets.count |
|
387 | assert_equal 0, @repository.changesets.count | |
388 | @repository.fetch_changesets |
|
388 | @repository.fetch_changesets | |
389 | @project.reload |
|
389 | @project.reload | |
390 | assert_equal NUM_REV, @repository.changesets.count |
|
390 | assert_equal NUM_REV, @repository.changesets.count | |
391 | c = @repository.changesets.find_by_revision('2') |
|
391 | c = @repository.changesets.find_by_revision('2') | |
392 | assert_equal c.scmid, c.identifier |
|
392 | assert_equal c.scmid, c.identifier | |
393 | end |
|
393 | end | |
394 |
|
394 | |||
395 | def test_format_identifier |
|
395 | def test_format_identifier | |
396 | assert_equal 0, @repository.changesets.count |
|
396 | assert_equal 0, @repository.changesets.count | |
397 | @repository.fetch_changesets |
|
397 | @repository.fetch_changesets | |
398 | @project.reload |
|
398 | @project.reload | |
399 | assert_equal NUM_REV, @repository.changesets.count |
|
399 | assert_equal NUM_REV, @repository.changesets.count | |
400 | c = @repository.changesets.find_by_revision('2') |
|
400 | c = @repository.changesets.find_by_revision('2') | |
401 | assert_equal '2:400bb8672109', c.format_identifier |
|
401 | assert_equal '2:400bb8672109', c.format_identifier | |
402 | end |
|
402 | end | |
403 |
|
403 | |||
404 | def test_format_identifier_long_id |
|
404 | def test_format_identifier_long_id | |
405 | assert_equal 0, @repository.changesets.count |
|
405 | assert_equal 0, @repository.changesets.count | |
406 | Changeset.create!(:repository => @repository, |
|
406 | Changeset.create!(:repository => @repository, | |
407 | :committed_on => Time.now, |
|
407 | :committed_on => Time.now, | |
408 | :revision => '0', |
|
408 | :revision => '0', | |
409 | :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce', |
|
409 | :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce', | |
410 | :comments => 'test') |
|
410 | :comments => 'test') | |
411 | c = @repository.changesets.find_by_revision('0') |
|
411 | c = @repository.changesets.find_by_revision('0') | |
412 | assert_equal '0:0885933ad4f6', c.format_identifier |
|
412 | assert_equal '0:0885933ad4f6', c.format_identifier | |
413 | end |
|
413 | end | |
414 |
|
414 | |||
415 | def test_find_changeset_by_empty_name |
|
415 | def test_find_changeset_by_empty_name | |
416 | assert_equal 0, @repository.changesets.count |
|
416 | assert_equal 0, @repository.changesets.count | |
417 | @repository.fetch_changesets |
|
417 | @repository.fetch_changesets | |
418 | @project.reload |
|
418 | @project.reload | |
419 | assert_equal NUM_REV, @repository.changesets.count |
|
419 | assert_equal NUM_REV, @repository.changesets.count | |
420 | ['', ' ', nil].each do |r| |
|
420 | ['', ' ', nil].each do |r| | |
421 | assert_nil @repository.find_changeset_by_name(r) |
|
421 | assert_nil @repository.find_changeset_by_name(r) | |
422 | end |
|
422 | end | |
423 | end |
|
423 | end | |
424 |
|
424 | |||
425 |
def |
|
425 | def assert_parents | |
426 | assert_equal 0, @repository.changesets.count |
|
|||
427 | @repository.fetch_changesets |
|
|||
428 | @project.reload |
|
|||
429 | assert_equal NUM_REV, @repository.changesets.count |
|
|||
430 | r1 = @repository.changesets.find_by_revision('0') |
|
426 | r1 = @repository.changesets.find_by_revision('0') | |
431 | assert_equal [], r1.parents |
|
427 | assert_equal [], r1.parents | |
432 | r2 = @repository.changesets.find_by_revision('1') |
|
428 | r2 = @repository.changesets.find_by_revision('1') | |
433 | assert_equal 1, r2.parents.length |
|
429 | assert_equal 1, r2.parents.length | |
434 | assert_equal "0885933ad4f6", |
|
430 | assert_equal "0885933ad4f6", | |
435 | r2.parents[0].identifier |
|
431 | r2.parents[0].identifier | |
436 | r3 = @repository.changesets.find_by_revision('30') |
|
432 | r3 = @repository.changesets.find_by_revision('30') | |
437 | assert_equal 2, r3.parents.length |
|
433 | assert_equal 2, r3.parents.length | |
438 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort |
|
434 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort | |
439 | assert_equal "3a330eb32958", r4[0] |
|
435 | assert_equal "3a330eb32958", r4[0] | |
440 | assert_equal "a94b0528f24f", r4[1] |
|
436 | assert_equal "a94b0528f24f", r4[1] | |
441 | end |
|
437 | end | |
|
438 | private :assert_parents | |||
|
439 | ||||
|
440 | def test_parents_short_id | |||
|
441 | assert_equal 0, @repository.changesets.count | |||
|
442 | @repository.fetch_changesets | |||
|
443 | @project.reload | |||
|
444 | assert_equal NUM_REV, @repository.changesets.count | |||
|
445 | assert_parents | |||
|
446 | end | |||
442 |
|
447 | |||
443 | def test_activities |
|
448 | def test_activities | |
444 | c = Changeset.new(:repository => @repository, |
|
449 | c = Changeset.new(:repository => @repository, | |
445 | :committed_on => Time.now, |
|
450 | :committed_on => Time.now, | |
446 | :revision => '123', |
|
451 | :revision => '123', | |
447 | :scmid => 'abc400bb8672', |
|
452 | :scmid => 'abc400bb8672', | |
448 | :comments => 'test') |
|
453 | :comments => 'test') | |
449 | assert c.event_title.include?('123:abc400bb8672:') |
|
454 | assert c.event_title.include?('123:abc400bb8672:') | |
450 | assert_equal 'abc400bb8672', c.event_url[:rev] |
|
455 | assert_equal 'abc400bb8672', c.event_url[:rev] | |
451 | end |
|
456 | end | |
452 |
|
457 | |||
453 | def test_previous |
|
458 | def test_previous | |
454 | assert_equal 0, @repository.changesets.count |
|
459 | assert_equal 0, @repository.changesets.count | |
455 | @repository.fetch_changesets |
|
460 | @repository.fetch_changesets | |
456 | @project.reload |
|
461 | @project.reload | |
457 | assert_equal NUM_REV, @repository.changesets.count |
|
462 | assert_equal NUM_REV, @repository.changesets.count | |
458 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
463 | %w|28 3ae45e2d177d 3ae45|.each do |r1| | |
459 | changeset = @repository.find_changeset_by_name(r1) |
|
464 | changeset = @repository.find_changeset_by_name(r1) | |
460 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
465 | %w|27 7bbf4c738e71 7bbf|.each do |r2| | |
461 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
466 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous | |
462 | end |
|
467 | end | |
463 | end |
|
468 | end | |
464 | end |
|
469 | end | |
465 |
|
470 | |||
466 | def test_previous_nil |
|
471 | def test_previous_nil | |
467 | assert_equal 0, @repository.changesets.count |
|
472 | assert_equal 0, @repository.changesets.count | |
468 | @repository.fetch_changesets |
|
473 | @repository.fetch_changesets | |
469 | @project.reload |
|
474 | @project.reload | |
470 | assert_equal NUM_REV, @repository.changesets.count |
|
475 | assert_equal NUM_REV, @repository.changesets.count | |
471 | %w|0 0885933ad4f6 0885|.each do |r1| |
|
476 | %w|0 0885933ad4f6 0885|.each do |r1| | |
472 | changeset = @repository.find_changeset_by_name(r1) |
|
477 | changeset = @repository.find_changeset_by_name(r1) | |
473 | assert_nil changeset.previous |
|
478 | assert_nil changeset.previous | |
474 | end |
|
479 | end | |
475 | end |
|
480 | end | |
476 |
|
481 | |||
477 | def test_next |
|
482 | def test_next | |
478 | assert_equal 0, @repository.changesets.count |
|
483 | assert_equal 0, @repository.changesets.count | |
479 | @repository.fetch_changesets |
|
484 | @repository.fetch_changesets | |
480 | @project.reload |
|
485 | @project.reload | |
481 | assert_equal NUM_REV, @repository.changesets.count |
|
486 | assert_equal NUM_REV, @repository.changesets.count | |
482 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
487 | %w|27 7bbf4c738e71 7bbf|.each do |r2| | |
483 | changeset = @repository.find_changeset_by_name(r2) |
|
488 | changeset = @repository.find_changeset_by_name(r2) | |
484 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
489 | %w|28 3ae45e2d177d 3ae45|.each do |r1| | |
485 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
490 | assert_equal @repository.find_changeset_by_name(r1), changeset.next | |
486 | end |
|
491 | end | |
487 | end |
|
492 | end | |
488 | end |
|
493 | end | |
489 |
|
494 | |||
490 | def test_next_nil |
|
495 | def test_next_nil | |
491 | assert_equal 0, @repository.changesets.count |
|
496 | assert_equal 0, @repository.changesets.count | |
492 | @repository.fetch_changesets |
|
497 | @repository.fetch_changesets | |
493 | @project.reload |
|
498 | @project.reload | |
494 | assert_equal NUM_REV, @repository.changesets.count |
|
499 | assert_equal NUM_REV, @repository.changesets.count | |
495 | %w|31 31eeee7395c8 31eee|.each do |r1| |
|
500 | %w|31 31eeee7395c8 31eee|.each do |r1| | |
496 | changeset = @repository.find_changeset_by_name(r1) |
|
501 | changeset = @repository.find_changeset_by_name(r1) | |
497 | assert_nil changeset.next |
|
502 | assert_nil changeset.next | |
498 | end |
|
503 | end | |
499 | end |
|
504 | end | |
500 | else |
|
505 | else | |
501 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
506 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
502 | def test_fake; assert true end |
|
507 | def test_fake; assert true end | |
503 | end |
|
508 | end | |
504 | end |
|
509 | end |
General Comments 0
You need to be logged in to leave comments.
Login now