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_subversion_test.rb 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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 RepositorySubversionTest < ActiveSupport::TestCase
  19. fixtures :projects, :repositories, :enabled_modules, :users, :roles
  20. NUM_REV = 11
  21. def setup
  22. @project = Project.find(3)
  23. @repository = Repository::Subversion.create(:project => @project,
  24. :url => self.class.subversion_repository_url)
  25. assert @repository
  26. end
  27. if repository_configured?('subversion')
  28. def test_fetch_changesets_from_scratch
  29. assert_equal 0, @repository.changesets.count
  30. @repository.fetch_changesets
  31. @project.reload
  32. assert_equal NUM_REV, @repository.changesets.count
  33. assert_equal 20, @repository.filechanges.count
  34. assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
  35. end
  36. def test_fetch_changesets_incremental
  37. assert_equal 0, @repository.changesets.count
  38. @repository.fetch_changesets
  39. @project.reload
  40. assert_equal NUM_REV, @repository.changesets.count
  41. # Remove changesets with revision > 5
  42. @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 5}
  43. @project.reload
  44. assert_equal 5, @repository.changesets.count
  45. @repository.fetch_changesets
  46. @project.reload
  47. assert_equal NUM_REV, @repository.changesets.count
  48. end
  49. def test_entries
  50. entries = @repository.entries
  51. assert_kind_of Redmine::Scm::Adapters::Entries, entries
  52. end
  53. def test_entries_for_invalid_path_should_return_nil
  54. entries = @repository.entries('invalid_path')
  55. assert_nil entries
  56. end
  57. def test_latest_changesets
  58. assert_equal 0, @repository.changesets.count
  59. @repository.fetch_changesets
  60. @project.reload
  61. assert_equal NUM_REV, @repository.changesets.count
  62. # with limit
  63. changesets = @repository.latest_changesets('', nil, 2)
  64. assert_equal 2, changesets.size
  65. assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
  66. # with path
  67. changesets = @repository.latest_changesets('subversion_test/folder', nil)
  68. assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
  69. # with path and revision
  70. changesets = @repository.latest_changesets('subversion_test/folder', 8)
  71. assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
  72. end
  73. def test_directory_listing_with_square_brackets_in_path
  74. assert_equal 0, @repository.changesets.count
  75. @repository.fetch_changesets
  76. @project.reload
  77. assert_equal NUM_REV, @repository.changesets.count
  78. entries = @repository.entries('subversion_test/[folder_with_brackets]')
  79. assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
  80. assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
  81. assert_equal 'README.txt', entries.first.name
  82. end
  83. def test_directory_listing_with_square_brackets_in_base
  84. @project = Project.find(3)
  85. @repository = Repository::Subversion.create(
  86. :project => @project,
  87. :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
  88. assert_equal 0, @repository.changesets.count
  89. @repository.fetch_changesets
  90. @project.reload
  91. assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
  92. assert_equal 2, @repository.filechanges.count, 'Expected to see 2 changes, dir add and file add'
  93. entries = @repository.entries('')
  94. assert_not_nil entries, 'Expect to find entries'
  95. assert_equal 1, entries.size, 'Expect a single entry'
  96. assert_equal 'README.txt', entries.first.name
  97. end
  98. def test_identifier
  99. assert_equal 0, @repository.changesets.count
  100. @repository.fetch_changesets
  101. @project.reload
  102. assert_equal NUM_REV, @repository.changesets.count
  103. c = @repository.changesets.find_by_revision('1')
  104. assert_equal c.revision, c.identifier
  105. end
  106. def test_find_changeset_by_empty_name
  107. assert_equal 0, @repository.changesets.count
  108. @repository.fetch_changesets
  109. @project.reload
  110. assert_equal NUM_REV, @repository.changesets.count
  111. ['', ' ', nil].each do |r|
  112. assert_nil @repository.find_changeset_by_name(r)
  113. end
  114. end
  115. def test_identifier_nine_digit
  116. c = Changeset.new(:repository => @repository, :committed_on => Time.now,
  117. :revision => '123456789', :comments => 'test')
  118. assert_equal c.identifier, c.revision
  119. end
  120. def test_format_identifier
  121. assert_equal 0, @repository.changesets.count
  122. @repository.fetch_changesets
  123. @project.reload
  124. assert_equal NUM_REV, @repository.changesets.count
  125. c = @repository.changesets.find_by_revision('1')
  126. assert_equal c.format_identifier, c.revision
  127. end
  128. def test_format_identifier_nine_digit
  129. c = Changeset.new(:repository => @repository, :committed_on => Time.now,
  130. :revision => '123456789', :comments => 'test')
  131. assert_equal c.format_identifier, c.revision
  132. end
  133. def test_activities
  134. c = Changeset.new(:repository => @repository, :committed_on => Time.now,
  135. :revision => '1', :comments => 'test')
  136. assert c.event_title.include?('1:')
  137. assert_equal '1', c.event_url[:rev]
  138. end
  139. def test_activities_nine_digit
  140. c = Changeset.new(:repository => @repository, :committed_on => Time.now,
  141. :revision => '123456789', :comments => 'test')
  142. assert c.event_title.include?('123456789:')
  143. assert_equal '123456789', c.event_url[:rev]
  144. end
  145. def test_log_encoding_ignore_setting
  146. with_settings :commit_logs_encoding => 'windows-1252' do
  147. s1 = "\xC2\x80"
  148. s2 = "\xc3\x82\xc2\x80"
  149. if s1.respond_to?(:force_encoding)
  150. s1.force_encoding('ISO-8859-1')
  151. s2.force_encoding('UTF-8')
  152. assert_equal s1.encode('UTF-8'), s2
  153. end
  154. c = Changeset.new(:repository => @repository,
  155. :comments => s2,
  156. :revision => '123',
  157. :committed_on => Time.now)
  158. assert c.save
  159. assert_equal s2, c.comments
  160. end
  161. end
  162. def test_previous
  163. assert_equal 0, @repository.changesets.count
  164. @repository.fetch_changesets
  165. @project.reload
  166. assert_equal NUM_REV, @repository.changesets.count
  167. changeset = @repository.find_changeset_by_name('3')
  168. assert_equal @repository.find_changeset_by_name('2'), changeset.previous
  169. end
  170. def test_previous_nil
  171. assert_equal 0, @repository.changesets.count
  172. @repository.fetch_changesets
  173. @project.reload
  174. assert_equal NUM_REV, @repository.changesets.count
  175. changeset = @repository.find_changeset_by_name('1')
  176. assert_nil changeset.previous
  177. end
  178. def test_next
  179. assert_equal 0, @repository.changesets.count
  180. @repository.fetch_changesets
  181. @project.reload
  182. assert_equal NUM_REV, @repository.changesets.count
  183. changeset = @repository.find_changeset_by_name('2')
  184. assert_equal @repository.find_changeset_by_name('3'), changeset.next
  185. end
  186. def test_next_nil
  187. assert_equal 0, @repository.changesets.count
  188. @repository.fetch_changesets
  189. @project.reload
  190. assert_equal NUM_REV, @repository.changesets.count
  191. changeset = @repository.find_changeset_by_name('11')
  192. assert_nil changeset.next
  193. end
  194. else
  195. puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
  196. def test_fake; assert true end
  197. end
  198. end