annotate .svn/pristine/e6/e69e1b12c742c2fed3eb747a9348573816cd63d1.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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