annotate test/functional/repositories_darcs_controller_test.rb @ 1621:3a510bf6a9bc

Merge from live branch
author Chris Cannam
date Fri, 13 Jul 2018 10:44:33 +0100
parents e248c7af89ec
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19
Chris@0 20 class RepositoriesDarcsControllerTest < ActionController::TestCase
Chris@1115 21 tests RepositoriesController
Chris@1115 22
Chris@909 23 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@909 24 :repositories, :enabled_modules
Chris@0 25
Chris@909 26 REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
Chris@245 27 PRJ_ID = 3
Chris@909 28 NUM_REV = 6
Chris@0 29
Chris@0 30 def setup
Chris@0 31 User.current = nil
Chris@245 32 @project = Project.find(PRJ_ID)
Chris@245 33 @repository = Repository::Darcs.create(
Chris@909 34 :project => @project,
Chris@909 35 :url => REPOSITORY_PATH,
Chris@909 36 :log_encoding => 'UTF-8'
Chris@909 37 )
Chris@245 38 assert @repository
Chris@0 39 end
Chris@245 40
Chris@0 41 if File.directory?(REPOSITORY_PATH)
Chris@1115 42 def test_get_new
Chris@1115 43 @request.session[:user_id] = 1
Chris@1115 44 @project.repository.destroy
Chris@1115 45 get :new, :project_id => 'subproject1', :repository_scm => 'Darcs'
Chris@1115 46 assert_response :success
Chris@1115 47 assert_template 'new'
Chris@1115 48 assert_kind_of Repository::Darcs, assigns(:repository)
Chris@1115 49 assert assigns(:repository).new_record?
Chris@1115 50 end
Chris@1115 51
Chris@0 52 def test_browse_root
Chris@909 53 assert_equal 0, @repository.changesets.count
Chris@245 54 @repository.fetch_changesets
Chris@909 55 @project.reload
Chris@909 56 assert_equal NUM_REV, @repository.changesets.count
Chris@245 57 get :show, :id => PRJ_ID
Chris@0 58 assert_response :success
Chris@0 59 assert_template 'show'
Chris@0 60 assert_not_nil assigns(:entries)
Chris@0 61 assert_equal 3, assigns(:entries).size
Chris@0 62 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
Chris@0 63 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
Chris@0 64 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
Chris@0 65 end
Chris@245 66
Chris@0 67 def test_browse_directory
Chris@909 68 assert_equal 0, @repository.changesets.count
Chris@245 69 @repository.fetch_changesets
Chris@909 70 @project.reload
Chris@909 71 assert_equal NUM_REV, @repository.changesets.count
Chris@1115 72 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
Chris@0 73 assert_response :success
Chris@0 74 assert_template 'show'
Chris@0 75 assert_not_nil assigns(:entries)
Chris@0 76 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 77 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@0 78 assert_not_nil entry
Chris@0 79 assert_equal 'file', entry.kind
Chris@0 80 assert_equal 'images/edit.png', entry.path
Chris@0 81 end
Chris@245 82
Chris@0 83 def test_browse_at_given_revision
Chris@909 84 assert_equal 0, @repository.changesets.count
Chris@245 85 @repository.fetch_changesets
Chris@909 86 @project.reload
Chris@909 87 assert_equal NUM_REV, @repository.changesets.count
Chris@1115 88 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
Chris@1115 89 :rev => 1
Chris@0 90 assert_response :success
Chris@0 91 assert_template 'show'
Chris@0 92 assert_not_nil assigns(:entries)
Chris@0 93 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
Chris@0 94 end
Chris@245 95
Chris@0 96 def test_changes
Chris@909 97 assert_equal 0, @repository.changesets.count
Chris@245 98 @repository.fetch_changesets
Chris@909 99 @project.reload
Chris@909 100 assert_equal NUM_REV, @repository.changesets.count
Chris@1115 101 get :changes, :id => PRJ_ID,
Chris@1115 102 :path => repository_path_hash(['images', 'edit.png'])[:param]
Chris@0 103 assert_response :success
Chris@0 104 assert_template 'changes'
Chris@0 105 assert_tag :tag => 'h2', :content => 'edit.png'
Chris@0 106 end
Chris@245 107
Chris@0 108 def test_diff
Chris@909 109 assert_equal 0, @repository.changesets.count
Chris@245 110 @repository.fetch_changesets
Chris@909 111 @project.reload
Chris@909 112 assert_equal NUM_REV, @repository.changesets.count
Chris@0 113 # Full diff of changeset 5
Chris@909 114 ['inline', 'sbs'].each do |dt|
Chris@909 115 get :diff, :id => PRJ_ID, :rev => 5, :type => dt
Chris@909 116 assert_response :success
Chris@909 117 assert_template 'diff'
Chris@909 118 # Line 22 removed
Chris@909 119 assert_tag :tag => 'th',
Chris@909 120 :content => '22',
Chris@909 121 :sibling => { :tag => 'td',
Chris@909 122 :attributes => { :class => /diff_out/ },
Chris@909 123 :content => /def remove/ }
Chris@909 124 end
Chris@909 125 end
Chris@909 126
Chris@909 127 def test_destroy_valid_repository
Chris@909 128 @request.session[:user_id] = 1 # admin
Chris@909 129 assert_equal 0, @repository.changesets.count
Chris@909 130 @repository.fetch_changesets
Chris@909 131 @project.reload
Chris@909 132 assert_equal NUM_REV, @repository.changesets.count
Chris@909 133
Chris@1115 134 assert_difference 'Repository.count', -1 do
Chris@1115 135 delete :destroy, :id => @repository.id
Chris@1115 136 end
Chris@909 137 assert_response 302
Chris@909 138 @project.reload
Chris@909 139 assert_nil @project.repository
Chris@909 140 end
Chris@909 141
Chris@909 142 def test_destroy_invalid_repository
Chris@909 143 @request.session[:user_id] = 1 # admin
Chris@1115 144 @project.repository.destroy
Chris@1115 145 @repository = Repository::Darcs.create!(
Chris@909 146 :project => @project,
Chris@909 147 :url => "/invalid",
Chris@909 148 :log_encoding => 'UTF-8'
Chris@909 149 )
Chris@909 150 @repository.fetch_changesets
Chris@909 151 @project.reload
Chris@909 152 assert_equal 0, @repository.changesets.count
Chris@909 153
Chris@1115 154 assert_difference 'Repository.count', -1 do
Chris@1115 155 delete :destroy, :id => @repository.id
Chris@1115 156 end
Chris@909 157 assert_response 302
Chris@909 158 @project.reload
Chris@909 159 assert_nil @project.repository
Chris@0 160 end
Chris@0 161 else
Chris@0 162 puts "Darcs test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 163 def test_fake; assert true end
Chris@0 164 end
Chris@0 165 end