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

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