annotate test/unit/repository_git_test.rb @ 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 RepositoryGitTest < ActiveSupport::TestCase
Chris@117 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
Chris@0 22
Chris@0 23 # No '..' in the repository path
Chris@0 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
Chris@0 25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
Chris@0 26
Chris@0 27 def setup
Chris@0 28 @project = Project.find(1)
Chris@0 29 assert @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH)
Chris@0 30 end
Chris@0 31
Chris@0 32 if File.directory?(REPOSITORY_PATH)
Chris@0 33 def test_fetch_changesets_from_scratch
Chris@0 34 @repository.fetch_changesets
Chris@0 35 @repository.reload
Chris@0 36
chris@37 37 assert_equal 15, @repository.changesets.count
chris@37 38 assert_equal 24, @repository.changes.count
Chris@0 39
Chris@0 40 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
Chris@0 41 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
Chris@0 42 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
Chris@0 43 assert_equal User.find_by_login('jsmith'), commit.user
Chris@0 44 # TODO: add a commit with commit time <> author time to the test repository
Chris@0 45 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
Chris@0 46 assert_equal "2007-12-14".to_date, commit.commit_date
Chris@0 47 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
Chris@0 48 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
Chris@0 49 assert_equal 3, commit.changes.count
Chris@0 50 change = commit.changes.sort_by(&:path).first
Chris@0 51 assert_equal "README", change.path
Chris@0 52 assert_equal "A", change.action
Chris@0 53 end
Chris@0 54
Chris@0 55 def test_fetch_changesets_incremental
Chris@0 56 @repository.fetch_changesets
Chris@0 57 # Remove the 3 latest changesets
Chris@0 58 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
Chris@0 59 @repository.reload
chris@37 60 assert_equal 12, @repository.changesets.count
Chris@0 61
Chris@0 62 @repository.fetch_changesets
chris@37 63 assert_equal 15, @repository.changesets.count
Chris@0 64 end
Chris@117 65
Chris@117 66 def test_find_changeset_by_name
Chris@117 67 @repository.fetch_changesets
Chris@117 68 @repository.reload
Chris@117 69 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
Chris@117 70 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
Chris@117 71 @repository.find_changeset_by_name(r).revision
Chris@117 72 end
Chris@117 73 end
Chris@117 74
Chris@117 75 def test_find_changeset_by_empty_name
Chris@117 76 @repository.fetch_changesets
Chris@117 77 @repository.reload
Chris@117 78 ['', ' ', nil].each do |r|
Chris@117 79 assert_nil @repository.find_changeset_by_name(r)
Chris@117 80 end
Chris@117 81 end
Chris@117 82
Chris@117 83 def test_identifier
Chris@117 84 @repository.fetch_changesets
Chris@117 85 @repository.reload
Chris@117 86 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
Chris@117 87 assert_equal c.scmid, c.identifier
Chris@117 88 end
Chris@117 89
Chris@117 90 def test_format_identifier
Chris@117 91 @repository.fetch_changesets
Chris@117 92 @repository.reload
Chris@117 93 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
Chris@117 94 assert_equal '7234cb27', c.format_identifier
Chris@117 95 end
Chris@117 96
Chris@117 97 def test_activities
Chris@117 98 c = Changeset.new(:repository => @repository,
Chris@117 99 :committed_on => Time.now,
Chris@117 100 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
Chris@117 101 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
Chris@117 102 :comments => 'test')
Chris@117 103 assert c.event_title.include?('abc7234c:')
Chris@117 104 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
Chris@117 105 end
Chris@0 106 else
Chris@0 107 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
Chris@0 108 def test_fake; assert true end
Chris@0 109 end
Chris@0 110 end