# HG changeset patch # User Alessio Caiazza # Parent c56eabc916b44cdcd4897fec40df9f3ad874da70 Tests for the new features diff --git a/test/unit/mercurial_hgrc_test.rb b/test/unit/mercurial_hgrc_test.rb new file mode 100644 --- /dev/null +++ b/test/unit/mercurial_hgrc_test.rb @@ -0,0 +1,116 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# Copyright (C) 2010 Alessio Caiazza +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' + +class MercurialHgrcTest < ActiveSupport::TestCase + fixtures :projects + + # No '..' in the repository path + REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' + + def setup + @project = Project.find(1) + assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH) + end + + if File.directory?(REPOSITORY_PATH) + + def test_mixin_loading + assert @repository.public_methods.include?('load_hgrc') + assert @repository.private_methods.include?('save_hgrc') + + %w[hgrc_hooks_issues_update hgrc_web_contact hgrc_web_description hgrc_web_style].each do |m| + assert @repository.public_methods.include?(m), "missing #{m} method" + assert @repository.public_methods.include?(m+'='), "missing #{m}= method" + end + end + + def test_hgrc_changes + desc = "Repository Description" + style = "gitweb" + contact = "Name Surname " + + @repository.hgrc_web_contact = contact + @repository.hgrc_web_description = desc + @repository.hgrc_web_style = style + @repository.hgrc_hooks_issues_update = false + + @repository.save! + + ini = Ini.new(File.join(REPOSITORY_PATH, '.hg', 'hgrc')) + assert_not_nil ini, "Should create #{File.join(REPOSITORY_PATH, '.hg', 'hgrc')}" + assert_not_nil ini['hooks'] + assert_send [ini['hooks'], :empty? ], "[hooks] must be empty" + assert_not_nil ini['web'] + assert_equal ini['web']['contact'], contact + assert_equal ini['web']['description'], desc + assert_equal ini['web']['style'], style + end + + def test_fetch_changesets_from_scratch + @repository.fetch_changesets + @repository.reload + + assert_equal 6, @repository.changesets.count + assert_equal 11, @repository.changes.count + assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments + end + + def test_hgrc_hooks_issues_update + @repository.hgrc_hooks_issues_update = false + assert_equal 0, @repository.hgrc_hooks_issues_update + + @repository.hgrc_hooks_issues_update = true + assert_equal 1, @repository.hgrc_hooks_issues_update + + @repository.hgrc_hooks_issues_update = 0 + assert_equal 0, @repository.hgrc_hooks_issues_update + + @repository.hgrc_hooks_issues_update = 1 + assert_equal 1, @repository.hgrc_hooks_issues_update + + #not so elegant.... + @repository.hgrc_hooks_issues_update = :something_elese + assert_equal 0, @repository.hgrc_hooks_issues_update + end + + def test_hgrc_hooks_issues_update_result + desc = "Repository Description" + style = "gitweb" + contact = "Name Surname " + hook = "cd #{RAILS_ROOT} && ruby script/runner \"Repository.find(#{@repository[:id]}).fetch_changesets\" -e #{RAILS_ENV}" + + @repository.hgrc_web_contact = contact + @repository.hgrc_web_description = desc + @repository.hgrc_web_style = style + @repository.hgrc_hooks_issues_update = true + + @repository.save! + + ini = Ini.new(File.join(REPOSITORY_PATH, '.hg', 'hgrc')) + assert_not_nil ini, "Should create #{File.join(REPOSITORY_PATH, '.hg', 'hgrc')}" + assert_not_nil ini['hooks'] + assert_not_nil ini['hooks']['changegroup.redmine'] + assert_equal ini['hooks']['changegroup.redmine'], hook + end + else + puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" + def test_fake; assert true end + end +end