annotate test/functional/repositories_filesystem_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@441 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@441 3 #
Chris@441 4 # This program is free software; you can redistribute it and/or
Chris@441 5 # modify it under the terms of the GNU General Public License
Chris@441 6 # as published by the Free Software Foundation; either version 2
Chris@441 7 # of the License, or (at your option) any later version.
Chris@441 8 #
Chris@441 9 # This program is distributed in the hope that it will be useful,
Chris@441 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@441 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@441 12 # GNU General Public License for more details.
Chris@441 13 #
Chris@441 14 # You should have received a copy of the GNU General Public License
Chris@441 15 # along with this program; if not, write to the Free Software
Chris@441 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@441 17
Chris@441 18 require File.expand_path('../../test_helper', __FILE__)
Chris@441 19
Chris@441 20 class RepositoriesFilesystemControllerTest < 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@441 25
Chris@909 26 REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s
Chris@441 27 PRJ_ID = 3
Chris@441 28
Chris@441 29 def setup
Chris@441 30 @ruby19_non_utf8_pass =
Chris@441 31 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
Chris@441 32 User.current = nil
Chris@441 33 Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
Chris@909 34 @project = Project.find(PRJ_ID)
Chris@441 35 @repository = Repository::Filesystem.create(
Chris@909 36 :project => @project,
Chris@441 37 :url => REPOSITORY_PATH,
Chris@441 38 :path_encoding => ''
Chris@441 39 )
Chris@441 40 assert @repository
Chris@441 41 end
Chris@441 42
Chris@441 43 if File.directory?(REPOSITORY_PATH)
Chris@1115 44 def test_get_new
Chris@1115 45 @request.session[:user_id] = 1
Chris@1115 46 @project.repository.destroy
Chris@1115 47 get :new, :project_id => 'subproject1', :repository_scm => 'Filesystem'
Chris@1115 48 assert_response :success
Chris@1115 49 assert_template 'new'
Chris@1115 50 assert_kind_of Repository::Filesystem, assigns(:repository)
Chris@1115 51 assert assigns(:repository).new_record?
Chris@1115 52 end
Chris@1115 53
Chris@441 54 def test_browse_root
Chris@441 55 @repository.fetch_changesets
Chris@441 56 @repository.reload
Chris@441 57 get :show, :id => PRJ_ID
Chris@441 58 assert_response :success
Chris@441 59 assert_template 'show'
Chris@441 60 assert_not_nil assigns(:entries)
Chris@441 61 assert assigns(:entries).size > 0
Chris@441 62 assert_not_nil assigns(:changesets)
Chris@441 63 assert assigns(:changesets).size == 0
Chris@1115 64
Chris@1115 65 assert_no_tag 'input', :attributes => {:name => 'rev'}
Chris@1115 66 assert_no_tag 'a', :content => 'Statistics'
Chris@1115 67 assert_no_tag 'a', :content => 'Atom'
Chris@441 68 end
Chris@441 69
Chris@441 70 def test_show_no_extension
Chris@1115 71 get :entry, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param]
Chris@441 72 assert_response :success
Chris@441 73 assert_template 'entry'
Chris@441 74 assert_tag :tag => 'th',
Chris@441 75 :content => '1',
Chris@441 76 :attributes => { :class => 'line-num' },
Chris@441 77 :sibling => { :tag => 'td', :content => /TEST CAT/ }
Chris@441 78 end
Chris@441 79
Chris@441 80 def test_entry_download_no_extension
Chris@1115 81 get :raw, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param]
Chris@441 82 assert_response :success
Chris@441 83 assert_equal 'application/octet-stream', @response.content_type
Chris@441 84 end
Chris@441 85
Chris@441 86 def test_show_non_ascii_contents
Chris@441 87 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
Chris@1115 88 get :entry, :id => PRJ_ID,
Chris@1115 89 :path => repository_path_hash(['japanese', 'euc-jp.txt'])[:param]
Chris@441 90 assert_response :success
Chris@441 91 assert_template 'entry'
Chris@441 92 assert_tag :tag => 'th',
Chris@441 93 :content => '2',
Chris@441 94 :attributes => { :class => 'line-num' },
Chris@441 95 :sibling => { :tag => 'td', :content => /japanese/ }
Chris@441 96 if @ruby19_non_utf8_pass
Chris@441 97 puts "TODO: show repository file contents test fails in Ruby 1.9 " +
Chris@441 98 "and Encoding.default_external is not UTF-8. " +
Chris@441 99 "Current value is '#{Encoding.default_external.to_s}'"
Chris@441 100 else
Chris@441 101 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
Chris@441 102 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
Chris@441 103 assert_tag :tag => 'th',
Chris@441 104 :content => '3',
Chris@441 105 :attributes => { :class => 'line-num' },
Chris@441 106 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
Chris@441 107 end
Chris@441 108 end
Chris@441 109 end
Chris@441 110
Chris@441 111 def test_show_utf16
Chris@1464 112 enc = (RUBY_VERSION == "1.9.2" ? 'UTF-16LE' : 'UTF-16')
Chris@1464 113 with_settings :repositories_encodings => enc do
Chris@1115 114 get :entry, :id => PRJ_ID,
Chris@1115 115 :path => repository_path_hash(['japanese', 'utf-16.txt'])[:param]
Chris@441 116 assert_response :success
Chris@441 117 assert_tag :tag => 'th',
Chris@441 118 :content => '2',
Chris@441 119 :attributes => { :class => 'line-num' },
Chris@441 120 :sibling => { :tag => 'td', :content => /japanese/ }
Chris@441 121 end
Chris@441 122 end
Chris@441 123
Chris@441 124 def test_show_text_file_should_send_if_too_big
Chris@441 125 with_settings :file_max_size_displayed => 1 do
Chris@1115 126 get :entry, :id => PRJ_ID,
Chris@1115 127 :path => repository_path_hash(['japanese', 'big-file.txt'])[:param]
Chris@441 128 assert_response :success
Chris@441 129 assert_equal 'text/plain', @response.content_type
Chris@441 130 end
Chris@441 131 end
Chris@909 132
Chris@909 133 def test_destroy_valid_repository
Chris@909 134 @request.session[:user_id] = 1 # admin
Chris@909 135
Chris@1115 136 assert_difference 'Repository.count', -1 do
Chris@1115 137 delete :destroy, :id => @repository.id
Chris@1115 138 end
Chris@909 139 assert_response 302
Chris@909 140 @project.reload
Chris@909 141 assert_nil @project.repository
Chris@909 142 end
Chris@909 143
Chris@909 144 def test_destroy_invalid_repository
Chris@909 145 @request.session[:user_id] = 1 # admin
Chris@1115 146 @project.repository.destroy
Chris@1115 147 @repository = Repository::Filesystem.create!(
Chris@1115 148 :project => @project,
Chris@909 149 :url => "/invalid",
Chris@909 150 :path_encoding => ''
Chris@909 151 )
Chris@909 152
Chris@1115 153 assert_difference 'Repository.count', -1 do
Chris@1115 154 delete :destroy, :id => @repository.id
Chris@1115 155 end
Chris@909 156 assert_response 302
Chris@909 157 @project.reload
Chris@909 158 assert_nil @project.repository
Chris@909 159 end
Chris@441 160 else
Chris@441 161 puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
Chris@441 162 def test_fake; assert true end
Chris@441 163 end
Chris@441 164 end