Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

repository_subversion_test.rb 9.1KB

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