annotate .svn/pristine/b0/b080561727eb14f1a6a2cf717727d6923d2488b6.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../../../../../../test_helper', __FILE__)
Chris@1494 19 begin
Chris@1494 20 require 'mocha/setup'
Chris@1494 21
Chris@1494 22 class CvsAdapterTest < ActiveSupport::TestCase
Chris@1494 23 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
Chris@1494 24 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
Chris@1494 25 MODULE_NAME = 'test'
Chris@1494 26
Chris@1494 27 if File.directory?(REPOSITORY_PATH)
Chris@1494 28 def setup
Chris@1494 29 @adapter = Redmine::Scm::Adapters::CvsAdapter.new(MODULE_NAME, REPOSITORY_PATH)
Chris@1494 30 end
Chris@1494 31
Chris@1494 32 def test_scm_version
Chris@1494 33 to_test = { "\nConcurrent Versions System (CVS) 1.12.13 (client/server)\n" => [1,12,13],
Chris@1494 34 "\r\n1.12.12\r\n1.12.11" => [1,12,12],
Chris@1494 35 "1.12.11\r\n1.12.10\r\n" => [1,12,11]}
Chris@1494 36 to_test.each do |s, v|
Chris@1494 37 test_scm_version_for(s, v)
Chris@1494 38 end
Chris@1494 39 end
Chris@1494 40
Chris@1494 41 def test_revisions_all
Chris@1494 42 cnt = 0
Chris@1494 43 @adapter.revisions('', nil, nil, :log_encoding => 'UTF-8') do |revision|
Chris@1494 44 cnt += 1
Chris@1494 45 end
Chris@1494 46 assert_equal 16, cnt
Chris@1494 47 end
Chris@1494 48
Chris@1494 49 def test_revisions_from_rev3
Chris@1494 50 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
Chris@1494 51 cnt = 0
Chris@1494 52 @adapter.revisions('', rev3_committed_on, nil, :log_encoding => 'UTF-8') do |revision|
Chris@1494 53 cnt += 1
Chris@1494 54 end
Chris@1494 55 assert_equal 4, cnt
Chris@1494 56 end
Chris@1494 57
Chris@1494 58 def test_entries_rev3
Chris@1494 59 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
Chris@1494 60 entries = @adapter.entries('sources', rev3_committed_on)
Chris@1494 61 assert_equal 2, entries.size
Chris@1494 62 assert_equal entries[0].name, "watchers_controller.rb"
Chris@1494 63 assert_equal entries[0].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
Chris@1494 64 end
Chris@1494 65
Chris@1494 66 def test_path_encoding_default_utf8
Chris@1494 67 adpt1 = Redmine::Scm::Adapters::CvsAdapter.new(
Chris@1494 68 MODULE_NAME,
Chris@1494 69 REPOSITORY_PATH
Chris@1494 70 )
Chris@1494 71 assert_equal "UTF-8", adpt1.path_encoding
Chris@1494 72 adpt2 = Redmine::Scm::Adapters::CvsAdapter.new(
Chris@1494 73 MODULE_NAME,
Chris@1494 74 REPOSITORY_PATH,
Chris@1494 75 nil,
Chris@1494 76 nil,
Chris@1494 77 ""
Chris@1494 78 )
Chris@1494 79 assert_equal "UTF-8", adpt2.path_encoding
Chris@1494 80 end
Chris@1494 81
Chris@1494 82 def test_root_url_path
Chris@1494 83 to_test = {
Chris@1494 84 ':pserver:cvs_user:cvs_password@123.456.789.123:9876/repo' => '/repo',
Chris@1494 85 ':pserver:cvs_user:cvs_password@123.456.789.123/repo' => '/repo',
Chris@1494 86 ':pserver:cvs_user:cvs_password@cvs_server:/repo' => '/repo',
Chris@1494 87 ':pserver:cvs_user:cvs_password@cvs_server:9876/repo' => '/repo',
Chris@1494 88 ':pserver:cvs_user:cvs_password@cvs_server/repo' => '/repo',
Chris@1494 89 ':pserver:cvs_user:cvs_password@cvs_server/path/repo' => '/path/repo',
Chris@1494 90 ':ext:cvsservername:/path' => '/path'
Chris@1494 91 }
Chris@1494 92
Chris@1494 93 to_test.each do |string, expected|
Chris@1494 94 assert_equal expected, Redmine::Scm::Adapters::CvsAdapter.new('foo', string).send(:root_url_path), "#{string} failed"
Chris@1494 95 end
Chris@1494 96 end
Chris@1494 97
Chris@1494 98 private
Chris@1494 99
Chris@1494 100 def test_scm_version_for(scm_command_version, version)
Chris@1494 101 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
Chris@1494 102 assert_equal version, @adapter.class.scm_command_version
Chris@1494 103 end
Chris@1494 104 else
Chris@1494 105 puts "Cvs test repository NOT FOUND. Skipping unit tests !!!"
Chris@1494 106 def test_fake; assert true end
Chris@1494 107 end
Chris@1494 108 end
Chris@1494 109
Chris@1494 110 rescue LoadError
Chris@1494 111 class CvsMochaFake < ActiveSupport::TestCase
Chris@1494 112 def test_fake; assert(false, "Requires mocha to run those tests") end
Chris@1494 113 end
Chris@1494 114 end
Chris@1494 115