To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 41 / 4159ae2540b71521a40b7a57fa4731829b5f161b.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (4.49 KB)

1 1296:038ba2d95de8 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
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
#
9
# 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
#
14
# 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
require File.expand_path('../../test_helper', __FILE__)
19
20
class RepositoryDarcsTest < ActiveSupport::TestCase
21
  fixtures :projects
22
23
  include Redmine::I18n
24
25
  REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
26
  NUM_REV = 6
27
28
  def setup
29
    @project = Project.find(3)
30
    @repository = Repository::Darcs.create(
31
                      :project      => @project,
32
                      :url          => REPOSITORY_PATH,
33
                      :log_encoding => 'UTF-8'
34
                      )
35
    assert @repository
36
  end
37
38
  def test_blank_path_to_repository_error_message
39
    set_language_if_valid 'en'
40
    repo = Repository::Darcs.new(
41
                          :project      => @project,
42
                          :identifier   => 'test',
43
                          :log_encoding => 'UTF-8'
44
                        )
45
    assert !repo.save
46
    assert_include "Path to repository can't be blank",
47
                   repo.errors.full_messages
48
  end
49
50
  def test_blank_path_to_repository_error_message_fr
51
    set_language_if_valid 'fr'
52
    str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
53
    str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
54
    repo = Repository::Darcs.new(
55
                          :project      => @project,
56
                          :url          => "",
57
                          :identifier   => 'test',
58
                          :log_encoding => 'UTF-8'
59
                        )
60
    assert !repo.save
61
    assert_include str, repo.errors.full_messages
62
  end
63
64
  if File.directory?(REPOSITORY_PATH)
65
    def test_fetch_changesets_from_scratch
66
      assert_equal 0, @repository.changesets.count
67
      @repository.fetch_changesets
68
      @project.reload
69
70
      assert_equal NUM_REV, @repository.changesets.count
71
      assert_equal 13, @repository.filechanges.count
72
      assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
73
    end
74
75
    def test_fetch_changesets_incremental
76
      assert_equal 0, @repository.changesets.count
77
      @repository.fetch_changesets
78
      @project.reload
79
      assert_equal NUM_REV, @repository.changesets.count
80
81
      # Remove changesets with revision > 3
82
      @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
83
      @project.reload
84
      assert_equal 3, @repository.changesets.count
85
86
      @repository.fetch_changesets
87
      @project.reload
88
      assert_equal NUM_REV, @repository.changesets.count
89
    end
90
91
    def test_entries
92
      entries = @repository.entries
93
      assert_kind_of Redmine::Scm::Adapters::Entries, entries
94
    end
95
96
    def test_entries_invalid_revision
97
      assert_equal 0, @repository.changesets.count
98
      @repository.fetch_changesets
99
      @project.reload
100
      assert_equal NUM_REV, @repository.changesets.count
101
      assert_nil @repository.entries('', '123')
102
    end
103
104
    def test_deleted_files_should_not_be_listed
105
      assert_equal 0, @repository.changesets.count
106
      @repository.fetch_changesets
107
      @project.reload
108
      assert_equal NUM_REV, @repository.changesets.count
109
      entries = @repository.entries('sources')
110
      assert entries.detect {|e| e.name == 'watchers_controller.rb'}
111
      assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
112
    end
113
114
    def test_cat
115
      if @repository.scm.supports_cat?
116
        assert_equal 0, @repository.changesets.count
117
        @repository.fetch_changesets
118
        @project.reload
119
        assert_equal NUM_REV, @repository.changesets.count
120
        cat = @repository.cat("sources/welcome_controller.rb", 2)
121
        assert_not_nil cat
122
        assert cat.include?('class WelcomeController < ApplicationController')
123
      end
124
    end
125
  else
126
    puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
127
    def test_fake; assert true end
128
  end
129
end