annotate .svn/pristine/a0/a0e32e2a6eec71e9da13861adc671e42ba3333c5.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19 require 'repositories_controller'
Chris@909 20
Chris@909 21 # Re-raise errors caught by the controller.
Chris@909 22 class RepositoriesController; def rescue_action(e) raise e end; end
Chris@909 23
Chris@909 24 class RepositoriesFilesystemControllerTest < ActionController::TestCase
Chris@909 25 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@909 26 :repositories, :enabled_modules
Chris@909 27
Chris@909 28 REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s
Chris@909 29 PRJ_ID = 3
Chris@909 30
Chris@909 31 def setup
Chris@909 32 @ruby19_non_utf8_pass =
Chris@909 33 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
Chris@909 34 @controller = RepositoriesController.new
Chris@909 35 @request = ActionController::TestRequest.new
Chris@909 36 @response = ActionController::TestResponse.new
Chris@909 37 User.current = nil
Chris@909 38 Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
Chris@909 39 @project = Project.find(PRJ_ID)
Chris@909 40 @repository = Repository::Filesystem.create(
Chris@909 41 :project => @project,
Chris@909 42 :url => REPOSITORY_PATH,
Chris@909 43 :path_encoding => ''
Chris@909 44 )
Chris@909 45 assert @repository
Chris@909 46 end
Chris@909 47
Chris@909 48 if File.directory?(REPOSITORY_PATH)
Chris@909 49 def test_browse_root
Chris@909 50 @repository.fetch_changesets
Chris@909 51 @repository.reload
Chris@909 52 get :show, :id => PRJ_ID
Chris@909 53 assert_response :success
Chris@909 54 assert_template 'show'
Chris@909 55 assert_not_nil assigns(:entries)
Chris@909 56 assert assigns(:entries).size > 0
Chris@909 57 assert_not_nil assigns(:changesets)
Chris@909 58 assert assigns(:changesets).size == 0
Chris@909 59 end
Chris@909 60
Chris@909 61 def test_show_no_extension
Chris@909 62 get :entry, :id => PRJ_ID, :path => ['test']
Chris@909 63 assert_response :success
Chris@909 64 assert_template 'entry'
Chris@909 65 assert_tag :tag => 'th',
Chris@909 66 :content => '1',
Chris@909 67 :attributes => { :class => 'line-num' },
Chris@909 68 :sibling => { :tag => 'td', :content => /TEST CAT/ }
Chris@909 69 end
Chris@909 70
Chris@909 71 def test_entry_download_no_extension
Chris@909 72 get :entry, :id => PRJ_ID, :path => ['test'], :format => 'raw'
Chris@909 73 assert_response :success
Chris@909 74 assert_equal 'application/octet-stream', @response.content_type
Chris@909 75 end
Chris@909 76
Chris@909 77 def test_show_non_ascii_contents
Chris@909 78 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
Chris@909 79 get :entry, :id => PRJ_ID, :path => ['japanese', 'euc-jp.txt']
Chris@909 80 assert_response :success
Chris@909 81 assert_template 'entry'
Chris@909 82 assert_tag :tag => 'th',
Chris@909 83 :content => '2',
Chris@909 84 :attributes => { :class => 'line-num' },
Chris@909 85 :sibling => { :tag => 'td', :content => /japanese/ }
Chris@909 86 if @ruby19_non_utf8_pass
Chris@909 87 puts "TODO: show repository file contents test fails in Ruby 1.9 " +
Chris@909 88 "and Encoding.default_external is not UTF-8. " +
Chris@909 89 "Current value is '#{Encoding.default_external.to_s}'"
Chris@909 90 else
Chris@909 91 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
Chris@909 92 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
Chris@909 93 assert_tag :tag => 'th',
Chris@909 94 :content => '3',
Chris@909 95 :attributes => { :class => 'line-num' },
Chris@909 96 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
Chris@909 97 end
Chris@909 98 end
Chris@909 99 end
Chris@909 100
Chris@909 101 def test_show_utf16
Chris@909 102 with_settings :repositories_encodings => 'UTF-16' do
Chris@909 103 get :entry, :id => PRJ_ID, :path => ['japanese', 'utf-16.txt']
Chris@909 104 assert_response :success
Chris@909 105 assert_tag :tag => 'th',
Chris@909 106 :content => '2',
Chris@909 107 :attributes => { :class => 'line-num' },
Chris@909 108 :sibling => { :tag => 'td', :content => /japanese/ }
Chris@909 109 end
Chris@909 110 end
Chris@909 111
Chris@909 112 def test_show_text_file_should_send_if_too_big
Chris@909 113 with_settings :file_max_size_displayed => 1 do
Chris@909 114 get :entry, :id => PRJ_ID, :path => ['japanese', 'big-file.txt']
Chris@909 115 assert_response :success
Chris@909 116 assert_equal 'text/plain', @response.content_type
Chris@909 117 end
Chris@909 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@909 149 else
Chris@909 150 puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
Chris@909 151 def test_fake; assert true end
Chris@909 152 end
Chris@909 153 end