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