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