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