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