From 47f399104b9c3062ea27d30146c1873df2efa750 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 14 Dec 2007 17:46:45 +0000 Subject: [PATCH] Added a Mercurial test repository with unit and functional tests. git-svn-id: http://redmine.rubyforge.org/svn/trunk@991 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- doc/RUNNING_TESTS | 6 +- test/fixtures/enabled_modules.yml | 5 + .../repositories/mercurial_repository.tar.gz | Bin 0 -> 7827 bytes .../repositories_mercurial_controller_test.rb | 117 ++++++++++++++++++ test/unit/repository_mercurial_test.rb | 55 ++++++++ 5 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/repositories/mercurial_repository.tar.gz create mode 100644 test/functional/repositories_mercurial_controller_test.rb create mode 100644 test/unit/repository_mercurial_test.rb diff --git a/doc/RUNNING_TESTS b/doc/RUNNING_TESTS index eb8787d95..fde24413b 100644 --- a/doc/RUNNING_TESTS +++ b/doc/RUNNING_TESTS @@ -14,4 +14,8 @@ gunzip < test/fixtures/repositories/cvs_repository.tar.gz | tar -xv -C tmp/test Bazaar ------ -gunzip < test/fixtures/repositories/bazaar_repository.tar.gz | tar -xv -C tmp/test \ No newline at end of file +gunzip < test/fixtures/repositories/bazaar_repository.tar.gz | tar -xv -C tmp/test + +Mercurial +--------- +gunzip < test/fixtures/repositories/mercurial_repository.tar.gz | tar -xv -C tmp/test diff --git a/test/fixtures/enabled_modules.yml b/test/fixtures/enabled_modules.yml index 1f05cd9a7..dfc2f0090 100644 --- a/test/fixtures/enabled_modules.yml +++ b/test/fixtures/enabled_modules.yml @@ -31,3 +31,8 @@ enabled_modules_008: name: boards project_id: 1 id: 8 +enabled_modules_009: + name: repository + project_id: 3 + id: 9 + \ No newline at end of file diff --git a/test/fixtures/repositories/mercurial_repository.tar.gz b/test/fixtures/repositories/mercurial_repository.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..1d8ad305732f7a0d7bfbcd52bbeec919da88e3f1 GIT binary patch literal 7827 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FXc64swX3bYSmXt6B_g z*NR{&5UQc{rF3;2>1-!pJuV-(OE4|&juIp|6dNv<6AJX33A7%xELMrjNZuqJ7y?H+y;*_c#^$e>Gx%b{qMWHv6g>S~k6B6d@?c(ia0XI%E(NAd2kuq@ zSy_{D++jPcVt|h+O%@K8bRm_YZ71Xrn5BmOhI@j%d^J==`2c-FcGU{#7mDdh-L2e0 z%GUqHuv0TVY>jJA_FQ7C3eraZ&|hpPT96cO6JlqfTe3fG47WvSRF+0%X<(L0fkOf` z8BT{ZXLwjymx(1hch85r1XgFskJ#y25h1fx6Kqq|(>gk{6YsDxX%=qd2uW1T=knXz lPJcXav%`P^0|pEjFkrxd0RsjM7%=EX{0^uzbfy4!001CPd#eBd literal 0 HcmV?d00001 diff --git a/test/functional/repositories_mercurial_controller_test.rb b/test/functional/repositories_mercurial_controller_test.rb new file mode 100644 index 000000000..db0029017 --- /dev/null +++ b/test/functional/repositories_mercurial_controller_test.rb @@ -0,0 +1,117 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# 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' +require 'repositories_controller' + +# Re-raise errors caught by the controller. +class RepositoriesController; def rescue_action(e) raise e end; end + +class RepositoriesMercurialControllerTest < Test::Unit::TestCase + fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules + + # No '..' in the repository path + REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' + + def setup + @controller = RepositoriesController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + User.current = nil + Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH) + end + + def test_show + get :show, :id => 3 + assert_response :success + assert_template 'show' + assert_not_nil assigns(:entries) + assert_not_nil assigns(:changesets) + end + + def test_browse_root + get :browse, :id => 3 + assert_response :success + assert_template 'browse' + assert_not_nil assigns(:entries) + assert_equal 3, assigns(:entries).size + assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} + assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} + assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} + end + + def test_browse_directory + get :browse, :id => 3, :path => ['images'] + assert_response :success + assert_template 'browse' + assert_not_nil assigns(:entries) + assert_equal 2, assigns(:entries).size + entry = assigns(:entries).detect {|e| e.name == 'edit.png'} + assert_not_nil entry + assert_equal 'file', entry.kind + assert_equal 'images/edit.png', entry.path + end + + def test_changes + get :changes, :id => 3, :path => ['images', 'edit.png'] + assert_response :success + assert_template 'changes' + assert_tag :tag => 'h2', :content => 'edit.png' + end + + def test_entry_show + get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] + assert_response :success + assert_template 'entry' + # Line 19 + assert_tag :tag => 'th', + :content => /10/, + :attributes => { :class => /line-num/ }, + :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } + end + + def test_entry_download + get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' + assert_response :success + # File content + assert @response.body.include?('WITHOUT ANY WARRANTY') + end + + def test_diff + # Full diff of changeset 4 + get :diff, :id => 3, :rev => 4 + assert_response :success + assert_template 'diff' + # Line 22 removed + assert_tag :tag => 'th', + :content => /22/, + :sibling => { :tag => 'td', + :attributes => { :class => /diff_out/ }, + :content => /def remove/ } + end + + def test_annotate + get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] + assert_response :success + assert_template 'annotate' + # Line 23, revision 4 + assert_tag :tag => 'th', :content => /23/, + :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /4/ } }, + :sibling => { :tag => 'td', :content => /jsmith/ }, + :sibling => { :tag => 'td', :content => /watcher =/ } + end +end diff --git a/test/unit/repository_mercurial_test.rb b/test/unit/repository_mercurial_test.rb new file mode 100644 index 000000000..e6cfdf9b2 --- /dev/null +++ b/test/unit/repository_mercurial_test.rb @@ -0,0 +1,55 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# 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 RepositoryMercurialTest < Test::Unit::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_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_fetch_changesets_incremental + @repository.fetch_changesets + # Remove changesets with revision > 2 + @repository.changesets.find(:all, :conditions => 'revision > 2').each(&:destroy) + @repository.reload + assert_equal 3, @repository.changesets.count + + @repository.fetch_changesets + assert_equal 6, @repository.changesets.count + end + else + puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" + def test_fake; assert true end + end +end