You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repositories_filesystem_controller_test.rb 6.0KB

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