|
1 |
# redMine - project management software
|
|
2 |
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
|
3 |
# Copyright (C) 2010 Alessio Caiazza
|
|
4 |
#
|
|
5 |
# This program is free software; you can redistribute it and/or
|
|
6 |
# modify it under the terms of the GNU General Public License
|
|
7 |
# as published by the Free Software Foundation; either version 2
|
|
8 |
# of the License, or (at your option) any later version.
|
|
9 |
#
|
|
10 |
# This program is distributed in the hope that it will be useful,
|
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
# GNU General Public License for more details.
|
|
14 |
#
|
|
15 |
# You should have received a copy of the GNU General Public License
|
|
16 |
# along with this program; if not, write to the Free Software
|
|
17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
18 |
|
|
19 |
require File.dirname(__FILE__) + '/../test_helper'
|
|
20 |
|
|
21 |
class MercurialHgrcTest < ActiveSupport::TestCase
|
|
22 |
fixtures :projects
|
|
23 |
|
|
24 |
# No '..' in the repository path
|
|
25 |
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
|
|
26 |
|
|
27 |
def setup
|
|
28 |
@project = Project.find(1)
|
|
29 |
assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
|
|
30 |
end
|
|
31 |
|
|
32 |
if File.directory?(REPOSITORY_PATH)
|
|
33 |
|
|
34 |
def test_mixin_loading
|
|
35 |
assert @repository.public_methods.include?('load_hgrc')
|
|
36 |
assert @repository.private_methods.include?('save_hgrc')
|
|
37 |
|
|
38 |
%w[hgrc_hooks_issues_update hgrc_web_contact hgrc_web_description hgrc_web_style].each do |m|
|
|
39 |
assert @repository.public_methods.include?(m), "missing #{m} method"
|
|
40 |
assert @repository.public_methods.include?(m+'='), "missing #{m}= method"
|
|
41 |
end
|
|
42 |
end
|
|
43 |
|
|
44 |
def test_hgrc_changes
|
|
45 |
desc = "Repository Description"
|
|
46 |
style = "gitweb"
|
|
47 |
contact = "Name Surname <name.surname@example.net>"
|
|
48 |
|
|
49 |
@repository.hgrc_web_contact = contact
|
|
50 |
@repository.hgrc_web_description = desc
|
|
51 |
@repository.hgrc_web_style = style
|
|
52 |
@repository.hgrc_hooks_issues_update = false
|
|
53 |
|
|
54 |
@repository.save!
|
|
55 |
|
|
56 |
ini = Ini.new(File.join(REPOSITORY_PATH, '.hg', 'hgrc'))
|
|
57 |
assert_not_nil ini, "Should create #{File.join(REPOSITORY_PATH, '.hg', 'hgrc')}"
|
|
58 |
assert_not_nil ini['hooks']
|
|
59 |
assert_send [ini['hooks'], :empty? ], "[hooks] must be empty"
|
|
60 |
assert_not_nil ini['web']
|
|
61 |
assert_equal ini['web']['contact'], contact
|
|
62 |
assert_equal ini['web']['description'], desc
|
|
63 |
assert_equal ini['web']['style'], style
|
|
64 |
end
|
|
65 |
|
|
66 |
def test_fetch_changesets_from_scratch
|
|
67 |
@repository.fetch_changesets
|
|
68 |
@repository.reload
|
|
69 |
|
|
70 |
assert_equal 6, @repository.changesets.count
|
|
71 |
assert_equal 11, @repository.changes.count
|
|
72 |
assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments
|
|
73 |
end
|
|
74 |
|
|
75 |
def test_hgrc_hooks_issues_update
|
|
76 |
@repository.hgrc_hooks_issues_update = false
|
|
77 |
assert_equal 0, @repository.hgrc_hooks_issues_update
|
|
78 |
|
|
79 |
@repository.hgrc_hooks_issues_update = true
|
|
80 |
assert_equal 1, @repository.hgrc_hooks_issues_update
|
|
81 |
|
|
82 |
@repository.hgrc_hooks_issues_update = 0
|
|
83 |
assert_equal 0, @repository.hgrc_hooks_issues_update
|
|
84 |
|
|
85 |
@repository.hgrc_hooks_issues_update = 1
|
|
86 |
assert_equal 1, @repository.hgrc_hooks_issues_update
|
|
87 |
|
|
88 |
#not so elegant....
|
|
89 |
@repository.hgrc_hooks_issues_update = :something_elese
|
|
90 |
assert_equal 0, @repository.hgrc_hooks_issues_update
|
|
91 |
end
|
|
92 |
|
|
93 |
def test_hgrc_hooks_issues_update_result
|
|
94 |
desc = "Repository Description"
|
|
95 |
style = "gitweb"
|
|
96 |
contact = "Name Surname <name.surname@example.net>"
|
|
97 |
hook = "cd #{RAILS_ROOT} && ruby script/runner \"Repository.find(#{@repository[:id]}).fetch_changesets\" -e #{RAILS_ENV}"
|
|
98 |
|
|
99 |
@repository.hgrc_web_contact = contact
|
|
100 |
@repository.hgrc_web_description = desc
|
|
101 |
@repository.hgrc_web_style = style
|
|
102 |
@repository.hgrc_hooks_issues_update = true
|
|
103 |
|
|
104 |
@repository.save!
|
|
105 |
|
|
106 |
ini = Ini.new(File.join(REPOSITORY_PATH, '.hg', 'hgrc'))
|
|
107 |
assert_not_nil ini, "Should create #{File.join(REPOSITORY_PATH, '.hg', 'hgrc')}"
|
|
108 |
assert_not_nil ini['hooks']
|
|
109 |
assert_not_nil ini['hooks']['changegroup.redmine']
|
|
110 |
assert_equal ini['hooks']['changegroup.redmine'], hook
|
|
111 |
end
|
|
112 |
else
|
|
113 |
puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
|
|
114 |
def test_fake; assert true end
|
|
115 |
end
|
|
116 |
end
|