@@ -1,260 +1,260 | |||||
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_equal ["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 |
|
78 | @repository.changesets.each {|c| c.destroy if c.revision.to_i > 5} | |
79 | @project.reload |
|
79 | @project.reload | |
80 | @repository.reload |
|
80 | @repository.reload | |
81 | assert_equal 5, @repository.changesets.count |
|
81 | assert_equal 5, @repository.changesets.count | |
82 |
|
82 | |||
83 | @repository.fetch_changesets |
|
83 | @repository.fetch_changesets | |
84 | @project.reload |
|
84 | @project.reload | |
85 | assert_equal NUM_REV, @repository.changesets.count |
|
85 | assert_equal NUM_REV, @repository.changesets.count | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def test_entries |
|
88 | def test_entries | |
89 | entries = @repository.entries |
|
89 | entries = @repository.entries | |
90 | assert_kind_of Redmine::Scm::Adapters::Entries, entries |
|
90 | assert_kind_of Redmine::Scm::Adapters::Entries, entries | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def test_entries_for_invalid_path_should_return_nil |
|
93 | def test_entries_for_invalid_path_should_return_nil | |
94 | entries = @repository.entries('invalid_path') |
|
94 | entries = @repository.entries('invalid_path') | |
95 | assert_nil entries |
|
95 | assert_nil entries | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def test_latest_changesets |
|
98 | def test_latest_changesets | |
99 | assert_equal 0, @repository.changesets.count |
|
99 | assert_equal 0, @repository.changesets.count | |
100 | @repository.fetch_changesets |
|
100 | @repository.fetch_changesets | |
101 | @project.reload |
|
101 | @project.reload | |
102 | assert_equal NUM_REV, @repository.changesets.count |
|
102 | assert_equal NUM_REV, @repository.changesets.count | |
103 |
|
103 | |||
104 | # with limit |
|
104 | # with limit | |
105 | changesets = @repository.latest_changesets('', nil, 2) |
|
105 | changesets = @repository.latest_changesets('', nil, 2) | |
106 | assert_equal 2, changesets.size |
|
106 | assert_equal 2, changesets.size | |
107 | assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets |
|
107 | assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets | |
108 |
|
108 | |||
109 | # with path |
|
109 | # with path | |
110 | changesets = @repository.latest_changesets('subversion_test/folder', nil) |
|
110 | changesets = @repository.latest_changesets('subversion_test/folder', nil) | |
111 | assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision) |
|
111 | assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision) | |
112 |
|
112 | |||
113 | # with path and revision |
|
113 | # with path and revision | |
114 | changesets = @repository.latest_changesets('subversion_test/folder', 8) |
|
114 | changesets = @repository.latest_changesets('subversion_test/folder', 8) | |
115 | assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision) |
|
115 | assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision) | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | def test_directory_listing_with_square_brackets_in_path |
|
118 | def test_directory_listing_with_square_brackets_in_path | |
119 | assert_equal 0, @repository.changesets.count |
|
119 | assert_equal 0, @repository.changesets.count | |
120 | @repository.fetch_changesets |
|
120 | @repository.fetch_changesets | |
121 | @project.reload |
|
121 | @project.reload | |
122 | assert_equal NUM_REV, @repository.changesets.count |
|
122 | assert_equal NUM_REV, @repository.changesets.count | |
123 |
|
123 | |||
124 | entries = @repository.entries('subversion_test/[folder_with_brackets]') |
|
124 | entries = @repository.entries('subversion_test/[folder_with_brackets]') | |
125 | assert_not_nil entries, 'Expect to find entries in folder_with_brackets' |
|
125 | assert_not_nil entries, 'Expect to find entries in folder_with_brackets' | |
126 | assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets' |
|
126 | assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets' | |
127 | assert_equal 'README.txt', entries.first.name |
|
127 | assert_equal 'README.txt', entries.first.name | |
128 | end |
|
128 | end | |
129 |
|
129 | |||
130 | def test_directory_listing_with_square_brackets_in_base |
|
130 | def test_directory_listing_with_square_brackets_in_base | |
131 | @project = Project.find(3) |
|
131 | @project = Project.find(3) | |
132 | @repository = Repository::Subversion.create( |
|
132 | @repository = Repository::Subversion.create( | |
133 | :project => @project, |
|
133 | :project => @project, | |
134 | :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]") |
|
134 | :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]") | |
135 |
|
135 | |||
136 | assert_equal 0, @repository.changesets.count |
|
136 | assert_equal 0, @repository.changesets.count | |
137 | @repository.fetch_changesets |
|
137 | @repository.fetch_changesets | |
138 | @project.reload |
|
138 | @project.reload | |
139 |
|
139 | |||
140 | assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision' |
|
140 | assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision' | |
141 | assert_equal 2, @repository.filechanges.count, 'Expected to see 2 changes, dir add and file add' |
|
141 | assert_equal 2, @repository.filechanges.count, 'Expected to see 2 changes, dir add and file add' | |
142 |
|
142 | |||
143 | entries = @repository.entries('') |
|
143 | entries = @repository.entries('') | |
144 | assert_not_nil entries, 'Expect to find entries' |
|
144 | assert_not_nil entries, 'Expect to find entries' | |
145 | assert_equal 1, entries.size, 'Expect a single entry' |
|
145 | assert_equal 1, entries.size, 'Expect a single entry' | |
146 | assert_equal 'README.txt', entries.first.name |
|
146 | assert_equal 'README.txt', entries.first.name | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | def test_identifier |
|
149 | def test_identifier | |
150 | assert_equal 0, @repository.changesets.count |
|
150 | assert_equal 0, @repository.changesets.count | |
151 | @repository.fetch_changesets |
|
151 | @repository.fetch_changesets | |
152 | @project.reload |
|
152 | @project.reload | |
153 | assert_equal NUM_REV, @repository.changesets.count |
|
153 | assert_equal NUM_REV, @repository.changesets.count | |
154 | c = @repository.changesets.find_by_revision('1') |
|
154 | c = @repository.changesets.find_by_revision('1') | |
155 | assert_equal c.revision, c.identifier |
|
155 | assert_equal c.revision, c.identifier | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | def test_find_changeset_by_empty_name |
|
158 | def test_find_changeset_by_empty_name | |
159 | assert_equal 0, @repository.changesets.count |
|
159 | assert_equal 0, @repository.changesets.count | |
160 | @repository.fetch_changesets |
|
160 | @repository.fetch_changesets | |
161 | @project.reload |
|
161 | @project.reload | |
162 | assert_equal NUM_REV, @repository.changesets.count |
|
162 | assert_equal NUM_REV, @repository.changesets.count | |
163 | ['', ' ', nil].each do |r| |
|
163 | ['', ' ', nil].each do |r| | |
164 | assert_nil @repository.find_changeset_by_name(r) |
|
164 | assert_nil @repository.find_changeset_by_name(r) | |
165 | end |
|
165 | end | |
166 | end |
|
166 | end | |
167 |
|
167 | |||
168 | def test_identifier_nine_digit |
|
168 | def test_identifier_nine_digit | |
169 | c = Changeset.new(:repository => @repository, :committed_on => Time.now, |
|
169 | c = Changeset.new(:repository => @repository, :committed_on => Time.now, | |
170 | :revision => '123456789', :comments => 'test') |
|
170 | :revision => '123456789', :comments => 'test') | |
171 | assert_equal c.identifier, c.revision |
|
171 | assert_equal c.identifier, c.revision | |
172 | end |
|
172 | end | |
173 |
|
173 | |||
174 | def test_format_identifier |
|
174 | def test_format_identifier | |
175 | assert_equal 0, @repository.changesets.count |
|
175 | assert_equal 0, @repository.changesets.count | |
176 | @repository.fetch_changesets |
|
176 | @repository.fetch_changesets | |
177 | @project.reload |
|
177 | @project.reload | |
178 | assert_equal NUM_REV, @repository.changesets.count |
|
178 | assert_equal NUM_REV, @repository.changesets.count | |
179 | c = @repository.changesets.find_by_revision('1') |
|
179 | c = @repository.changesets.find_by_revision('1') | |
180 | assert_equal c.format_identifier, c.revision |
|
180 | assert_equal c.format_identifier, c.revision | |
181 | end |
|
181 | end | |
182 |
|
182 | |||
183 | def test_format_identifier_nine_digit |
|
183 | def test_format_identifier_nine_digit | |
184 | c = Changeset.new(:repository => @repository, :committed_on => Time.now, |
|
184 | c = Changeset.new(:repository => @repository, :committed_on => Time.now, | |
185 | :revision => '123456789', :comments => 'test') |
|
185 | :revision => '123456789', :comments => 'test') | |
186 | assert_equal c.format_identifier, c.revision |
|
186 | assert_equal c.format_identifier, c.revision | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | def test_activities |
|
189 | def test_activities | |
190 | c = Changeset.new(:repository => @repository, :committed_on => Time.now, |
|
190 | c = Changeset.new(:repository => @repository, :committed_on => Time.now, | |
191 | :revision => '1', :comments => 'test') |
|
191 | :revision => '1', :comments => 'test') | |
192 | assert c.event_title.include?('1:') |
|
192 | assert c.event_title.include?('1:') | |
193 | assert_equal '1', c.event_url[:rev] |
|
193 | assert_equal '1', c.event_url[:rev] | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | def test_activities_nine_digit |
|
196 | def test_activities_nine_digit | |
197 | c = Changeset.new(:repository => @repository, :committed_on => Time.now, |
|
197 | c = Changeset.new(:repository => @repository, :committed_on => Time.now, | |
198 | :revision => '123456789', :comments => 'test') |
|
198 | :revision => '123456789', :comments => 'test') | |
199 | assert c.event_title.include?('123456789:') |
|
199 | assert c.event_title.include?('123456789:') | |
200 | assert_equal '123456789', c.event_url[:rev] |
|
200 | assert_equal '123456789', c.event_url[:rev] | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | def test_log_encoding_ignore_setting |
|
203 | def test_log_encoding_ignore_setting | |
204 | with_settings :commit_logs_encoding => 'windows-1252' do |
|
204 | with_settings :commit_logs_encoding => 'windows-1252' do | |
205 | s1 = "\xC2\x80" |
|
205 | s1 = "\xC2\x80" | |
206 | s2 = "\xc3\x82\xc2\x80" |
|
206 | s2 = "\xc3\x82\xc2\x80" | |
207 | if s1.respond_to?(:force_encoding) |
|
207 | if s1.respond_to?(:force_encoding) | |
208 | s1.force_encoding('ISO-8859-1') |
|
208 | s1.force_encoding('ISO-8859-1') | |
209 | s2.force_encoding('UTF-8') |
|
209 | s2.force_encoding('UTF-8') | |
210 | assert_equal s1.encode('UTF-8'), s2 |
|
210 | assert_equal s1.encode('UTF-8'), s2 | |
211 | end |
|
211 | end | |
212 | c = Changeset.new(:repository => @repository, |
|
212 | c = Changeset.new(:repository => @repository, | |
213 | :comments => s2, |
|
213 | :comments => s2, | |
214 | :revision => '123', |
|
214 | :revision => '123', | |
215 | :committed_on => Time.now) |
|
215 | :committed_on => Time.now) | |
216 | assert c.save |
|
216 | assert c.save | |
217 | assert_equal s2, c.comments |
|
217 | assert_equal s2, c.comments | |
218 | end |
|
218 | end | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | def test_previous |
|
221 | def test_previous | |
222 | assert_equal 0, @repository.changesets.count |
|
222 | assert_equal 0, @repository.changesets.count | |
223 | @repository.fetch_changesets |
|
223 | @repository.fetch_changesets | |
224 | @project.reload |
|
224 | @project.reload | |
225 | assert_equal NUM_REV, @repository.changesets.count |
|
225 | assert_equal NUM_REV, @repository.changesets.count | |
226 | changeset = @repository.find_changeset_by_name('3') |
|
226 | changeset = @repository.find_changeset_by_name('3') | |
227 | assert_equal @repository.find_changeset_by_name('2'), changeset.previous |
|
227 | assert_equal @repository.find_changeset_by_name('2'), changeset.previous | |
228 | end |
|
228 | end | |
229 |
|
229 | |||
230 | def test_previous_nil |
|
230 | def test_previous_nil | |
231 | assert_equal 0, @repository.changesets.count |
|
231 | assert_equal 0, @repository.changesets.count | |
232 | @repository.fetch_changesets |
|
232 | @repository.fetch_changesets | |
233 | @project.reload |
|
233 | @project.reload | |
234 | assert_equal NUM_REV, @repository.changesets.count |
|
234 | assert_equal NUM_REV, @repository.changesets.count | |
235 | changeset = @repository.find_changeset_by_name('1') |
|
235 | changeset = @repository.find_changeset_by_name('1') | |
236 | assert_nil changeset.previous |
|
236 | assert_nil changeset.previous | |
237 | end |
|
237 | end | |
238 |
|
238 | |||
239 | def test_next |
|
239 | def test_next | |
240 | assert_equal 0, @repository.changesets.count |
|
240 | assert_equal 0, @repository.changesets.count | |
241 | @repository.fetch_changesets |
|
241 | @repository.fetch_changesets | |
242 | @project.reload |
|
242 | @project.reload | |
243 | assert_equal NUM_REV, @repository.changesets.count |
|
243 | assert_equal NUM_REV, @repository.changesets.count | |
244 | changeset = @repository.find_changeset_by_name('2') |
|
244 | changeset = @repository.find_changeset_by_name('2') | |
245 | assert_equal @repository.find_changeset_by_name('3'), changeset.next |
|
245 | assert_equal @repository.find_changeset_by_name('3'), changeset.next | |
246 | end |
|
246 | end | |
247 |
|
247 | |||
248 | def test_next_nil |
|
248 | def test_next_nil | |
249 | assert_equal 0, @repository.changesets.count |
|
249 | assert_equal 0, @repository.changesets.count | |
250 | @repository.fetch_changesets |
|
250 | @repository.fetch_changesets | |
251 | @project.reload |
|
251 | @project.reload | |
252 | assert_equal NUM_REV, @repository.changesets.count |
|
252 | assert_equal NUM_REV, @repository.changesets.count | |
253 | changeset = @repository.find_changeset_by_name('11') |
|
253 | changeset = @repository.find_changeset_by_name('11') | |
254 | assert_nil changeset.next |
|
254 | assert_nil changeset.next | |
255 | end |
|
255 | end | |
256 | else |
|
256 | else | |
257 | puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" |
|
257 | puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" | |
258 | def test_fake; assert true end |
|
258 | def test_fake; assert true end | |
259 | end |
|
259 | end | |
260 | end |
|
260 | end |
General Comments 0
You need to be logged in to leave comments.
Login now