Mercurial > hg > soundsoftware-site
comparison test/unit/repository_mercurial_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | bb32da3bea34 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 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. |
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 | |
24 | |
23 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s | 25 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
24 NUM_REV = 32 | 26 NUM_REV = 32 |
25 CHAR_1_HEX = "\xc3\x9c" | 27 CHAR_1_HEX = "\xc3\x9c" |
26 | 28 |
29 def setup | |
30 @project = Project.find(3) | |
31 @repository = Repository::Mercurial.create( | |
32 :project => @project, | |
33 :url => REPOSITORY_PATH, | |
34 :path_encoding => 'ISO-8859-1' | |
35 ) | |
36 assert @repository | |
37 @char_1 = CHAR_1_HEX.dup | |
38 @tag_char_1 = "tag-#{CHAR_1_HEX}-00" | |
39 @branch_char_0 = "branch-#{CHAR_1_HEX}-00" | |
40 @branch_char_1 = "branch-#{CHAR_1_HEX}-01" | |
41 if @char_1.respond_to?(:force_encoding) | |
42 @char_1.force_encoding('UTF-8') | |
43 @tag_char_1.force_encoding('UTF-8') | |
44 @branch_char_0.force_encoding('UTF-8') | |
45 @branch_char_1.force_encoding('UTF-8') | |
46 end | |
47 end | |
48 | |
49 | |
50 def test_blank_path_to_repository_error_message | |
51 set_language_if_valid 'en' | |
52 repo = Repository::Mercurial.new( | |
53 :project => @project, | |
54 :identifier => 'test' | |
55 ) | |
56 assert !repo.save | |
57 assert_include "Path to repository can't be blank", | |
58 repo.errors.full_messages | |
59 end | |
60 | |
61 def test_blank_path_to_repository_error_message_fr | |
62 set_language_if_valid 'fr' | |
63 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)" | |
64 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) | |
65 repo = Repository::Mercurial.new( | |
66 :project => @project, | |
67 :url => "", | |
68 :identifier => 'test', | |
69 :path_encoding => '' | |
70 ) | |
71 assert !repo.save | |
72 assert_include str, repo.errors.full_messages | |
73 end | |
74 | |
27 if File.directory?(REPOSITORY_PATH) | 75 if File.directory?(REPOSITORY_PATH) |
28 def setup | 76 def test_scm_available |
29 klass = Repository::Mercurial | 77 klass = Repository::Mercurial |
30 assert_equal "Mercurial", klass.scm_name | 78 assert_equal "Mercurial", klass.scm_name |
31 assert klass.scm_adapter_class | 79 assert klass.scm_adapter_class |
32 assert_not_equal "", klass.scm_command | 80 assert_not_equal "", klass.scm_command |
33 assert_equal true, klass.scm_available | 81 assert_equal true, klass.scm_available |
34 | 82 end |
35 @project = Project.find(3) | 83 |
36 @repository = Repository::Mercurial.create( | 84 def test_entries |
37 :project => @project, | 85 entries = @repository.entries |
38 :url => REPOSITORY_PATH, | 86 assert_kind_of Redmine::Scm::Adapters::Entries, entries |
39 :path_encoding => 'ISO-8859-1' | |
40 ) | |
41 assert @repository | |
42 @char_1 = CHAR_1_HEX.dup | |
43 @tag_char_1 = "tag-#{CHAR_1_HEX}-00" | |
44 @branch_char_0 = "branch-#{CHAR_1_HEX}-00" | |
45 @branch_char_1 = "branch-#{CHAR_1_HEX}-01" | |
46 if @char_1.respond_to?(:force_encoding) | |
47 @char_1.force_encoding('UTF-8') | |
48 @tag_char_1.force_encoding('UTF-8') | |
49 @branch_char_0.force_encoding('UTF-8') | |
50 @branch_char_1.force_encoding('UTF-8') | |
51 end | |
52 end | 87 end |
53 | 88 |
54 def test_fetch_changesets_from_scratch | 89 def test_fetch_changesets_from_scratch |
55 assert_equal 0, @repository.changesets.count | 90 assert_equal 0, @repository.changesets.count |
56 @repository.fetch_changesets | 91 @repository.fetch_changesets |
57 @project.reload | 92 @project.reload |
58 assert_equal NUM_REV, @repository.changesets.count | 93 assert_equal NUM_REV, @repository.changesets.count |
59 assert_equal 46, @repository.changes.count | 94 assert_equal 46, @repository.filechanges.count |
60 assert_equal "Initial import.\nThe repository contains 3 files.", | 95 assert_equal "Initial import.\nThe repository contains 3 files.", |
61 @repository.changesets.find_by_revision('0').comments | 96 @repository.changesets.find_by_revision('0').comments |
62 end | 97 end |
63 | 98 |
64 def test_fetch_changesets_incremental | 99 def test_fetch_changesets_incremental |
182 @project.reload | 217 @project.reload |
183 assert_equal NUM_REV, @repository.changesets.count | 218 assert_equal NUM_REV, @repository.changesets.count |
184 | 219 |
185 cs1 = @repository.changesets.find_by_revision('13') | 220 cs1 = @repository.changesets.find_by_revision('13') |
186 assert_not_nil cs1 | 221 assert_not_nil cs1 |
187 c1 = cs1.changes.sort_by(&:path) | 222 c1 = cs1.filechanges.sort_by(&:path) |
188 assert_equal 2, c1.size | 223 assert_equal 2, c1.size |
189 | 224 |
190 assert_equal 'A', c1[0].action | 225 assert_equal 'A', c1[0].action |
191 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path | 226 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path |
192 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path | 227 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path |
195 assert_equal 'A', c1[1].action | 230 assert_equal 'A', c1[1].action |
196 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path | 231 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path |
197 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path | 232 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path |
198 | 233 |
199 cs2 = @repository.changesets.find_by_revision('15') | 234 cs2 = @repository.changesets.find_by_revision('15') |
200 c2 = cs2.changes | 235 c2 = cs2.filechanges |
201 assert_equal 1, c2.size | 236 assert_equal 1, c2.size |
202 | 237 |
203 assert_equal 'A', c2[0].action | 238 assert_equal 'A', c2[0].action |
204 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path | 239 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
205 assert_equal '/README', c2[0].from_path | 240 assert_equal '/README', c2[0].from_path |
206 assert_equal '933ca60293d7', c2[0].from_revision | 241 assert_equal '933ca60293d7', c2[0].from_revision |
207 | 242 |
208 cs3 = @repository.changesets.find_by_revision('19') | 243 cs3 = @repository.changesets.find_by_revision('19') |
209 c3 = cs3.changes | 244 c3 = cs3.filechanges |
210 assert_equal 1, c3.size | 245 assert_equal 1, c3.size |
211 assert_equal 'A', c3[0].action | 246 assert_equal 'A', c3[0].action |
212 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path | 247 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path |
213 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path | 248 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path |
214 assert_equal '5d9891a1b425', c3[0].from_revision | 249 assert_equal '5d9891a1b425', c3[0].from_revision |