annotate test/unit/lib/redmine/scm/adapters/git_adapter_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@119 1 # encoding: utf-8
Chris@119 2
Chris@245 3 # This file includes UTF-8 "Felix Schäfer".
Chris@245 4 # We need to consider Ruby 1.9 compatibility.
Chris@245 5
Chris@119 6 require File.expand_path('../../../../../../test_helper', __FILE__)
Chris@245 7 begin
Chris@245 8 require 'mocha'
Chris@0 9
Chris@245 10 class GitAdapterTest < ActiveSupport::TestCase
Chris@245 11 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
Chris@0 12
Chris@245 13 FELIX_UTF8 = "Felix Schäfer"
Chris@245 14 FELIX_HEX = "Felix Sch\xC3\xA4fer"
Chris@245 15
Chris@245 16 if File.directory?(REPOSITORY_PATH)
Chris@245 17 def setup
Chris@245 18 @adapter = Redmine::Scm::Adapters::GitAdapter.new(REPOSITORY_PATH)
Chris@245 19 end
Chris@245 20
Chris@245 21 def test_scm_version
Chris@245 22 to_test = { "git version 1.7.3.4\n" => [1,7,3,4],
Chris@245 23 "1.6.1\n1.7\n1.8" => [1,6,1],
Chris@245 24 "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
Chris@245 25 to_test.each do |s, v|
Chris@245 26 test_scm_version_for(s, v)
Chris@245 27 end
Chris@245 28 end
Chris@245 29
Chris@245 30 def test_branches
Chris@245 31 assert_equal @adapter.branches, ['master', 'test-latin-1', 'test_branch']
Chris@245 32 end
Chris@245 33
Chris@245 34 def test_getting_all_revisions
Chris@245 35 assert_equal 16, @adapter.revisions('',nil,nil,:all => true).length
Chris@245 36 end
Chris@245 37
Chris@245 38 def test_getting_certain_revisions
Chris@245 39 assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length
Chris@245 40 end
Chris@245 41
Chris@245 42 def test_getting_revisions_with_spaces_in_filename
Chris@245 43 assert_equal 1, @adapter.revisions("filemane with spaces.txt",
Chris@245 44 nil, nil, :all => true).length
Chris@245 45 end
Chris@245 46
Chris@245 47 def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
Chris@245 48 assert_equal " filename with a leading space.txt ",
Chris@245 49 @adapter.revisions(" filename with a leading space.txt ",
Chris@245 50 nil, nil, :all => true)[0].paths[0][:path]
Chris@245 51 end
Chris@245 52
Chris@245 53 def test_getting_entries_with_leading_and_trailing_spaces_in_filename
Chris@245 54 assert_equal " filename with a leading space.txt ",
Chris@245 55 @adapter.entries('',
Chris@245 56 '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
Chris@245 57 end
Chris@245 58
Chris@245 59 def test_annotate
Chris@245 60 annotate = @adapter.annotate('sources/watchers_controller.rb')
Chris@245 61 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
Chris@245 62 assert_equal 41, annotate.lines.size
Chris@245 63 assert_equal "# This program is free software; you can redistribute it and/or", annotate.lines[4].strip
Chris@245 64 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
Chris@245 65 annotate.revisions[4].identifier
Chris@245 66 assert_equal "jsmith", annotate.revisions[4].author
Chris@245 67 end
Chris@245 68
Chris@245 69 def test_annotate_moved_file
Chris@245 70 annotate = @adapter.annotate('renamed_test.txt')
Chris@245 71 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
Chris@245 72 assert_equal 2, annotate.lines.size
Chris@245 73 end
Chris@245 74
Chris@245 75 def test_last_rev
Chris@245 76 last_rev = @adapter.lastrev("README",
Chris@245 77 "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
Chris@245 78 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
Chris@245 79 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
Chris@245 80 assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
Chris@245 81 assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
Chris@245 82 end
Chris@245 83
Chris@245 84 def test_last_rev_with_spaces_in_filename
Chris@245 85 last_rev = @adapter.lastrev("filemane with spaces.txt",
Chris@245 86 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
Chris@245 87 str_felix_utf8 = FELIX_UTF8
Chris@245 88 str_felix_hex = FELIX_HEX
Chris@245 89 last_rev_author = last_rev.author
Chris@245 90 if last_rev_author.respond_to?(:force_encoding)
Chris@245 91 last_rev_author.force_encoding('UTF-8')
Chris@245 92 end
Chris@245 93 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
Chris@245 94 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
Chris@245 95 assert_equal "#{str_felix_utf8} <felix@fachschaften.org>",
Chris@245 96 last_rev.author
Chris@245 97 assert_equal "#{str_felix_hex} <felix@fachschaften.org>",
Chris@245 98 last_rev.author
Chris@245 99 assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
Chris@245 100 end
Chris@245 101
Chris@245 102 private
Chris@245 103
Chris@245 104 def test_scm_version_for(scm_command_version, version)
Chris@245 105 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
Chris@245 106 assert_equal version, @adapter.class.scm_command_version
Chris@245 107 end
Chris@245 108
Chris@245 109 else
Chris@245 110 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
Chris@245 111 def test_fake; assert true end
Chris@0 112 end
Chris@245 113 end
Chris@0 114
Chris@245 115 rescue LoadError
Chris@245 116 class GitMochaFake < ActiveSupport::TestCase
Chris@245 117 def test_fake; assert(false, "Requires mocha to run those tests") end
Chris@0 118 end
Chris@0 119 end
Chris@245 120