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