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

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