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