annotate .svn/pristine/85/856339cef1bdf5f11b116c77c2ac5a76171899ce.svn-base @ 1494:e248c7af89ec redmine-2.4

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