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.

repository_darcs_test.rb 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 RepositoryDarcsTest < ActiveSupport::TestCase
  19. fixtures :projects
  20. include Redmine::I18n
  21. REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
  22. NUM_REV = 6
  23. def setup
  24. @project = Project.find(3)
  25. @repository = Repository::Darcs.create(
  26. :project => @project,
  27. :url => REPOSITORY_PATH,
  28. :log_encoding => 'UTF-8'
  29. )
  30. assert @repository
  31. end
  32. def test_blank_path_to_repository_error_message
  33. set_language_if_valid 'en'
  34. repo = Repository::Darcs.new(
  35. :project => @project,
  36. :identifier => 'test',
  37. :log_encoding => 'UTF-8'
  38. )
  39. assert !repo.save
  40. assert_include "Path to repository can't be blank",
  41. repo.errors.full_messages
  42. end
  43. def test_blank_path_to_repository_error_message_fr
  44. set_language_if_valid 'fr'
  45. str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
  46. str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
  47. repo = Repository::Darcs.new(
  48. :project => @project,
  49. :url => "",
  50. :identifier => 'test',
  51. :log_encoding => 'UTF-8'
  52. )
  53. assert !repo.save
  54. assert_include str, repo.errors.full_messages
  55. end
  56. if File.directory?(REPOSITORY_PATH)
  57. def test_fetch_changesets_from_scratch
  58. assert_equal 0, @repository.changesets.count
  59. @repository.fetch_changesets
  60. @project.reload
  61. assert_equal NUM_REV, @repository.changesets.count
  62. assert_equal 13, @repository.filechanges.count
  63. assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
  64. end
  65. def test_fetch_changesets_incremental
  66. assert_equal 0, @repository.changesets.count
  67. @repository.fetch_changesets
  68. @project.reload
  69. assert_equal NUM_REV, @repository.changesets.count
  70. # Remove changesets with revision > 3
  71. @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 3}
  72. @project.reload
  73. assert_equal 3, @repository.changesets.count
  74. @repository.fetch_changesets
  75. @project.reload
  76. assert_equal NUM_REV, @repository.changesets.count
  77. end
  78. def test_entries
  79. entries = @repository.entries
  80. assert_kind_of Redmine::Scm::Adapters::Entries, entries
  81. end
  82. def test_entries_invalid_revision
  83. assert_equal 0, @repository.changesets.count
  84. @repository.fetch_changesets
  85. @project.reload
  86. assert_equal NUM_REV, @repository.changesets.count
  87. assert_nil @repository.entries('', '123')
  88. end
  89. def test_deleted_files_should_not_be_listed
  90. assert_equal 0, @repository.changesets.count
  91. @repository.fetch_changesets
  92. @project.reload
  93. assert_equal NUM_REV, @repository.changesets.count
  94. entries = @repository.entries('sources')
  95. assert entries.detect {|e| e.name == 'watchers_controller.rb'}
  96. assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
  97. end
  98. def test_cat
  99. if @repository.scm.supports_cat?
  100. assert_equal 0, @repository.changesets.count
  101. @repository.fetch_changesets
  102. @project.reload
  103. assert_equal NUM_REV, @repository.changesets.count
  104. cat = @repository.cat("sources/welcome_controller.rb", 2)
  105. assert_not_nil cat
  106. assert cat.include?('class WelcomeController < ApplicationController')
  107. end
  108. end
  109. else
  110. puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
  111. def test_fake; assert true end
  112. end
  113. end