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