##// END OF EJS Templates
Rails3: scm: subversion: fix error of test_find_changeset_by_empty_name at unit model test...
Toshi MARUYAMA -
r7034:2deaa21f72a6
parent child
Show More
@@ -1,209 +1,211
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 RepositorySubversionTest < ActiveSupport::TestCase
21 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22 22
23 23 NUM_REV = 11
24 24
25 25 def setup
26 26 @project = Project.find(3)
27 27 @repository = Repository::Subversion.create(:project => @project,
28 28 :url => self.class.subversion_repository_url)
29 29 assert @repository
30 30 end
31 31
32 32 if repository_configured?('subversion')
33 33 def test_fetch_changesets_from_scratch
34 34 assert_equal 0, @repository.changesets.count
35 35 @repository.fetch_changesets
36 36 @project.reload
37 37
38 38 assert_equal NUM_REV, @repository.changesets.count
39 39 assert_equal 20, @repository.changes.count
40 40 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
41 41 end
42 42
43 43 def test_fetch_changesets_incremental
44 44 assert_equal 0, @repository.changesets.count
45 45 @repository.fetch_changesets
46 46 @project.reload
47 47 assert_equal NUM_REV, @repository.changesets.count
48 48
49 49 # Remove changesets with revision > 5
50 50 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5}
51 51 @project.reload
52 52 assert_equal 5, @repository.changesets.count
53 53
54 54 @repository.fetch_changesets
55 55 @project.reload
56 56 assert_equal NUM_REV, @repository.changesets.count
57 57 end
58 58
59 59 def test_latest_changesets
60 60 assert_equal 0, @repository.changesets.count
61 61 @repository.fetch_changesets
62 62 @project.reload
63 63 assert_equal NUM_REV, @repository.changesets.count
64 64
65 65 # with limit
66 66 changesets = @repository.latest_changesets('', nil, 2)
67 67 assert_equal 2, changesets.size
68 68 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
69 69
70 70 # with path
71 71 changesets = @repository.latest_changesets('subversion_test/folder', nil)
72 72 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
73 73
74 74 # with path and revision
75 75 changesets = @repository.latest_changesets('subversion_test/folder', 8)
76 76 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
77 77 end
78 78
79 79 def test_directory_listing_with_square_brackets_in_path
80 80 assert_equal 0, @repository.changesets.count
81 81 @repository.fetch_changesets
82 82 @project.reload
83 83 assert_equal NUM_REV, @repository.changesets.count
84 84
85 85 entries = @repository.entries('subversion_test/[folder_with_brackets]')
86 86 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
87 87 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
88 88 assert_equal 'README.txt', entries.first.name
89 89 end
90 90
91 91 def test_directory_listing_with_square_brackets_in_base
92 92 @project = Project.find(3)
93 93 @repository = Repository::Subversion.create(
94 94 :project => @project,
95 95 :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
96 96
97 97 assert_equal 0, @repository.changesets.count
98 98 @repository.fetch_changesets
99 99 @project.reload
100 100
101 101 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
102 102 assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add'
103 103
104 104 entries = @repository.entries('')
105 105 assert_not_nil entries, 'Expect to find entries'
106 106 assert_equal 1, entries.size, 'Expect a single entry'
107 107 assert_equal 'README.txt', entries.first.name
108 108 end
109 109
110 110 def test_identifier
111 111 assert_equal 0, @repository.changesets.count
112 112 @repository.fetch_changesets
113 113 @project.reload
114 114 assert_equal NUM_REV, @repository.changesets.count
115 115 c = @repository.changesets.find_by_revision('1')
116 116 assert_equal c.revision, c.identifier
117 117 end
118 118
119 119 def test_find_changeset_by_empty_name
120 assert_equal 0, @repository.changesets.count
120 121 @repository.fetch_changesets
121 @repository.reload
122 @project.reload
123 assert_equal NUM_REV, @repository.changesets.count
122 124 ['', ' ', nil].each do |r|
123 125 assert_nil @repository.find_changeset_by_name(r)
124 126 end
125 127 end
126 128
127 129 def test_identifier_nine_digit
128 130 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
129 131 :revision => '123456789', :comments => 'test')
130 132 assert_equal c.identifier, c.revision
131 133 end
132 134
133 135 def test_format_identifier
134 136 @repository.fetch_changesets
135 137 @repository.reload
136 138 c = @repository.changesets.find_by_revision('1')
137 139 assert_equal c.format_identifier, c.revision
138 140 end
139 141
140 142 def test_format_identifier_nine_digit
141 143 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
142 144 :revision => '123456789', :comments => 'test')
143 145 assert_equal c.format_identifier, c.revision
144 146 end
145 147
146 148 def test_activities
147 149 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
148 150 :revision => '1', :comments => 'test')
149 151 assert c.event_title.include?('1:')
150 152 assert_equal '1', c.event_url[:rev]
151 153 end
152 154
153 155 def test_activities_nine_digit
154 156 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
155 157 :revision => '123456789', :comments => 'test')
156 158 assert c.event_title.include?('123456789:')
157 159 assert_equal '123456789', c.event_url[:rev]
158 160 end
159 161
160 162 def test_log_encoding_ignore_setting
161 163 with_settings :commit_logs_encoding => 'windows-1252' do
162 164 s1 = "\xC2\x80"
163 165 s2 = "\xc3\x82\xc2\x80"
164 166 if s1.respond_to?(:force_encoding)
165 167 s1.force_encoding('ISO-8859-1')
166 168 s2.force_encoding('UTF-8')
167 169 assert_equal s1.encode('UTF-8'), s2
168 170 end
169 171 c = Changeset.new(:repository => @repository,
170 172 :comments => s2,
171 173 :revision => '123',
172 174 :committed_on => Time.now)
173 175 assert c.save
174 176 assert_equal s2, c.comments
175 177 end
176 178 end
177 179
178 180 def test_previous
179 181 @repository.fetch_changesets
180 182 @repository.reload
181 183 changeset = @repository.find_changeset_by_name('3')
182 184 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
183 185 end
184 186
185 187 def test_previous_nil
186 188 @repository.fetch_changesets
187 189 @repository.reload
188 190 changeset = @repository.find_changeset_by_name('1')
189 191 assert_nil changeset.previous
190 192 end
191 193
192 194 def test_next
193 195 @repository.fetch_changesets
194 196 @repository.reload
195 197 changeset = @repository.find_changeset_by_name('2')
196 198 assert_equal @repository.find_changeset_by_name('3'), changeset.next
197 199 end
198 200
199 201 def test_next_nil
200 202 @repository.fetch_changesets
201 203 @repository.reload
202 204 changeset = @repository.find_changeset_by_name('11')
203 205 assert_nil changeset.next
204 206 end
205 207 else
206 208 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
207 209 def test_fake; assert true end
208 210 end
209 211 end
General Comments 0
You need to be logged in to leave comments. Login now