2011-05-08 09:08:44 +04:00
|
|
|
# Redmine - project management software
|
2012-05-05 16:56:53 +04:00
|
|
|
# Copyright (C) 2006-2012 Jean-Philippe Lang
|
2007-12-13 21:52:09 +03: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.
|
2011-05-08 09:08:44 +04:00
|
|
|
#
|
2007-12-13 21:52:09 +03:00
|
|
|
# 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.
|
2011-05-08 09:08:44 +04:00
|
|
|
#
|
2007-12-13 21:52:09 +03:00
|
|
|
# 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.
|
|
|
|
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2007-12-13 21:52:09 +03:00
|
|
|
require 'pp'
|
2009-09-13 21:14:35 +04:00
|
|
|
class RepositoryCvsTest < ActiveSupport::TestCase
|
2007-12-13 21:52:09 +03:00
|
|
|
fixtures :projects
|
2011-04-12 16:24:25 +04:00
|
|
|
|
2012-02-24 18:02:26 +04:00
|
|
|
include Redmine::I18n
|
|
|
|
|
2011-06-10 16:53:41 +04:00
|
|
|
REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
|
2008-08-25 15:01:37 +04:00
|
|
|
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
|
2007-12-13 21:52:09 +03:00
|
|
|
# CVS module
|
2011-04-14 09:03:36 +04:00
|
|
|
MODULE_NAME = 'test'
|
|
|
|
CHANGESETS_NUM = 7
|
2011-04-12 16:24:25 +04:00
|
|
|
|
2007-12-13 21:52:09 +03:00
|
|
|
def setup
|
2011-02-02 07:00:36 +03:00
|
|
|
@project = Project.find(3)
|
2011-05-08 09:08:44 +04:00
|
|
|
@repository = Repository::Cvs.create(:project => @project,
|
2011-03-01 13:27:30 +03:00
|
|
|
:root_url => REPOSITORY_PATH,
|
2011-05-08 09:08:44 +04:00
|
|
|
:url => MODULE_NAME,
|
2011-03-01 13:27:30 +03:00
|
|
|
:log_encoding => 'UTF-8')
|
|
|
|
assert @repository
|
2007-12-13 21:52:09 +03:00
|
|
|
end
|
2011-04-12 16:24:25 +04:00
|
|
|
|
2012-02-24 18:02:26 +04:00
|
|
|
def test_blank_module_error_message
|
|
|
|
set_language_if_valid 'en'
|
|
|
|
repo = Repository::Cvs.new(
|
|
|
|
:project => @project,
|
|
|
|
:identifier => 'test',
|
|
|
|
:log_encoding => 'UTF-8',
|
|
|
|
:root_url => REPOSITORY_PATH
|
|
|
|
)
|
|
|
|
assert !repo.save
|
|
|
|
assert_include "Module can't be blank",
|
|
|
|
repo.errors.full_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_blank_module_error_message_fr
|
|
|
|
set_language_if_valid 'fr'
|
|
|
|
str = "Module doit \xc3\xaatre renseign\xc3\xa9(e)"
|
|
|
|
str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
|
|
|
|
repo = Repository::Cvs.new(
|
|
|
|
:project => @project,
|
|
|
|
:identifier => 'test',
|
|
|
|
:log_encoding => 'UTF-8',
|
|
|
|
:path_encoding => '',
|
|
|
|
:url => '',
|
|
|
|
:root_url => REPOSITORY_PATH
|
|
|
|
)
|
|
|
|
assert !repo.save
|
|
|
|
assert_include str, repo.errors.full_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_blank_cvsroot_error_message
|
|
|
|
set_language_if_valid 'en'
|
|
|
|
repo = Repository::Cvs.new(
|
|
|
|
:project => @project,
|
|
|
|
:identifier => 'test',
|
|
|
|
:log_encoding => 'UTF-8',
|
|
|
|
:url => MODULE_NAME
|
|
|
|
)
|
|
|
|
assert !repo.save
|
|
|
|
assert_include "CVSROOT can't be blank",
|
|
|
|
repo.errors.full_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_blank_cvsroot_error_message_fr
|
|
|
|
set_language_if_valid 'fr'
|
|
|
|
str = "CVSROOT doit \xc3\xaatre renseign\xc3\xa9(e)"
|
|
|
|
str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
|
|
|
|
repo = Repository::Cvs.new(
|
|
|
|
:project => @project,
|
|
|
|
:identifier => 'test',
|
|
|
|
:log_encoding => 'UTF-8',
|
|
|
|
:path_encoding => '',
|
|
|
|
:url => MODULE_NAME,
|
|
|
|
:root_url => ''
|
|
|
|
)
|
|
|
|
assert !repo.save
|
|
|
|
assert_include str, repo.errors.full_messages
|
|
|
|
end
|
|
|
|
|
2011-05-08 09:08:44 +04:00
|
|
|
if File.directory?(REPOSITORY_PATH)
|
2007-12-13 21:52:09 +03:00
|
|
|
def test_fetch_changesets_from_scratch
|
2011-02-02 13:00:20 +03:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2007-12-13 21:52:09 +03:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 06:42:49 +04:00
|
|
|
@project.reload
|
2011-04-12 16:24:25 +04:00
|
|
|
|
2011-04-14 09:03:36 +04:00
|
|
|
assert_equal CHANGESETS_NUM, @repository.changesets.count
|
2012-06-03 15:46:58 +04:00
|
|
|
assert_equal 16, @repository.filechanges.count
|
2008-03-12 23:28:49 +03:00
|
|
|
assert_not_nil @repository.changesets.find_by_comments('Two files changed')
|
2011-02-07 13:26:15 +03:00
|
|
|
|
|
|
|
r2 = @repository.changesets.find_by_revision('2')
|
|
|
|
assert_equal 'v1-20071213-162510', r2.scmid
|
2007-12-13 21:52:09 +03:00
|
|
|
end
|
2011-04-12 16:24:25 +04:00
|
|
|
|
2007-12-13 21:52:09 +03:00
|
|
|
def test_fetch_changesets_incremental
|
2011-02-02 13:00:20 +03:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2007-12-13 21:52:09 +03:00
|
|
|
@repository.fetch_changesets
|
2012-02-26 18:09:21 +04:00
|
|
|
@project.reload
|
|
|
|
assert_equal CHANGESETS_NUM, @repository.changesets.count
|
|
|
|
|
2011-02-07 13:25:52 +03:00
|
|
|
# Remove changesets with revision > 3
|
|
|
|
@repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
|
2012-02-26 18:09:21 +04:00
|
|
|
@project.reload
|
2011-02-07 13:25:52 +03:00
|
|
|
assert_equal 3, @repository.changesets.count
|
2012-02-26 18:09:21 +04:00
|
|
|
assert_equal %w|3 2 1|, @repository.changesets.all.collect(&:revision)
|
2011-02-07 13:25:52 +03:00
|
|
|
|
|
|
|
rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
|
|
|
|
assert_equal '3', rev3_commit.revision
|
|
|
|
# 2007-12-14 01:27:22 +0900
|
|
|
|
rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
|
2011-02-07 13:26:15 +03:00
|
|
|
assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
|
2011-02-07 13:25:52 +03:00
|
|
|
assert_equal rev3_committed_on, rev3_commit.committed_on
|
|
|
|
latest_rev = @repository.latest_changeset
|
|
|
|
assert_equal rev3_committed_on, latest_rev.committed_on
|
|
|
|
|
2007-12-13 21:52:09 +03:00
|
|
|
@repository.fetch_changesets
|
2012-02-26 18:09:21 +04:00
|
|
|
@project.reload
|
2011-04-14 09:03:36 +04:00
|
|
|
assert_equal CHANGESETS_NUM, @repository.changesets.count
|
2012-02-26 18:09:21 +04:00
|
|
|
assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.all.collect(&:revision)
|
2011-04-14 09:03:36 +04:00
|
|
|
rev5_commit = @repository.changesets.find_by_revision('5')
|
2011-02-07 13:26:15 +03:00
|
|
|
assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
|
2011-02-07 13:25:52 +03:00
|
|
|
# 2007-12-14 01:30:01 +0900
|
|
|
|
rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
|
|
|
|
assert_equal rev5_committed_on, rev5_commit.committed_on
|
2007-12-13 21:52:09 +03:00
|
|
|
end
|
2011-04-12 16:24:25 +04:00
|
|
|
|
2008-12-14 18:57:13 +03:00
|
|
|
def test_deleted_files_should_not_be_listed
|
2011-02-02 13:00:20 +03:00
|
|
|
assert_equal 0, @repository.changesets.count
|
|
|
|
@repository.fetch_changesets
|
2011-09-12 06:43:19 +04:00
|
|
|
@project.reload
|
2011-04-14 09:03:36 +04:00
|
|
|
assert_equal CHANGESETS_NUM, @repository.changesets.count
|
2011-02-02 13:00:20 +03:00
|
|
|
|
2008-12-14 18:57:13 +03:00
|
|
|
entries = @repository.entries('sources')
|
|
|
|
assert entries.detect {|e| e.name == 'watchers_controller.rb'}
|
|
|
|
assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
|
|
|
|
end
|
2011-03-11 15:06:05 +03:00
|
|
|
|
|
|
|
def test_entries_rev3
|
2011-09-12 06:43:44 +04:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-03-11 15:06:05 +03:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 06:43:44 +04:00
|
|
|
@project.reload
|
|
|
|
assert_equal CHANGESETS_NUM, @repository.changesets.count
|
2011-03-11 15:06:05 +03:00
|
|
|
entries = @repository.entries('', '3')
|
2012-06-10 21:01:33 +04:00
|
|
|
assert_kind_of Redmine::Scm::Adapters::Entries, entries
|
2011-03-11 15:06:05 +03:00
|
|
|
assert_equal 3, entries.size
|
|
|
|
assert_equal entries[2].name, "README"
|
|
|
|
assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
|
|
|
|
assert_equal entries[2].lastrev.identifier, '3'
|
|
|
|
assert_equal entries[2].lastrev.revision, '3'
|
|
|
|
assert_equal entries[2].lastrev.author, 'LANG'
|
|
|
|
end
|
2011-04-11 10:29:24 +04:00
|
|
|
|
2011-04-12 09:46:21 +04:00
|
|
|
def test_entries_invalid_path
|
2011-09-12 06:44:08 +04:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-04-11 11:01:30 +04:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 06:44:08 +04:00
|
|
|
@project.reload
|
|
|
|
assert_equal CHANGESETS_NUM, @repository.changesets.count
|
2011-04-11 11:01:30 +04:00
|
|
|
assert_nil @repository.entries('missing')
|
|
|
|
assert_nil @repository.entries('missing', '3')
|
|
|
|
end
|
|
|
|
|
2011-04-12 09:46:21 +04:00
|
|
|
def test_entries_invalid_revision
|
2011-09-12 06:44:31 +04:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-04-12 09:46:21 +04:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 06:44:31 +04:00
|
|
|
@project.reload
|
|
|
|
assert_equal CHANGESETS_NUM, @repository.changesets.count
|
2011-04-12 09:46:21 +04:00
|
|
|
assert_nil @repository.entries('', '123')
|
|
|
|
end
|
|
|
|
|
2011-04-11 10:29:24 +04:00
|
|
|
def test_cat
|
2011-09-12 06:44:55 +04:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-04-11 10:29:24 +04:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 06:44:55 +04:00
|
|
|
@project.reload
|
|
|
|
assert_equal CHANGESETS_NUM, @repository.changesets.count
|
2011-04-11 10:29:24 +04:00
|
|
|
buf = @repository.cat('README')
|
|
|
|
assert buf
|
|
|
|
lines = buf.split("\n")
|
2011-04-14 09:03:36 +04:00
|
|
|
assert_equal 3, lines.length
|
2011-04-12 16:24:43 +04:00
|
|
|
buf = lines[1].gsub(/\r$/, "")
|
|
|
|
assert_equal 'with one change', buf
|
2011-04-11 20:54:35 +04:00
|
|
|
buf = @repository.cat('README', '1')
|
2011-04-11 10:29:24 +04:00
|
|
|
assert buf
|
|
|
|
lines = buf.split("\n")
|
|
|
|
assert_equal 1, lines.length
|
2011-04-12 16:24:43 +04:00
|
|
|
buf = lines[0].gsub(/\r$/, "")
|
|
|
|
assert_equal 'CVS test repository', buf
|
2011-04-11 16:04:58 +04:00
|
|
|
assert_nil @repository.cat('missing.rb')
|
2011-04-11 16:19:05 +04:00
|
|
|
|
|
|
|
# sources/welcome_controller.rb is removed at revision 5.
|
|
|
|
assert @repository.cat('sources/welcome_controller.rb', '4')
|
|
|
|
assert @repository.cat('sources/welcome_controller.rb', '5').blank?
|
2011-04-11 17:13:42 +04:00
|
|
|
|
|
|
|
# invalid revision
|
|
|
|
assert @repository.cat('README', '123').blank?
|
2011-04-11 10:29:24 +04:00
|
|
|
end
|
2011-04-11 19:44:38 +04:00
|
|
|
|
|
|
|
def test_annotate
|
2011-09-12 06:45:20 +04:00
|
|
|
assert_equal 0, @repository.changesets.count
|
2011-04-11 19:44:38 +04:00
|
|
|
@repository.fetch_changesets
|
2011-09-12 06:45:20 +04:00
|
|
|
@project.reload
|
|
|
|
assert_equal CHANGESETS_NUM, @repository.changesets.count
|
2011-04-11 19:44:38 +04:00
|
|
|
ann = @repository.annotate('README')
|
|
|
|
assert ann
|
2011-04-14 09:03:36 +04:00
|
|
|
assert_equal 3, ann.revisions.length
|
2011-04-11 19:44:38 +04:00
|
|
|
assert_equal '1.2', ann.revisions[1].revision
|
|
|
|
assert_equal 'LANG', ann.revisions[1].author
|
|
|
|
assert_equal 'with one change', ann.lines[1]
|
2011-04-11 19:46:07 +04:00
|
|
|
|
|
|
|
ann = @repository.annotate('README', '1')
|
|
|
|
assert ann
|
|
|
|
assert_equal 1, ann.revisions.length
|
|
|
|
assert_equal '1.1', ann.revisions[0].revision
|
|
|
|
assert_equal 'LANG', ann.revisions[0].author
|
|
|
|
assert_equal 'CVS test repository', ann.lines[0]
|
2011-04-11 19:47:04 +04:00
|
|
|
|
|
|
|
# invalid revision
|
|
|
|
assert_nil @repository.annotate('README', '123')
|
2011-04-11 19:44:38 +04:00
|
|
|
end
|
|
|
|
|
2007-12-13 21:52:09 +03:00
|
|
|
else
|
|
|
|
puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
|
|
|
|
def test_fake; assert true end
|
|
|
|
end
|
|
|
|
end
|