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