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