##// 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 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositorySubversionTest < ActiveSupport::TestCase
21 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22
22
23 23 def setup
24 24 @project = Project.find(3)
25 assert @repository = Repository::Subversion.create(:project => @project,
25 @repository = Repository::Subversion.create(:project => @project,
26 26 :url => "file://#{self.class.repository_path('subversion')}")
27 assert @repository
27 28 end
28
29
29 30 if repository_configured?('subversion')
30 31 def test_fetch_changesets_from_scratch
31 32 @repository.fetch_changesets
32 33 @repository.reload
33 34
34 35 assert_equal 11, @repository.changesets.count
35 36 assert_equal 20, @repository.changes.count
36 37 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
37 38 end
38
39
39 40 def test_fetch_changesets_incremental
40 41 @repository.fetch_changesets
41 42 # Remove changesets with revision > 5
42 43 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5}
43 44 @repository.reload
44 45 assert_equal 5, @repository.changesets.count
45 46
46 47 @repository.fetch_changesets
47 48 assert_equal 11, @repository.changesets.count
48 49 end
49
50
50 51 def test_latest_changesets
51 52 @repository.fetch_changesets
52 53
53 54 # with limit
54 55 changesets = @repository.latest_changesets('', nil, 2)
55 56 assert_equal 2, changesets.size
56 57 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
57 58
58 59 # with path
59 60 changesets = @repository.latest_changesets('subversion_test/folder', nil)
60 61 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
61 62
62 63 # with path and revision
63 64 changesets = @repository.latest_changesets('subversion_test/folder', 8)
64 65 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
65 66 end
66 67
67 68 def test_directory_listing_with_square_brackets_in_path
68 69 @repository.fetch_changesets
69 70 @repository.reload
70 71
71 72 entries = @repository.entries('subversion_test/[folder_with_brackets]')
72 73 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
73 74 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
74 75 assert_equal 'README.txt', entries.first.name
75 76 end
76 77
77 78 def test_directory_listing_with_square_brackets_in_base
78 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 84 @repository.fetch_changesets
82 85 @repository.reload
83 86
84 87 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
85 88 assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add'
86 89
87 90 entries = @repository.entries('')
88 91 assert_not_nil entries, 'Expect to find entries'
89 92 assert_equal 1, entries.size, 'Expect a single entry'
90 93 assert_equal 'README.txt', entries.first.name
91 94 end
92 95
93 96 def test_identifier
94 97 @repository.fetch_changesets
95 98 @repository.reload
96 99 c = @repository.changesets.find_by_revision('1')
97 100 assert_equal c.revision, c.identifier
98 101 end
99 102
100 103 def test_find_changeset_by_empty_name
101 104 @repository.fetch_changesets
102 105 @repository.reload
103 106 ['', ' ', nil].each do |r|
104 107 assert_nil @repository.find_changeset_by_name(r)
105 108 end
106 109 end
107 110
108 111 def test_identifier_nine_digit
109 112 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
110 113 :revision => '123456789', :comments => 'test')
111 114 assert_equal c.identifier, c.revision
112 115 end
113 116
114 117 def test_format_identifier
115 118 @repository.fetch_changesets
116 119 @repository.reload
117 120 c = @repository.changesets.find_by_revision('1')
118 121 assert_equal c.format_identifier, c.revision
119 122 end
120 123
121 124 def test_format_identifier_nine_digit
122 125 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
123 126 :revision => '123456789', :comments => 'test')
124 127 assert_equal c.format_identifier, c.revision
125 128 end
126 129
127 130 def test_activities
128 131 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
129 132 :revision => '1', :comments => 'test')
130 133 assert c.event_title.include?('1:')
131 134 assert_equal '1', c.event_url[:rev]
132 135 end
133 136
134 137 def test_activities_nine_digit
135 138 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
136 139 :revision => '123456789', :comments => 'test')
137 140 assert c.event_title.include?('123456789:')
138 141 assert_equal '123456789', c.event_url[:rev]
139 142 end
140 143
141 144 def test_log_encoding_ignore_setting
142 145 with_settings :commit_logs_encoding => 'windows-1252' do
143 146 s1 = "\xC2\x80"
144 147 s2 = "\xc3\x82\xc2\x80"
145 148 if s1.respond_to?(:force_encoding)
146 149 s1.force_encoding('ISO-8859-1')
147 150 s2.force_encoding('UTF-8')
148 151 assert_equal s1.encode('UTF-8'), s2
149 152 end
150 153 c = Changeset.new(:repository => @repository,
151 154 :comments => s2,
152 155 :revision => '123',
153 156 :committed_on => Time.now)
154 157 assert c.save
155 158 assert_equal s2, c.comments
156 159 end
157 160 end
158 161
159 162 def test_previous
160 163 @repository.fetch_changesets
161 164 @repository.reload
162 165 changeset = @repository.find_changeset_by_name('3')
163 166 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
164 167 end
165 168
166 169 def test_previous_nil
167 170 @repository.fetch_changesets
168 171 @repository.reload
169 172 changeset = @repository.find_changeset_by_name('1')
170 173 assert_nil changeset.previous
171 174 end
172 175
173 176 def test_next
174 177 @repository.fetch_changesets
175 178 @repository.reload
176 179 changeset = @repository.find_changeset_by_name('2')
177 180 assert_equal @repository.find_changeset_by_name('3'), changeset.next
178 181 end
179 182
180 183 def test_next_nil
181 184 @repository.fetch_changesets
182 185 @repository.reload
183 186 changeset = @repository.find_changeset_by_name('11')
184 187 assert_nil changeset.next
185 188 end
186 189 else
187 190 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
188 191 def test_fake; assert true end
189 192 end
190 193 end
General Comments 0
You need to be logged in to leave comments. Login now