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_git_test.rb 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2020 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class RepositoriesGitTest < Redmine::IntegrationTest
  20. fixtures :projects, :users, :roles, :members, :member_roles,
  21. :repositories, :enabled_modules
  22. REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
  23. REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?
  24. PRJ_ID = 3
  25. NUM_REV = 28
  26. def setup
  27. User.current = nil
  28. @project = Project.find(PRJ_ID)
  29. @repository = Repository::Git.create(
  30. :project => @project,
  31. :url => REPOSITORY_PATH,
  32. :path_encoding => 'ISO-8859-1'
  33. )
  34. assert @repository
  35. end
  36. if File.directory?(REPOSITORY_PATH)
  37. def test_index
  38. get '/projects/subproject1/repository/'
  39. assert_response :success
  40. end
  41. def test_diff_two_revs
  42. get "/projects/subproject1/repository/#{@repository.id}/diff?rev=61b685fbe&rev_to=2f9c0091"
  43. assert_response :success
  44. end
  45. def test_get_raw_diff_of_a_whole_revision
  46. @repository.fetch_changesets
  47. assert_equal NUM_REV, @repository.changesets.count
  48. get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/diff"
  49. assert_response :success
  50. assert a = css_select("a.diff").first
  51. assert_equal 'Unified diff', a.text
  52. get a['href']
  53. assert_response :success
  54. assert_match /\Acommit deff712f05a90d96edbd70facc47d944be5897e3/, response.body
  55. end
  56. def test_get_raw_diff_of_a_single_file_change
  57. @repository.fetch_changesets
  58. assert_equal NUM_REV, @repository.changesets.count
  59. get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/diff/sources/watchers_controller.rb"
  60. assert_response :success
  61. assert a = css_select("a.diff").first
  62. assert_equal 'Unified diff', a.text
  63. get a['href']
  64. assert_response :success
  65. assert_match /\Acommit deff712f05a90d96edbd70facc47d944be5897e3/, response.body
  66. end
  67. def test_get_diff_with_format_text_should_return_html
  68. @repository.fetch_changesets
  69. assert_equal NUM_REV, @repository.changesets.count
  70. get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/diff/sources/watchers_controller.rb", :params => { :format => 'txt' }
  71. assert_response :success
  72. assert a = css_select("a.diff").first
  73. assert_equal 'Unified diff', a.text
  74. get a['href']
  75. assert_response :success
  76. assert_match /\Acommit deff712f05a90d96edbd70facc47d944be5897e3/, response.body
  77. end
  78. def test_entry_txt_should_return_html
  79. @repository.fetch_changesets
  80. assert_equal NUM_REV, @repository.changesets.count
  81. get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/entry/new_file.txt"
  82. assert_response :success
  83. assert l1 = css_select("#L1").first
  84. assert l1_code = css_select(l1, "td.line-code").first
  85. assert_match 'This is a brand new file', l1_code.text
  86. end
  87. else
  88. puts "Git test repository NOT FOUND. Skipping integration tests !!!"
  89. def test_fake; assert true end
  90. end
  91. end