##// END OF EJS Templates
scm: mercurial: unit app test for latest_changeset....
Toshi MARUYAMA -
r4749:0e0a8c01ea86
parent child
Show More
@@ -1,165 +1,186
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 @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
29 29 assert @repository
30 30 end
31 31
32 32 if File.directory?(REPOSITORY_PATH)
33 33 def test_fetch_changesets_from_scratch
34 34 @repository.fetch_changesets
35 35 @repository.reload
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.",
39 39 @repository.changesets.find_by_revision('0').comments
40 40 end
41 41
42 42 def test_fetch_changesets_incremental
43 43 @repository.fetch_changesets
44 44 # Remove changesets with revision > 2
45 45 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
46 46 @repository.reload
47 47 assert_equal 3, @repository.changesets.count
48 48
49 49 @repository.fetch_changesets
50 50 assert_equal 17, @repository.changesets.count
51 51 end
52 52
53 53 def test_isodatesec
54 54 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
55 55 if @repository.scm.class.client_version_above?([1, 0])
56 56 @repository.fetch_changesets
57 57 @repository.reload
58 58 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
59 59 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
60 60 end
61 61 end
62 62
63 63 def test_changeset_order_by_revision
64 64 @repository.fetch_changesets
65 65 @repository.reload
66 66
67 67 c0 = @repository.latest_changeset
68 68 c1 = @repository.changesets.find_by_revision('0')
69 69 # sorted by revision (id), not by date
70 70 assert c0.revision.to_i > c1.revision.to_i
71 71 assert c0.committed_on < c1.committed_on
72 72 end
73 73
74 74 def test_latest_changesets
75 75 @repository.fetch_changesets
76 76 @repository.reload
77 77
78 78 # with_limit
79 79 changesets = @repository.latest_changesets('', nil, 2)
80 80 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
81 81
82 82 # with_filepath
83 83 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil)
84 84 assert_equal %w|11 10 9|, changesets.collect(&:revision)
85 85
86 86 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil)
87 87 assert_equal %w|12 9|, changesets.collect(&:revision)
88 88 end
89 89
90 90 def test_copied_files
91 91 @repository.fetch_changesets
92 92 @repository.reload
93 93
94 94 cs1 = @repository.changesets.find_by_revision('13')
95 95 assert_not_nil cs1
96 96 c1 = cs1.changes.sort_by(&:path)
97 97 assert_equal 2, c1.size
98 98
99 99 assert_equal 'A', c1[0].action
100 100 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
101 101 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
102 102
103 103 assert_equal 'A', c1[1].action
104 104 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
105 105 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
106 106
107 107 cs2 = @repository.changesets.find_by_revision('15')
108 108 c2 = cs2.changes
109 109 assert_equal 1, c2.size
110 110
111 111 assert_equal 'A', c2[0].action
112 112 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
113 113 assert_equal '/README', c2[0].from_path
114 114 end
115 115
116 116 def test_find_changeset_by_name
117 117 @repository.fetch_changesets
118 118 @repository.reload
119 119 %w|2 400bb8672109 400|.each do |r|
120 120 assert_equal '2', @repository.find_changeset_by_name(r).revision
121 121 end
122 122 end
123 123
124 124 def test_find_changeset_by_invalid_name
125 125 @repository.fetch_changesets
126 126 @repository.reload
127 127 assert_nil @repository.find_changeset_by_name('100000')
128 128 end
129 129
130 130 def test_identifier
131 131 @repository.fetch_changesets
132 132 @repository.reload
133 133 c = @repository.changesets.find_by_revision('2')
134 134 assert_equal c.scmid, c.identifier
135 135 end
136 136
137 137 def test_format_identifier
138 138 @repository.fetch_changesets
139 139 @repository.reload
140 140 c = @repository.changesets.find_by_revision('2')
141 141 assert_equal '2:400bb8672109', c.format_identifier
142 142 end
143 143
144 144 def test_find_changeset_by_empty_name
145 145 @repository.fetch_changesets
146 146 @repository.reload
147 147 ['', ' ', nil].each do |r|
148 148 assert_nil @repository.find_changeset_by_name(r)
149 149 end
150 150 end
151 151
152 152 def test_activities
153 153 c = Changeset.new(:repository => @repository,
154 154 :committed_on => Time.now,
155 155 :revision => '123',
156 156 :scmid => 'abc400bb8672',
157 157 :comments => 'test')
158 158 assert c.event_title.include?('123:abc400bb8672:')
159 159 assert_equal 'abc400bb8672', c.event_url[:rev]
160 160 end
161
162 def test_latest_changesets_with_limit
163 @repository.fetch_changesets
164 @repository.reload
165 changesets = @repository.latest_changesets('', nil, 2)
166 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
167 end
168
169 def test_latest_changesets_with_filepath
170 @repository.fetch_changesets
171 @repository.reload
172 changesets = @repository.latest_changesets('README', nil)
173 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
174 end
175
176 def test_latest_changesets_with_dirpath
177 @repository.fetch_changesets
178 @repository.reload
179 changesets = @repository.latest_changesets('images', nil)
180 assert_equal %w|1 0|, changesets.collect(&:revision)
181 end
161 182 else
162 183 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
163 184 def test_fake; assert true end
164 185 end
165 186 end
General Comments 0
You need to be logged in to leave comments. Login now