annotate test/unit/repository_cvs_test.rb @ 851:2f5046e94b6d bug_255

Close obsolete branch bug_255
author Chris Cannam
date Sat, 13 Aug 2011 14:40:15 +0100
parents cbce1fd3b1b7
children cbb26bc654de
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@441 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@441 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'pp'
Chris@0 20 class RepositoryCvsTest < ActiveSupport::TestCase
Chris@0 21 fixtures :projects
Chris@441 22
Chris@0 23 # No '..' in the repository path
Chris@0 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository'
Chris@0 25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
Chris@0 26 # CVS module
Chris@441 27 MODULE_NAME = 'test'
Chris@441 28 CHANGESETS_NUM = 7
Chris@441 29
Chris@0 30 def setup
Chris@210 31 @project = Project.find(3)
Chris@441 32 @repository = Repository::Cvs.create(:project => @project,
Chris@245 33 :root_url => REPOSITORY_PATH,
Chris@441 34 :url => MODULE_NAME,
Chris@245 35 :log_encoding => 'UTF-8')
Chris@245 36 assert @repository
Chris@0 37 end
Chris@441 38
Chris@441 39 if File.directory?(REPOSITORY_PATH)
Chris@0 40 def test_fetch_changesets_from_scratch
Chris@210 41 assert_equal 0, @repository.changesets.count
Chris@0 42 @repository.fetch_changesets
Chris@0 43 @repository.reload
Chris@441 44
Chris@441 45 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@441 46 assert_equal 16, @repository.changes.count
Chris@0 47 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
Chris@210 48
Chris@210 49 r2 = @repository.changesets.find_by_revision('2')
Chris@210 50 assert_equal 'v1-20071213-162510', r2.scmid
Chris@0 51 end
Chris@441 52
Chris@0 53 def test_fetch_changesets_incremental
Chris@210 54 assert_equal 0, @repository.changesets.count
Chris@0 55 @repository.fetch_changesets
Chris@210 56 # Remove changesets with revision > 3
Chris@210 57 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
Chris@0 58 @repository.reload
Chris@210 59 assert_equal 3, @repository.changesets.count
Chris@210 60 assert_equal %w|3 2 1|, @repository.changesets.collect(&:revision)
Chris@210 61
Chris@210 62 rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
Chris@210 63 assert_equal '3', rev3_commit.revision
Chris@210 64 # 2007-12-14 01:27:22 +0900
Chris@210 65 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
Chris@210 66 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
Chris@210 67 assert_equal rev3_committed_on, rev3_commit.committed_on
Chris@210 68 latest_rev = @repository.latest_changeset
Chris@210 69 assert_equal rev3_committed_on, latest_rev.committed_on
Chris@210 70
Chris@0 71 @repository.fetch_changesets
Chris@210 72 @repository.reload
Chris@441 73 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@210 74
Chris@441 75 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.collect(&:revision)
Chris@441 76 rev5_commit = @repository.changesets.find_by_revision('5')
Chris@210 77 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
Chris@210 78 # 2007-12-14 01:30:01 +0900
Chris@210 79 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
Chris@210 80 assert_equal rev5_committed_on, rev5_commit.committed_on
Chris@0 81 end
Chris@441 82
Chris@0 83 def test_deleted_files_should_not_be_listed
Chris@210 84 assert_equal 0, @repository.changesets.count
Chris@210 85 @repository.fetch_changesets
Chris@210 86 @repository.reload
Chris@441 87 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@210 88
Chris@0 89 entries = @repository.entries('sources')
Chris@0 90 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
Chris@0 91 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
Chris@0 92 end
Chris@441 93
Chris@441 94 def test_entries_rev3
Chris@441 95 @repository.fetch_changesets
Chris@441 96 @repository.reload
Chris@441 97 entries = @repository.entries('', '3')
Chris@441 98 assert_equal 3, entries.size
Chris@441 99 assert_equal entries[2].name, "README"
Chris@441 100 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
Chris@441 101 assert_equal entries[2].lastrev.identifier, '3'
Chris@441 102 assert_equal entries[2].lastrev.revision, '3'
Chris@441 103 assert_equal entries[2].lastrev.author, 'LANG'
Chris@441 104 end
Chris@441 105
Chris@441 106 def test_entries_invalid_path
Chris@441 107 @repository.fetch_changesets
Chris@441 108 @repository.reload
Chris@441 109 assert_nil @repository.entries('missing')
Chris@441 110 assert_nil @repository.entries('missing', '3')
Chris@441 111 end
Chris@441 112
Chris@441 113 def test_entries_invalid_revision
Chris@441 114 @repository.fetch_changesets
Chris@441 115 @repository.reload
Chris@441 116 assert_nil @repository.entries('', '123')
Chris@441 117 end
Chris@441 118
Chris@441 119 def test_cat
Chris@441 120 @repository.fetch_changesets
Chris@441 121 @repository.reload
Chris@441 122 buf = @repository.cat('README')
Chris@441 123 assert buf
Chris@441 124 lines = buf.split("\n")
Chris@441 125 assert_equal 3, lines.length
Chris@441 126 buf = lines[1].gsub(/\r$/, "")
Chris@441 127 assert_equal 'with one change', buf
Chris@441 128 buf = @repository.cat('README', '1')
Chris@441 129 assert buf
Chris@441 130 lines = buf.split("\n")
Chris@441 131 assert_equal 1, lines.length
Chris@441 132 buf = lines[0].gsub(/\r$/, "")
Chris@441 133 assert_equal 'CVS test repository', buf
Chris@441 134 assert_nil @repository.cat('missing.rb')
Chris@441 135
Chris@441 136 # sources/welcome_controller.rb is removed at revision 5.
Chris@441 137 assert @repository.cat('sources/welcome_controller.rb', '4')
Chris@441 138 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
Chris@441 139
Chris@441 140 # invalid revision
Chris@441 141 assert @repository.cat('README', '123').blank?
Chris@441 142 end
Chris@441 143
Chris@441 144 def test_annotate
Chris@441 145 @repository.fetch_changesets
Chris@441 146 @repository.reload
Chris@441 147 ann = @repository.annotate('README')
Chris@441 148 assert ann
Chris@441 149 assert_equal 3, ann.revisions.length
Chris@441 150 assert_equal '1.2', ann.revisions[1].revision
Chris@441 151 assert_equal 'LANG', ann.revisions[1].author
Chris@441 152 assert_equal 'with one change', ann.lines[1]
Chris@441 153
Chris@441 154 ann = @repository.annotate('README', '1')
Chris@441 155 assert ann
Chris@441 156 assert_equal 1, ann.revisions.length
Chris@441 157 assert_equal '1.1', ann.revisions[0].revision
Chris@441 158 assert_equal 'LANG', ann.revisions[0].author
Chris@441 159 assert_equal 'CVS test repository', ann.lines[0]
Chris@441 160
Chris@441 161 # invalid revision
Chris@441 162 assert_nil @repository.annotate('README', '123')
Chris@441 163 end
Chris@441 164
Chris@0 165 else
Chris@0 166 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
Chris@0 167 def test_fake; assert true end
Chris@0 168 end
Chris@0 169 end