annotate .svn/pristine/4c/4c998cfe872582fc9c34765173f146ee719b1024.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 RepositoriesDarcsControllerTest < 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/darcs_repository').to_s
Chris@1296 27 PRJ_ID = 3
Chris@1296 28 NUM_REV = 6
Chris@1296 29
Chris@1296 30 def setup
Chris@1296 31 User.current = nil
Chris@1296 32 @project = Project.find(PRJ_ID)
Chris@1296 33 @repository = Repository::Darcs.create(
Chris@1296 34 :project => @project,
Chris@1296 35 :url => REPOSITORY_PATH,
Chris@1296 36 :log_encoding => 'UTF-8'
Chris@1296 37 )
Chris@1296 38 assert @repository
Chris@1296 39 end
Chris@1296 40
Chris@1296 41 if File.directory?(REPOSITORY_PATH)
Chris@1296 42 def test_get_new
Chris@1296 43 @request.session[:user_id] = 1
Chris@1296 44 @project.repository.destroy
Chris@1296 45 get :new, :project_id => 'subproject1', :repository_scm => 'Darcs'
Chris@1296 46 assert_response :success
Chris@1296 47 assert_template 'new'
Chris@1296 48 assert_kind_of Repository::Darcs, assigns(:repository)
Chris@1296 49 assert assigns(:repository).new_record?
Chris@1296 50 end
Chris@1296 51
Chris@1296 52 def test_browse_root
Chris@1296 53 assert_equal 0, @repository.changesets.count
Chris@1296 54 @repository.fetch_changesets
Chris@1296 55 @project.reload
Chris@1296 56 assert_equal NUM_REV, @repository.changesets.count
Chris@1296 57 get :show, :id => PRJ_ID
Chris@1296 58 assert_response :success
Chris@1296 59 assert_template 'show'
Chris@1296 60 assert_not_nil assigns(:entries)
Chris@1296 61 assert_equal 3, assigns(:entries).size
Chris@1296 62 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
Chris@1296 63 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
Chris@1296 64 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
Chris@1296 65 end
Chris@1296 66
Chris@1296 67 def test_browse_directory
Chris@1296 68 assert_equal 0, @repository.changesets.count
Chris@1296 69 @repository.fetch_changesets
Chris@1296 70 @project.reload
Chris@1296 71 assert_equal NUM_REV, @repository.changesets.count
Chris@1296 72 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
Chris@1296 73 assert_response :success
Chris@1296 74 assert_template 'show'
Chris@1296 75 assert_not_nil assigns(:entries)
Chris@1296 76 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@1296 77 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@1296 78 assert_not_nil entry
Chris@1296 79 assert_equal 'file', entry.kind
Chris@1296 80 assert_equal 'images/edit.png', entry.path
Chris@1296 81 end
Chris@1296 82
Chris@1296 83 def test_browse_at_given_revision
Chris@1296 84 assert_equal 0, @repository.changesets.count
Chris@1296 85 @repository.fetch_changesets
Chris@1296 86 @project.reload
Chris@1296 87 assert_equal NUM_REV, @repository.changesets.count
Chris@1296 88 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
Chris@1296 89 :rev => 1
Chris@1296 90 assert_response :success
Chris@1296 91 assert_template 'show'
Chris@1296 92 assert_not_nil assigns(:entries)
Chris@1296 93 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
Chris@1296 94 end
Chris@1296 95
Chris@1296 96 def test_changes
Chris@1296 97 assert_equal 0, @repository.changesets.count
Chris@1296 98 @repository.fetch_changesets
Chris@1296 99 @project.reload
Chris@1296 100 assert_equal NUM_REV, @repository.changesets.count
Chris@1296 101 get :changes, :id => PRJ_ID,
Chris@1296 102 :path => repository_path_hash(['images', 'edit.png'])[:param]
Chris@1296 103 assert_response :success
Chris@1296 104 assert_template 'changes'
Chris@1296 105 assert_tag :tag => 'h2', :content => 'edit.png'
Chris@1296 106 end
Chris@1296 107
Chris@1296 108 def test_diff
Chris@1296 109 assert_equal 0, @repository.changesets.count
Chris@1296 110 @repository.fetch_changesets
Chris@1296 111 @project.reload
Chris@1296 112 assert_equal NUM_REV, @repository.changesets.count
Chris@1296 113 # Full diff of changeset 5
Chris@1296 114 ['inline', 'sbs'].each do |dt|
Chris@1296 115 get :diff, :id => PRJ_ID, :rev => 5, :type => dt
Chris@1296 116 assert_response :success
Chris@1296 117 assert_template 'diff'
Chris@1296 118 # Line 22 removed
Chris@1296 119 assert_tag :tag => 'th',
Chris@1296 120 :content => '22',
Chris@1296 121 :sibling => { :tag => 'td',
Chris@1296 122 :attributes => { :class => /diff_out/ },
Chris@1296 123 :content => /def remove/ }
Chris@1296 124 end
Chris@1296 125 end
Chris@1296 126
Chris@1296 127 def test_destroy_valid_repository
Chris@1296 128 @request.session[:user_id] = 1 # admin
Chris@1296 129 assert_equal 0, @repository.changesets.count
Chris@1296 130 @repository.fetch_changesets
Chris@1296 131 @project.reload
Chris@1296 132 assert_equal NUM_REV, @repository.changesets.count
Chris@1296 133
Chris@1296 134 assert_difference 'Repository.count', -1 do
Chris@1296 135 delete :destroy, :id => @repository.id
Chris@1296 136 end
Chris@1296 137 assert_response 302
Chris@1296 138 @project.reload
Chris@1296 139 assert_nil @project.repository
Chris@1296 140 end
Chris@1296 141
Chris@1296 142 def test_destroy_invalid_repository
Chris@1296 143 @request.session[:user_id] = 1 # admin
Chris@1296 144 @project.repository.destroy
Chris@1296 145 @repository = Repository::Darcs.create!(
Chris@1296 146 :project => @project,
Chris@1296 147 :url => "/invalid",
Chris@1296 148 :log_encoding => 'UTF-8'
Chris@1296 149 )
Chris@1296 150 @repository.fetch_changesets
Chris@1296 151 @project.reload
Chris@1296 152 assert_equal 0, @repository.changesets.count
Chris@1296 153
Chris@1296 154 assert_difference 'Repository.count', -1 do
Chris@1296 155 delete :destroy, :id => @repository.id
Chris@1296 156 end
Chris@1296 157 assert_response 302
Chris@1296 158 @project.reload
Chris@1296 159 assert_nil @project.repository
Chris@1296 160 end
Chris@1296 161 else
Chris@1296 162 puts "Darcs test repository NOT FOUND. Skipping functional tests !!!"
Chris@1296 163 def test_fake; assert true end
Chris@1296 164 end
Chris@1296 165 end