##// END OF EJS Templates
scm: mercurial: remove duplicates tests in unit model test....
Toshi MARUYAMA -
r4970:cb8c2d59bf75
parent child
Show More
@@ -1,244 +1,237
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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 # No '..' in the repository path
23 # No '..' in the repository path
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
25
25
26 CHAR_1_HEX = "\xc3\x9c"
26 CHAR_1_HEX = "\xc3\x9c"
27
27
28 def setup
28 def setup
29 @project = Project.find(3)
29 @project = Project.find(3)
30 @repository = Repository::Mercurial.create(
30 @repository = Repository::Mercurial.create(
31 :project => @project,
31 :project => @project,
32 :url => REPOSITORY_PATH,
32 :url => REPOSITORY_PATH,
33 :path_encoding => 'ISO-8859-1'
33 :path_encoding => 'ISO-8859-1'
34 )
34 )
35 assert @repository
35 assert @repository
36 @char_1 = CHAR_1_HEX.dup
36 @char_1 = CHAR_1_HEX.dup
37 if @char_1.respond_to?(:force_encoding)
37 if @char_1.respond_to?(:force_encoding)
38 @char_1.force_encoding('UTF-8')
38 @char_1.force_encoding('UTF-8')
39 end
39 end
40 end
40 end
41
41
42 if File.directory?(REPOSITORY_PATH)
42 if File.directory?(REPOSITORY_PATH)
43 def test_fetch_changesets_from_scratch
43 def test_fetch_changesets_from_scratch
44 @repository.fetch_changesets
44 @repository.fetch_changesets
45 @repository.reload
45 @repository.reload
46 assert_equal 29, @repository.changesets.count
46 assert_equal 29, @repository.changesets.count
47 assert_equal 37, @repository.changes.count
47 assert_equal 37, @repository.changes.count
48 assert_equal "Initial import.\nThe repository contains 3 files.",
48 assert_equal "Initial import.\nThe repository contains 3 files.",
49 @repository.changesets.find_by_revision('0').comments
49 @repository.changesets.find_by_revision('0').comments
50 end
50 end
51
51
52 def test_fetch_changesets_incremental
52 def test_fetch_changesets_incremental
53 @repository.fetch_changesets
53 @repository.fetch_changesets
54 # Remove changesets with revision > 2
54 # Remove changesets with revision > 2
55 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
55 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
56 @repository.reload
56 @repository.reload
57 assert_equal 3, @repository.changesets.count
57 assert_equal 3, @repository.changesets.count
58
58
59 @repository.fetch_changesets
59 @repository.fetch_changesets
60 assert_equal 29, @repository.changesets.count
60 assert_equal 29, @repository.changesets.count
61 end
61 end
62
62
63 def test_isodatesec
63 def test_isodatesec
64 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
64 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
65 if @repository.scm.class.client_version_above?([1, 0])
65 if @repository.scm.class.client_version_above?([1, 0])
66 @repository.fetch_changesets
66 @repository.fetch_changesets
67 @repository.reload
67 @repository.reload
68 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
68 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
69 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
69 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
70 end
70 end
71 end
71 end
72
72
73 def test_changeset_order_by_revision
73 def test_changeset_order_by_revision
74 @repository.fetch_changesets
74 @repository.fetch_changesets
75 @repository.reload
75 @repository.reload
76
76
77 c0 = @repository.latest_changeset
77 c0 = @repository.latest_changeset
78 c1 = @repository.changesets.find_by_revision('0')
78 c1 = @repository.changesets.find_by_revision('0')
79 # sorted by revision (id), not by date
79 # sorted by revision (id), not by date
80 assert c0.revision.to_i > c1.revision.to_i
80 assert c0.revision.to_i > c1.revision.to_i
81 assert c0.committed_on < c1.committed_on
81 assert c0.committed_on < c1.committed_on
82 end
82 end
83
83
84 def test_latest_changesets
84 def test_latest_changesets
85 @repository.fetch_changesets
85 @repository.fetch_changesets
86 @repository.reload
86 @repository.reload
87
87
88 # with_limit
88 # with_limit
89 changesets = @repository.latest_changesets('', nil, 2)
89 changesets = @repository.latest_changesets('', nil, 2)
90 assert_equal %w|28 27|, changesets.collect(&:revision)
90 assert_equal %w|28 27|, changesets.collect(&:revision)
91
91
92 # with_filepath
92 # with_filepath
93 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil)
93 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil)
94 assert_equal %w|11 10 9|, changesets.collect(&:revision)
94 assert_equal %w|11 10 9|, changesets.collect(&:revision)
95
95
96 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil)
96 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil)
97 assert_equal %w|12 9|, changesets.collect(&:revision)
97 assert_equal %w|12 9|, changesets.collect(&:revision)
98
98
99 changesets = @repository.latest_changesets('README', nil)
99 changesets = @repository.latest_changesets('README', nil)
100 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision)
100 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision)
101
101
102 # with_dirpath
102 # with_dirpath
103 changesets = @repository.latest_changesets('images', nil)
103 changesets = @repository.latest_changesets('images', nil)
104 assert_equal %w|1 0|, changesets.collect(&:revision)
104 assert_equal %w|1 0|, changesets.collect(&:revision)
105
105
106 path = 'sql_escape/percent%dir'
106 path = 'sql_escape/percent%dir'
107 changesets = @repository.latest_changesets(path, nil)
107 changesets = @repository.latest_changesets(path, nil)
108 assert_equal %w|13 11 10 9|, changesets.collect(&:revision)
108 assert_equal %w|13 11 10 9|, changesets.collect(&:revision)
109
109
110 path = 'sql_escape/underscore_dir'
110 path = 'sql_escape/underscore_dir'
111 changesets = @repository.latest_changesets(path, nil)
111 changesets = @repository.latest_changesets(path, nil)
112 assert_equal %w|13 12 9|, changesets.collect(&:revision)
112 assert_equal %w|13 12 9|, changesets.collect(&:revision)
113 end
113 end
114
114
115 def test_copied_files
115 def test_copied_files
116 @repository.fetch_changesets
116 @repository.fetch_changesets
117 @repository.reload
117 @repository.reload
118
118
119 cs1 = @repository.changesets.find_by_revision('13')
119 cs1 = @repository.changesets.find_by_revision('13')
120 assert_not_nil cs1
120 assert_not_nil cs1
121 c1 = cs1.changes.sort_by(&:path)
121 c1 = cs1.changes.sort_by(&:path)
122 assert_equal 2, c1.size
122 assert_equal 2, c1.size
123
123
124 assert_equal 'A', c1[0].action
124 assert_equal 'A', c1[0].action
125 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
125 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
126 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
126 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
127
127
128 assert_equal 'A', c1[1].action
128 assert_equal 'A', c1[1].action
129 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
129 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
130 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
130 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
131
131
132 cs2 = @repository.changesets.find_by_revision('15')
132 cs2 = @repository.changesets.find_by_revision('15')
133 c2 = cs2.changes
133 c2 = cs2.changes
134 assert_equal 1, c2.size
134 assert_equal 1, c2.size
135
135
136 assert_equal 'A', c2[0].action
136 assert_equal 'A', c2[0].action
137 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
137 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
138 assert_equal '/README', c2[0].from_path
138 assert_equal '/README', c2[0].from_path
139
139
140 cs3 = @repository.changesets.find_by_revision('19')
140 cs3 = @repository.changesets.find_by_revision('19')
141 c3 = cs3.changes
141 c3 = cs3.changes
142 assert_equal 1, c3.size
142 assert_equal 1, c3.size
143 assert_equal 'A', c3[0].action
143 assert_equal 'A', c3[0].action
144 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
144 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
145 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
145 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
146 end
146 end
147
147
148 def test_find_changeset_by_name
148 def test_find_changeset_by_name
149 @repository.fetch_changesets
149 @repository.fetch_changesets
150 @repository.reload
150 @repository.reload
151 %w|2 400bb8672109 400|.each do |r|
151 %w|2 400bb8672109 400|.each do |r|
152 assert_equal '2', @repository.find_changeset_by_name(r).revision
152 assert_equal '2', @repository.find_changeset_by_name(r).revision
153 end
153 end
154 end
154 end
155
155
156 def test_find_changeset_by_invalid_name
156 def test_find_changeset_by_invalid_name
157 @repository.fetch_changesets
157 @repository.fetch_changesets
158 @repository.reload
158 @repository.reload
159 assert_nil @repository.find_changeset_by_name('100000')
159 assert_nil @repository.find_changeset_by_name('100000')
160 end
160 end
161
161
162 def test_identifier
162 def test_identifier
163 @repository.fetch_changesets
163 @repository.fetch_changesets
164 @repository.reload
164 @repository.reload
165 c = @repository.changesets.find_by_revision('2')
165 c = @repository.changesets.find_by_revision('2')
166 assert_equal c.scmid, c.identifier
166 assert_equal c.scmid, c.identifier
167 end
167 end
168
168
169 def test_format_identifier
169 def test_format_identifier
170 @repository.fetch_changesets
170 @repository.fetch_changesets
171 @repository.reload
171 @repository.reload
172 c = @repository.changesets.find_by_revision('2')
172 c = @repository.changesets.find_by_revision('2')
173 assert_equal '2:400bb8672109', c.format_identifier
173 assert_equal '2:400bb8672109', c.format_identifier
174 end
174 end
175
175
176 def test_find_changeset_by_empty_name
176 def test_find_changeset_by_empty_name
177 @repository.fetch_changesets
177 @repository.fetch_changesets
178 @repository.reload
178 @repository.reload
179 ['', ' ', nil].each do |r|
179 ['', ' ', nil].each do |r|
180 assert_nil @repository.find_changeset_by_name(r)
180 assert_nil @repository.find_changeset_by_name(r)
181 end
181 end
182 end
182 end
183
183
184 def test_activities
184 def test_activities
185 c = Changeset.new(:repository => @repository,
185 c = Changeset.new(:repository => @repository,
186 :committed_on => Time.now,
186 :committed_on => Time.now,
187 :revision => '123',
187 :revision => '123',
188 :scmid => 'abc400bb8672',
188 :scmid => 'abc400bb8672',
189 :comments => 'test')
189 :comments => 'test')
190 assert c.event_title.include?('123:abc400bb8672:')
190 assert c.event_title.include?('123:abc400bb8672:')
191 assert_equal 'abc400bb8672', c.event_url[:rev]
191 assert_equal 'abc400bb8672', c.event_url[:rev]
192 end
192 end
193
193
194 def test_latest_changesets_with_limit
195 @repository.fetch_changesets
196 @repository.reload
197 changesets = @repository.latest_changesets('', nil, 2)
198 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
199 end
200
201 def test_previous
194 def test_previous
202 @repository.fetch_changesets
195 @repository.fetch_changesets
203 @repository.reload
196 @repository.reload
204 %w|28 3ae45e2d177d 3ae45|.each do |r1|
197 %w|28 3ae45e2d177d 3ae45|.each do |r1|
205 changeset = @repository.find_changeset_by_name(r1)
198 changeset = @repository.find_changeset_by_name(r1)
206 %w|27 7bbf4c738e71 7bbf|.each do |r2|
199 %w|27 7bbf4c738e71 7bbf|.each do |r2|
207 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
200 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
208 end
201 end
209 end
202 end
210 end
203 end
211
204
212 def test_previous_nil
205 def test_previous_nil
213 @repository.fetch_changesets
206 @repository.fetch_changesets
214 @repository.reload
207 @repository.reload
215 %w|0 0885933ad4f6 0885|.each do |r1|
208 %w|0 0885933ad4f6 0885|.each do |r1|
216 changeset = @repository.find_changeset_by_name(r1)
209 changeset = @repository.find_changeset_by_name(r1)
217 assert_nil changeset.previous
210 assert_nil changeset.previous
218 end
211 end
219 end
212 end
220
213
221 def test_next
214 def test_next
222 @repository.fetch_changesets
215 @repository.fetch_changesets
223 @repository.reload
216 @repository.reload
224 %w|27 7bbf4c738e71 7bbf|.each do |r2|
217 %w|27 7bbf4c738e71 7bbf|.each do |r2|
225 changeset = @repository.find_changeset_by_name(r2)
218 changeset = @repository.find_changeset_by_name(r2)
226 %w|28 3ae45e2d177d 3ae45|.each do |r1|
219 %w|28 3ae45e2d177d 3ae45|.each do |r1|
227 assert_equal @repository.find_changeset_by_name(r1), changeset.next
220 assert_equal @repository.find_changeset_by_name(r1), changeset.next
228 end
221 end
229 end
222 end
230 end
223 end
231
224
232 def test_next_nil
225 def test_next_nil
233 @repository.fetch_changesets
226 @repository.fetch_changesets
234 @repository.reload
227 @repository.reload
235 %w|28 3ae45e2d177d 3ae45|.each do |r1|
228 %w|28 3ae45e2d177d 3ae45|.each do |r1|
236 changeset = @repository.find_changeset_by_name(r1)
229 changeset = @repository.find_changeset_by_name(r1)
237 assert_nil changeset.next
230 assert_nil changeset.next
238 end
231 end
239 end
232 end
240 else
233 else
241 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
234 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
242 def test_fake; assert true end
235 def test_fake; assert true end
243 end
236 end
244 end
237 end
General Comments 0
You need to be logged in to leave comments. Login now