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