annotate test/unit/repository_bazaar_test.rb @ 507:0c939c159af4 redmine-1.2

Update to Redmine 1.2.1 on 1.2-stable branch (Redmine SVN rev 6270)
author Chris Cannam
date Thu, 14 Jul 2011 10:32:19 +0100
parents cbce1fd3b1b7
children cbb26bc654de
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@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19
Chris@0 20 class RepositoryBazaarTest < ActiveSupport::TestCase
Chris@0 21 fixtures :projects
Chris@245 22
Chris@0 23 # No '..' in the repository path
Chris@0 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository'
Chris@0 25 REPOSITORY_PATH.gsub!(/\/+/, '/')
Chris@0 26
Chris@0 27 def setup
Chris@245 28 @project = Project.find(3)
Chris@245 29 @repository = Repository::Bazaar.create(
Chris@245 30 :project => @project, :url => "file:///#{REPOSITORY_PATH}",
Chris@245 31 :log_encoding => 'UTF-8')
Chris@245 32 assert @repository
Chris@0 33 end
Chris@245 34
Chris@0 35 if File.directory?(REPOSITORY_PATH)
Chris@0 36 def test_fetch_changesets_from_scratch
Chris@0 37 @repository.fetch_changesets
Chris@0 38 @repository.reload
Chris@0 39
Chris@0 40 assert_equal 4, @repository.changesets.count
Chris@0 41 assert_equal 9, @repository.changes.count
Chris@0 42 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
Chris@0 43 end
Chris@245 44
Chris@0 45 def test_fetch_changesets_incremental
Chris@0 46 @repository.fetch_changesets
Chris@0 47 # Remove changesets with revision > 5
Chris@0 48 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
Chris@0 49 @repository.reload
Chris@0 50 assert_equal 2, @repository.changesets.count
Chris@0 51
Chris@0 52 @repository.fetch_changesets
Chris@0 53 assert_equal 4, @repository.changesets.count
Chris@0 54 end
Chris@245 55
Chris@0 56 def test_entries
Chris@0 57 entries = @repository.entries
Chris@0 58 assert_equal 2, entries.size
Chris@0 59
Chris@0 60 assert_equal 'dir', entries[0].kind
Chris@0 61 assert_equal 'directory', entries[0].name
Chris@0 62
Chris@0 63 assert_equal 'file', entries[1].kind
Chris@0 64 assert_equal 'doc-mkdir.txt', entries[1].name
Chris@0 65 end
Chris@0 66
Chris@0 67 def test_entries_in_subdirectory
Chris@0 68 entries = @repository.entries('directory')
Chris@0 69 assert_equal 3, entries.size
Chris@0 70
Chris@0 71 assert_equal 'file', entries.last.kind
Chris@0 72 assert_equal 'edit.png', entries.last.name
Chris@0 73 end
Chris@441 74
Chris@441 75 def test_previous
Chris@441 76 @repository.fetch_changesets
Chris@441 77 @repository.reload
Chris@441 78 changeset = @repository.find_changeset_by_name('3')
Chris@441 79 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
Chris@441 80 end
Chris@441 81
Chris@441 82 def test_previous_nil
Chris@441 83 @repository.fetch_changesets
Chris@441 84 @repository.reload
Chris@441 85 changeset = @repository.find_changeset_by_name('1')
Chris@441 86 assert_nil changeset.previous
Chris@441 87 end
Chris@441 88
Chris@441 89 def test_next
Chris@441 90 @repository.fetch_changesets
Chris@441 91 @repository.reload
Chris@441 92 changeset = @repository.find_changeset_by_name('2')
Chris@441 93 assert_equal @repository.find_changeset_by_name('3'), changeset.next
Chris@441 94 end
Chris@441 95
Chris@441 96 def test_next_nil
Chris@441 97 @repository.fetch_changesets
Chris@441 98 @repository.reload
Chris@441 99 changeset = @repository.find_changeset_by_name('4')
Chris@441 100 assert_nil changeset.next
Chris@441 101 end
Chris@0 102 else
Chris@0 103 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
Chris@0 104 def test_fake; assert true end
Chris@0 105 end
Chris@0 106 end