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