annotate test/unit/repository_cvs_test.rb @ 1171:b4558bc5837f bug_505

Close obsolete branch bug_505
author Chris Cannam
date Fri, 03 Aug 2012 19:40:23 +0100
parents cbb26bc654de
children 433d4f72a19b
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@909 23 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
Chris@0 24 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
Chris@0 25 # CVS module
Chris@441 26 MODULE_NAME = 'test'
Chris@441 27 CHANGESETS_NUM = 7
Chris@441 28
Chris@0 29 def setup
Chris@210 30 @project = Project.find(3)
Chris@441 31 @repository = Repository::Cvs.create(:project => @project,
Chris@245 32 :root_url => REPOSITORY_PATH,
Chris@441 33 :url => MODULE_NAME,
Chris@245 34 :log_encoding => 'UTF-8')
Chris@245 35 assert @repository
Chris@0 36 end
Chris@441 37
Chris@441 38 if File.directory?(REPOSITORY_PATH)
Chris@0 39 def test_fetch_changesets_from_scratch
Chris@210 40 assert_equal 0, @repository.changesets.count
Chris@0 41 @repository.fetch_changesets
Chris@909 42 @project.reload
Chris@441 43
Chris@441 44 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@441 45 assert_equal 16, @repository.changes.count
Chris@0 46 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
Chris@210 47
Chris@210 48 r2 = @repository.changesets.find_by_revision('2')
Chris@210 49 assert_equal 'v1-20071213-162510', r2.scmid
Chris@0 50 end
Chris@441 51
Chris@0 52 def test_fetch_changesets_incremental
Chris@210 53 assert_equal 0, @repository.changesets.count
Chris@0 54 @repository.fetch_changesets
Chris@210 55 # Remove changesets with revision > 3
Chris@210 56 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
Chris@0 57 @repository.reload
Chris@210 58 assert_equal 3, @repository.changesets.count
Chris@210 59 assert_equal %w|3 2 1|, @repository.changesets.collect(&:revision)
Chris@210 60
Chris@210 61 rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
Chris@210 62 assert_equal '3', rev3_commit.revision
Chris@210 63 # 2007-12-14 01:27:22 +0900
Chris@210 64 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
Chris@210 65 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
Chris@210 66 assert_equal rev3_committed_on, rev3_commit.committed_on
Chris@210 67 latest_rev = @repository.latest_changeset
Chris@210 68 assert_equal rev3_committed_on, latest_rev.committed_on
Chris@210 69
Chris@0 70 @repository.fetch_changesets
Chris@210 71 @repository.reload
Chris@441 72 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@210 73
Chris@441 74 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.collect(&:revision)
Chris@441 75 rev5_commit = @repository.changesets.find_by_revision('5')
Chris@210 76 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
Chris@210 77 # 2007-12-14 01:30:01 +0900
Chris@210 78 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
Chris@210 79 assert_equal rev5_committed_on, rev5_commit.committed_on
Chris@0 80 end
Chris@441 81
Chris@0 82 def test_deleted_files_should_not_be_listed
Chris@210 83 assert_equal 0, @repository.changesets.count
Chris@210 84 @repository.fetch_changesets
Chris@909 85 @project.reload
Chris@441 86 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@210 87
Chris@0 88 entries = @repository.entries('sources')
Chris@0 89 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
Chris@0 90 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
Chris@0 91 end
Chris@441 92
Chris@441 93 def test_entries_rev3
Chris@909 94 assert_equal 0, @repository.changesets.count
Chris@441 95 @repository.fetch_changesets
Chris@909 96 @project.reload
Chris@909 97 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@441 98 entries = @repository.entries('', '3')
Chris@441 99 assert_equal 3, entries.size
Chris@441 100 assert_equal entries[2].name, "README"
Chris@441 101 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
Chris@441 102 assert_equal entries[2].lastrev.identifier, '3'
Chris@441 103 assert_equal entries[2].lastrev.revision, '3'
Chris@441 104 assert_equal entries[2].lastrev.author, 'LANG'
Chris@441 105 end
Chris@441 106
Chris@441 107 def test_entries_invalid_path
Chris@909 108 assert_equal 0, @repository.changesets.count
Chris@441 109 @repository.fetch_changesets
Chris@909 110 @project.reload
Chris@909 111 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@441 112 assert_nil @repository.entries('missing')
Chris@441 113 assert_nil @repository.entries('missing', '3')
Chris@441 114 end
Chris@441 115
Chris@441 116 def test_entries_invalid_revision
Chris@909 117 assert_equal 0, @repository.changesets.count
Chris@441 118 @repository.fetch_changesets
Chris@909 119 @project.reload
Chris@909 120 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@441 121 assert_nil @repository.entries('', '123')
Chris@441 122 end
Chris@441 123
Chris@441 124 def test_cat
Chris@909 125 assert_equal 0, @repository.changesets.count
Chris@441 126 @repository.fetch_changesets
Chris@909 127 @project.reload
Chris@909 128 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@441 129 buf = @repository.cat('README')
Chris@441 130 assert buf
Chris@441 131 lines = buf.split("\n")
Chris@441 132 assert_equal 3, lines.length
Chris@441 133 buf = lines[1].gsub(/\r$/, "")
Chris@441 134 assert_equal 'with one change', buf
Chris@441 135 buf = @repository.cat('README', '1')
Chris@441 136 assert buf
Chris@441 137 lines = buf.split("\n")
Chris@441 138 assert_equal 1, lines.length
Chris@441 139 buf = lines[0].gsub(/\r$/, "")
Chris@441 140 assert_equal 'CVS test repository', buf
Chris@441 141 assert_nil @repository.cat('missing.rb')
Chris@441 142
Chris@441 143 # sources/welcome_controller.rb is removed at revision 5.
Chris@441 144 assert @repository.cat('sources/welcome_controller.rb', '4')
Chris@441 145 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
Chris@441 146
Chris@441 147 # invalid revision
Chris@441 148 assert @repository.cat('README', '123').blank?
Chris@441 149 end
Chris@441 150
Chris@441 151 def test_annotate
Chris@909 152 assert_equal 0, @repository.changesets.count
Chris@441 153 @repository.fetch_changesets
Chris@909 154 @project.reload
Chris@909 155 assert_equal CHANGESETS_NUM, @repository.changesets.count
Chris@441 156 ann = @repository.annotate('README')
Chris@441 157 assert ann
Chris@441 158 assert_equal 3, ann.revisions.length
Chris@441 159 assert_equal '1.2', ann.revisions[1].revision
Chris@441 160 assert_equal 'LANG', ann.revisions[1].author
Chris@441 161 assert_equal 'with one change', ann.lines[1]
Chris@441 162
Chris@441 163 ann = @repository.annotate('README', '1')
Chris@441 164 assert ann
Chris@441 165 assert_equal 1, ann.revisions.length
Chris@441 166 assert_equal '1.1', ann.revisions[0].revision
Chris@441 167 assert_equal 'LANG', ann.revisions[0].author
Chris@441 168 assert_equal 'CVS test repository', ann.lines[0]
Chris@441 169
Chris@441 170 # invalid revision
Chris@441 171 assert_nil @repository.annotate('README', '123')
Chris@441 172 end
Chris@441 173
Chris@0 174 else
Chris@0 175 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
Chris@0 176 def test_fake; assert true end
Chris@0 177 end
Chris@0 178 end