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_bazaar_test.rb 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 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 RepositoryBazaarTest < ActiveSupport::TestCase
  19. fixtures :projects
  20. include Redmine::I18n
  21. REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s
  22. REPOSITORY_PATH.gsub!(/\/+/, '/')
  23. NUM_REV = 4
  24. def setup
  25. @project = Project.find(3)
  26. @repository = Repository::Bazaar.create(
  27. :project => @project, :url => "file:///#{REPOSITORY_PATH}",
  28. :log_encoding => 'UTF-8')
  29. assert @repository
  30. end
  31. def test_blank_path_to_repository_error_message
  32. set_language_if_valid 'en'
  33. repo = Repository::Bazaar.new(
  34. :project => @project,
  35. :identifier => 'test',
  36. :log_encoding => 'UTF-8'
  37. )
  38. assert !repo.save
  39. assert_include "Path to repository can't be blank",
  40. repo.errors.full_messages
  41. end
  42. def test_blank_path_to_repository_error_message_fr
  43. set_language_if_valid 'fr'
  44. str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
  45. str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
  46. repo = Repository::Bazaar.new(
  47. :project => @project,
  48. :url => "",
  49. :identifier => 'test',
  50. :log_encoding => 'UTF-8'
  51. )
  52. assert !repo.save
  53. assert_include str, repo.errors.full_messages
  54. end
  55. if File.directory?(REPOSITORY_PATH)
  56. def test_fetch_changesets_from_scratch
  57. assert_equal 0, @repository.changesets.count
  58. @repository.fetch_changesets
  59. @project.reload
  60. assert_equal NUM_REV, @repository.changesets.count
  61. assert_equal 9, @repository.changes.count
  62. assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
  63. end
  64. def test_fetch_changesets_incremental
  65. assert_equal 0, @repository.changesets.count
  66. @repository.fetch_changesets
  67. @project.reload
  68. assert_equal NUM_REV, @repository.changesets.count
  69. # Remove changesets with revision > 5
  70. @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
  71. @project.reload
  72. assert_equal 2, @repository.changesets.count
  73. @repository.fetch_changesets
  74. @project.reload
  75. assert_equal NUM_REV, @repository.changesets.count
  76. end
  77. def test_entries
  78. entries = @repository.entries
  79. assert_equal 2, entries.size
  80. assert_equal 'dir', entries[0].kind
  81. assert_equal 'directory', entries[0].name
  82. assert_equal 'file', entries[1].kind
  83. assert_equal 'doc-mkdir.txt', entries[1].name
  84. end
  85. def test_entries_in_subdirectory
  86. entries = @repository.entries('directory')
  87. assert_equal 3, entries.size
  88. assert_equal 'file', entries.last.kind
  89. assert_equal 'edit.png', entries.last.name
  90. end
  91. def test_previous
  92. assert_equal 0, @repository.changesets.count
  93. @repository.fetch_changesets
  94. @project.reload
  95. assert_equal NUM_REV, @repository.changesets.count
  96. changeset = @repository.find_changeset_by_name('3')
  97. assert_equal @repository.find_changeset_by_name('2'), changeset.previous
  98. end
  99. def test_previous_nil
  100. assert_equal 0, @repository.changesets.count
  101. @repository.fetch_changesets
  102. @project.reload
  103. assert_equal NUM_REV, @repository.changesets.count
  104. changeset = @repository.find_changeset_by_name('1')
  105. assert_nil changeset.previous
  106. end
  107. def test_next
  108. assert_equal 0, @repository.changesets.count
  109. @repository.fetch_changesets
  110. @project.reload
  111. assert_equal NUM_REV, @repository.changesets.count
  112. changeset = @repository.find_changeset_by_name('2')
  113. assert_equal @repository.find_changeset_by_name('3'), changeset.next
  114. end
  115. def test_next_nil
  116. assert_equal 0, @repository.changesets.count
  117. @repository.fetch_changesets
  118. @project.reload
  119. assert_equal NUM_REV, @repository.changesets.count
  120. changeset = @repository.find_changeset_by_name('4')
  121. assert_nil changeset.next
  122. end
  123. else
  124. puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
  125. def test_fake; assert true end
  126. end
  127. end