comparison test/unit/repository_mercurial_test.rb @ 119:8661b858af72

* Update to Redmine trunk rev 4705
author Chris Cannam
date Thu, 13 Jan 2011 14:12:06 +0000
parents 513646585e45
children cd2282d2aa55 051f544170fe
comparison
equal deleted inserted replaced
39:150ceac17a8d 119:8661b858af72
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.dirname(__FILE__) + '/../test_helper' 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
31 if File.directory?(REPOSITORY_PATH) 31 if File.directory?(REPOSITORY_PATH)
32 def test_fetch_changesets_from_scratch 32 def test_fetch_changesets_from_scratch
33 @repository.fetch_changesets 33 @repository.fetch_changesets
34 @repository.reload 34 @repository.reload
35 35
36 assert_equal 6, @repository.changesets.count 36 assert_equal 17, @repository.changesets.count
37 assert_equal 11, @repository.changes.count 37 assert_equal 25, @repository.changes.count
38 assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments 38 assert_equal "Initial import.\nThe repository contains 3 files.",
39 @repository.changesets.find_by_revision('0').comments
39 end 40 end
40 41
41 def test_fetch_changesets_incremental 42 def test_fetch_changesets_incremental
42 @repository.fetch_changesets 43 @repository.fetch_changesets
43 # Remove changesets with revision > 2 44 # Remove changesets with revision > 2
44 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} 45 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
45 @repository.reload 46 @repository.reload
46 assert_equal 3, @repository.changesets.count 47 assert_equal 3, @repository.changesets.count
47 48
48 @repository.fetch_changesets 49 @repository.fetch_changesets
49 assert_equal 6, @repository.changesets.count 50 assert_equal 17, @repository.changesets.count
50 end 51 end
51 52
52 def test_entries 53 def test_entries
53 assert_equal 2, @repository.entries("sources", 2).size 54 assert_equal 2, @repository.entries("sources", 2).size
55 assert_equal 2, @repository.entries("sources", '400bb8672109').size
54 assert_equal 1, @repository.entries("sources", 3).size 56 assert_equal 1, @repository.entries("sources", 3).size
57 assert_equal 1, @repository.entries("sources", 'b3a615152df8').size
55 end 58 end
56 59
57 def test_locate_on_outdated_repository 60 def test_locate_on_outdated_repository
58 # Change the working dir state
59 %x{hg -R #{REPOSITORY_PATH} up -r 0}
60 assert_equal 1, @repository.entries("images", 0).size 61 assert_equal 1, @repository.entries("images", 0).size
61 assert_equal 2, @repository.entries("images").size 62 assert_equal 2, @repository.entries("images").size
62 assert_equal 2, @repository.entries("images", 2).size 63 assert_equal 2, @repository.entries("images", 2).size
63 end 64 end
64 65
65 66 def test_isodatesec
66 def test_cat 67 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
67 assert @repository.scm.cat("sources/welcome_controller.rb", 2) 68 if @repository.scm.class.client_version_above?([1, 0])
68 assert_nil @repository.scm.cat("sources/welcome_controller.rb") 69 @repository.fetch_changesets
70 @repository.reload
71 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
72 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
73 end
69 end 74 end
70 75
76 def test_changeset_order_by_revision
77 @repository.fetch_changesets
78 @repository.reload
79
80 c0 = @repository.latest_changeset
81 c1 = @repository.changesets.find_by_revision('0')
82 # sorted by revision (id), not by date
83 assert c0.revision.to_i > c1.revision.to_i
84 assert c0.committed_on < c1.committed_on
85 end
86
87 def test_latest_changesets
88 @repository.fetch_changesets
89 @repository.reload
90
91 # with_limit
92 changesets = @repository.latest_changesets('', nil, 2)
93 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
94
95 # with_filepath
96 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil)
97 assert_equal %w|11 10 9|, changesets.collect(&:revision)
98
99 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil)
100 assert_equal %w|12 9|, changesets.collect(&:revision)
101 end
102
103 def test_copied_files
104 @repository.fetch_changesets
105 @repository.reload
106
107 cs1 = @repository.changesets.find_by_revision('13')
108 assert_not_nil cs1
109 c1 = cs1.changes.sort_by(&:path)
110 assert_equal 2, c1.size
111
112 assert_equal 'A', c1[0].action
113 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
114 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
115
116 assert_equal 'A', c1[1].action
117 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
118 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
119
120 cs2 = @repository.changesets.find_by_revision('15')
121 c2 = cs2.changes
122 assert_equal 1, c2.size
123
124 assert_equal 'A', c2[0].action
125 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
126 assert_equal '/README', c2[0].from_path
127 end
128
129 def test_find_changeset_by_name
130 @repository.fetch_changesets
131 @repository.reload
132 %w|2 400bb8672109 400|.each do |r|
133 assert_equal '2', @repository.find_changeset_by_name(r).revision
134 end
135 end
136
137 def test_find_changeset_by_invalid_name
138 @repository.fetch_changesets
139 @repository.reload
140 assert_nil @repository.find_changeset_by_name('100000')
141 end
142
143 def test_identifier
144 @repository.fetch_changesets
145 @repository.reload
146 c = @repository.changesets.find_by_revision('2')
147 assert_equal c.scmid, c.identifier
148 end
149
150 def test_format_identifier
151 @repository.fetch_changesets
152 @repository.reload
153 c = @repository.changesets.find_by_revision('2')
154 assert_equal '2:400bb8672109', c.format_identifier
155 end
156
157 def test_find_changeset_by_empty_name
158 @repository.fetch_changesets
159 @repository.reload
160 ['', ' ', nil].each do |r|
161 assert_nil @repository.find_changeset_by_name(r)
162 end
163 end
164
165 def test_activities
166 c = Changeset.new(:repository => @repository,
167 :committed_on => Time.now,
168 :revision => '123',
169 :scmid => 'abc400bb8672',
170 :comments => 'test')
171 assert c.event_title.include?('123:abc400bb8672:')
172 assert_equal 'abc400bb8672', c.event_url[:rev]
173 end
71 else 174 else
72 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" 175 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
73 def test_fake; assert true end 176 def test_fake; assert true end
74 end 177 end
75 end 178 end