annotate .svn/pristine/e6/e69e1b12c742c2fed3eb747a9348573816cd63d1.svn-base @ 1496:17c7ffe039b1 redmine-2.4-integration

Merge from default branch
author Chris Cannam
date Mon, 17 Mar 2014 08:57:53 +0000
parents 261b3d9a4903
children
rev   line source
Chris@1464 1 # Redmine - project management software
Chris@1464 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1464 3 #
Chris@1464 4 # This program is free software; you can redistribute it and/or
Chris@1464 5 # modify it under the terms of the GNU General Public License
Chris@1464 6 # as published by the Free Software Foundation; either version 2
Chris@1464 7 # of the License, or (at your option) any later version.
Chris@1464 8 #
Chris@1464 9 # This program is distributed in the hope that it will be useful,
Chris@1464 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1464 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1464 12 # GNU General Public License for more details.
Chris@1464 13 #
Chris@1464 14 # You should have received a copy of the GNU General Public License
Chris@1464 15 # along with this program; if not, write to the Free Software
Chris@1464 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1464 17
Chris@1464 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1464 19
Chris@1464 20 class RepositoriesCvsControllerTest < ActionController::TestCase
Chris@1464 21 tests RepositoriesController
Chris@1464 22
Chris@1464 23 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@1464 24 :repositories, :enabled_modules
Chris@1464 25
Chris@1464 26 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
Chris@1464 27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
Chris@1464 28 # CVS module
Chris@1464 29 MODULE_NAME = 'test'
Chris@1464 30 PRJ_ID = 3
Chris@1464 31 NUM_REV = 7
Chris@1464 32
Chris@1464 33 def setup
Chris@1464 34 Setting.default_language = 'en'
Chris@1464 35 User.current = nil
Chris@1464 36
Chris@1464 37 @project = Project.find(PRJ_ID)
Chris@1464 38 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
Chris@1464 39 :root_url => REPOSITORY_PATH,
Chris@1464 40 :url => MODULE_NAME,
Chris@1464 41 :log_encoding => 'UTF-8')
Chris@1464 42 assert @repository
Chris@1464 43 end
Chris@1464 44
Chris@1464 45 if File.directory?(REPOSITORY_PATH)
Chris@1464 46 def test_get_new
Chris@1464 47 @request.session[:user_id] = 1
Chris@1464 48 @project.repository.destroy
Chris@1464 49 get :new, :project_id => 'subproject1', :repository_scm => 'Cvs'
Chris@1464 50 assert_response :success
Chris@1464 51 assert_template 'new'
Chris@1464 52 assert_kind_of Repository::Cvs, assigns(:repository)
Chris@1464 53 assert assigns(:repository).new_record?
Chris@1464 54 end
Chris@1464 55
Chris@1464 56 def test_browse_root
Chris@1464 57 assert_equal 0, @repository.changesets.count
Chris@1464 58 @repository.fetch_changesets
Chris@1464 59 @project.reload
Chris@1464 60 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 61 get :show, :id => PRJ_ID
Chris@1464 62 assert_response :success
Chris@1464 63 assert_template 'show'
Chris@1464 64 assert_not_nil assigns(:entries)
Chris@1464 65 assert_equal 3, assigns(:entries).size
Chris@1464 66
Chris@1464 67 entry = assigns(:entries).detect {|e| e.name == 'images'}
Chris@1464 68 assert_equal 'dir', entry.kind
Chris@1464 69
Chris@1464 70 entry = assigns(:entries).detect {|e| e.name == 'README'}
Chris@1464 71 assert_equal 'file', entry.kind
Chris@1464 72
Chris@1464 73 assert_not_nil assigns(:changesets)
Chris@1464 74 assert assigns(:changesets).size > 0
Chris@1464 75 end
Chris@1464 76
Chris@1464 77 def test_browse_directory
Chris@1464 78 assert_equal 0, @repository.changesets.count
Chris@1464 79 @repository.fetch_changesets
Chris@1464 80 @project.reload
Chris@1464 81 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 82 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
Chris@1464 83 assert_response :success
Chris@1464 84 assert_template 'show'
Chris@1464 85 assert_not_nil assigns(:entries)
Chris@1464 86 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@1464 87 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@1464 88 assert_not_nil entry
Chris@1464 89 assert_equal 'file', entry.kind
Chris@1464 90 assert_equal 'images/edit.png', entry.path
Chris@1464 91 end
Chris@1464 92
Chris@1464 93 def test_browse_at_given_revision
Chris@1464 94 assert_equal 0, @repository.changesets.count
Chris@1464 95 @repository.fetch_changesets
Chris@1464 96 @project.reload
Chris@1464 97 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 98 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
Chris@1464 99 :rev => 1
Chris@1464 100 assert_response :success
Chris@1464 101 assert_template 'show'
Chris@1464 102 assert_not_nil assigns(:entries)
Chris@1464 103 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@1464 104 end
Chris@1464 105
Chris@1464 106 def test_entry
Chris@1464 107 assert_equal 0, @repository.changesets.count
Chris@1464 108 @repository.fetch_changesets
Chris@1464 109 @project.reload
Chris@1464 110 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 111 get :entry, :id => PRJ_ID,
Chris@1464 112 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
Chris@1464 113 assert_response :success
Chris@1464 114 assert_template 'entry'
Chris@1464 115 assert_no_tag :tag => 'td',
Chris@1464 116 :attributes => { :class => /line-code/},
Chris@1464 117 :content => /before_filter/
Chris@1464 118 end
Chris@1464 119
Chris@1464 120 def test_entry_at_given_revision
Chris@1464 121 # changesets must be loaded
Chris@1464 122 assert_equal 0, @repository.changesets.count
Chris@1464 123 @repository.fetch_changesets
Chris@1464 124 @project.reload
Chris@1464 125 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 126 get :entry, :id => PRJ_ID,
Chris@1464 127 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
Chris@1464 128 :rev => 2
Chris@1464 129 assert_response :success
Chris@1464 130 assert_template 'entry'
Chris@1464 131 # this line was removed in r3
Chris@1464 132 assert_tag :tag => 'td',
Chris@1464 133 :attributes => { :class => /line-code/},
Chris@1464 134 :content => /before_filter/
Chris@1464 135 end
Chris@1464 136
Chris@1464 137 def test_entry_not_found
Chris@1464 138 assert_equal 0, @repository.changesets.count
Chris@1464 139 @repository.fetch_changesets
Chris@1464 140 @project.reload
Chris@1464 141 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 142 get :entry, :id => PRJ_ID,
Chris@1464 143 :path => repository_path_hash(['sources', 'zzz.c'])[:param]
Chris@1464 144 assert_tag :tag => 'p',
Chris@1464 145 :attributes => { :id => /errorExplanation/ },
Chris@1464 146 :content => /The entry or revision was not found in the repository/
Chris@1464 147 end
Chris@1464 148
Chris@1464 149 def test_entry_download
Chris@1464 150 assert_equal 0, @repository.changesets.count
Chris@1464 151 @repository.fetch_changesets
Chris@1464 152 @project.reload
Chris@1464 153 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 154 get :entry, :id => PRJ_ID,
Chris@1464 155 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
Chris@1464 156 :format => 'raw'
Chris@1464 157 assert_response :success
Chris@1464 158 end
Chris@1464 159
Chris@1464 160 def test_directory_entry
Chris@1464 161 assert_equal 0, @repository.changesets.count
Chris@1464 162 @repository.fetch_changesets
Chris@1464 163 @project.reload
Chris@1464 164 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 165 get :entry, :id => PRJ_ID,
Chris@1464 166 :path => repository_path_hash(['sources'])[:param]
Chris@1464 167 assert_response :success
Chris@1464 168 assert_template 'show'
Chris@1464 169 assert_not_nil assigns(:entry)
Chris@1464 170 assert_equal 'sources', assigns(:entry).name
Chris@1464 171 end
Chris@1464 172
Chris@1464 173 def test_diff
Chris@1464 174 assert_equal 0, @repository.changesets.count
Chris@1464 175 @repository.fetch_changesets
Chris@1464 176 @project.reload
Chris@1464 177 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 178 ['inline', 'sbs'].each do |dt|
Chris@1464 179 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
Chris@1464 180 assert_response :success
Chris@1464 181 assert_template 'diff'
Chris@1464 182 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
Chris@1464 183 :content => /before_filter :require_login/
Chris@1464 184 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
Chris@1464 185 :content => /with one change/
Chris@1464 186 end
Chris@1464 187 end
Chris@1464 188
Chris@1464 189 def test_diff_new_files
Chris@1464 190 assert_equal 0, @repository.changesets.count
Chris@1464 191 @repository.fetch_changesets
Chris@1464 192 @project.reload
Chris@1464 193 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 194 ['inline', 'sbs'].each do |dt|
Chris@1464 195 get :diff, :id => PRJ_ID, :rev => 1, :type => dt
Chris@1464 196 assert_response :success
Chris@1464 197 assert_template 'diff'
Chris@1464 198 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
Chris@1464 199 :content => /watched.remove_watcher/
Chris@1464 200 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@1464 201 :content => /test\/README/
Chris@1464 202 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@1464 203 :content => /test\/images\/delete.png /
Chris@1464 204 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@1464 205 :content => /test\/images\/edit.png/
Chris@1464 206 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@1464 207 :content => /test\/sources\/watchers_controller.rb/
Chris@1464 208 end
Chris@1464 209 end
Chris@1464 210
Chris@1464 211 def test_annotate
Chris@1464 212 assert_equal 0, @repository.changesets.count
Chris@1464 213 @repository.fetch_changesets
Chris@1464 214 @project.reload
Chris@1464 215 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 216 get :annotate, :id => PRJ_ID,
Chris@1464 217 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
Chris@1464 218 assert_response :success
Chris@1464 219 assert_template 'annotate'
Chris@1464 220
Chris@1464 221 # 1.1 line
Chris@1464 222 assert_select 'tr' do
Chris@1464 223 assert_select 'th.line-num', :text => '21'
Chris@1464 224 assert_select 'td.revision', :text => /1.1/
Chris@1464 225 assert_select 'td.author', :text => /LANG/
Chris@1464 226 end
Chris@1464 227 # 1.2 line
Chris@1464 228 assert_select 'tr' do
Chris@1464 229 assert_select 'th.line-num', :text => '32'
Chris@1464 230 assert_select 'td.revision', :text => /1.2/
Chris@1464 231 assert_select 'td.author', :text => /LANG/
Chris@1464 232 end
Chris@1464 233 end
Chris@1464 234
Chris@1464 235 def test_destroy_valid_repository
Chris@1464 236 @request.session[:user_id] = 1 # admin
Chris@1464 237 assert_equal 0, @repository.changesets.count
Chris@1464 238 @repository.fetch_changesets
Chris@1464 239 @project.reload
Chris@1464 240 assert_equal NUM_REV, @repository.changesets.count
Chris@1464 241
Chris@1464 242 assert_difference 'Repository.count', -1 do
Chris@1464 243 delete :destroy, :id => @repository.id
Chris@1464 244 end
Chris@1464 245 assert_response 302
Chris@1464 246 @project.reload
Chris@1464 247 assert_nil @project.repository
Chris@1464 248 end
Chris@1464 249
Chris@1464 250 def test_destroy_invalid_repository
Chris@1464 251 @request.session[:user_id] = 1 # admin
Chris@1464 252 @project.repository.destroy
Chris@1464 253 @repository = Repository::Cvs.create!(
Chris@1464 254 :project => Project.find(PRJ_ID),
Chris@1464 255 :root_url => "/invalid",
Chris@1464 256 :url => MODULE_NAME,
Chris@1464 257 :log_encoding => 'UTF-8'
Chris@1464 258 )
Chris@1464 259 @repository.fetch_changesets
Chris@1464 260 @project.reload
Chris@1464 261 assert_equal 0, @repository.changesets.count
Chris@1464 262
Chris@1464 263 assert_difference 'Repository.count', -1 do
Chris@1464 264 delete :destroy, :id => @repository.id
Chris@1464 265 end
Chris@1464 266 assert_response 302
Chris@1464 267 @project.reload
Chris@1464 268 assert_nil @project.repository
Chris@1464 269 end
Chris@1464 270 else
Chris@1464 271 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
Chris@1464 272 def test_fake; assert true end
Chris@1464 273 end
Chris@1464 274 end