annotate test/unit/repository_git_test.rb @ 245:051f544170fe

* Update to SVN trunk revision 4993
author Chris Cannam
date Thu, 03 Mar 2011 11:42:28 +0000
parents 8661b858af72
children cbce1fd3b1b7
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 RepositoryGitTest < ActiveSupport::TestCase
Chris@245 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
Chris@245 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@245 26
Chris@245 27 FELIX_HEX = "Felix Sch\xC3\xA4fer"
Chris@245 28
Chris@0 29 def setup
Chris@245 30 Setting.commit_logs_encoding = 'UTF-8'
Chris@245 31 @project = Project.find(3)
Chris@245 32 @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH)
Chris@245 33 assert @repository
Chris@0 34 end
Chris@245 35
Chris@0 36 if File.directory?(REPOSITORY_PATH)
Chris@0 37 def test_fetch_changesets_from_scratch
Chris@0 38 @repository.fetch_changesets
Chris@0 39 @repository.reload
Chris@245 40
Chris@245 41 assert_equal 16, @repository.changesets.count
Chris@245 42 assert_equal 25, @repository.changes.count
Chris@245 43
Chris@0 44 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
Chris@0 45 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
Chris@0 46 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
Chris@0 47 assert_equal User.find_by_login('jsmith'), commit.user
Chris@0 48 # TODO: add a commit with commit time <> author time to the test repository
Chris@0 49 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
Chris@0 50 assert_equal "2007-12-14".to_date, commit.commit_date
Chris@0 51 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
Chris@0 52 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
Chris@0 53 assert_equal 3, commit.changes.count
Chris@0 54 change = commit.changes.sort_by(&:path).first
Chris@0 55 assert_equal "README", change.path
Chris@0 56 assert_equal "A", change.action
Chris@0 57 end
Chris@0 58
Chris@0 59 def test_fetch_changesets_incremental
Chris@0 60 @repository.fetch_changesets
Chris@0 61 # Remove the 3 latest changesets
Chris@0 62 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
Chris@0 63 @repository.reload
Chris@245 64 cs1 = @repository.changesets
Chris@245 65 assert_equal 13, cs1.count
Chris@245 66
Chris@245 67 rev_a_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
Chris@245 68 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision
Chris@245 69 # Mon Jul 5 22:34:26 2010 +0200
Chris@245 70 rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26)
Chris@245 71 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid
Chris@245 72 assert_equal rev_a_committed_on, rev_a_commit.committed_on
Chris@245 73 latest_rev = @repository.latest_changeset
Chris@245 74 assert_equal rev_a_committed_on, latest_rev.committed_on
Chris@245 75
Chris@0 76 @repository.fetch_changesets
Chris@245 77 assert_equal 16, @repository.changesets.count
Chris@0 78 end
Chris@119 79
Chris@119 80 def test_find_changeset_by_name
Chris@119 81 @repository.fetch_changesets
Chris@119 82 @repository.reload
Chris@119 83 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
Chris@119 84 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
Chris@119 85 @repository.find_changeset_by_name(r).revision
Chris@119 86 end
Chris@119 87 end
Chris@119 88
Chris@119 89 def test_find_changeset_by_empty_name
Chris@119 90 @repository.fetch_changesets
Chris@119 91 @repository.reload
Chris@119 92 ['', ' ', nil].each do |r|
Chris@119 93 assert_nil @repository.find_changeset_by_name(r)
Chris@119 94 end
Chris@119 95 end
Chris@119 96
Chris@119 97 def test_identifier
Chris@119 98 @repository.fetch_changesets
Chris@119 99 @repository.reload
Chris@119 100 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
Chris@119 101 assert_equal c.scmid, c.identifier
Chris@119 102 end
Chris@119 103
Chris@119 104 def test_format_identifier
Chris@119 105 @repository.fetch_changesets
Chris@119 106 @repository.reload
Chris@119 107 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
Chris@119 108 assert_equal '7234cb27', c.format_identifier
Chris@119 109 end
Chris@119 110
Chris@119 111 def test_activities
Chris@119 112 c = Changeset.new(:repository => @repository,
Chris@119 113 :committed_on => Time.now,
Chris@119 114 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
Chris@119 115 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
Chris@119 116 :comments => 'test')
Chris@119 117 assert c.event_title.include?('abc7234c:')
Chris@119 118 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
Chris@119 119 end
Chris@245 120
Chris@245 121 def test_log_utf8
Chris@245 122 @repository.fetch_changesets
Chris@245 123 @repository.reload
Chris@245 124 str_felix_hex = FELIX_HEX
Chris@245 125 if str_felix_hex.respond_to?(:force_encoding)
Chris@245 126 str_felix_hex.force_encoding('UTF-8')
Chris@245 127 end
Chris@245 128 c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
Chris@245 129 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
Chris@245 130 end
Chris@0 131 else
Chris@0 132 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
Chris@0 133 def test_fake; assert true end
Chris@0 134 end
Chris@0 135 end