annotate test/functional/repositories_cvs_controller_test.rb @ 1171:b4558bc5837f bug_505

Close obsolete branch bug_505
author Chris Cannam
date Fri, 03 Aug 2012 19:40:23 +0100
parents cbb26bc654de
children 433d4f72a19b
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@909 25 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@909 26 :repositories, :enabled_modules
Chris@0 27
Chris@909 28 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
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@909 33 NUM_REV = 7
Chris@210 34
Chris@0 35 def setup
Chris@0 36 @controller = RepositoriesController.new
Chris@0 37 @request = ActionController::TestRequest.new
Chris@0 38 @response = ActionController::TestResponse.new
Chris@0 39 Setting.default_language = 'en'
Chris@0 40 User.current = nil
Chris@0 41
Chris@210 42 @project = Project.find(PRJ_ID)
Chris@441 43 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
Chris@441 44 :root_url => REPOSITORY_PATH,
Chris@441 45 :url => MODULE_NAME,
Chris@245 46 :log_encoding => 'UTF-8')
Chris@210 47 assert @repository
Chris@0 48 end
Chris@441 49
Chris@0 50 if File.directory?(REPOSITORY_PATH)
Chris@0 51 def test_browse_root
Chris@909 52 assert_equal 0, @repository.changesets.count
Chris@210 53 @repository.fetch_changesets
Chris@909 54 @project.reload
Chris@909 55 assert_equal NUM_REV, @repository.changesets.count
Chris@210 56 get :show, :id => PRJ_ID
Chris@0 57 assert_response :success
Chris@0 58 assert_template 'show'
Chris@0 59 assert_not_nil assigns(:entries)
Chris@0 60 assert_equal 3, assigns(:entries).size
Chris@441 61
Chris@0 62 entry = assigns(:entries).detect {|e| e.name == 'images'}
Chris@0 63 assert_equal 'dir', entry.kind
Chris@0 64
Chris@0 65 entry = assigns(:entries).detect {|e| e.name == 'README'}
Chris@0 66 assert_equal 'file', entry.kind
Chris@441 67
Chris@441 68 assert_not_nil assigns(:changesets)
Chris@909 69 assert assigns(:changesets).size > 0
Chris@0 70 end
Chris@441 71
Chris@0 72 def test_browse_directory
Chris@909 73 assert_equal 0, @repository.changesets.count
Chris@210 74 @repository.fetch_changesets
Chris@909 75 @project.reload
Chris@909 76 assert_equal NUM_REV, @repository.changesets.count
Chris@210 77 get :show, :id => PRJ_ID, :path => ['images']
Chris@0 78 assert_response :success
Chris@0 79 assert_template 'show'
Chris@0 80 assert_not_nil assigns(:entries)
Chris@0 81 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 82 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@0 83 assert_not_nil entry
Chris@0 84 assert_equal 'file', entry.kind
Chris@0 85 assert_equal 'images/edit.png', entry.path
Chris@0 86 end
Chris@441 87
Chris@0 88 def test_browse_at_given_revision
Chris@909 89 assert_equal 0, @repository.changesets.count
Chris@210 90 @repository.fetch_changesets
Chris@909 91 @project.reload
Chris@909 92 assert_equal NUM_REV, @repository.changesets.count
Chris@210 93 get :show, :id => PRJ_ID, :path => ['images'], :rev => 1
Chris@0 94 assert_response :success
Chris@0 95 assert_template 'show'
Chris@0 96 assert_not_nil assigns(:entries)
Chris@0 97 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 98 end
Chris@441 99
Chris@0 100 def test_entry
Chris@909 101 assert_equal 0, @repository.changesets.count
Chris@210 102 @repository.fetch_changesets
Chris@909 103 @project.reload
Chris@909 104 assert_equal NUM_REV, @repository.changesets.count
Chris@210 105 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
Chris@0 106 assert_response :success
Chris@0 107 assert_template 'entry'
Chris@441 108 assert_no_tag :tag => 'td',
Chris@441 109 :attributes => { :class => /line-code/},
Chris@441 110 :content => /before_filter/
Chris@0 111 end
Chris@441 112
Chris@0 113 def test_entry_at_given_revision
Chris@0 114 # changesets must be loaded
Chris@909 115 assert_equal 0, @repository.changesets.count
Chris@210 116 @repository.fetch_changesets
Chris@909 117 @project.reload
Chris@909 118 assert_equal NUM_REV, @repository.changesets.count
Chris@210 119 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 2
Chris@0 120 assert_response :success
Chris@0 121 assert_template 'entry'
Chris@0 122 # this line was removed in r3
Chris@441 123 assert_tag :tag => 'td',
Chris@441 124 :attributes => { :class => /line-code/},
Chris@441 125 :content => /before_filter/
Chris@0 126 end
Chris@441 127
Chris@0 128 def test_entry_not_found
Chris@909 129 assert_equal 0, @repository.changesets.count
Chris@210 130 @repository.fetch_changesets
Chris@909 131 @project.reload
Chris@909 132 assert_equal NUM_REV, @repository.changesets.count
Chris@210 133 get :entry, :id => PRJ_ID, :path => ['sources', 'zzz.c']
Chris@441 134 assert_tag :tag => 'p',
Chris@441 135 :attributes => { :id => /errorExplanation/ },
Chris@441 136 :content => /The entry or revision was not found in the repository/
Chris@0 137 end
Chris@441 138
Chris@0 139 def test_entry_download
Chris@909 140 assert_equal 0, @repository.changesets.count
Chris@210 141 @repository.fetch_changesets
Chris@909 142 @project.reload
Chris@909 143 assert_equal NUM_REV, @repository.changesets.count
Chris@909 144 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
Chris@909 145 :format => 'raw'
Chris@0 146 assert_response :success
Chris@0 147 end
Chris@0 148
Chris@0 149 def test_directory_entry
Chris@909 150 assert_equal 0, @repository.changesets.count
Chris@210 151 @repository.fetch_changesets
Chris@909 152 @project.reload
Chris@909 153 assert_equal NUM_REV, @repository.changesets.count
Chris@210 154 get :entry, :id => PRJ_ID, :path => ['sources']
Chris@0 155 assert_response :success
Chris@0 156 assert_template 'show'
Chris@0 157 assert_not_nil assigns(:entry)
Chris@0 158 assert_equal 'sources', assigns(:entry).name
Chris@0 159 end
Chris@441 160
Chris@0 161 def test_diff
Chris@909 162 assert_equal 0, @repository.changesets.count
Chris@210 163 @repository.fetch_changesets
Chris@909 164 @project.reload
Chris@909 165 assert_equal NUM_REV, @repository.changesets.count
Chris@909 166 ['inline', 'sbs'].each do |dt|
Chris@909 167 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
Chris@909 168 assert_response :success
Chris@909 169 assert_template 'diff'
Chris@909 170 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
Chris@909 171 :content => /before_filter :require_login/
Chris@909 172 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
Chris@909 173 :content => /with one change/
Chris@909 174 end
Chris@0 175 end
Chris@441 176
Chris@245 177 def test_diff_new_files
Chris@909 178 assert_equal 0, @repository.changesets.count
Chris@245 179 @repository.fetch_changesets
Chris@909 180 @project.reload
Chris@909 181 assert_equal NUM_REV, @repository.changesets.count
Chris@909 182 ['inline', 'sbs'].each do |dt|
Chris@909 183 get :diff, :id => PRJ_ID, :rev => 1, :type => dt
Chris@909 184 assert_response :success
Chris@909 185 assert_template 'diff'
Chris@909 186 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
Chris@909 187 :content => /watched.remove_watcher/
Chris@909 188 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@909 189 :content => /test\/README/
Chris@909 190 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@909 191 :content => /test\/images\/delete.png /
Chris@909 192 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@909 193 :content => /test\/images\/edit.png/
Chris@909 194 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@909 195 :content => /test\/sources\/watchers_controller.rb/
Chris@909 196 end
Chris@245 197 end
Chris@0 198
Chris@0 199 def test_annotate
Chris@909 200 assert_equal 0, @repository.changesets.count
Chris@210 201 @repository.fetch_changesets
Chris@909 202 @project.reload
Chris@909 203 assert_equal NUM_REV, @repository.changesets.count
Chris@210 204 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
Chris@0 205 assert_response :success
Chris@0 206 assert_template 'annotate'
Chris@0 207 # 1.1 line
Chris@441 208 assert_tag :tag => 'th',
Chris@441 209 :attributes => { :class => 'line-num' },
Chris@441 210 :content => '18',
Chris@441 211 :sibling => {
Chris@441 212 :tag => 'td',
Chris@441 213 :attributes => { :class => 'revision' },
Chris@441 214 :content => /1.1/,
Chris@441 215 :sibling => {
Chris@441 216 :tag => 'td',
Chris@441 217 :attributes => { :class => 'author' },
Chris@441 218 :content => /LANG/
Chris@441 219 }
Chris@441 220 }
Chris@0 221 # 1.2 line
Chris@441 222 assert_tag :tag => 'th',
Chris@441 223 :attributes => { :class => 'line-num' },
Chris@441 224 :content => '32',
Chris@441 225 :sibling => {
Chris@441 226 :tag => 'td',
Chris@441 227 :attributes => { :class => 'revision' },
Chris@441 228 :content => /1.2/,
Chris@441 229 :sibling => {
Chris@441 230 :tag => 'td',
Chris@441 231 :attributes => { :class => 'author' },
Chris@441 232 :content => /LANG/
Chris@441 233 }
Chris@441 234 }
Chris@0 235 end
Chris@909 236
Chris@909 237 def test_destroy_valid_repository
Chris@909 238 @request.session[:user_id] = 1 # admin
Chris@909 239 assert_equal 0, @repository.changesets.count
Chris@909 240 @repository.fetch_changesets
Chris@909 241 @project.reload
Chris@909 242 assert_equal NUM_REV, @repository.changesets.count
Chris@909 243
Chris@909 244 get :destroy, :id => PRJ_ID
Chris@909 245 assert_response 302
Chris@909 246 @project.reload
Chris@909 247 assert_nil @project.repository
Chris@909 248 end
Chris@909 249
Chris@909 250 def test_destroy_invalid_repository
Chris@909 251 @request.session[:user_id] = 1 # admin
Chris@909 252 assert_equal 0, @repository.changesets.count
Chris@909 253 @repository.fetch_changesets
Chris@909 254 @project.reload
Chris@909 255 assert_equal NUM_REV, @repository.changesets.count
Chris@909 256
Chris@909 257 get :destroy, :id => PRJ_ID
Chris@909 258 assert_response 302
Chris@909 259 @project.reload
Chris@909 260 assert_nil @project.repository
Chris@909 261
Chris@909 262 @repository = Repository::Cvs.create(
Chris@909 263 :project => Project.find(PRJ_ID),
Chris@909 264 :root_url => "/invalid",
Chris@909 265 :url => MODULE_NAME,
Chris@909 266 :log_encoding => 'UTF-8'
Chris@909 267 )
Chris@909 268 assert @repository
Chris@909 269 @repository.fetch_changesets
Chris@909 270 @project.reload
Chris@909 271 assert_equal 0, @repository.changesets.count
Chris@909 272
Chris@909 273 get :destroy, :id => PRJ_ID
Chris@909 274 assert_response 302
Chris@909 275 @project.reload
Chris@909 276 assert_nil @project.repository
Chris@909 277 end
Chris@0 278 else
Chris@0 279 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 280 def test_fake; assert true end
Chris@0 281 end
Chris@0 282 end