annotate test/functional/.svn/text-base/repositories_cvs_controller_test.rb.svn-base @ 904:0a8317a50fa0 redmine-1.1

Close obsolete branch redmine-1.1
author Chris Cannam
date Fri, 14 Jan 2011 12:53:21 +0000
parents af80e5618e9b
children 0579821a129a
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@117 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'repositories_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class RepositoriesController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class RepositoriesCvsControllerTest < ActionController::TestCase
Chris@117 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
Chris@0 26
Chris@0 27 # No '..' in the repository path
Chris@0 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository'
Chris@0 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
Chris@0 30 # CVS module
Chris@0 31 MODULE_NAME = 'test'
Chris@0 32
Chris@0 33 def setup
Chris@0 34 @controller = RepositoriesController.new
Chris@0 35 @request = ActionController::TestRequest.new
Chris@0 36 @response = ActionController::TestResponse.new
Chris@0 37 Setting.default_language = 'en'
Chris@0 38 User.current = nil
Chris@0 39
Chris@0 40 @project = Project.find(1)
Chris@0 41 @project.repository = Repository::Cvs.create(:root_url => REPOSITORY_PATH,
Chris@0 42 :url => MODULE_NAME)
Chris@0 43 end
Chris@0 44
Chris@0 45 if File.directory?(REPOSITORY_PATH)
Chris@0 46 def test_show
Chris@0 47 get :show, :id => 1
Chris@0 48 assert_response :success
Chris@0 49 assert_template 'show'
Chris@0 50 assert_not_nil assigns(:entries)
Chris@0 51 assert_not_nil assigns(:changesets)
Chris@0 52 end
Chris@0 53
Chris@0 54 def test_browse_root
Chris@0 55 get :show, :id => 1
Chris@0 56 assert_response :success
Chris@0 57 assert_template 'show'
Chris@0 58 assert_not_nil assigns(:entries)
Chris@0 59 assert_equal 3, assigns(:entries).size
Chris@0 60
Chris@0 61 entry = assigns(:entries).detect {|e| e.name == 'images'}
Chris@0 62 assert_equal 'dir', entry.kind
Chris@0 63
Chris@0 64 entry = assigns(:entries).detect {|e| e.name == 'README'}
Chris@0 65 assert_equal 'file', entry.kind
Chris@0 66 end
Chris@0 67
Chris@0 68 def test_browse_directory
Chris@0 69 get :show, :id => 1, :path => ['images']
Chris@0 70 assert_response :success
Chris@0 71 assert_template 'show'
Chris@0 72 assert_not_nil assigns(:entries)
Chris@0 73 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 74 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@0 75 assert_not_nil entry
Chris@0 76 assert_equal 'file', entry.kind
Chris@0 77 assert_equal 'images/edit.png', entry.path
Chris@0 78 end
Chris@0 79
Chris@0 80 def test_browse_at_given_revision
Chris@0 81 Project.find(1).repository.fetch_changesets
Chris@0 82 get :show, :id => 1, :path => ['images'], :rev => 1
Chris@0 83 assert_response :success
Chris@0 84 assert_template 'show'
Chris@0 85 assert_not_nil assigns(:entries)
Chris@0 86 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 87 end
Chris@0 88
Chris@0 89 def test_entry
Chris@0 90 get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb']
Chris@0 91 assert_response :success
Chris@0 92 assert_template 'entry'
Chris@0 93 assert_no_tag :tag => 'td', :attributes => { :class => /line-code/},
Chris@0 94 :content => /before_filter/
Chris@0 95 end
Chris@0 96
Chris@0 97 def test_entry_at_given_revision
Chris@0 98 # changesets must be loaded
Chris@0 99 Project.find(1).repository.fetch_changesets
Chris@0 100 get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb'], :rev => 2
Chris@0 101 assert_response :success
Chris@0 102 assert_template 'entry'
Chris@0 103 # this line was removed in r3
Chris@0 104 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
Chris@0 105 :content => /before_filter/
Chris@0 106 end
Chris@0 107
Chris@0 108 def test_entry_not_found
Chris@0 109 get :entry, :id => 1, :path => ['sources', 'zzz.c']
chris@37 110 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
Chris@0 111 :content => /The entry or revision was not found in the repository/
Chris@0 112 end
Chris@0 113
Chris@0 114 def test_entry_download
Chris@0 115 get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
Chris@0 116 assert_response :success
Chris@0 117 end
Chris@0 118
Chris@0 119 def test_directory_entry
Chris@0 120 get :entry, :id => 1, :path => ['sources']
Chris@0 121 assert_response :success
Chris@0 122 assert_template 'show'
Chris@0 123 assert_not_nil assigns(:entry)
Chris@0 124 assert_equal 'sources', assigns(:entry).name
Chris@0 125 end
Chris@0 126
Chris@0 127 def test_diff
Chris@0 128 Project.find(1).repository.fetch_changesets
Chris@0 129 get :diff, :id => 1, :rev => 3, :type => 'inline'
Chris@0 130 assert_response :success
Chris@0 131 assert_template 'diff'
Chris@0 132 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
Chris@0 133 :content => /watched.remove_watcher/
Chris@0 134 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
Chris@0 135 :content => /watched.remove_all_watcher/
Chris@0 136 end
Chris@0 137
Chris@0 138 def test_annotate
Chris@0 139 Project.find(1).repository.fetch_changesets
Chris@0 140 get :annotate, :id => 1, :path => ['sources', 'watchers_controller.rb']
Chris@0 141 assert_response :success
Chris@0 142 assert_template 'annotate'
Chris@0 143 # 1.1 line
Chris@0 144 assert_tag :tag => 'th', :attributes => { :class => 'line-num' },
Chris@0 145 :content => '18',
Chris@0 146 :sibling => { :tag => 'td', :attributes => { :class => 'revision' },
Chris@0 147 :content => /1.1/,
Chris@0 148 :sibling => { :tag => 'td', :attributes => { :class => 'author' },
Chris@0 149 :content => /LANG/
Chris@0 150 }
Chris@0 151 }
Chris@0 152 # 1.2 line
Chris@0 153 assert_tag :tag => 'th', :attributes => { :class => 'line-num' },
Chris@0 154 :content => '32',
Chris@0 155 :sibling => { :tag => 'td', :attributes => { :class => 'revision' },
Chris@0 156 :content => /1.2/,
Chris@0 157 :sibling => { :tag => 'td', :attributes => { :class => 'author' },
Chris@0 158 :content => /LANG/
Chris@0 159 }
Chris@0 160 }
Chris@0 161 end
Chris@0 162 else
Chris@0 163 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 164 def test_fake; assert true end
Chris@0 165 end
Chris@0 166 end