annotate test/functional/repositories_cvs_controller_test.rb @ 856:0dac80e40800 bug_208

Close obsolete branch bug_208
author Chris Cannam
date Thu, 14 Jul 2011 11:08:06 +0100
parents cbce1fd3b1b7
children cbb26bc654de
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 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@441 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@441 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@119 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@119 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@210 32 PRJ_ID = 3
Chris@210 33
Chris@0 34 def setup
Chris@0 35 @controller = RepositoriesController.new
Chris@0 36 @request = ActionController::TestRequest.new
Chris@0 37 @response = ActionController::TestResponse.new
Chris@0 38 Setting.default_language = 'en'
Chris@0 39 User.current = nil
Chris@0 40
Chris@210 41 @project = Project.find(PRJ_ID)
Chris@441 42 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
Chris@441 43 :root_url => REPOSITORY_PATH,
Chris@441 44 :url => MODULE_NAME,
Chris@245 45 :log_encoding => 'UTF-8')
Chris@210 46 assert @repository
Chris@0 47 end
Chris@441 48
Chris@0 49 if File.directory?(REPOSITORY_PATH)
Chris@0 50 def test_browse_root
Chris@210 51 @repository.fetch_changesets
Chris@210 52 @repository.reload
Chris@210 53 get :show, :id => PRJ_ID
Chris@0 54 assert_response :success
Chris@0 55 assert_template 'show'
Chris@0 56 assert_not_nil assigns(:entries)
Chris@0 57 assert_equal 3, assigns(:entries).size
Chris@441 58
Chris@0 59 entry = assigns(:entries).detect {|e| e.name == 'images'}
Chris@0 60 assert_equal 'dir', entry.kind
Chris@0 61
Chris@0 62 entry = assigns(:entries).detect {|e| e.name == 'README'}
Chris@0 63 assert_equal 'file', entry.kind
Chris@441 64
Chris@441 65 assert_not_nil assigns(:changesets)
Chris@441 66 assigns(:changesets).size > 0
Chris@0 67 end
Chris@441 68
Chris@0 69 def test_browse_directory
Chris@210 70 @repository.fetch_changesets
Chris@210 71 @repository.reload
Chris@210 72 get :show, :id => PRJ_ID, :path => ['images']
Chris@0 73 assert_response :success
Chris@0 74 assert_template 'show'
Chris@0 75 assert_not_nil assigns(:entries)
Chris@0 76 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 77 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@0 78 assert_not_nil entry
Chris@0 79 assert_equal 'file', entry.kind
Chris@0 80 assert_equal 'images/edit.png', entry.path
Chris@0 81 end
Chris@441 82
Chris@0 83 def test_browse_at_given_revision
Chris@210 84 @repository.fetch_changesets
Chris@210 85 @repository.reload
Chris@210 86 get :show, :id => PRJ_ID, :path => ['images'], :rev => 1
Chris@0 87 assert_response :success
Chris@0 88 assert_template 'show'
Chris@0 89 assert_not_nil assigns(:entries)
Chris@0 90 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 91 end
Chris@441 92
Chris@0 93 def test_entry
Chris@210 94 @repository.fetch_changesets
Chris@210 95 @repository.reload
Chris@210 96 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
Chris@0 97 assert_response :success
Chris@0 98 assert_template 'entry'
Chris@441 99 assert_no_tag :tag => 'td',
Chris@441 100 :attributes => { :class => /line-code/},
Chris@441 101 :content => /before_filter/
Chris@0 102 end
Chris@441 103
Chris@0 104 def test_entry_at_given_revision
Chris@0 105 # changesets must be loaded
Chris@210 106 @repository.fetch_changesets
Chris@210 107 @repository.reload
Chris@210 108 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 2
Chris@0 109 assert_response :success
Chris@0 110 assert_template 'entry'
Chris@0 111 # this line was removed in r3
Chris@441 112 assert_tag :tag => 'td',
Chris@441 113 :attributes => { :class => /line-code/},
Chris@441 114 :content => /before_filter/
Chris@0 115 end
Chris@441 116
Chris@0 117 def test_entry_not_found
Chris@210 118 @repository.fetch_changesets
Chris@210 119 @repository.reload
Chris@210 120 get :entry, :id => PRJ_ID, :path => ['sources', 'zzz.c']
Chris@441 121 assert_tag :tag => 'p',
Chris@441 122 :attributes => { :id => /errorExplanation/ },
Chris@441 123 :content => /The entry or revision was not found in the repository/
Chris@0 124 end
Chris@441 125
Chris@0 126 def test_entry_download
Chris@210 127 @repository.fetch_changesets
Chris@210 128 @repository.reload
Chris@210 129 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
Chris@0 130 assert_response :success
Chris@0 131 end
Chris@0 132
Chris@0 133 def test_directory_entry
Chris@210 134 @repository.fetch_changesets
Chris@210 135 @repository.reload
Chris@210 136 get :entry, :id => PRJ_ID, :path => ['sources']
Chris@0 137 assert_response :success
Chris@0 138 assert_template 'show'
Chris@0 139 assert_not_nil assigns(:entry)
Chris@0 140 assert_equal 'sources', assigns(:entry).name
Chris@0 141 end
Chris@441 142
Chris@0 143 def test_diff
Chris@210 144 @repository.fetch_changesets
Chris@210 145 @repository.reload
Chris@210 146 get :diff, :id => PRJ_ID, :rev => 3, :type => 'inline'
Chris@0 147 assert_response :success
Chris@0 148 assert_template 'diff'
Chris@0 149 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
Chris@441 150 :content => /before_filter :require_login/
Chris@0 151 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
Chris@441 152 :content => /with one change/
Chris@0 153 end
Chris@441 154
Chris@245 155 def test_diff_new_files
Chris@245 156 @repository.fetch_changesets
Chris@245 157 @repository.reload
Chris@245 158 get :diff, :id => PRJ_ID, :rev => 1, :type => 'inline'
Chris@245 159 assert_response :success
Chris@245 160 assert_template 'diff'
Chris@245 161 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
Chris@245 162 :content => /watched.remove_watcher/
Chris@245 163 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@245 164 :content => /test\/README/
Chris@245 165 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@245 166 :content => /test\/images\/delete.png /
Chris@245 167 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@245 168 :content => /test\/images\/edit.png/
Chris@245 169 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@441 170 :content => /test\/sources\/watchers_controller.rb/
Chris@245 171 end
Chris@0 172
Chris@0 173 def test_annotate
Chris@210 174 @repository.fetch_changesets
Chris@210 175 @repository.reload
Chris@210 176 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
Chris@0 177 assert_response :success
Chris@0 178 assert_template 'annotate'
Chris@0 179 # 1.1 line
Chris@441 180 assert_tag :tag => 'th',
Chris@441 181 :attributes => { :class => 'line-num' },
Chris@441 182 :content => '18',
Chris@441 183 :sibling => {
Chris@441 184 :tag => 'td',
Chris@441 185 :attributes => { :class => 'revision' },
Chris@441 186 :content => /1.1/,
Chris@441 187 :sibling => {
Chris@441 188 :tag => 'td',
Chris@441 189 :attributes => { :class => 'author' },
Chris@441 190 :content => /LANG/
Chris@441 191 }
Chris@441 192 }
Chris@0 193 # 1.2 line
Chris@441 194 assert_tag :tag => 'th',
Chris@441 195 :attributes => { :class => 'line-num' },
Chris@441 196 :content => '32',
Chris@441 197 :sibling => {
Chris@441 198 :tag => 'td',
Chris@441 199 :attributes => { :class => 'revision' },
Chris@441 200 :content => /1.2/,
Chris@441 201 :sibling => {
Chris@441 202 :tag => 'td',
Chris@441 203 :attributes => { :class => 'author' },
Chris@441 204 :content => /LANG/
Chris@441 205 }
Chris@441 206 }
Chris@0 207 end
Chris@0 208 else
Chris@0 209 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 210 def test_fake; assert true end
Chris@0 211 end
Chris@0 212 end