2012-09-15 01:40:45 +04:00
|
|
|
# Redmine - project management software
|
2014-01-30 02:45:39 +04:00
|
|
|
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
2012-09-15 01:40:45 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2011-02-02 16:13:20 +03:00
|
|
|
require File.expand_path('../../../../../../test_helper', __FILE__)
|
|
|
|
begin
|
2013-05-21 16:57:11 +04:00
|
|
|
require 'mocha/setup'
|
2011-05-13 10:15:21 +04:00
|
|
|
|
2011-02-02 16:13:20 +03:00
|
|
|
class CvsAdapterTest < ActiveSupport::TestCase
|
2011-06-10 16:53:19 +04:00
|
|
|
REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
|
2011-02-11 18:32:45 +03:00
|
|
|
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
|
2011-02-02 16:13:20 +03:00
|
|
|
MODULE_NAME = 'test'
|
|
|
|
|
2011-05-13 10:15:21 +04:00
|
|
|
if File.directory?(REPOSITORY_PATH)
|
2011-02-02 16:13:20 +03:00
|
|
|
def setup
|
|
|
|
@adapter = Redmine::Scm::Adapters::CvsAdapter.new(MODULE_NAME, REPOSITORY_PATH)
|
|
|
|
end
|
|
|
|
|
2011-02-15 11:04:11 +03:00
|
|
|
def test_scm_version
|
|
|
|
to_test = { "\nConcurrent Versions System (CVS) 1.12.13 (client/server)\n" => [1,12,13],
|
|
|
|
"\r\n1.12.12\r\n1.12.11" => [1,12,12],
|
|
|
|
"1.12.11\r\n1.12.10\r\n" => [1,12,11]}
|
|
|
|
to_test.each do |s, v|
|
|
|
|
test_scm_version_for(s, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-02 16:13:20 +03:00
|
|
|
def test_revisions_all
|
|
|
|
cnt = 0
|
2011-04-14 19:39:00 +04:00
|
|
|
@adapter.revisions('', nil, nil, :log_encoding => 'UTF-8') do |revision|
|
2011-02-02 16:13:20 +03:00
|
|
|
cnt += 1
|
|
|
|
end
|
2011-04-14 09:03:36 +04:00
|
|
|
assert_equal 16, cnt
|
2011-02-02 16:13:20 +03:00
|
|
|
end
|
2011-02-02 16:13:44 +03:00
|
|
|
|
|
|
|
def test_revisions_from_rev3
|
|
|
|
rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
|
|
|
|
cnt = 0
|
2011-04-14 19:39:00 +04:00
|
|
|
@adapter.revisions('', rev3_committed_on, nil, :log_encoding => 'UTF-8') do |revision|
|
2011-02-02 16:13:44 +03:00
|
|
|
cnt += 1
|
|
|
|
end
|
2011-04-14 09:03:36 +04:00
|
|
|
assert_equal 4, cnt
|
2011-02-02 16:13:44 +03:00
|
|
|
end
|
2011-02-15 11:04:11 +03:00
|
|
|
|
2011-03-11 07:19:33 +03:00
|
|
|
def test_entries_rev3
|
|
|
|
rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
|
|
|
|
entries = @adapter.entries('sources', rev3_committed_on)
|
|
|
|
assert_equal 2, entries.size
|
|
|
|
assert_equal entries[0].name, "watchers_controller.rb"
|
|
|
|
assert_equal entries[0].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
|
|
|
|
end
|
|
|
|
|
2011-05-21 06:19:38 +04:00
|
|
|
def test_path_encoding_default_utf8
|
|
|
|
adpt1 = Redmine::Scm::Adapters::CvsAdapter.new(
|
|
|
|
MODULE_NAME,
|
|
|
|
REPOSITORY_PATH
|
|
|
|
)
|
|
|
|
assert_equal "UTF-8", adpt1.path_encoding
|
|
|
|
adpt2 = Redmine::Scm::Adapters::CvsAdapter.new(
|
|
|
|
MODULE_NAME,
|
|
|
|
REPOSITORY_PATH,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
""
|
|
|
|
)
|
|
|
|
assert_equal "UTF-8", adpt2.path_encoding
|
|
|
|
end
|
|
|
|
|
2013-07-13 15:03:37 +04:00
|
|
|
def test_root_url_path
|
2013-07-16 01:06:54 +04:00
|
|
|
to_test = {
|
|
|
|
':pserver:cvs_user:cvs_password@123.456.789.123:9876/repo' => '/repo',
|
|
|
|
':pserver:cvs_user:cvs_password@123.456.789.123/repo' => '/repo',
|
|
|
|
':pserver:cvs_user:cvs_password@cvs_server:/repo' => '/repo',
|
|
|
|
':pserver:cvs_user:cvs_password@cvs_server:9876/repo' => '/repo',
|
|
|
|
':pserver:cvs_user:cvs_password@cvs_server/repo' => '/repo',
|
|
|
|
':pserver:cvs_user:cvs_password@cvs_server/path/repo' => '/path/repo',
|
|
|
|
':ext:cvsservername:/path' => '/path'
|
|
|
|
}
|
|
|
|
|
|
|
|
to_test.each do |string, expected|
|
|
|
|
assert_equal expected, Redmine::Scm::Adapters::CvsAdapter.new('foo', string).send(:root_url_path), "#{string} failed"
|
|
|
|
end
|
2013-07-13 15:03:37 +04:00
|
|
|
end
|
|
|
|
|
2011-02-15 11:04:11 +03:00
|
|
|
private
|
|
|
|
|
|
|
|
def test_scm_version_for(scm_command_version, version)
|
|
|
|
@adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
|
|
|
|
assert_equal version, @adapter.class.scm_command_version
|
|
|
|
end
|
2011-02-02 16:13:20 +03:00
|
|
|
else
|
|
|
|
puts "Cvs test repository NOT FOUND. Skipping unit tests !!!"
|
|
|
|
def test_fake; assert true end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue LoadError
|
|
|
|
class CvsMochaFake < ActiveSupport::TestCase
|
|
|
|
def test_fake; assert(false, "Requires mocha to run those tests") end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|