comparison test/unit/repository_mercurial_test.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 051f544170fe
children 753f1380d6bc cbb26bc654de
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
8 # 8 #
9 # This program is distributed in the hope that it will be useful, 9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details. 12 # GNU General Public License for more details.
13 # 13 #
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 class RepositoryMercurialTest < ActiveSupport::TestCase 20 class RepositoryMercurialTest < ActiveSupport::TestCase
21 fixtures :projects 21 fixtures :projects
22 22
23 # 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 def setup 26 CHAR_1_HEX = "\xc3\x9c"
27 @project = Project.find(3) 27
28 @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH) 28 if File.directory?(REPOSITORY_PATH)
29 assert @repository 29
30 end 30 def setup
31 31 klass = Repository::Mercurial
32 if File.directory?(REPOSITORY_PATH) 32 assert_equal "Mercurial", klass.scm_name
33 assert klass.scm_adapter_class
34 assert_not_equal "", klass.scm_command
35 assert_equal true, klass.scm_available
36
37 @project = Project.find(3)
38 @repository = Repository::Mercurial.create(
39 :project => @project,
40 :url => REPOSITORY_PATH,
41 :path_encoding => 'ISO-8859-1'
42 )
43 assert @repository
44 @char_1 = CHAR_1_HEX.dup
45 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
46 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
47 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
48 if @char_1.respond_to?(:force_encoding)
49 @char_1.force_encoding('UTF-8')
50 @tag_char_1.force_encoding('UTF-8')
51 @branch_char_0.force_encoding('UTF-8')
52 @branch_char_1.force_encoding('UTF-8')
53 end
54 end
55
33 def test_fetch_changesets_from_scratch 56 def test_fetch_changesets_from_scratch
34 @repository.fetch_changesets 57 @repository.fetch_changesets
35 @repository.reload 58 @repository.reload
36 assert_equal 17, @repository.changesets.count 59 assert_equal 29, @repository.changesets.count
37 assert_equal 25, @repository.changes.count 60 assert_equal 37, @repository.changes.count
38 assert_equal "Initial import.\nThe repository contains 3 files.", 61 assert_equal "Initial import.\nThe repository contains 3 files.",
39 @repository.changesets.find_by_revision('0').comments 62 @repository.changesets.find_by_revision('0').comments
40 end 63 end
41 64
42 def test_fetch_changesets_incremental 65 def test_fetch_changesets_incremental
43 @repository.fetch_changesets 66 @repository.fetch_changesets
44 # Remove changesets with revision > 2 67 # Remove changesets with revision > 2
45 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} 68 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
46 @repository.reload 69 @repository.reload
47 assert_equal 3, @repository.changesets.count 70 assert_equal 3, @repository.changesets.count
48 71
49 @repository.fetch_changesets 72 @repository.fetch_changesets
50 assert_equal 17, @repository.changesets.count 73 assert_equal 29, @repository.changesets.count
51 end 74 end
52 75
53 def test_isodatesec 76 def test_isodatesec
54 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher 77 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
55 if @repository.scm.class.client_version_above?([1, 0]) 78 if @repository.scm.class.client_version_above?([1, 0])
75 @repository.fetch_changesets 98 @repository.fetch_changesets
76 @repository.reload 99 @repository.reload
77 100
78 # with_limit 101 # with_limit
79 changesets = @repository.latest_changesets('', nil, 2) 102 changesets = @repository.latest_changesets('', nil, 2)
80 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets 103 assert_equal %w|28 27|, changesets.collect(&:revision)
81 104
82 # with_filepath 105 # with_filepath
83 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil) 106 changesets = @repository.latest_changesets(
107 '/sql_escape/percent%dir/percent%file1.txt', nil)
84 assert_equal %w|11 10 9|, changesets.collect(&:revision) 108 assert_equal %w|11 10 9|, changesets.collect(&:revision)
85 109
86 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil) 110 changesets = @repository.latest_changesets(
111 '/sql_escape/underscore_dir/understrike_file.txt', nil)
87 assert_equal %w|12 9|, changesets.collect(&:revision) 112 assert_equal %w|12 9|, changesets.collect(&:revision)
113
114 changesets = @repository.latest_changesets('README', nil)
115 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision)
116
117 changesets = @repository.latest_changesets('README','8')
118 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
119
120 changesets = @repository.latest_changesets('README','8', 2)
121 assert_equal %w|8 6|, changesets.collect(&:revision)
122
123 # with_dirpath
124 changesets = @repository.latest_changesets('images', nil)
125 assert_equal %w|1 0|, changesets.collect(&:revision)
126
127 path = 'sql_escape/percent%dir'
128 changesets = @repository.latest_changesets(path, nil)
129 assert_equal %w|13 11 10 9|, changesets.collect(&:revision)
130
131 changesets = @repository.latest_changesets(path, '11')
132 assert_equal %w|11 10 9|, changesets.collect(&:revision)
133
134 changesets = @repository.latest_changesets(path, '11', 2)
135 assert_equal %w|11 10|, changesets.collect(&:revision)
136
137 path = 'sql_escape/underscore_dir'
138 changesets = @repository.latest_changesets(path, nil)
139 assert_equal %w|13 12 9|, changesets.collect(&:revision)
140
141 changesets = @repository.latest_changesets(path, '12')
142 assert_equal %w|12 9|, changesets.collect(&:revision)
143
144 changesets = @repository.latest_changesets(path, '12', 1)
145 assert_equal %w|12|, changesets.collect(&:revision)
146
147 # tag
148 changesets = @repository.latest_changesets('', 'tag_test.00')
149 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
150
151 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
152 assert_equal %w|5 4|, changesets.collect(&:revision)
153
154 changesets = @repository.latest_changesets('sources', 'tag_test.00')
155 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
156
157 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
158 assert_equal %w|4 3|, changesets.collect(&:revision)
159
160 # named branch
161 changesets = @repository.latest_changesets('', @branch_char_1)
162 assert_equal %w|27 26|, changesets.collect(&:revision)
163
164 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
165 assert_equal %w|27|, changesets.collect(&:revision)
88 end 166 end
89 167
90 def test_copied_files 168 def test_copied_files
91 @repository.fetch_changesets 169 @repository.fetch_changesets
92 @repository.reload 170 @repository.reload
97 assert_equal 2, c1.size 175 assert_equal 2, c1.size
98 176
99 assert_equal 'A', c1[0].action 177 assert_equal 'A', c1[0].action
100 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path 178 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
101 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path 179 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
180 assert_equal '3a330eb32958', c1[0].from_revision
102 181
103 assert_equal 'A', c1[1].action 182 assert_equal 'A', c1[1].action
104 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path 183 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
105 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path 184 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
106 185
109 assert_equal 1, c2.size 188 assert_equal 1, c2.size
110 189
111 assert_equal 'A', c2[0].action 190 assert_equal 'A', c2[0].action
112 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path 191 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
113 assert_equal '/README', c2[0].from_path 192 assert_equal '/README', c2[0].from_path
193 assert_equal '933ca60293d7', c2[0].from_revision
194
195 cs3 = @repository.changesets.find_by_revision('19')
196 c3 = cs3.changes
197 assert_equal 1, c3.size
198 assert_equal 'A', c3[0].action
199 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
200 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
201 assert_equal '5d9891a1b425', c3[0].from_revision
114 end 202 end
115 203
116 def test_find_changeset_by_name 204 def test_find_changeset_by_name
117 @repository.fetch_changesets 205 @repository.fetch_changesets
118 @repository.reload 206 @repository.reload
157 :comments => 'test') 245 :comments => 'test')
158 assert c.event_title.include?('123:abc400bb8672:') 246 assert c.event_title.include?('123:abc400bb8672:')
159 assert_equal 'abc400bb8672', c.event_url[:rev] 247 assert_equal 'abc400bb8672', c.event_url[:rev]
160 end 248 end
161 249
162 def test_latest_changesets_with_limit 250 def test_previous
163 @repository.fetch_changesets 251 @repository.fetch_changesets
164 @repository.reload 252 @repository.reload
165 changesets = @repository.latest_changesets('', nil, 2) 253 %w|28 3ae45e2d177d 3ae45|.each do |r1|
166 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets 254 changeset = @repository.find_changeset_by_name(r1)
167 end 255 %w|27 7bbf4c738e71 7bbf|.each do |r2|
168 256 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
169 def test_latest_changesets_with_filepath 257 end
170 @repository.fetch_changesets 258 end
171 @repository.reload 259 end
172 changesets = @repository.latest_changesets('README', nil) 260
173 assert_equal %w|8 6 1 0|, changesets.collect(&:revision) 261 def test_previous_nil
174 262 @repository.fetch_changesets
175 path = 'sql_escape/percent%dir/percent%file1.txt' 263 @repository.reload
176 changesets = @repository.latest_changesets(path, nil) 264 %w|0 0885933ad4f6 0885|.each do |r1|
177 assert_equal %w|11 10 9|, changesets.collect(&:revision) 265 changeset = @repository.find_changeset_by_name(r1)
178 266 assert_nil changeset.previous
179 path = 'sql_escape/underscore_dir/understrike_file.txt' 267 end
180 changesets = @repository.latest_changesets(path, nil) 268 end
181 assert_equal %w|12 9|, changesets.collect(&:revision) 269
182 end 270 def test_next
183 271 @repository.fetch_changesets
184 def test_latest_changesets_with_dirpath 272 @repository.reload
185 @repository.fetch_changesets 273 %w|27 7bbf4c738e71 7bbf|.each do |r2|
186 @repository.reload 274 changeset = @repository.find_changeset_by_name(r2)
187 changesets = @repository.latest_changesets('images', nil) 275 %w|28 3ae45e2d177d 3ae45|.each do |r1|
188 assert_equal %w|1 0|, changesets.collect(&:revision) 276 assert_equal @repository.find_changeset_by_name(r1), changeset.next
189 277 end
190 path = 'sql_escape/percent%dir' 278 end
191 changesets = @repository.latest_changesets(path, nil) 279 end
192 assert_equal %w|13 11 10 9|, changesets.collect(&:revision) 280
193 281 def test_next_nil
194 path = 'sql_escape/underscore_dir' 282 @repository.fetch_changesets
195 changesets = @repository.latest_changesets(path, nil) 283 @repository.reload
196 assert_equal %w|13 12 9|, changesets.collect(&:revision) 284 %w|28 3ae45e2d177d 3ae45|.each do |r1|
285 changeset = @repository.find_changeset_by_name(r1)
286 assert_nil changeset.next
287 end
197 end 288 end
198 else 289 else
199 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" 290 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
200 def test_fake; assert true end 291 def test_fake; assert true end
201 end 292 end