annotate .svn/pristine/4c/4c998cfe872582fc9c34765173f146ee719b1024.svn-base @ 1295:622f24f53b42 redmine-2.3

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