Chris@0: # redMine - project management software Chris@0: # Copyright (C) 2006-2008 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@119: require File.expand_path('../../test_helper', __FILE__) Chris@0: require 'repositories_controller' Chris@0: Chris@0: # Re-raise errors caught by the controller. Chris@0: class RepositoriesController; def rescue_action(e) raise e end; end Chris@0: Chris@0: class RepositoriesMercurialControllerTest < ActionController::TestCase Chris@0: fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules Chris@0: Chris@0: # No '..' in the repository path Chris@0: REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' Chris@0: Chris@0: def setup Chris@0: @controller = RepositoriesController.new Chris@0: @request = ActionController::TestRequest.new Chris@0: @response = ActionController::TestResponse.new Chris@0: User.current = nil Chris@119: @repository = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH) Chris@119: assert @repository Chris@0: end Chris@119: Chris@0: if File.directory?(REPOSITORY_PATH) Chris@0: def test_show Chris@0: get :show, :id => 3 Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@0: assert_not_nil assigns(:changesets) Chris@0: end Chris@128: Chris@0: def test_show_root Chris@0: get :show, :id => 3 Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@119: assert_equal 4, assigns(:entries).size Chris@119: assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} Chris@0: assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} Chris@119: assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} Chris@0: end Chris@128: Chris@0: def test_show_directory Chris@0: get :show, :id => 3, :path => ['images'] Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@0: assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) Chris@0: entry = assigns(:entries).detect {|e| e.name == 'edit.png'} Chris@0: assert_not_nil entry Chris@0: assert_equal 'file', entry.kind Chris@0: assert_equal 'images/edit.png', entry.path Chris@0: end Chris@119: Chris@0: def test_show_at_given_revision Chris@119: [0, '0', '0885933ad4f6'].each do |r1| Chris@119: get :show, :id => 3, :path => ['images'], :rev => r1 Chris@119: assert_response :success Chris@119: assert_template 'show' Chris@119: assert_not_nil assigns(:entries) Chris@119: assert_equal ['delete.png'], assigns(:entries).collect(&:name) Chris@119: end Chris@0: end Chris@119: Chris@119: def test_show_directory_sql_escape_percent Chris@119: [13, '13', '3a330eb32958'].each do |r1| Chris@119: get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1 Chris@119: assert_response :success Chris@119: assert_template 'show' Chris@119: Chris@119: assert_not_nil assigns(:entries) Chris@119: assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name) Chris@119: changesets = assigns(:changesets) Chris@119: Chris@119: ## This is not yet implemented. Chris@119: # assert_not_nil changesets Chris@119: # assert_equal %w(13 11 10 9), changesets.collect(&:revision) Chris@119: end Chris@119: end Chris@119: Chris@0: def test_changes Chris@0: get :changes, :id => 3, :path => ['images', 'edit.png'] Chris@0: assert_response :success Chris@0: assert_template 'changes' Chris@0: assert_tag :tag => 'h2', :content => 'edit.png' Chris@0: end Chris@0: Chris@0: def test_entry_show Chris@0: get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] Chris@0: assert_response :success Chris@0: assert_template 'entry' Chris@119: # Line 10 Chris@0: assert_tag :tag => 'th', Chris@119: :content => '10', Chris@119: :attributes => { :class => 'line-num' }, Chris@0: :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } Chris@0: end Chris@0: Chris@0: def test_entry_download Chris@0: get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' Chris@0: assert_response :success Chris@0: # File content Chris@0: assert @response.body.include?('WITHOUT ANY WARRANTY') Chris@0: end Chris@0: Chris@0: def test_directory_entry Chris@0: get :entry, :id => 3, :path => ['sources'] Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entry) Chris@0: assert_equal 'sources', assigns(:entry).name Chris@0: end Chris@0: Chris@0: def test_diff Chris@119: @repository.fetch_changesets Chris@119: @repository.reload Chris@119: Chris@119: [4, '4', 'def6d2f1254a'].each do |r1| Chris@119: # Full diff of changeset 4 Chris@128: get :diff, :id => 3, :rev => r1 Chris@119: assert_response :success Chris@119: assert_template 'diff' Chris@119: Chris@119: if @repository.scm.class.client_version_above?([1, 2]) Chris@119: # Line 22 removed Chris@119: assert_tag :tag => 'th', Chris@119: :content => '22', Chris@119: :sibling => { :tag => 'td', Chris@119: :attributes => { :class => /diff_out/ }, Chris@119: :content => /def remove/ } Chris@119: assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ Chris@119: end Chris@119: end Chris@0: end Chris@119: Chris@119: def test_diff_two_revs Chris@119: @repository.fetch_changesets Chris@119: @repository.reload Chris@119: Chris@119: [2, '400bb8672109', '400', 400].each do |r1| Chris@119: [4, 'def6d2f1254a'].each do |r2| Chris@119: get :diff, :id => 3, :rev => r1, Chris@119: :rev_to => r2 Chris@119: assert_response :success Chris@119: assert_template 'diff' Chris@119: Chris@119: diff = assigns(:diff) Chris@119: assert_not_nil diff Chris@119: assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/ Chris@119: end Chris@119: end Chris@119: end Chris@119: Chris@0: def test_annotate Chris@0: get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] Chris@0: assert_response :success Chris@0: assert_template 'annotate' Chris@119: # Line 23, revision 4:def6d2f1254a Chris@119: assert_tag :tag => 'th', Chris@119: :content => '23', Chris@119: :attributes => { :class => 'line-num' }, Chris@119: :sibling => Chris@119: { Chris@119: :tag => 'td', Chris@119: :attributes => { :class => 'revision' }, Chris@119: :child => { :tag => 'a', :content => '4:def6d2f1254a' } Chris@119: } Chris@119: assert_tag :tag => 'th', Chris@119: :content => '23', Chris@119: :attributes => { :class => 'line-num' }, Chris@119: :sibling => Chris@119: { Chris@119: :tag => 'td' , Chris@119: :content => 'jsmith' , Chris@119: :attributes => { :class => 'author' }, Chris@119: } Chris@119: assert_tag :tag => 'th', Chris@119: :content => '23', Chris@119: :attributes => { :class => 'line-num' }, Chris@0: :sibling => { :tag => 'td', :content => /watcher =/ } Chris@0: end Chris@119: Chris@119: def test_empty_revision Chris@119: @repository.fetch_changesets Chris@119: @repository.reload Chris@119: ['', ' ', nil].each do |r| Chris@128: get :revision, :id => 3, :rev => r Chris@128: assert_response 404 Chris@119: assert_error_tag :content => /was not found/ Chris@119: end Chris@119: end Chris@0: else Chris@0: puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" Chris@0: def test_fake; assert true end Chris@0: end Chris@0: end