annotate test/functional/repositories_filesystem_controller_test.rb @ 1169:492ff72268e3 bug_521

Close obsolete branch bug_521
author Chris Cannam
date Thu, 18 Oct 2012 10:42:48 +0100
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 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 require 'repositories_controller'
Chris@441 20
Chris@441 21 # Re-raise errors caught by the controller.
Chris@441 22 class RepositoriesController; def rescue_action(e) raise e end; end
Chris@441 23
Chris@441 24 class RepositoriesFilesystemControllerTest < ActionController::TestCase
Chris@909 25 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@909 26 :repositories, :enabled_modules
Chris@441 27
Chris@909 28 REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s
Chris@441 29 PRJ_ID = 3
Chris@441 30
Chris@441 31 def setup
Chris@441 32 @ruby19_non_utf8_pass =
Chris@441 33 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
Chris@441 34 @controller = RepositoriesController.new
Chris@441 35 @request = ActionController::TestRequest.new
Chris@441 36 @response = ActionController::TestResponse.new
Chris@441 37 User.current = nil
Chris@441 38 Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
Chris@909 39 @project = Project.find(PRJ_ID)
Chris@441 40 @repository = Repository::Filesystem.create(
Chris@909 41 :project => @project,
Chris@441 42 :url => REPOSITORY_PATH,
Chris@441 43 :path_encoding => ''
Chris@441 44 )
Chris@441 45 assert @repository
Chris@441 46 end
Chris@441 47
Chris@441 48 if File.directory?(REPOSITORY_PATH)
Chris@441 49 def test_browse_root
Chris@441 50 @repository.fetch_changesets
Chris@441 51 @repository.reload
Chris@441 52 get :show, :id => PRJ_ID
Chris@441 53 assert_response :success
Chris@441 54 assert_template 'show'
Chris@441 55 assert_not_nil assigns(:entries)
Chris@441 56 assert assigns(:entries).size > 0
Chris@441 57 assert_not_nil assigns(:changesets)
Chris@441 58 assert assigns(:changesets).size == 0
Chris@441 59 end
Chris@441 60
Chris@441 61 def test_show_no_extension
Chris@441 62 get :entry, :id => PRJ_ID, :path => ['test']
Chris@441 63 assert_response :success
Chris@441 64 assert_template 'entry'
Chris@441 65 assert_tag :tag => 'th',
Chris@441 66 :content => '1',
Chris@441 67 :attributes => { :class => 'line-num' },
Chris@441 68 :sibling => { :tag => 'td', :content => /TEST CAT/ }
Chris@441 69 end
Chris@441 70
Chris@441 71 def test_entry_download_no_extension
Chris@441 72 get :entry, :id => PRJ_ID, :path => ['test'], :format => 'raw'
Chris@441 73 assert_response :success
Chris@441 74 assert_equal 'application/octet-stream', @response.content_type
Chris@441 75 end
Chris@441 76
Chris@441 77 def test_show_non_ascii_contents
Chris@441 78 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
Chris@441 79 get :entry, :id => PRJ_ID, :path => ['japanese', 'euc-jp.txt']
Chris@441 80 assert_response :success
Chris@441 81 assert_template 'entry'
Chris@441 82 assert_tag :tag => 'th',
Chris@441 83 :content => '2',
Chris@441 84 :attributes => { :class => 'line-num' },
Chris@441 85 :sibling => { :tag => 'td', :content => /japanese/ }
Chris@441 86 if @ruby19_non_utf8_pass
Chris@441 87 puts "TODO: show repository file contents test fails in Ruby 1.9 " +
Chris@441 88 "and Encoding.default_external is not UTF-8. " +
Chris@441 89 "Current value is '#{Encoding.default_external.to_s}'"
Chris@441 90 else
Chris@441 91 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
Chris@441 92 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
Chris@441 93 assert_tag :tag => 'th',
Chris@441 94 :content => '3',
Chris@441 95 :attributes => { :class => 'line-num' },
Chris@441 96 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
Chris@441 97 end
Chris@441 98 end
Chris@441 99 end
Chris@441 100
Chris@441 101 def test_show_utf16
Chris@441 102 with_settings :repositories_encodings => 'UTF-16' do
Chris@441 103 get :entry, :id => PRJ_ID, :path => ['japanese', 'utf-16.txt']
Chris@441 104 assert_response :success
Chris@441 105 assert_tag :tag => 'th',
Chris@441 106 :content => '2',
Chris@441 107 :attributes => { :class => 'line-num' },
Chris@441 108 :sibling => { :tag => 'td', :content => /japanese/ }
Chris@441 109 end
Chris@441 110 end
Chris@441 111
Chris@441 112 def test_show_text_file_should_send_if_too_big
Chris@441 113 with_settings :file_max_size_displayed => 1 do
Chris@441 114 get :entry, :id => PRJ_ID, :path => ['japanese', 'big-file.txt']
Chris@441 115 assert_response :success
Chris@441 116 assert_equal 'text/plain', @response.content_type
Chris@441 117 end
Chris@441 118 end
Chris@909 119
Chris@909 120 def test_destroy_valid_repository
Chris@909 121 @request.session[:user_id] = 1 # admin
Chris@909 122
Chris@909 123 get :destroy, :id => PRJ_ID
Chris@909 124 assert_response 302
Chris@909 125 @project.reload
Chris@909 126 assert_nil @project.repository
Chris@909 127 end
Chris@909 128
Chris@909 129 def test_destroy_invalid_repository
Chris@909 130 @request.session[:user_id] = 1 # admin
Chris@909 131
Chris@909 132 get :destroy, :id => PRJ_ID
Chris@909 133 assert_response 302
Chris@909 134 @project.reload
Chris@909 135 assert_nil @project.repository
Chris@909 136
Chris@909 137 @repository = Repository::Filesystem.create(
Chris@909 138 :project => Project.find(PRJ_ID),
Chris@909 139 :url => "/invalid",
Chris@909 140 :path_encoding => ''
Chris@909 141 )
Chris@909 142 assert @repository
Chris@909 143
Chris@909 144 get :destroy, :id => PRJ_ID
Chris@909 145 assert_response 302
Chris@909 146 @project.reload
Chris@909 147 assert_nil @project.repository
Chris@909 148 end
Chris@441 149 else
Chris@441 150 puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
Chris@441 151 def test_fake; assert true end
Chris@441 152 end
Chris@441 153 end