##// END OF EJS Templates
stricter asserting of subversion url validation test...
Toshi MARUYAMA -
r11488:32ee6b32756e
parent child
Show More
@@ -1,259 +1,259
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
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.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositorySubversionTest < ActiveSupport::TestCase
20 class RepositorySubversionTest < ActiveSupport::TestCase
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22
22
23 include Redmine::I18n
23 include Redmine::I18n
24
24
25 NUM_REV = 11
25 NUM_REV = 11
26
26
27 def setup
27 def setup
28 @project = Project.find(3)
28 @project = Project.find(3)
29 @repository = Repository::Subversion.create(:project => @project,
29 @repository = Repository::Subversion.create(:project => @project,
30 :url => self.class.subversion_repository_url)
30 :url => self.class.subversion_repository_url)
31 assert @repository
31 assert @repository
32 end
32 end
33
33
34 def test_invalid_url
34 def test_invalid_url
35 set_language_if_valid 'en'
35 set_language_if_valid 'en'
36 ['invalid', 'http://', 'svn://', 'svn+ssh://', 'file://'].each do |url|
36 ['invalid', 'http://', 'svn://', 'svn+ssh://', 'file://'].each do |url|
37 repo = Repository::Subversion.new(
37 repo = Repository::Subversion.new(
38 :project => @project,
38 :project => @project,
39 :identifier => 'test',
39 :identifier => 'test',
40 :url => url
40 :url => url
41 )
41 )
42 assert !repo.save
42 assert !repo.save
43 assert_include "is invalid", repo.errors[:url]
43 assert_equal ["is invalid"], repo.errors[:url]
44 end
44 end
45 end
45 end
46
46
47 def test_valid_url
47 def test_valid_url
48 ['http://valid', 'svn://valid', 'svn+ssh://valid', 'file://valid'].each do |url|
48 ['http://valid', 'svn://valid', 'svn+ssh://valid', 'file://valid'].each do |url|
49 repo = Repository::Subversion.new(
49 repo = Repository::Subversion.new(
50 :project => @project,
50 :project => @project,
51 :identifier => 'test',
51 :identifier => 'test',
52 :url => url
52 :url => url
53 )
53 )
54 assert repo.save
54 assert repo.save
55 assert_equal [], repo.errors[:url]
55 assert_equal [], repo.errors[:url]
56 assert repo.destroy
56 assert repo.destroy
57 end
57 end
58 end
58 end
59
59
60 if repository_configured?('subversion')
60 if repository_configured?('subversion')
61 def test_fetch_changesets_from_scratch
61 def test_fetch_changesets_from_scratch
62 assert_equal 0, @repository.changesets.count
62 assert_equal 0, @repository.changesets.count
63 @repository.fetch_changesets
63 @repository.fetch_changesets
64 @project.reload
64 @project.reload
65
65
66 assert_equal NUM_REV, @repository.changesets.count
66 assert_equal NUM_REV, @repository.changesets.count
67 assert_equal 20, @repository.filechanges.count
67 assert_equal 20, @repository.filechanges.count
68 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
68 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
69 end
69 end
70
70
71 def test_fetch_changesets_incremental
71 def test_fetch_changesets_incremental
72 assert_equal 0, @repository.changesets.count
72 assert_equal 0, @repository.changesets.count
73 @repository.fetch_changesets
73 @repository.fetch_changesets
74 @project.reload
74 @project.reload
75 assert_equal NUM_REV, @repository.changesets.count
75 assert_equal NUM_REV, @repository.changesets.count
76
76
77 # Remove changesets with revision > 5
77 # Remove changesets with revision > 5
78 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 5}
78 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 5}
79 @project.reload
79 @project.reload
80 assert_equal 5, @repository.changesets.count
80 assert_equal 5, @repository.changesets.count
81
81
82 @repository.fetch_changesets
82 @repository.fetch_changesets
83 @project.reload
83 @project.reload
84 assert_equal NUM_REV, @repository.changesets.count
84 assert_equal NUM_REV, @repository.changesets.count
85 end
85 end
86
86
87 def test_entries
87 def test_entries
88 entries = @repository.entries
88 entries = @repository.entries
89 assert_kind_of Redmine::Scm::Adapters::Entries, entries
89 assert_kind_of Redmine::Scm::Adapters::Entries, entries
90 end
90 end
91
91
92 def test_entries_for_invalid_path_should_return_nil
92 def test_entries_for_invalid_path_should_return_nil
93 entries = @repository.entries('invalid_path')
93 entries = @repository.entries('invalid_path')
94 assert_nil entries
94 assert_nil entries
95 end
95 end
96
96
97 def test_latest_changesets
97 def test_latest_changesets
98 assert_equal 0, @repository.changesets.count
98 assert_equal 0, @repository.changesets.count
99 @repository.fetch_changesets
99 @repository.fetch_changesets
100 @project.reload
100 @project.reload
101 assert_equal NUM_REV, @repository.changesets.count
101 assert_equal NUM_REV, @repository.changesets.count
102
102
103 # with limit
103 # with limit
104 changesets = @repository.latest_changesets('', nil, 2)
104 changesets = @repository.latest_changesets('', nil, 2)
105 assert_equal 2, changesets.size
105 assert_equal 2, changesets.size
106 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
106 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
107
107
108 # with path
108 # with path
109 changesets = @repository.latest_changesets('subversion_test/folder', nil)
109 changesets = @repository.latest_changesets('subversion_test/folder', nil)
110 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
110 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
111
111
112 # with path and revision
112 # with path and revision
113 changesets = @repository.latest_changesets('subversion_test/folder', 8)
113 changesets = @repository.latest_changesets('subversion_test/folder', 8)
114 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
114 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
115 end
115 end
116
116
117 def test_directory_listing_with_square_brackets_in_path
117 def test_directory_listing_with_square_brackets_in_path
118 assert_equal 0, @repository.changesets.count
118 assert_equal 0, @repository.changesets.count
119 @repository.fetch_changesets
119 @repository.fetch_changesets
120 @project.reload
120 @project.reload
121 assert_equal NUM_REV, @repository.changesets.count
121 assert_equal NUM_REV, @repository.changesets.count
122
122
123 entries = @repository.entries('subversion_test/[folder_with_brackets]')
123 entries = @repository.entries('subversion_test/[folder_with_brackets]')
124 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
124 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
125 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
125 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
126 assert_equal 'README.txt', entries.first.name
126 assert_equal 'README.txt', entries.first.name
127 end
127 end
128
128
129 def test_directory_listing_with_square_brackets_in_base
129 def test_directory_listing_with_square_brackets_in_base
130 @project = Project.find(3)
130 @project = Project.find(3)
131 @repository = Repository::Subversion.create(
131 @repository = Repository::Subversion.create(
132 :project => @project,
132 :project => @project,
133 :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
133 :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
134
134
135 assert_equal 0, @repository.changesets.count
135 assert_equal 0, @repository.changesets.count
136 @repository.fetch_changesets
136 @repository.fetch_changesets
137 @project.reload
137 @project.reload
138
138
139 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
139 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
140 assert_equal 2, @repository.filechanges.count, 'Expected to see 2 changes, dir add and file add'
140 assert_equal 2, @repository.filechanges.count, 'Expected to see 2 changes, dir add and file add'
141
141
142 entries = @repository.entries('')
142 entries = @repository.entries('')
143 assert_not_nil entries, 'Expect to find entries'
143 assert_not_nil entries, 'Expect to find entries'
144 assert_equal 1, entries.size, 'Expect a single entry'
144 assert_equal 1, entries.size, 'Expect a single entry'
145 assert_equal 'README.txt', entries.first.name
145 assert_equal 'README.txt', entries.first.name
146 end
146 end
147
147
148 def test_identifier
148 def test_identifier
149 assert_equal 0, @repository.changesets.count
149 assert_equal 0, @repository.changesets.count
150 @repository.fetch_changesets
150 @repository.fetch_changesets
151 @project.reload
151 @project.reload
152 assert_equal NUM_REV, @repository.changesets.count
152 assert_equal NUM_REV, @repository.changesets.count
153 c = @repository.changesets.find_by_revision('1')
153 c = @repository.changesets.find_by_revision('1')
154 assert_equal c.revision, c.identifier
154 assert_equal c.revision, c.identifier
155 end
155 end
156
156
157 def test_find_changeset_by_empty_name
157 def test_find_changeset_by_empty_name
158 assert_equal 0, @repository.changesets.count
158 assert_equal 0, @repository.changesets.count
159 @repository.fetch_changesets
159 @repository.fetch_changesets
160 @project.reload
160 @project.reload
161 assert_equal NUM_REV, @repository.changesets.count
161 assert_equal NUM_REV, @repository.changesets.count
162 ['', ' ', nil].each do |r|
162 ['', ' ', nil].each do |r|
163 assert_nil @repository.find_changeset_by_name(r)
163 assert_nil @repository.find_changeset_by_name(r)
164 end
164 end
165 end
165 end
166
166
167 def test_identifier_nine_digit
167 def test_identifier_nine_digit
168 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
168 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
169 :revision => '123456789', :comments => 'test')
169 :revision => '123456789', :comments => 'test')
170 assert_equal c.identifier, c.revision
170 assert_equal c.identifier, c.revision
171 end
171 end
172
172
173 def test_format_identifier
173 def test_format_identifier
174 assert_equal 0, @repository.changesets.count
174 assert_equal 0, @repository.changesets.count
175 @repository.fetch_changesets
175 @repository.fetch_changesets
176 @project.reload
176 @project.reload
177 assert_equal NUM_REV, @repository.changesets.count
177 assert_equal NUM_REV, @repository.changesets.count
178 c = @repository.changesets.find_by_revision('1')
178 c = @repository.changesets.find_by_revision('1')
179 assert_equal c.format_identifier, c.revision
179 assert_equal c.format_identifier, c.revision
180 end
180 end
181
181
182 def test_format_identifier_nine_digit
182 def test_format_identifier_nine_digit
183 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
183 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
184 :revision => '123456789', :comments => 'test')
184 :revision => '123456789', :comments => 'test')
185 assert_equal c.format_identifier, c.revision
185 assert_equal c.format_identifier, c.revision
186 end
186 end
187
187
188 def test_activities
188 def test_activities
189 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
189 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
190 :revision => '1', :comments => 'test')
190 :revision => '1', :comments => 'test')
191 assert c.event_title.include?('1:')
191 assert c.event_title.include?('1:')
192 assert_equal '1', c.event_url[:rev]
192 assert_equal '1', c.event_url[:rev]
193 end
193 end
194
194
195 def test_activities_nine_digit
195 def test_activities_nine_digit
196 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
196 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
197 :revision => '123456789', :comments => 'test')
197 :revision => '123456789', :comments => 'test')
198 assert c.event_title.include?('123456789:')
198 assert c.event_title.include?('123456789:')
199 assert_equal '123456789', c.event_url[:rev]
199 assert_equal '123456789', c.event_url[:rev]
200 end
200 end
201
201
202 def test_log_encoding_ignore_setting
202 def test_log_encoding_ignore_setting
203 with_settings :commit_logs_encoding => 'windows-1252' do
203 with_settings :commit_logs_encoding => 'windows-1252' do
204 s1 = "\xC2\x80"
204 s1 = "\xC2\x80"
205 s2 = "\xc3\x82\xc2\x80"
205 s2 = "\xc3\x82\xc2\x80"
206 if s1.respond_to?(:force_encoding)
206 if s1.respond_to?(:force_encoding)
207 s1.force_encoding('ISO-8859-1')
207 s1.force_encoding('ISO-8859-1')
208 s2.force_encoding('UTF-8')
208 s2.force_encoding('UTF-8')
209 assert_equal s1.encode('UTF-8'), s2
209 assert_equal s1.encode('UTF-8'), s2
210 end
210 end
211 c = Changeset.new(:repository => @repository,
211 c = Changeset.new(:repository => @repository,
212 :comments => s2,
212 :comments => s2,
213 :revision => '123',
213 :revision => '123',
214 :committed_on => Time.now)
214 :committed_on => Time.now)
215 assert c.save
215 assert c.save
216 assert_equal s2, c.comments
216 assert_equal s2, c.comments
217 end
217 end
218 end
218 end
219
219
220 def test_previous
220 def test_previous
221 assert_equal 0, @repository.changesets.count
221 assert_equal 0, @repository.changesets.count
222 @repository.fetch_changesets
222 @repository.fetch_changesets
223 @project.reload
223 @project.reload
224 assert_equal NUM_REV, @repository.changesets.count
224 assert_equal NUM_REV, @repository.changesets.count
225 changeset = @repository.find_changeset_by_name('3')
225 changeset = @repository.find_changeset_by_name('3')
226 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
226 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
227 end
227 end
228
228
229 def test_previous_nil
229 def test_previous_nil
230 assert_equal 0, @repository.changesets.count
230 assert_equal 0, @repository.changesets.count
231 @repository.fetch_changesets
231 @repository.fetch_changesets
232 @project.reload
232 @project.reload
233 assert_equal NUM_REV, @repository.changesets.count
233 assert_equal NUM_REV, @repository.changesets.count
234 changeset = @repository.find_changeset_by_name('1')
234 changeset = @repository.find_changeset_by_name('1')
235 assert_nil changeset.previous
235 assert_nil changeset.previous
236 end
236 end
237
237
238 def test_next
238 def test_next
239 assert_equal 0, @repository.changesets.count
239 assert_equal 0, @repository.changesets.count
240 @repository.fetch_changesets
240 @repository.fetch_changesets
241 @project.reload
241 @project.reload
242 assert_equal NUM_REV, @repository.changesets.count
242 assert_equal NUM_REV, @repository.changesets.count
243 changeset = @repository.find_changeset_by_name('2')
243 changeset = @repository.find_changeset_by_name('2')
244 assert_equal @repository.find_changeset_by_name('3'), changeset.next
244 assert_equal @repository.find_changeset_by_name('3'), changeset.next
245 end
245 end
246
246
247 def test_next_nil
247 def test_next_nil
248 assert_equal 0, @repository.changesets.count
248 assert_equal 0, @repository.changesets.count
249 @repository.fetch_changesets
249 @repository.fetch_changesets
250 @project.reload
250 @project.reload
251 assert_equal NUM_REV, @repository.changesets.count
251 assert_equal NUM_REV, @repository.changesets.count
252 changeset = @repository.find_changeset_by_name('11')
252 changeset = @repository.find_changeset_by_name('11')
253 assert_nil changeset.next
253 assert_nil changeset.next
254 end
254 end
255 else
255 else
256 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
256 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
257 def test_fake; assert true end
257 def test_fake; assert true end
258 end
258 end
259 end
259 end
General Comments 0
You need to be logged in to leave comments. Login now