annotate .svn/pristine/d1/d1641076738b16a5e8c3b02dfb1eb74a370bb3d4.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 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 RepositoriesBazaarControllerTest < 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/bazaar_repository/trunk').to_s
Chris@1295 27 PRJ_ID = 3
Chris@1295 28
Chris@1295 29 def setup
Chris@1295 30 User.current = nil
Chris@1295 31 @project = Project.find(PRJ_ID)
Chris@1295 32 @repository = Repository::Bazaar.create(
Chris@1295 33 :project => @project,
Chris@1295 34 :url => REPOSITORY_PATH,
Chris@1295 35 :log_encoding => 'UTF-8')
Chris@1295 36 assert @repository
Chris@1295 37 end
Chris@1295 38
Chris@1295 39 if File.directory?(REPOSITORY_PATH)
Chris@1295 40 def test_get_new
Chris@1295 41 @request.session[:user_id] = 1
Chris@1295 42 @project.repository.destroy
Chris@1295 43 get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
Chris@1295 44 assert_response :success
Chris@1295 45 assert_template 'new'
Chris@1295 46 assert_kind_of Repository::Bazaar, assigns(:repository)
Chris@1295 47 assert assigns(:repository).new_record?
Chris@1295 48 end
Chris@1295 49
Chris@1295 50 def test_browse_root
Chris@1295 51 get :show, :id => PRJ_ID
Chris@1295 52 assert_response :success
Chris@1295 53 assert_template 'show'
Chris@1295 54 assert_not_nil assigns(:entries)
Chris@1295 55 assert_equal 2, assigns(:entries).size
Chris@1295 56 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
Chris@1295 57 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
Chris@1295 58 end
Chris@1295 59
Chris@1295 60 def test_browse_directory
Chris@1295 61 get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param]
Chris@1295 62 assert_response :success
Chris@1295 63 assert_template 'show'
Chris@1295 64 assert_not_nil assigns(:entries)
Chris@1295 65 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
Chris@1295 66 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@1295 67 assert_not_nil entry
Chris@1295 68 assert_equal 'file', entry.kind
Chris@1295 69 assert_equal 'directory/edit.png', entry.path
Chris@1295 70 end
Chris@1295 71
Chris@1295 72 def test_browse_at_given_revision
Chris@1295 73 get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param],
Chris@1295 74 :rev => 3
Chris@1295 75 assert_response :success
Chris@1295 76 assert_template 'show'
Chris@1295 77 assert_not_nil assigns(:entries)
Chris@1295 78 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
Chris@1295 79 assigns(:entries).collect(&:name)
Chris@1295 80 end
Chris@1295 81
Chris@1295 82 def test_changes
Chris@1295 83 get :changes, :id => PRJ_ID,
Chris@1295 84 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
Chris@1295 85 assert_response :success
Chris@1295 86 assert_template 'changes'
Chris@1295 87 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
Chris@1295 88 end
Chris@1295 89
Chris@1295 90 def test_entry_show
Chris@1295 91 get :entry, :id => PRJ_ID,
Chris@1295 92 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
Chris@1295 93 assert_response :success
Chris@1295 94 assert_template 'entry'
Chris@1295 95 # Line 19
Chris@1295 96 assert_tag :tag => 'th',
Chris@1295 97 :content => /29/,
Chris@1295 98 :attributes => { :class => /line-num/ },
Chris@1295 99 :sibling => { :tag => 'td', :content => /Show help message/ }
Chris@1295 100 end
Chris@1295 101
Chris@1295 102 def test_entry_download
Chris@1295 103 get :entry, :id => PRJ_ID,
Chris@1295 104 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
Chris@1295 105 :format => 'raw'
Chris@1295 106 assert_response :success
Chris@1295 107 # File content
Chris@1295 108 assert @response.body.include?('Show help message')
Chris@1295 109 end
Chris@1295 110
Chris@1295 111 def test_directory_entry
Chris@1295 112 get :entry, :id => PRJ_ID,
Chris@1295 113 :path => repository_path_hash(['directory'])[:param]
Chris@1295 114 assert_response :success
Chris@1295 115 assert_template 'show'
Chris@1295 116 assert_not_nil assigns(:entry)
Chris@1295 117 assert_equal 'directory', assigns(:entry).name
Chris@1295 118 end
Chris@1295 119
Chris@1295 120 def test_diff
Chris@1295 121 # Full diff of changeset 3
Chris@1295 122 ['inline', 'sbs'].each do |dt|
Chris@1295 123 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
Chris@1295 124 assert_response :success
Chris@1295 125 assert_template 'diff'
Chris@1295 126 # Line 11 removed
Chris@1295 127 assert_tag :tag => 'th',
Chris@1295 128 :content => '11',
Chris@1295 129 :sibling => { :tag => 'td',
Chris@1295 130 :attributes => { :class => /diff_out/ },
Chris@1295 131 :content => /Display more information/ }
Chris@1295 132 end
Chris@1295 133 end
Chris@1295 134
Chris@1295 135 def test_annotate
Chris@1295 136 get :annotate, :id => PRJ_ID,
Chris@1295 137 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
Chris@1295 138 assert_response :success
Chris@1295 139 assert_template 'annotate'
Chris@1295 140 assert_tag :tag => 'th', :content => '2',
Chris@1295 141 :sibling => {
Chris@1295 142 :tag => 'td',
Chris@1295 143 :child => {
Chris@1295 144 :tag => 'a',
Chris@1295 145 :content => '3'
Chris@1295 146 }
Chris@1295 147 }
Chris@1295 148 assert_tag :tag => 'th', :content => '2',
Chris@1295 149 :sibling => { :tag => 'td', :content => /jsmith/ }
Chris@1295 150 assert_tag :tag => 'th', :content => '2',
Chris@1295 151 :sibling => {
Chris@1295 152 :tag => 'td',
Chris@1295 153 :child => {
Chris@1295 154 :tag => 'a',
Chris@1295 155 :content => '3'
Chris@1295 156 }
Chris@1295 157 }
Chris@1295 158 assert_tag :tag => 'th', :content => '2',
Chris@1295 159 :sibling => { :tag => 'td', :content => /Main purpose/ }
Chris@1295 160 end
Chris@1295 161
Chris@1295 162 def test_destroy_valid_repository
Chris@1295 163 @request.session[:user_id] = 1 # admin
Chris@1295 164 assert_equal 0, @repository.changesets.count
Chris@1295 165 @repository.fetch_changesets
Chris@1295 166 assert @repository.changesets.count > 0
Chris@1295 167
Chris@1295 168 assert_difference 'Repository.count', -1 do
Chris@1295 169 delete :destroy, :id => @repository.id
Chris@1295 170 end
Chris@1295 171 assert_response 302
Chris@1295 172 @project.reload
Chris@1295 173 assert_nil @project.repository
Chris@1295 174 end
Chris@1295 175
Chris@1295 176 def test_destroy_invalid_repository
Chris@1295 177 @request.session[:user_id] = 1 # admin
Chris@1295 178 @project.repository.destroy
Chris@1295 179 @repository = Repository::Bazaar.create!(
Chris@1295 180 :project => @project,
Chris@1295 181 :url => "/invalid",
Chris@1295 182 :log_encoding => 'UTF-8')
Chris@1295 183 @repository.fetch_changesets
Chris@1295 184 @repository.reload
Chris@1295 185 assert_equal 0, @repository.changesets.count
Chris@1295 186
Chris@1295 187 assert_difference 'Repository.count', -1 do
Chris@1295 188 delete :destroy, :id => @repository.id
Chris@1295 189 end
Chris@1295 190 assert_response 302
Chris@1295 191 @project.reload
Chris@1295 192 assert_nil @project.repository
Chris@1295 193 end
Chris@1295 194 else
Chris@1295 195 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
Chris@1295 196 def test_fake; assert true end
Chris@1295 197 end
Chris@1295 198 end