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