annotate test/unit/lib/redmine/scm/adapters/git_adapter_test.rb @ 889:e124b1258c0b bug_83

Close obsolete branch bug_83
author Chris Cannam
date Sat, 19 Feb 2011 09:58:02 +0000
parents 94944d00e43c
children af80e5618e9b
rev   line source
Chris@0 1 require File.dirname(__FILE__) + '/../../../../../test_helper'
Chris@0 2
Chris@0 3 class GitAdapterTest < ActiveSupport::TestCase
Chris@0 4 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
Chris@0 5
Chris@0 6 if File.directory?(REPOSITORY_PATH)
Chris@0 7 def setup
Chris@0 8 @adapter = Redmine::Scm::Adapters::GitAdapter.new(REPOSITORY_PATH)
Chris@0 9 end
Chris@0 10
Chris@0 11 def test_branches
Chris@0 12 assert_equal @adapter.branches, ['master', 'test_branch']
Chris@0 13 end
Chris@0 14
Chris@0 15 def test_getting_all_revisions
chris@37 16 assert_equal 15, @adapter.revisions('',nil,nil,:all => true).length
Chris@0 17 end
Chris@0 18
Chris@14 19 def test_getting_certain_revisions
Chris@14 20 assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length
Chris@14 21 end
Chris@14 22
chris@37 23 def test_getting_revisions_with_spaces_in_filename
chris@37 24 assert_equal 1, @adapter.revisions("filemane with spaces.txt", nil, nil, :all => true).length
chris@37 25 end
chris@37 26
chris@37 27 def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
chris@37 28 assert_equal " filename with a leading space.txt ", @adapter.revisions(" filename with a leading space.txt ", nil, nil, :all => true)[0].paths[0][:path]
chris@37 29 end
chris@37 30
chris@37 31 def test_getting_entries_with_leading_and_trailing_spaces_in_filename
chris@37 32 assert_equal " filename with a leading space.txt ", @adapter.entries('', '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
chris@37 33 end
chris@37 34
Chris@0 35 def test_annotate
Chris@0 36 annotate = @adapter.annotate('sources/watchers_controller.rb')
Chris@0 37 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
Chris@0 38 assert_equal 41, annotate.lines.size
Chris@0 39 assert_equal "# This program is free software; you can redistribute it and/or", annotate.lines[4].strip
Chris@0 40 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", annotate.revisions[4].identifier
Chris@0 41 assert_equal "jsmith", annotate.revisions[4].author
Chris@0 42 end
Chris@0 43
Chris@0 44 def test_annotate_moved_file
Chris@0 45 annotate = @adapter.annotate('renamed_test.txt')
Chris@0 46 assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
Chris@0 47 assert_equal 2, annotate.lines.size
Chris@0 48 end
chris@37 49
chris@37 50 def test_last_rev
chris@37 51 last_rev = @adapter.lastrev("README", "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
chris@37 52 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
chris@37 53 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
chris@37 54 assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
chris@37 55 assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
chris@37 56 end
chris@37 57
chris@37 58 def test_last_rev_with_spaces_in_filename
chris@37 59 last_rev = @adapter.lastrev("filemane with spaces.txt", "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
chris@37 60 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
chris@37 61 assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
chris@37 62 assert_equal "Felix Schäfer <felix@fachschaften.org>", last_rev.author
chris@37 63 assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
chris@37 64 end
Chris@0 65 else
Chris@0 66 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
Chris@0 67 def test_fake; assert true end
Chris@0 68 end
Chris@0 69 end