annotate test/unit/lib/redmine/scm/adapters/mercurial_adapter_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 cd2282d2aa55
rev   line source
Chris@117 1 require File.expand_path('../../../../../../test_helper', __FILE__)
Chris@0 2 begin
Chris@0 3 require 'mocha'
Chris@117 4
Chris@0 5 class MercurialAdapterTest < ActiveSupport::TestCase
Chris@117 6
Chris@0 7 TEMPLATES_DIR = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATES_DIR
Chris@0 8 TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME
Chris@0 9 TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
Chris@117 10
Chris@0 11 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
Chris@117 12
Chris@117 13 if File.directory?(REPOSITORY_PATH)
Chris@117 14 def setup
Chris@117 15 @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH)
Chris@0 16 end
Chris@117 17
Chris@117 18 def test_hgversion
Chris@117 19 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
Chris@117 20 "Mercurial Distributed SCM (1.0)\n" => [1,0],
Chris@117 21 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
Chris@117 22 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
Chris@117 23 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
Chris@117 24 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
Chris@117 25 "(1.6)\n(1.7)\n(1.8)" => [1,6],
Chris@117 26 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
Chris@117 27
Chris@117 28 to_test.each do |s, v|
Chris@117 29 test_hgversion_for(s, v)
Chris@117 30 end
Chris@0 31 end
Chris@117 32
Chris@117 33 def test_template_path
Chris@117 34 to_test = { [0,9,5] => "0.9.5",
Chris@117 35 [1,0] => "1.0",
Chris@117 36 [] => "1.0",
Chris@117 37 [1,0,1] => "1.0",
Chris@117 38 [1,7] => "1.0",
Chris@117 39 [1,7,1] => "1.0" }
Chris@117 40 to_test.each do |v, template|
Chris@117 41 test_template_path_for(v, template)
Chris@117 42 end
Chris@117 43 end
Chris@117 44
Chris@117 45 def test_cat
Chris@117 46 assert @adapter.cat("sources/welcome_controller.rb", 2)
Chris@117 47 assert_nil @adapter.cat("sources/welcome_controller.rb")
Chris@117 48 end
Chris@117 49
Chris@117 50 private
Chris@117 51
Chris@117 52 def test_hgversion_for(hgversion, version)
Chris@117 53 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
Chris@117 54 assert_equal version, @adapter.class.hgversion
Chris@117 55 end
Chris@117 56
Chris@117 57 def test_template_path_for(version, template)
Chris@117 58 assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
Chris@117 59 @adapter.class.template_path_for(version)
Chris@117 60 assert File.exist?(@adapter.class.template_path_for(version))
Chris@117 61 end
Chris@117 62 else
Chris@117 63 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
Chris@117 64 def test_fake; assert true end
Chris@0 65 end
Chris@0 66 end
Chris@117 67
Chris@0 68 rescue LoadError
Chris@117 69 class MercurialMochaFake < ActiveSupport::TestCase
Chris@117 70 def test_fake; assert(false, "Requires mocha to run those tests") end
Chris@117 71 end
Chris@0 72 end
Chris@117 73