Chris@1296: # Redmine - project management software Chris@1296: # Copyright (C) 2006-2012 Jean-Philippe Lang Chris@1296: # Chris@1296: # This program is free software; you can redistribute it and/or Chris@1296: # modify it under the terms of the GNU General Public License Chris@1296: # as published by the Free Software Foundation; either version 2 Chris@1296: # of the License, or (at your option) any later version. Chris@1296: # Chris@1296: # This program is distributed in the hope that it will be useful, Chris@1296: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1296: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1296: # GNU General Public License for more details. Chris@1296: # Chris@1296: # You should have received a copy of the GNU General Public License Chris@1296: # along with this program; if not, write to the Free Software Chris@1296: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1296: Chris@1296: require File.expand_path('../../test_helper', __FILE__) Chris@1296: Chris@1296: class RepositoriesFilesystemControllerTest < ActionController::TestCase Chris@1296: tests RepositoriesController Chris@1296: Chris@1296: fixtures :projects, :users, :roles, :members, :member_roles, Chris@1296: :repositories, :enabled_modules Chris@1296: Chris@1296: REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s Chris@1296: PRJ_ID = 3 Chris@1296: Chris@1296: def setup Chris@1296: @ruby19_non_utf8_pass = Chris@1296: (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') Chris@1296: User.current = nil Chris@1296: Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem') Chris@1296: @project = Project.find(PRJ_ID) Chris@1296: @repository = Repository::Filesystem.create( Chris@1296: :project => @project, Chris@1296: :url => REPOSITORY_PATH, Chris@1296: :path_encoding => '' Chris@1296: ) Chris@1296: assert @repository Chris@1296: end Chris@1296: Chris@1296: if File.directory?(REPOSITORY_PATH) Chris@1296: def test_get_new Chris@1296: @request.session[:user_id] = 1 Chris@1296: @project.repository.destroy Chris@1296: get :new, :project_id => 'subproject1', :repository_scm => 'Filesystem' Chris@1296: assert_response :success Chris@1296: assert_template 'new' Chris@1296: assert_kind_of Repository::Filesystem, assigns(:repository) Chris@1296: assert assigns(:repository).new_record? Chris@1296: end Chris@1296: Chris@1296: def test_browse_root Chris@1296: @repository.fetch_changesets Chris@1296: @repository.reload Chris@1296: get :show, :id => PRJ_ID Chris@1296: assert_response :success Chris@1296: assert_template 'show' Chris@1296: assert_not_nil assigns(:entries) Chris@1296: assert assigns(:entries).size > 0 Chris@1296: assert_not_nil assigns(:changesets) Chris@1296: assert assigns(:changesets).size == 0 Chris@1296: Chris@1296: assert_no_tag 'input', :attributes => {:name => 'rev'} Chris@1296: assert_no_tag 'a', :content => 'Statistics' Chris@1296: assert_no_tag 'a', :content => 'Atom' Chris@1296: end Chris@1296: Chris@1296: def test_show_no_extension Chris@1296: get :entry, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param] Chris@1296: assert_response :success Chris@1296: assert_template 'entry' Chris@1296: assert_tag :tag => 'th', Chris@1296: :content => '1', Chris@1296: :attributes => { :class => 'line-num' }, Chris@1296: :sibling => { :tag => 'td', :content => /TEST CAT/ } Chris@1296: end Chris@1296: Chris@1296: def test_entry_download_no_extension Chris@1296: get :raw, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param] Chris@1296: assert_response :success Chris@1296: assert_equal 'application/octet-stream', @response.content_type Chris@1296: end Chris@1296: Chris@1296: def test_show_non_ascii_contents Chris@1296: with_settings :repositories_encodings => 'UTF-8,EUC-JP' do Chris@1296: get :entry, :id => PRJ_ID, Chris@1296: :path => repository_path_hash(['japanese', 'euc-jp.txt'])[:param] Chris@1296: assert_response :success Chris@1296: assert_template 'entry' Chris@1296: assert_tag :tag => 'th', Chris@1296: :content => '2', Chris@1296: :attributes => { :class => 'line-num' }, Chris@1296: :sibling => { :tag => 'td', :content => /japanese/ } Chris@1296: if @ruby19_non_utf8_pass Chris@1296: puts "TODO: show repository file contents test fails in Ruby 1.9 " + Chris@1296: "and Encoding.default_external is not UTF-8. " + Chris@1296: "Current value is '#{Encoding.default_external.to_s}'" Chris@1296: else Chris@1296: str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" Chris@1296: str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding) Chris@1296: assert_tag :tag => 'th', Chris@1296: :content => '3', Chris@1296: :attributes => { :class => 'line-num' }, Chris@1296: :sibling => { :tag => 'td', :content => /#{str_japanese}/ } Chris@1296: end Chris@1296: end Chris@1296: end Chris@1296: Chris@1296: def test_show_utf16 Chris@1296: with_settings :repositories_encodings => 'UTF-16' do Chris@1296: get :entry, :id => PRJ_ID, Chris@1296: :path => repository_path_hash(['japanese', 'utf-16.txt'])[:param] Chris@1296: assert_response :success Chris@1296: assert_tag :tag => 'th', Chris@1296: :content => '2', Chris@1296: :attributes => { :class => 'line-num' }, Chris@1296: :sibling => { :tag => 'td', :content => /japanese/ } Chris@1296: end Chris@1296: end Chris@1296: Chris@1296: def test_show_text_file_should_send_if_too_big Chris@1296: with_settings :file_max_size_displayed => 1 do Chris@1296: get :entry, :id => PRJ_ID, Chris@1296: :path => repository_path_hash(['japanese', 'big-file.txt'])[:param] Chris@1296: assert_response :success Chris@1296: assert_equal 'text/plain', @response.content_type Chris@1296: end Chris@1296: end Chris@1296: Chris@1296: def test_destroy_valid_repository Chris@1296: @request.session[:user_id] = 1 # admin Chris@1296: Chris@1296: assert_difference 'Repository.count', -1 do Chris@1296: delete :destroy, :id => @repository.id Chris@1296: end Chris@1296: assert_response 302 Chris@1296: @project.reload Chris@1296: assert_nil @project.repository Chris@1296: end Chris@1296: Chris@1296: def test_destroy_invalid_repository Chris@1296: @request.session[:user_id] = 1 # admin Chris@1296: @project.repository.destroy Chris@1296: @repository = Repository::Filesystem.create!( Chris@1296: :project => @project, Chris@1296: :url => "/invalid", Chris@1296: :path_encoding => '' Chris@1296: ) Chris@1296: Chris@1296: assert_difference 'Repository.count', -1 do Chris@1296: delete :destroy, :id => @repository.id Chris@1296: end Chris@1296: assert_response 302 Chris@1296: @project.reload Chris@1296: assert_nil @project.repository Chris@1296: end Chris@1296: else Chris@1296: puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!" Chris@1296: def test_fake; assert true end Chris@1296: end Chris@1296: end