annotate test/functional/repositories_bazaar_controller_test.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +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 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@1464 26 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
Chris@1464 27 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
Chris@909 28 PRJ_ID = 3
Chris@1464 29 CHAR_1_UTF8_HEX = "\xc3\x9c"
Chris@0 30
Chris@0 31 def setup
Chris@0 32 User.current = nil
Chris@909 33 @project = Project.find(PRJ_ID)
Chris@245 34 @repository = Repository::Bazaar.create(
Chris@909 35 :project => @project,
Chris@1464 36 :url => REPOSITORY_PATH_TRUNK,
Chris@245 37 :log_encoding => 'UTF-8')
Chris@245 38 assert @repository
Chris@1464 39 @char_1_utf8 = CHAR_1_UTF8_HEX.dup
Chris@1464 40 if @char_1_utf8.respond_to?(:force_encoding)
Chris@1464 41 @char_1_utf8.force_encoding('UTF-8')
Chris@1464 42 end
Chris@0 43 end
Chris@245 44
Chris@0 45 if File.directory?(REPOSITORY_PATH)
Chris@1115 46 def test_get_new
Chris@1115 47 @request.session[:user_id] = 1
Chris@1115 48 @project.repository.destroy
Chris@1115 49 get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
Chris@1115 50 assert_response :success
Chris@1115 51 assert_template 'new'
Chris@1115 52 assert_kind_of Repository::Bazaar, assigns(:repository)
Chris@1115 53 assert assigns(:repository).new_record?
Chris@1115 54 end
Chris@1115 55
Chris@0 56 def test_browse_root
Chris@909 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 2, assigns(:entries).size
Chris@0 62 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
Chris@0 63 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
Chris@0 64 end
Chris@245 65
Chris@0 66 def test_browse_directory
Chris@1115 67 get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param]
Chris@0 68 assert_response :success
Chris@0 69 assert_template 'show'
Chris@0 70 assert_not_nil assigns(:entries)
Chris@0 71 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 72 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@0 73 assert_not_nil entry
Chris@0 74 assert_equal 'file', entry.kind
Chris@0 75 assert_equal 'directory/edit.png', entry.path
Chris@0 76 end
Chris@909 77
Chris@0 78 def test_browse_at_given_revision
Chris@1115 79 get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param],
Chris@1115 80 :rev => 3
Chris@0 81 assert_response :success
Chris@0 82 assert_template 'show'
Chris@0 83 assert_not_nil assigns(:entries)
Chris@909 84 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
Chris@909 85 assigns(:entries).collect(&:name)
Chris@0 86 end
Chris@909 87
Chris@0 88 def test_changes
Chris@1115 89 get :changes, :id => PRJ_ID,
Chris@1115 90 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
Chris@0 91 assert_response :success
Chris@0 92 assert_template 'changes'
Chris@0 93 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
Chris@0 94 end
Chris@909 95
Chris@0 96 def test_entry_show
Chris@1115 97 get :entry, :id => PRJ_ID,
Chris@1115 98 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
Chris@0 99 assert_response :success
Chris@0 100 assert_template 'entry'
Chris@0 101 # Line 19
Chris@0 102 assert_tag :tag => 'th',
Chris@0 103 :content => /29/,
Chris@0 104 :attributes => { :class => /line-num/ },
Chris@0 105 :sibling => { :tag => 'td', :content => /Show help message/ }
Chris@0 106 end
Chris@909 107
Chris@0 108 def test_entry_download
Chris@1115 109 get :entry, :id => PRJ_ID,
Chris@1115 110 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
Chris@1115 111 :format => 'raw'
Chris@0 112 assert_response :success
Chris@0 113 # File content
Chris@0 114 assert @response.body.include?('Show help message')
Chris@0 115 end
Chris@909 116
Chris@0 117 def test_directory_entry
Chris@1115 118 get :entry, :id => PRJ_ID,
Chris@1115 119 :path => repository_path_hash(['directory'])[:param]
Chris@0 120 assert_response :success
Chris@0 121 assert_template 'show'
Chris@0 122 assert_not_nil assigns(:entry)
Chris@0 123 assert_equal 'directory', assigns(:entry).name
Chris@0 124 end
Chris@0 125
Chris@0 126 def test_diff
Chris@0 127 # Full diff of changeset 3
Chris@909 128 ['inline', 'sbs'].each do |dt|
Chris@909 129 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
Chris@909 130 assert_response :success
Chris@909 131 assert_template 'diff'
Chris@909 132 # Line 11 removed
Chris@909 133 assert_tag :tag => 'th',
Chris@909 134 :content => '11',
Chris@909 135 :sibling => { :tag => 'td',
Chris@909 136 :attributes => { :class => /diff_out/ },
Chris@909 137 :content => /Display more information/ }
Chris@909 138 end
Chris@0 139 end
Chris@909 140
Chris@0 141 def test_annotate
Chris@1115 142 get :annotate, :id => PRJ_ID,
Chris@1115 143 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
Chris@0 144 assert_response :success
Chris@0 145 assert_template 'annotate'
Chris@1464 146 assert_select "th.line-num", :text => '2' do
Chris@1464 147 assert_select "+ td.revision" do
Chris@1464 148 assert_select "a", :text => '3'
Chris@1464 149 assert_select "+ td.author", :text => "jsmith@" do
Chris@1464 150 assert_select "+ td",
Chris@1464 151 :text => "Main purpose:"
Chris@1464 152 end
Chris@1464 153 end
Chris@1464 154 end
Chris@1464 155 end
Chris@1464 156
Chris@1464 157 def test_annotate_author_escaping
Chris@1464 158 repository = Repository::Bazaar.create(
Chris@1464 159 :project => @project,
Chris@1464 160 :url => File.join(REPOSITORY_PATH, "author_escaping"),
Chris@1464 161 :identifier => 'author_escaping',
Chris@1464 162 :log_encoding => 'UTF-8')
Chris@1464 163 assert repository
Chris@1464 164 get :annotate, :id => PRJ_ID, :repository_id => 'author_escaping',
Chris@1464 165 :path => repository_path_hash(['author-escaping-test.txt'])[:param]
Chris@1464 166 assert_response :success
Chris@1464 167 assert_template 'annotate'
Chris@1464 168 assert_select "th.line-num", :text => '1' do
Chris@1464 169 assert_select "+ td.revision" do
Chris@1464 170 assert_select "a", :text => '2'
Chris@1464 171 assert_select "+ td.author", :text => "test &amp;" do
Chris@1464 172 assert_select "+ td",
Chris@1464 173 :text => "author escaping test"
Chris@1464 174 end
Chris@1464 175 end
Chris@1464 176 end
Chris@1464 177 end
Chris@1464 178
Chris@1464 179 if REPOSITORY_PATH.respond_to?(:force_encoding)
Chris@1464 180 def test_annotate_author_non_ascii
Chris@1464 181 log_encoding = nil
Chris@1464 182 if Encoding.locale_charmap == "UTF-8" ||
Chris@1464 183 Encoding.locale_charmap == "ISO-8859-1"
Chris@1464 184 log_encoding = Encoding.locale_charmap
Chris@1464 185 end
Chris@1464 186 unless log_encoding.nil?
Chris@1464 187 repository = Repository::Bazaar.create(
Chris@1464 188 :project => @project,
Chris@1464 189 :url => File.join(REPOSITORY_PATH, "author_non_ascii"),
Chris@1464 190 :identifier => 'author_non_ascii',
Chris@1464 191 :log_encoding => log_encoding)
Chris@1464 192 assert repository
Chris@1464 193 get :annotate, :id => PRJ_ID, :repository_id => 'author_non_ascii',
Chris@1464 194 :path => repository_path_hash(['author-non-ascii-test.txt'])[:param]
Chris@1464 195 assert_response :success
Chris@1464 196 assert_template 'annotate'
Chris@1464 197 assert_select "th.line-num", :text => '1' do
Chris@1464 198 assert_select "+ td.revision" do
Chris@1464 199 assert_select "a", :text => '2'
Chris@1464 200 assert_select "+ td.author", :text => "test #{@char_1_utf8}" do
Chris@1464 201 assert_select "+ td",
Chris@1464 202 :text => "author non ASCII test"
Chris@1464 203 end
Chris@1464 204 end
Chris@1464 205 end
Chris@1464 206 end
Chris@1464 207 end
Chris@0 208 end
Chris@909 209
Chris@909 210 def test_destroy_valid_repository
Chris@909 211 @request.session[:user_id] = 1 # admin
Chris@909 212 assert_equal 0, @repository.changesets.count
Chris@909 213 @repository.fetch_changesets
Chris@909 214 assert @repository.changesets.count > 0
Chris@909 215
Chris@1115 216 assert_difference 'Repository.count', -1 do
Chris@1115 217 delete :destroy, :id => @repository.id
Chris@1115 218 end
Chris@909 219 assert_response 302
Chris@909 220 @project.reload
Chris@909 221 assert_nil @project.repository
Chris@909 222 end
Chris@909 223
Chris@909 224 def test_destroy_invalid_repository
Chris@909 225 @request.session[:user_id] = 1 # admin
Chris@1115 226 @project.repository.destroy
Chris@1115 227 @repository = Repository::Bazaar.create!(
Chris@909 228 :project => @project,
Chris@909 229 :url => "/invalid",
Chris@909 230 :log_encoding => 'UTF-8')
Chris@909 231 @repository.fetch_changesets
Chris@909 232 @repository.reload
Chris@909 233 assert_equal 0, @repository.changesets.count
Chris@909 234
Chris@1115 235 assert_difference 'Repository.count', -1 do
Chris@1115 236 delete :destroy, :id => @repository.id
Chris@1115 237 end
Chris@909 238 assert_response 302
Chris@909 239 @project.reload
Chris@909 240 assert_nil @project.repository
Chris@909 241 end
Chris@0 242 else
Chris@0 243 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 244 def test_fake; assert true end
Chris@0 245 end
Chris@0 246 end