annotate .svn/pristine/ef/efbace8abba59017b7f556c0a5154d7988541023.svn-base @ 1465:ab8bd24eeb65 bug_635

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