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