@@ -1,103 +1,128 | |||
|
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 | def setup |
|
27 | 27 | @project = Project.find(1) |
|
28 | 28 | assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH) |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | if File.directory?(REPOSITORY_PATH) |
|
32 | 32 | def test_fetch_changesets_from_scratch |
|
33 | 33 | @repository.fetch_changesets |
|
34 | 34 | @repository.reload |
|
35 | 35 | |
|
36 | 36 | assert_equal 17, @repository.changesets.count |
|
37 | 37 | assert_equal 25, @repository.changes.count |
|
38 | 38 | assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_fetch_changesets_incremental |
|
42 | 42 | @repository.fetch_changesets |
|
43 | 43 | # Remove changesets with revision > 2 |
|
44 | 44 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} |
|
45 | 45 | @repository.reload |
|
46 | 46 | assert_equal 3, @repository.changesets.count |
|
47 | 47 | |
|
48 | 48 | @repository.fetch_changesets |
|
49 | 49 | assert_equal 17, @repository.changesets.count |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def test_entries |
|
53 | 53 | assert_equal 2, @repository.entries("sources", 2).size |
|
54 | 54 | assert_equal 1, @repository.entries("sources", 3).size |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def test_locate_on_outdated_repository |
|
58 | 58 | assert_equal 1, @repository.entries("images", 0).size |
|
59 | 59 | assert_equal 2, @repository.entries("images").size |
|
60 | 60 | assert_equal 2, @repository.entries("images", 2).size |
|
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 @repository.latest_changesets('', nil)[0, 2], changesets |
|
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 | end |
|
99 | ||
|
100 | def test_copied_files | |
|
101 | @repository.fetch_changesets | |
|
102 | @repository.reload | |
|
103 | ||
|
104 | cs1 = @repository.changesets.find_by_revision('13') | |
|
105 | c1 = cs1.changes | |
|
106 | assert_equal 2, c1.size | |
|
107 | ||
|
108 | assert_equal 'A', c1[0].action | |
|
109 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path | |
|
110 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path | |
|
111 | ||
|
112 | assert_equal 'A', c1[1].action | |
|
113 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path | |
|
114 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path | |
|
115 | ||
|
116 | cs2 = @repository.changesets.find_by_revision('15') | |
|
117 | c2 = cs2.changes | |
|
118 | assert_equal 1, c2.size | |
|
119 | ||
|
120 | assert_equal 'A', c2[0].action | |
|
121 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path | |
|
122 | assert_equal '/README', c2[0].from_path | |
|
123 | end | |
|
99 | 124 | else |
|
100 | 125 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
101 | 126 | def test_fake; assert true end |
|
102 | 127 | end |
|
103 | 128 | end |
General Comments 0
You need to be logged in to leave comments.
Login now