PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/test/unit/repository_cvs_test.rb

https://bitbucket.org/eimajenthat/redmine
Ruby | 241 lines | 193 code | 25 blank | 23 comment | 6 complexity | 2a10d2e61dd19782556e5550ae28eb93 MD5 | raw file
Possible License(s): GPL-2.0
  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. require 'pp'
  19. class RepositoryCvsTest < ActiveSupport::TestCase
  20. fixtures :projects
  21. include Redmine::I18n
  22. REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
  23. REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
  24. # CVS module
  25. MODULE_NAME = 'test'
  26. CHANGESETS_NUM = 7
  27. def setup
  28. @project = Project.find(3)
  29. @repository = Repository::Cvs.create(:project => @project,
  30. :root_url => REPOSITORY_PATH,
  31. :url => MODULE_NAME,
  32. :log_encoding => 'UTF-8')
  33. assert @repository
  34. end
  35. def test_blank_module_error_message
  36. set_language_if_valid 'en'
  37. repo = Repository::Cvs.new(
  38. :project => @project,
  39. :identifier => 'test',
  40. :log_encoding => 'UTF-8',
  41. :root_url => REPOSITORY_PATH
  42. )
  43. assert !repo.save
  44. assert_include "Module can't be blank",
  45. repo.errors.full_messages
  46. end
  47. def test_blank_module_error_message_fr
  48. set_language_if_valid 'fr'
  49. str = "Module doit \xc3\xaatre renseign\xc3\xa9(e)"
  50. str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
  51. repo = Repository::Cvs.new(
  52. :project => @project,
  53. :identifier => 'test',
  54. :log_encoding => 'UTF-8',
  55. :path_encoding => '',
  56. :url => '',
  57. :root_url => REPOSITORY_PATH
  58. )
  59. assert !repo.save
  60. assert_include str, repo.errors.full_messages
  61. end
  62. def test_blank_cvsroot_error_message
  63. set_language_if_valid 'en'
  64. repo = Repository::Cvs.new(
  65. :project => @project,
  66. :identifier => 'test',
  67. :log_encoding => 'UTF-8',
  68. :url => MODULE_NAME
  69. )
  70. assert !repo.save
  71. assert_include "CVSROOT can't be blank",
  72. repo.errors.full_messages
  73. end
  74. def test_blank_cvsroot_error_message_fr
  75. set_language_if_valid 'fr'
  76. str = "CVSROOT doit \xc3\xaatre renseign\xc3\xa9(e)"
  77. str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
  78. repo = Repository::Cvs.new(
  79. :project => @project,
  80. :identifier => 'test',
  81. :log_encoding => 'UTF-8',
  82. :path_encoding => '',
  83. :url => MODULE_NAME,
  84. :root_url => ''
  85. )
  86. assert !repo.save
  87. assert_include str, repo.errors.full_messages
  88. end
  89. if File.directory?(REPOSITORY_PATH)
  90. def test_fetch_changesets_from_scratch
  91. assert_equal 0, @repository.changesets.count
  92. @repository.fetch_changesets
  93. @project.reload
  94. assert_equal CHANGESETS_NUM, @repository.changesets.count
  95. assert_equal 16, @repository.filechanges.count
  96. assert_not_nil @repository.changesets.find_by_comments('Two files changed')
  97. r2 = @repository.changesets.find_by_revision('2')
  98. assert_equal 'v1-20071213-162510', r2.scmid
  99. end
  100. def test_fetch_changesets_incremental
  101. assert_equal 0, @repository.changesets.count
  102. @repository.fetch_changesets
  103. @project.reload
  104. assert_equal CHANGESETS_NUM, @repository.changesets.count
  105. # Remove changesets with revision > 3
  106. @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 3}
  107. @project.reload
  108. assert_equal 3, @repository.changesets.count
  109. assert_equal %w|3 2 1|, @repository.changesets.all.collect(&:revision)
  110. rev3_commit = @repository.changesets.reorder('committed_on DESC').first
  111. assert_equal '3', rev3_commit.revision
  112. # 2007-12-14 01:27:22 +0900
  113. rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
  114. assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
  115. assert_equal rev3_committed_on, rev3_commit.committed_on
  116. latest_rev = @repository.latest_changeset
  117. assert_equal rev3_committed_on, latest_rev.committed_on
  118. @repository.fetch_changesets
  119. @project.reload
  120. assert_equal CHANGESETS_NUM, @repository.changesets.count
  121. assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.all.collect(&:revision)
  122. rev5_commit = @repository.changesets.find_by_revision('5')
  123. assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
  124. # 2007-12-14 01:30:01 +0900
  125. rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
  126. assert_equal rev5_committed_on, rev5_commit.committed_on
  127. end
  128. def test_deleted_files_should_not_be_listed
  129. assert_equal 0, @repository.changesets.count
  130. @repository.fetch_changesets
  131. @project.reload
  132. assert_equal CHANGESETS_NUM, @repository.changesets.count
  133. entries = @repository.entries('sources')
  134. assert entries.detect {|e| e.name == 'watchers_controller.rb'}
  135. assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
  136. end
  137. def test_entries_rev3
  138. assert_equal 0, @repository.changesets.count
  139. @repository.fetch_changesets
  140. @project.reload
  141. assert_equal CHANGESETS_NUM, @repository.changesets.count
  142. entries = @repository.entries('', '3')
  143. assert_kind_of Redmine::Scm::Adapters::Entries, entries
  144. assert_equal 3, entries.size
  145. assert_equal entries[2].name, "README"
  146. assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
  147. assert_equal entries[2].lastrev.identifier, '3'
  148. assert_equal entries[2].lastrev.revision, '3'
  149. assert_equal entries[2].lastrev.author, 'LANG'
  150. end
  151. def test_entries_invalid_path
  152. assert_equal 0, @repository.changesets.count
  153. @repository.fetch_changesets
  154. @project.reload
  155. assert_equal CHANGESETS_NUM, @repository.changesets.count
  156. assert_nil @repository.entries('missing')
  157. assert_nil @repository.entries('missing', '3')
  158. end
  159. def test_entries_invalid_revision
  160. assert_equal 0, @repository.changesets.count
  161. @repository.fetch_changesets
  162. @project.reload
  163. assert_equal CHANGESETS_NUM, @repository.changesets.count
  164. assert_nil @repository.entries('', '123')
  165. end
  166. def test_cat
  167. assert_equal 0, @repository.changesets.count
  168. @repository.fetch_changesets
  169. @project.reload
  170. assert_equal CHANGESETS_NUM, @repository.changesets.count
  171. buf = @repository.cat('README')
  172. assert buf
  173. lines = buf.split("\n")
  174. assert_equal 3, lines.length
  175. buf = lines[1].gsub(/\r$/, "")
  176. assert_equal 'with one change', buf
  177. buf = @repository.cat('README', '1')
  178. assert buf
  179. lines = buf.split("\n")
  180. assert_equal 1, lines.length
  181. buf = lines[0].gsub(/\r$/, "")
  182. assert_equal 'CVS test repository', buf
  183. assert_nil @repository.cat('missing.rb')
  184. # sources/welcome_controller.rb is removed at revision 5.
  185. assert @repository.cat('sources/welcome_controller.rb', '4')
  186. assert @repository.cat('sources/welcome_controller.rb', '5').blank?
  187. # invalid revision
  188. assert @repository.cat('README', '123').blank?
  189. end
  190. def test_annotate
  191. assert_equal 0, @repository.changesets.count
  192. @repository.fetch_changesets
  193. @project.reload
  194. assert_equal CHANGESETS_NUM, @repository.changesets.count
  195. ann = @repository.annotate('README')
  196. assert ann
  197. assert_equal 3, ann.revisions.length
  198. assert_equal '1.2', ann.revisions[1].revision
  199. assert_equal 'LANG', ann.revisions[1].author
  200. assert_equal 'with one change', ann.lines[1]
  201. ann = @repository.annotate('README', '1')
  202. assert ann
  203. assert_equal 1, ann.revisions.length
  204. assert_equal '1.1', ann.revisions[0].revision
  205. assert_equal 'LANG', ann.revisions[0].author
  206. assert_equal 'CVS test repository', ann.lines[0]
  207. # invalid revision
  208. assert_nil @repository.annotate('README', '123')
  209. end
  210. else
  211. puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
  212. def test_fake; assert true end
  213. end
  214. end