annotate test/unit/.svn/text-base/repository_subversion_test.rb.svn-base @ 904:0a8317a50fa0 redmine-1.1

Close obsolete branch redmine-1.1
author Chris Cannam
date Fri, 14 Jan 2011 12:53:21 +0000
parents af80e5618e9b
children 051f544170fe
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@117 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19
Chris@0 20 class RepositorySubversionTest < ActiveSupport::TestCase
Chris@117 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
Chris@0 22
Chris@0 23 def setup
Chris@0 24 @project = Project.find(1)
Chris@0 25 assert @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}")
Chris@0 26 end
Chris@0 27
Chris@0 28 if repository_configured?('subversion')
Chris@0 29 def test_fetch_changesets_from_scratch
Chris@0 30 @repository.fetch_changesets
Chris@0 31 @repository.reload
Chris@0 32
Chris@0 33 assert_equal 11, @repository.changesets.count
Chris@0 34 assert_equal 20, @repository.changes.count
Chris@0 35 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
Chris@0 36 end
Chris@0 37
Chris@0 38 def test_fetch_changesets_incremental
Chris@0 39 @repository.fetch_changesets
Chris@0 40 # Remove changesets with revision > 5
Chris@0 41 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5}
Chris@0 42 @repository.reload
Chris@0 43 assert_equal 5, @repository.changesets.count
Chris@0 44
Chris@0 45 @repository.fetch_changesets
Chris@0 46 assert_equal 11, @repository.changesets.count
Chris@0 47 end
Chris@0 48
Chris@0 49 def test_latest_changesets
Chris@0 50 @repository.fetch_changesets
Chris@0 51
Chris@0 52 # with limit
Chris@0 53 changesets = @repository.latest_changesets('', nil, 2)
Chris@0 54 assert_equal 2, changesets.size
Chris@0 55 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
Chris@0 56
Chris@0 57 # with path
Chris@0 58 changesets = @repository.latest_changesets('subversion_test/folder', nil)
Chris@0 59 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
Chris@0 60
Chris@0 61 # with path and revision
Chris@0 62 changesets = @repository.latest_changesets('subversion_test/folder', 8)
Chris@0 63 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
Chris@0 64 end
Chris@0 65
Chris@0 66 def test_directory_listing_with_square_brackets_in_path
Chris@0 67 @repository.fetch_changesets
Chris@0 68 @repository.reload
Chris@0 69
Chris@0 70 entries = @repository.entries('subversion_test/[folder_with_brackets]')
Chris@0 71 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
Chris@0 72 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
Chris@0 73 assert_equal 'README.txt', entries.first.name
Chris@0 74 end
Chris@0 75
Chris@0 76 def test_directory_listing_with_square_brackets_in_base
Chris@0 77 @project = Project.find(1)
Chris@0 78 @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
Chris@0 79
Chris@0 80 @repository.fetch_changesets
Chris@0 81 @repository.reload
Chris@0 82
Chris@0 83 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
Chris@0 84 assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add'
Chris@0 85
Chris@0 86 entries = @repository.entries('')
Chris@0 87 assert_not_nil entries, 'Expect to find entries'
Chris@0 88 assert_equal 1, entries.size, 'Expect a single entry'
Chris@0 89 assert_equal 'README.txt', entries.first.name
Chris@0 90 end
Chris@117 91
Chris@117 92 def test_identifier
Chris@117 93 @repository.fetch_changesets
Chris@117 94 @repository.reload
Chris@117 95 c = @repository.changesets.find_by_revision('1')
Chris@117 96 assert_equal c.revision, c.identifier
Chris@117 97 end
Chris@117 98
Chris@117 99 def test_find_changeset_by_empty_name
Chris@117 100 @repository.fetch_changesets
Chris@117 101 @repository.reload
Chris@117 102 ['', ' ', nil].each do |r|
Chris@117 103 assert_nil @repository.find_changeset_by_name(r)
Chris@117 104 end
Chris@117 105 end
Chris@117 106
Chris@117 107 def test_identifier_nine_digit
Chris@117 108 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
Chris@117 109 :revision => '123456789', :comments => 'test')
Chris@117 110 assert_equal c.identifier, c.revision
Chris@117 111 end
Chris@117 112
Chris@117 113 def test_format_identifier
Chris@117 114 @repository.fetch_changesets
Chris@117 115 @repository.reload
Chris@117 116 c = @repository.changesets.find_by_revision('1')
Chris@117 117 assert_equal c.format_identifier, c.revision
Chris@117 118 end
Chris@117 119
Chris@117 120 def test_format_identifier_nine_digit
Chris@117 121 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
Chris@117 122 :revision => '123456789', :comments => 'test')
Chris@117 123 assert_equal c.format_identifier, c.revision
Chris@117 124 end
Chris@117 125
Chris@117 126 def test_activities
Chris@117 127 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
Chris@117 128 :revision => '1', :comments => 'test')
Chris@117 129 assert c.event_title.include?('1:')
Chris@117 130 assert_equal '1', c.event_url[:rev]
Chris@117 131 end
Chris@117 132
Chris@117 133 def test_activities_nine_digit
Chris@117 134 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
Chris@117 135 :revision => '123456789', :comments => 'test')
Chris@117 136 assert c.event_title.include?('123456789:')
Chris@117 137 assert_equal '123456789', c.event_url[:rev]
Chris@117 138 end
Chris@0 139 else
Chris@0 140 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
Chris@0 141 def test_fake; assert true end
Chris@0 142 end
Chris@0 143 end