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