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_mercurial_test.rb 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class RepositoryMercurialTest < ActiveSupport::TestCase
  20. fixtures :projects
  21. include Redmine::I18n
  22. REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
  23. NUM_REV = 43
  24. def setup
  25. User.current = nil
  26. @project = Project.find(3)
  27. @repository =
  28. Repository::Mercurial.create(
  29. :project => @project,
  30. :url => REPOSITORY_PATH,
  31. :path_encoding => 'ISO-8859-1'
  32. )
  33. assert @repository
  34. end
  35. def test_blank_path_to_repository_error_message
  36. set_language_if_valid 'en'
  37. repo =
  38. Repository::Mercurial.new(
  39. :project => @project,
  40. :identifier => 'test'
  41. )
  42. assert !repo.save
  43. assert_include "Path to repository cannot be blank",
  44. repo.errors.full_messages
  45. end
  46. def test_blank_path_to_repository_error_message_fr
  47. set_language_if_valid 'fr'
  48. repo =
  49. Repository::Mercurial.new(
  50. :project => @project,
  51. :url => "",
  52. :identifier => 'test',
  53. :path_encoding => ''
  54. )
  55. assert !repo.save
  56. assert_include 'Chemin du dépôt doit être renseigné(e)', repo.errors.full_messages
  57. end
  58. if File.directory?(REPOSITORY_PATH)
  59. def test_scm_available
  60. klass = Repository::Mercurial
  61. assert_equal "Mercurial", klass.scm_name
  62. assert klass.scm_adapter_class
  63. assert_not_equal "", klass.scm_command
  64. assert_equal true, klass.scm_available
  65. end
  66. def test_entries_on_tip
  67. entries = @repository.entries
  68. assert_kind_of Redmine::Scm::Adapters::Entries, entries
  69. end
  70. def assert_entries(is_short_scmid=true)
  71. hex = "9d5b5b00419901478496242e0768deba1ce8c51e"
  72. scmid = scmid_for_assert(hex, is_short_scmid)
  73. [2, '400bb8672109', '400', 400].each do |r|
  74. entries1 = @repository.entries(nil, r)
  75. assert entries1
  76. assert_kind_of Redmine::Scm::Adapters::Entries, entries1
  77. assert_equal 3, entries1.size
  78. readme = entries1[2]
  79. assert_equal '1', readme.lastrev.revision
  80. assert_equal scmid, readme.lastrev.identifier
  81. assert_equal '1', readme.changeset.revision
  82. assert_equal scmid, readme.changeset.scmid
  83. end
  84. end
  85. private :assert_entries
  86. def test_entries_short_id
  87. assert_equal 0, @repository.changesets.count
  88. create_rev0_short_id
  89. assert_equal 1, @repository.changesets.count
  90. @repository.fetch_changesets
  91. @project.reload
  92. assert_equal NUM_REV, @repository.changesets.count
  93. assert_entries(true)
  94. end
  95. def test_entries_long_id
  96. assert_equal 0, @repository.changesets.count
  97. @repository.fetch_changesets
  98. @project.reload
  99. assert_equal NUM_REV, @repository.changesets.count
  100. assert_entries(false)
  101. end
  102. def test_entry_on_tip
  103. entry = @repository.entry
  104. assert_kind_of Redmine::Scm::Adapters::Entry, entry
  105. assert_equal "", entry.path
  106. assert_equal 'dir', entry.kind
  107. end
  108. def assert_entry(is_short_scmid=true)
  109. hex = "0885933ad4f68d77c2649cd11f8311276e7ef7ce"
  110. scmid = scmid_for_assert(hex, is_short_scmid)
  111. ["README", "/README"].each do |path|
  112. ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
  113. entry = @repository.entry(path, rev)
  114. assert_kind_of Redmine::Scm::Adapters::Entry, entry
  115. assert_equal "README", entry.path
  116. assert_equal "file", entry.kind
  117. assert_equal '0', entry.lastrev.revision
  118. assert_equal scmid, entry.lastrev.identifier
  119. end
  120. end
  121. ["sources", "/sources", "/sources/"].each do |path|
  122. ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
  123. entry = @repository.entry(path, rev)
  124. assert_kind_of Redmine::Scm::Adapters::Entry, entry
  125. assert_equal "sources", entry.path
  126. assert_equal "dir", entry.kind
  127. end
  128. end
  129. ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
  130. ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
  131. entry = @repository.entry(path, rev)
  132. assert_kind_of Redmine::Scm::Adapters::Entry, entry
  133. assert_equal "sources/watchers_controller.rb", entry.path
  134. assert_equal "file", entry.kind
  135. assert_equal '0', entry.lastrev.revision
  136. assert_equal scmid, entry.lastrev.identifier
  137. end
  138. end
  139. end
  140. private :assert_entry
  141. def test_entry_short_id
  142. assert_equal 0, @repository.changesets.count
  143. create_rev0_short_id
  144. assert_equal 1, @repository.changesets.count
  145. assert_entry(true)
  146. end
  147. def test_entry_long_id
  148. assert_entry(false)
  149. end
  150. def test_fetch_changesets_from_scratch
  151. assert_equal 0, @repository.changesets.count
  152. @repository.fetch_changesets
  153. @project.reload
  154. assert_equal NUM_REV, @repository.changesets.count
  155. assert_equal 53, @repository.filechanges.count
  156. rev0 = @repository.changesets.find_by_revision('0')
  157. assert_equal "Initial import.\nThe repository contains 3 files.",
  158. rev0.comments
  159. assert_equal "0885933ad4f68d77c2649cd11f8311276e7ef7ce", rev0.scmid
  160. first_rev = @repository.changesets.first
  161. last_rev = @repository.changesets.last
  162. assert_equal (NUM_REV - 1).to_s, first_rev.revision
  163. assert_equal "0", last_rev.revision
  164. end
  165. def test_fetch_changesets_keep_short_id
  166. assert_equal 0, @repository.changesets.count
  167. create_rev0_short_id
  168. assert_equal 1, @repository.changesets.count
  169. @repository.fetch_changesets
  170. @project.reload
  171. assert_equal NUM_REV, @repository.changesets.count
  172. rev1 = @repository.changesets.find_by_revision('1')
  173. assert_equal "9d5b5b004199", rev1.scmid
  174. end
  175. def test_fetch_changesets_keep_long_id
  176. assert_equal 0, @repository.changesets.count
  177. Changeset.create!(:repository => @repository,
  178. :committed_on => Time.now,
  179. :revision => '0',
  180. :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
  181. :comments => 'test')
  182. assert_equal 1, @repository.changesets.count
  183. @repository.fetch_changesets
  184. @project.reload
  185. assert_equal NUM_REV, @repository.changesets.count
  186. rev1 = @repository.changesets.find_by_revision('1')
  187. assert_equal "9d5b5b00419901478496242e0768deba1ce8c51e", rev1.scmid
  188. end
  189. def test_fetch_changesets_incremental
  190. assert_equal 0, @repository.changesets.count
  191. @repository.fetch_changesets
  192. @project.reload
  193. assert_equal NUM_REV, @repository.changesets.count
  194. # Remove changesets with revision > 2
  195. @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
  196. @project.reload
  197. @repository.reload
  198. assert_equal 3, @repository.changesets.count
  199. @repository.fetch_changesets
  200. @project.reload
  201. assert_equal NUM_REV, @repository.changesets.count
  202. end
  203. def test_isodatesec
  204. # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
  205. if @repository.scm.class.client_version_above?([1, 0])
  206. assert_equal 0, @repository.changesets.count
  207. @repository.fetch_changesets
  208. @project.reload
  209. assert_equal NUM_REV, @repository.changesets.count
  210. rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
  211. assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
  212. end
  213. end
  214. def test_changeset_order_by_revision
  215. assert_equal 0, @repository.changesets.count
  216. @repository.fetch_changesets
  217. @project.reload
  218. assert_equal NUM_REV, @repository.changesets.count
  219. c0 = @repository.latest_changeset
  220. c1 = @repository.changesets.find_by_revision('0')
  221. # sorted by revision (id), not by date
  222. assert c0.revision.to_i > c1.revision.to_i
  223. assert c0.committed_on < c1.committed_on
  224. end
  225. def test_latest_changesets
  226. assert_equal 0, @repository.changesets.count
  227. @repository.fetch_changesets
  228. @project.reload
  229. assert_equal NUM_REV, @repository.changesets.count
  230. # with_limit
  231. changesets = @repository.latest_changesets('', nil, 2)
  232. assert_equal [(NUM_REV - 1).to_s, (NUM_REV - 2).to_s], changesets.collect(&:revision)
  233. # with_filepath
  234. changesets =
  235. @repository.latest_changesets(
  236. '/sql_escape/percent%dir/percent%file1.txt', nil
  237. )
  238. assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
  239. changesets =
  240. @repository.latest_changesets(
  241. '/sql_escape/underscore_dir/understrike_file.txt', nil
  242. )
  243. assert_equal %w|30 12 9|, changesets.collect(&:revision)
  244. changesets = @repository.latest_changesets('README', nil)
  245. assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
  246. changesets = @repository.latest_changesets('README', '8')
  247. assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
  248. changesets = @repository.latest_changesets('README', '8', 2)
  249. assert_equal %w|8 6|, changesets.collect(&:revision)
  250. # with_dirpath
  251. changesets = @repository.latest_changesets('images', nil)
  252. assert_equal %w|1 0|, changesets.collect(&:revision)
  253. path = 'sql_escape/percent%dir'
  254. changesets = @repository.latest_changesets(path, nil)
  255. assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
  256. changesets = @repository.latest_changesets(path, '11')
  257. assert_equal %w|11 10 9|, changesets.collect(&:revision)
  258. changesets = @repository.latest_changesets(path, '11', 2)
  259. assert_equal %w|11 10|, changesets.collect(&:revision)
  260. path = 'sql_escape/underscore_dir'
  261. changesets = @repository.latest_changesets(path, nil)
  262. assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
  263. changesets = @repository.latest_changesets(path, '12')
  264. assert_equal %w|12 9|, changesets.collect(&:revision)
  265. changesets = @repository.latest_changesets(path, '12', 1)
  266. assert_equal %w|12|, changesets.collect(&:revision)
  267. end
  268. def assert_latest_changesets_tag
  269. changesets = @repository.latest_changesets('', 'tag_test.00')
  270. assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
  271. end
  272. private :assert_latest_changesets_tag
  273. def test_latest_changesets_tag
  274. assert_equal 0, @repository.changesets.count
  275. @repository.fetch_changesets
  276. @project.reload
  277. assert_equal NUM_REV, @repository.changesets.count
  278. assert_latest_changesets_tag
  279. end
  280. def test_latest_changesets_tag_short_id
  281. assert_equal 0, @repository.changesets.count
  282. create_rev0_short_id
  283. assert_equal 1, @repository.changesets.count
  284. @repository.fetch_changesets
  285. @project.reload
  286. assert_equal NUM_REV, @repository.changesets.count
  287. assert_latest_changesets_tag
  288. end
  289. def test_latest_changesets_tag_with_path
  290. assert_equal 0, @repository.changesets.count
  291. @repository.fetch_changesets
  292. @project.reload
  293. assert_equal NUM_REV, @repository.changesets.count
  294. changesets = @repository.latest_changesets('sources', 'tag_test.00')
  295. assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
  296. end
  297. def test_latest_changesets_tag_with_limit
  298. assert_equal 0, @repository.changesets.count
  299. @repository.fetch_changesets
  300. @project.reload
  301. assert_equal NUM_REV, @repository.changesets.count
  302. changesets = @repository.latest_changesets('', 'tag_test.00', 2)
  303. assert_equal %w|5 4|, changesets.collect(&:revision)
  304. changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
  305. assert_equal %w|4 3|, changesets.collect(&:revision)
  306. end
  307. def test_latest_changesets_branch
  308. assert_equal 0, @repository.changesets.count
  309. @repository.fetch_changesets
  310. @project.reload
  311. assert_equal NUM_REV, @repository.changesets.count
  312. if @repository.scm.class.client_version_above?([1, 6])
  313. changesets = @repository.latest_changesets('', 'branch-Ü-01')
  314. assert_equal %w|27 26|, changesets.collect(&:revision)
  315. end
  316. changesets = @repository.latest_changesets('latin-1-dir/test-Ü-subdir', 'branch-Ü-01')
  317. assert_equal %w|27|, changesets.collect(&:revision)
  318. end
  319. def assert_latest_changesets_default_branch
  320. changesets = @repository.latest_changesets('', 'default')
  321. assert_equal %w|31 28 24 6 4 3 2 1 0|, changesets.collect(&:revision)
  322. end
  323. private :assert_latest_changesets_default_branch
  324. def test_latest_changesets_default_branch
  325. assert_equal 0, @repository.changesets.count
  326. @repository.fetch_changesets
  327. @project.reload
  328. assert_equal NUM_REV, @repository.changesets.count
  329. assert_latest_changesets_default_branch
  330. end
  331. def test_latest_changesets_default_branch_short_id
  332. assert_equal 0, @repository.changesets.count
  333. create_rev0_short_id
  334. assert_equal 1, @repository.changesets.count
  335. @repository.fetch_changesets
  336. @project.reload
  337. assert_equal NUM_REV, @repository.changesets.count
  338. assert_latest_changesets_default_branch
  339. end
  340. def assert_copied_files(is_short_scmid=true)
  341. cs1 = @repository.changesets.find_by_revision('13')
  342. assert_not_nil cs1
  343. c1 = cs1.filechanges.sort_by(&:path)
  344. assert_equal 2, c1.size
  345. hex1 = "3a330eb329586ea2adb3f83237c23310e744ebe9"
  346. scmid1 = scmid_for_assert(hex1, is_short_scmid)
  347. assert_equal 'A', c1[0].action
  348. assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
  349. assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
  350. assert_equal scmid1, c1[0].from_revision
  351. assert_equal 'A', c1[1].action
  352. assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
  353. assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
  354. cs2 = @repository.changesets.find_by_revision('15')
  355. c2 = cs2.filechanges
  356. assert_equal 1, c2.size
  357. hex2 = "933ca60293d78f7c7979dd123cc0c02431683575"
  358. scmid2 = scmid_for_assert(hex2, is_short_scmid)
  359. assert_equal 'A', c2[0].action
  360. assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
  361. assert_equal '/README', c2[0].from_path
  362. assert_equal scmid2, c2[0].from_revision
  363. cs3 = @repository.changesets.find_by_revision('19')
  364. c3 = cs3.filechanges
  365. hex3 = "5d9891a1b4258ea256552aa856e388f2da28256a"
  366. scmid3 = scmid_for_assert(hex3, is_short_scmid)
  367. assert_equal 1, c3.size
  368. assert_equal 'A', c3[0].action
  369. assert_equal '/latin-1-dir/test-Ü-1.txt', c3[0].path
  370. assert_equal '/latin-1-dir/test-Ü.txt', c3[0].from_path
  371. assert_equal scmid3, c3[0].from_revision
  372. end
  373. private :assert_copied_files
  374. def test_copied_files_short_id
  375. assert_equal 0, @repository.changesets.count
  376. create_rev0_short_id
  377. assert_equal 1, @repository.changesets.count
  378. @repository.fetch_changesets
  379. @project.reload
  380. assert_equal NUM_REV, @repository.changesets.count
  381. assert_copied_files(true)
  382. end
  383. def test_copied_files_long_id
  384. assert_equal 0, @repository.changesets.count
  385. @repository.fetch_changesets
  386. @project.reload
  387. assert_equal NUM_REV, @repository.changesets.count
  388. assert_copied_files(false)
  389. end
  390. def test_find_changeset_by_name
  391. assert_equal 0, @repository.changesets.count
  392. @repository.fetch_changesets
  393. @project.reload
  394. assert_equal NUM_REV, @repository.changesets.count
  395. %w|2 400bb8672109 400|.each do |r|
  396. assert_equal '2', @repository.find_changeset_by_name(r).revision
  397. end
  398. end
  399. def test_find_changeset_by_invalid_name
  400. assert_equal 0, @repository.changesets.count
  401. @repository.fetch_changesets
  402. @project.reload
  403. assert_equal NUM_REV, @repository.changesets.count
  404. assert_nil @repository.find_changeset_by_name('100000')
  405. end
  406. def test_identifier
  407. assert_equal 0, @repository.changesets.count
  408. @repository.fetch_changesets
  409. @project.reload
  410. assert_equal NUM_REV, @repository.changesets.count
  411. c = @repository.changesets.find_by_revision('2')
  412. assert_equal c.scmid, c.identifier
  413. end
  414. def test_format_identifier
  415. assert_equal 0, @repository.changesets.count
  416. @repository.fetch_changesets
  417. @project.reload
  418. assert_equal NUM_REV, @repository.changesets.count
  419. c = @repository.changesets.find_by_revision('2')
  420. assert_equal '2:400bb8672109', c.format_identifier
  421. end
  422. def test_format_identifier_long_id
  423. assert_equal 0, @repository.changesets.count
  424. Changeset.create!(:repository => @repository,
  425. :committed_on => Time.now,
  426. :revision => '0',
  427. :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
  428. :comments => 'test')
  429. c = @repository.changesets.find_by_revision('0')
  430. assert_equal '0:0885933ad4f6', c.format_identifier
  431. end
  432. def test_find_changeset_by_empty_name
  433. assert_equal 0, @repository.changesets.count
  434. @repository.fetch_changesets
  435. @project.reload
  436. assert_equal NUM_REV, @repository.changesets.count
  437. ['', ' ', nil].each do |r|
  438. assert_nil @repository.find_changeset_by_name(r)
  439. end
  440. end
  441. def assert_parents(is_short_scmid=true)
  442. r1 = @repository.changesets.find_by_revision('0')
  443. assert_equal [], r1.parents
  444. r2 = @repository.changesets.find_by_revision('1')
  445. hex2 = "0885933ad4f68d77c2649cd11f8311276e7ef7ce"
  446. scmid2 = scmid_for_assert(hex2, is_short_scmid)
  447. assert_equal 1, r2.parents.length
  448. assert_equal scmid2, r2.parents[0].identifier
  449. r3 = @repository.changesets.find_by_revision('30')
  450. assert_equal 2, r3.parents.length
  451. r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
  452. hex41 = "3a330eb329586ea2adb3f83237c23310e744ebe9"
  453. scmid41 = scmid_for_assert(hex41, is_short_scmid)
  454. hex42 = "a94b0528f24fe05ebaef496ae0500bb050772e36"
  455. scmid42 = scmid_for_assert(hex42, is_short_scmid)
  456. assert_equal scmid41, r4[0]
  457. assert_equal scmid42, r4[1]
  458. end
  459. private :assert_parents
  460. def test_parents_short_id
  461. assert_equal 0, @repository.changesets.count
  462. create_rev0_short_id
  463. assert_equal 1, @repository.changesets.count
  464. @repository.fetch_changesets
  465. @project.reload
  466. assert_equal NUM_REV, @repository.changesets.count
  467. assert_parents(true)
  468. end
  469. def test_parents_long_id
  470. assert_equal 0, @repository.changesets.count
  471. @repository.fetch_changesets
  472. @project.reload
  473. assert_equal NUM_REV, @repository.changesets.count
  474. assert_parents(false)
  475. end
  476. def test_activities
  477. c = Changeset.new(:repository => @repository,
  478. :committed_on => Time.now,
  479. :revision => '123',
  480. :scmid => 'abc400bb8672',
  481. :comments => 'test')
  482. assert c.event_title.include?('123:abc400bb8672:')
  483. assert_equal 'abc400bb8672', c.event_url[:rev]
  484. end
  485. def test_previous
  486. assert_equal 0, @repository.changesets.count
  487. @repository.fetch_changesets
  488. @project.reload
  489. assert_equal NUM_REV, @repository.changesets.count
  490. %w|28 3ae45e2d177d 3ae45|.each do |r1|
  491. changeset = @repository.find_changeset_by_name(r1)
  492. %w|27 7bbf4c738e71 7bbf|.each do |r2|
  493. assert_equal @repository.find_changeset_by_name(r2), changeset.previous
  494. end
  495. end
  496. end
  497. def test_previous_nil
  498. assert_equal 0, @repository.changesets.count
  499. @repository.fetch_changesets
  500. @project.reload
  501. assert_equal NUM_REV, @repository.changesets.count
  502. %w|0 0885933ad4f6 0885|.each do |r1|
  503. changeset = @repository.find_changeset_by_name(r1)
  504. assert_nil changeset.previous
  505. end
  506. end
  507. def test_next
  508. assert_equal 0, @repository.changesets.count
  509. @repository.fetch_changesets
  510. @project.reload
  511. assert_equal NUM_REV, @repository.changesets.count
  512. %w|27 7bbf4c738e71 7bbf|.each do |r2|
  513. changeset = @repository.find_changeset_by_name(r2)
  514. %w|28 3ae45e2d177d 3ae45|.each do |r1|
  515. assert_equal @repository.find_changeset_by_name(r1), changeset.next
  516. end
  517. end
  518. end
  519. def test_next_nil
  520. assert_equal 0, @repository.changesets.count
  521. @repository.fetch_changesets
  522. @project.reload
  523. assert_equal NUM_REV, @repository.changesets.count
  524. [(NUM_REV - 1).to_s, "ba20ebce08db", "ba20e"].each do |r1|
  525. changeset = @repository.find_changeset_by_name(r1)
  526. assert_nil changeset.next
  527. end
  528. end
  529. def test_scmid_for_inserting_db_short_id
  530. assert_equal 0, @repository.changesets.count
  531. create_rev0_short_id
  532. assert_equal 1, @repository.changesets.count
  533. rev = "0123456789012345678901234567890123456789"
  534. assert_equal 12, @repository.scmid_for_inserting_db(rev).length
  535. end
  536. def test_scmid_for_inserting_db_long_id
  537. rev = "0123456789012345678901234567890123456789"
  538. assert_equal 0, @repository.changesets.count
  539. assert_equal 40, @repository.scmid_for_inserting_db(rev).length
  540. Changeset.create!(:repository => @repository,
  541. :committed_on => Time.now,
  542. :revision => '0',
  543. :scmid => rev,
  544. :comments => 'test')
  545. assert_equal 1, @repository.changesets.count
  546. assert_equal 40, @repository.scmid_for_inserting_db(rev).length
  547. end
  548. def test_scmid_for_assert
  549. rev = "0123456789012345678901234567890123456789"
  550. assert_equal rev, scmid_for_assert(rev, false)
  551. assert_equal "012345678901", scmid_for_assert(rev, true)
  552. end
  553. private
  554. def scmid_for_assert(hex, is_short=true)
  555. is_short ? hex[0, 12] : hex
  556. end
  557. def create_rev0_short_id
  558. Changeset.create!(:repository => @repository,
  559. :committed_on => Time.now,
  560. :revision => '0',
  561. :scmid => '0885933ad4f6',
  562. :comments => 'test')
  563. end
  564. else
  565. puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
  566. def test_fake; assert true end
  567. end
  568. end