annotate .svn/pristine/d8/d820b362da40aaa2b6531056312ceeddee3d097b.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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