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.

changeset_test.rb 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. # encoding: utf-8
  2. #
  3. # Redmine - project management software
  4. # Copyright (C) 2006-2017 Jean-Philippe Lang
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. require File.expand_path('../../test_helper', __FILE__)
  20. class ChangesetTest < ActiveSupport::TestCase
  21. fixtures :projects, :repositories,
  22. :issues, :issue_statuses, :issue_categories,
  23. :journals, :journal_details,
  24. :workflows,
  25. :changesets, :changes,
  26. :enumerations,
  27. :custom_fields, :custom_values,
  28. :users, :members, :member_roles,
  29. :email_addresses,
  30. :trackers, :projects_trackers,
  31. :enabled_modules, :roles
  32. def setup
  33. User.current = nil
  34. end
  35. def test_ref_keywords_any
  36. ActionMailer::Base.deliveries.clear
  37. Setting.commit_ref_keywords = '*'
  38. Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => '5', 'done_ratio' => '90'}]
  39. c = Changeset.new(:repository => Project.find(1).repository,
  40. :committed_on => Time.now,
  41. :comments => 'New commit (#2). Fixes #1',
  42. :revision => '12345')
  43. assert c.save
  44. assert_equal [1, 2], c.issue_ids.sort
  45. fixed = Issue.find(1)
  46. assert fixed.closed?
  47. assert_equal 90, fixed.done_ratio
  48. assert_equal 2, ActionMailer::Base.deliveries.size
  49. end
  50. def test_ref_keywords
  51. Setting.commit_ref_keywords = 'refs'
  52. Setting.commit_update_keywords = ''
  53. c = Changeset.new(:repository => Project.find(1).repository,
  54. :committed_on => Time.now,
  55. :comments => 'Ignores #2. Refs #1',
  56. :revision => '12345')
  57. assert c.save
  58. assert_equal [1], c.issue_ids.sort
  59. end
  60. def test_ref_keywords_any_only
  61. Setting.commit_ref_keywords = '*'
  62. Setting.commit_update_keywords = ''
  63. c = Changeset.new(:repository => Project.find(1).repository,
  64. :committed_on => Time.now,
  65. :comments => 'Ignores #2. Refs #1',
  66. :revision => '12345')
  67. assert c.save
  68. assert_equal [1, 2], c.issue_ids.sort
  69. end
  70. def test_ref_keywords_any_with_timelog
  71. Setting.commit_ref_keywords = '*'
  72. Setting.commit_logtime_enabled = '1'
  73. {
  74. '2' => 2.0,
  75. '2h' => 2.0,
  76. '2hours' => 2.0,
  77. '15m' => 0.25,
  78. '15min' => 0.25,
  79. '3h15' => 3.25,
  80. '3h15m' => 3.25,
  81. '3h15min' => 3.25,
  82. '3:15' => 3.25,
  83. '3.25' => 3.25,
  84. '3.25h' => 3.25,
  85. '3,25' => 3.25,
  86. '3,25h' => 3.25,
  87. }.each do |syntax, expected_hours|
  88. c = Changeset.new(:repository => Project.find(1).repository,
  89. :committed_on => 24.hours.ago,
  90. :comments => "Worked on this issue #1 @#{syntax}",
  91. :revision => '520',
  92. :user => User.find(2))
  93. assert_difference 'TimeEntry.count' do
  94. c.scan_comment_for_issue_ids
  95. end
  96. assert_equal [1], c.issue_ids.sort
  97. time = TimeEntry.order('id desc').first
  98. assert_equal 1, time.issue_id
  99. assert_equal 1, time.project_id
  100. assert_equal 2, time.user_id
  101. assert_equal expected_hours, time.hours,
  102. "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
  103. assert_equal Date.yesterday, time.spent_on
  104. assert time.activity.is_default?
  105. assert time.comments.include?('r520'),
  106. "r520 was expected in time_entry comments: #{time.comments}"
  107. end
  108. end
  109. def test_ref_keywords_closing_with_timelog
  110. Setting.commit_ref_keywords = '*'
  111. Setting.commit_update_keywords = [{'keywords' => 'fixes , closes',
  112. 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}]
  113. Setting.commit_logtime_enabled = '1'
  114. c = Changeset.new(:repository => Project.find(1).repository,
  115. :committed_on => Time.now,
  116. :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
  117. :user => User.find(2))
  118. assert_difference 'TimeEntry.count', 2 do
  119. c.scan_comment_for_issue_ids
  120. end
  121. assert_equal [1, 2], c.issue_ids.sort
  122. assert Issue.find(1).closed?
  123. assert Issue.find(2).closed?
  124. times = TimeEntry.order('id desc').limit(2)
  125. assert_equal [1, 2], times.collect(&:issue_id).sort
  126. end
  127. def test_ref_keywords_any_line_start
  128. Setting.commit_ref_keywords = '*'
  129. c = Changeset.new(:repository => Project.find(1).repository,
  130. :committed_on => Time.now,
  131. :comments => '#1 is the reason of this commit',
  132. :revision => '12345')
  133. assert c.save
  134. assert_equal [1], c.issue_ids.sort
  135. end
  136. def test_ref_keywords_allow_brackets_around_a_issue_number
  137. Setting.commit_ref_keywords = '*'
  138. c = Changeset.new(:repository => Project.find(1).repository,
  139. :committed_on => Time.now,
  140. :comments => '[#1] Worked on this issue',
  141. :revision => '12345')
  142. assert c.save
  143. assert_equal [1], c.issue_ids.sort
  144. end
  145. def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
  146. Setting.commit_ref_keywords = '*'
  147. c = Changeset.new(:repository => Project.find(1).repository,
  148. :committed_on => Time.now,
  149. :comments => '[#1 #2, #3] Worked on these',
  150. :revision => '12345')
  151. assert c.save
  152. assert_equal [1,2,3], c.issue_ids.sort
  153. end
  154. def test_ref_keywords_with_large_number_should_not_error
  155. Setting.commit_ref_keywords = '*'
  156. c = Changeset.new(:repository => Project.find(1).repository,
  157. :committed_on => Time.now,
  158. :comments => 'Out of range #2010021810000121',
  159. :revision => '12345')
  160. assert_nothing_raised do
  161. assert c.save
  162. end
  163. assert_equal [], c.issue_ids.sort
  164. end
  165. def test_update_keywords_with_changes_should_create_journal
  166. issue = Issue.generate!(:project_id => 1, :status_id => 1)
  167. with_settings :commit_update_keywords => [{'keywords' => 'fixes', 'status_id' => '3'}] do
  168. assert_difference 'Journal.count' do
  169. c = Changeset.generate!(:repository => Project.find(1).repository,:comments => "Fixes ##{issue.id}")
  170. assert_include c.id, issue.reload.changeset_ids
  171. journal = Journal.order('id DESC').first
  172. assert_equal 1, journal.details.count
  173. end
  174. end
  175. end
  176. def test_update_keywords_without_change_should_not_create_journal
  177. issue = Issue.generate!(:project_id => 1, :status_id => 3)
  178. with_settings :commit_update_keywords => [{'keywords' => 'fixes', 'status_id' => '3'}] do
  179. assert_no_difference 'Journal.count' do
  180. c = Changeset.generate!(:repository => Project.find(1).repository,:comments => "Fixes ##{issue.id}")
  181. assert_include c.id, issue.reload.changeset_ids
  182. end
  183. end
  184. end
  185. def test_update_keywords_with_multiple_rules
  186. with_settings :commit_update_keywords => [
  187. {'keywords' => 'fixes, closes', 'status_id' => '5'},
  188. {'keywords' => 'resolves', 'status_id' => '3'}
  189. ] do
  190. issue1 = Issue.generate!
  191. issue2 = Issue.generate!
  192. Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
  193. assert_equal 5, issue1.reload.status_id
  194. assert_equal 3, issue2.reload.status_id
  195. end
  196. end
  197. def test_update_keywords_with_multiple_rules_for_the_same_keyword_should_match_tracker
  198. with_settings :commit_update_keywords => [
  199. {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
  200. {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
  201. ] do
  202. issue1 = Issue.generate!(:tracker_id => 2)
  203. issue2 = Issue.generate!
  204. Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
  205. assert_equal 5, issue1.reload.status_id
  206. assert_equal 3, issue2.reload.status_id
  207. end
  208. end
  209. def test_update_keywords_with_multiple_rules_for_the_same_tracker_should_match_keyword
  210. with_settings :commit_update_keywords => [
  211. {'keywords' => 'Fixes, Closes', 'status_id' => '5', 'done_ratio' => '100', 'if_tracker_id' => '2'},
  212. {'keywords' => 'Testing', 'status_id' => '3', 'done_ratio' => '90', 'if_tracker_id' => '2'}
  213. ] do
  214. issue1 = Issue.generate!(:tracker_id => 2)
  215. issue2 = Issue.generate!(:tracker_id => 2)
  216. Changeset.generate!(:comments => "Testing ##{issue1.id}, Fixes ##{issue2.id}")
  217. issue1.reload
  218. assert_equal 3, issue1.status_id
  219. assert_equal 90, issue1.done_ratio
  220. issue2.reload
  221. assert_equal 5, issue2.status_id
  222. assert_equal 100, issue2.done_ratio
  223. end
  224. end
  225. def test_update_keywords_with_multiple_rules_and_no_match
  226. with_settings :commit_update_keywords => [
  227. {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
  228. {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
  229. ] do
  230. issue1 = Issue.generate!(:tracker_id => 2)
  231. issue2 = Issue.generate!
  232. Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
  233. assert_equal 5, issue1.reload.status_id
  234. assert_equal 1, issue2.reload.status_id # no updates
  235. end
  236. end
  237. def test_commit_referencing_a_subproject_issue
  238. c = Changeset.new(:repository => Project.find(1).repository,
  239. :committed_on => Time.now,
  240. :comments => 'refs #5, a subproject issue',
  241. :revision => '12345')
  242. assert c.save
  243. assert_equal [5], c.issue_ids.sort
  244. assert c.issues.first.project != c.project
  245. end
  246. def test_commit_closing_a_subproject_issue
  247. with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
  248. :default_language => 'en' do
  249. issue = Issue.find(5)
  250. assert !issue.closed?
  251. assert_difference 'Journal.count' do
  252. c = Changeset.new(:repository => Project.find(1).repository,
  253. :committed_on => Time.now,
  254. :comments => 'closes #5, a subproject issue',
  255. :revision => '12345')
  256. assert c.save
  257. end
  258. assert issue.reload.closed?
  259. journal = Journal.order('id DESC').first
  260. assert_equal issue, journal.issue
  261. assert_include "Applied in changeset ecookbook:r12345.", journal.notes
  262. end
  263. end
  264. def test_commit_referencing_a_parent_project_issue
  265. # repository of child project
  266. r = Repository::Subversion.create!(
  267. :project => Project.find(3),
  268. :url => 'svn://localhost/test')
  269. c = Changeset.new(:repository => r,
  270. :committed_on => Time.now,
  271. :comments => 'refs #2, an issue of a parent project',
  272. :revision => '12345')
  273. assert c.save
  274. assert_equal [2], c.issue_ids.sort
  275. assert c.issues.first.project != c.project
  276. end
  277. def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled
  278. r = Repository::Subversion.create!(
  279. :project => Project.find(3),
  280. :url => 'svn://localhost/test')
  281. with_settings :commit_cross_project_ref => '0' do
  282. c = Changeset.new(:repository => r,
  283. :committed_on => Time.now,
  284. :comments => 'refs #4, an issue of a different project',
  285. :revision => '12345')
  286. assert c.save
  287. assert_equal [], c.issue_ids
  288. end
  289. end
  290. def test_commit_referencing_a_project_with_commit_cross_project_ref_enabled
  291. r = Repository::Subversion.create!(
  292. :project => Project.find(3),
  293. :url => 'svn://localhost/test')
  294. with_settings :commit_cross_project_ref => '1' do
  295. c = Changeset.new(:repository => r,
  296. :committed_on => Time.now,
  297. :comments => 'refs #4, an issue of a different project',
  298. :revision => '12345')
  299. assert c.save
  300. assert_equal [4], c.issue_ids
  301. end
  302. end
  303. def test_old_commits_should_not_update_issues_nor_log_time
  304. Setting.commit_ref_keywords = '*'
  305. Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}}
  306. Setting.commit_logtime_enabled = '1'
  307. repository = Project.find(1).repository
  308. repository.created_on = Time.now
  309. repository.save!
  310. c = Changeset.new(:repository => repository,
  311. :committed_on => 1.month.ago,
  312. :comments => 'New commit (#2). Fixes #1 @1h',
  313. :revision => '12345')
  314. assert_no_difference 'TimeEntry.count' do
  315. assert c.save
  316. end
  317. assert_equal [1, 2], c.issue_ids.sort
  318. issue = Issue.find(1)
  319. assert_equal 1, issue.status_id
  320. assert_equal 0, issue.done_ratio
  321. end
  322. def test_2_repositories_with_same_backend_should_not_link_issue_multiple_times
  323. Setting.commit_ref_keywords = '*'
  324. r1 = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///svn1')
  325. r2 = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn2', :url => 'file:///svn1')
  326. now = Time.now
  327. assert_difference 'Issue.find(1).changesets.count' do
  328. c1 = Changeset.create!(:repository => r1, :committed_on => now, :comments => 'Fixes #1', :revision => '12345')
  329. c1 = Changeset.create!(:repository => r2, :committed_on => now, :comments => 'Fixes #1', :revision => '12345')
  330. end
  331. end
  332. def test_text_tag_revision
  333. c = Changeset.new(:revision => '520')
  334. assert_equal 'r520', c.text_tag
  335. end
  336. def test_text_tag_revision_with_same_project
  337. c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
  338. assert_equal 'r520', c.text_tag(Project.find(1))
  339. end
  340. def test_text_tag_revision_with_different_project
  341. c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
  342. assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
  343. end
  344. def test_text_tag_revision_with_repository_identifier
  345. r = Repository::Subversion.create!(
  346. :project_id => 1,
  347. :url => 'svn://localhost/test',
  348. :identifier => 'documents')
  349. c = Changeset.new(:revision => '520', :repository => r)
  350. assert_equal 'documents|r520', c.text_tag
  351. assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
  352. end
  353. def test_text_tag_hash
  354. c = Changeset.new(
  355. :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
  356. :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
  357. assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
  358. end
  359. def test_text_tag_hash_with_same_project
  360. c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
  361. assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
  362. end
  363. def test_text_tag_hash_with_different_project
  364. c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
  365. assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
  366. end
  367. def test_text_tag_hash_all_number
  368. c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
  369. assert_equal 'commit:0123456789', c.text_tag
  370. end
  371. def test_text_tag_hash_with_repository_identifier
  372. r = Repository::Subversion.new(
  373. :project_id => 1,
  374. :url => 'svn://localhost/test',
  375. :identifier => 'documents')
  376. c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => r)
  377. assert_equal 'commit:documents|7234cb27', c.text_tag
  378. assert_equal 'ecookbook:commit:documents|7234cb27', c.text_tag(Project.find(2))
  379. end
  380. def test_previous
  381. changeset = Changeset.find_by_revision('3')
  382. assert_equal Changeset.find_by_revision('2'), changeset.previous
  383. end
  384. def test_previous_nil
  385. changeset = Changeset.find_by_revision('1')
  386. assert_nil changeset.previous
  387. end
  388. def test_next
  389. changeset = Changeset.find_by_revision('2')
  390. assert_equal Changeset.find_by_revision('3'), changeset.next
  391. end
  392. def test_next_nil
  393. changeset = Changeset.find_by_revision('10')
  394. assert_nil changeset.next
  395. end
  396. def test_comments_should_be_converted_to_utf8
  397. proj = Project.find(3)
  398. # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
  399. str = "Texte encod\xe9 en ISO-8859-1.".force_encoding("ASCII-8BIT")
  400. r = Repository::Bazaar.create!(
  401. :project => proj,
  402. :url => '/tmp/test/bazaar',
  403. :log_encoding => 'ISO-8859-1' )
  404. assert r
  405. c = Changeset.new(:repository => r,
  406. :committed_on => Time.now,
  407. :revision => '123',
  408. :scmid => '12345',
  409. :comments => str)
  410. assert( c.save )
  411. str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1.".force_encoding("UTF-8")
  412. assert_equal str_utf8, c.comments
  413. end
  414. def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
  415. proj = Project.find(3)
  416. # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
  417. str1 = "Texte encod\xe9 en ISO-8859-1.".force_encoding("UTF-8")
  418. str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
  419. r = Repository::Bazaar.create!(
  420. :project => proj,
  421. :url => '/tmp/test/bazaar',
  422. :log_encoding => 'UTF-8' )
  423. assert r
  424. c = Changeset.new(:repository => r,
  425. :committed_on => Time.now,
  426. :revision => '123',
  427. :scmid => '12345',
  428. :comments => str1,
  429. :committer => str2)
  430. assert( c.save )
  431. assert_equal "Texte encod? en ISO-8859-1.", c.comments
  432. assert_equal "?a?b?c?d?e test", c.committer
  433. end
  434. def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
  435. proj = Project.find(3)
  436. str = "test\xb5\xfetest\xb5\xfe".force_encoding('ASCII-8BIT')
  437. r = Repository::Bazaar.create!(
  438. :project => proj,
  439. :url => '/tmp/test/bazaar',
  440. :log_encoding => 'ISO-2022-JP' )
  441. assert r
  442. c = Changeset.new(:repository => r,
  443. :committed_on => Time.now,
  444. :revision => '123',
  445. :scmid => '12345',
  446. :comments => str)
  447. assert( c.save )
  448. assert_equal "test??test??", c.comments
  449. end
  450. def test_comments_should_be_converted_all_latin1_to_utf8
  451. s1 = "\xC2\x80"
  452. s2 = "\xc3\x82\xc2\x80"
  453. s4 = s2.dup
  454. s3 = s1.dup
  455. s1.force_encoding('ASCII-8BIT')
  456. s2.force_encoding('ASCII-8BIT')
  457. s3.force_encoding('ISO-8859-1')
  458. s4.force_encoding('UTF-8')
  459. assert_equal s3.encode('UTF-8'), s4
  460. proj = Project.find(3)
  461. r = Repository::Bazaar.create!(
  462. :project => proj,
  463. :url => '/tmp/test/bazaar',
  464. :log_encoding => 'ISO-8859-1' )
  465. assert r
  466. c = Changeset.new(:repository => r,
  467. :committed_on => Time.now,
  468. :revision => '123',
  469. :scmid => '12345',
  470. :comments => s1)
  471. assert( c.save )
  472. assert_equal s4, c.comments
  473. end
  474. def test_invalid_utf8_sequences_in_paths_should_be_replaced
  475. proj = Project.find(3)
  476. str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
  477. str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
  478. r = Repository::Bazaar.create!(
  479. :project => proj,
  480. :url => '/tmp/test/bazaar',
  481. :log_encoding => 'UTF-8' )
  482. assert r
  483. cs = Changeset.new(
  484. :repository => r,
  485. :committed_on => Time.now,
  486. :revision => '123',
  487. :scmid => '12345',
  488. :comments => "test")
  489. assert(cs.save)
  490. ch = Change.new(
  491. :changeset => cs,
  492. :action => "A",
  493. :path => str1,
  494. :from_path => str2,
  495. :from_revision => "345")
  496. assert(ch.save)
  497. assert_equal "Texte encod? en ISO-8859-1", ch.path
  498. assert_equal "?a?b?c?d?e test", ch.from_path
  499. end
  500. def test_comments_nil
  501. proj = Project.find(3)
  502. r = Repository::Bazaar.create!(
  503. :project => proj,
  504. :url => '/tmp/test/bazaar',
  505. :log_encoding => 'ISO-8859-1' )
  506. assert r
  507. c = Changeset.new(:repository => r,
  508. :committed_on => Time.now,
  509. :revision => '123',
  510. :scmid => '12345',
  511. :comments => nil,
  512. :committer => nil)
  513. assert( c.save )
  514. assert_equal "", c.comments
  515. assert_nil c.committer
  516. assert_equal "UTF-8", c.comments.encoding.to_s
  517. end
  518. def test_comments_empty
  519. proj = Project.find(3)
  520. r = Repository::Bazaar.create!(
  521. :project => proj,
  522. :url => '/tmp/test/bazaar',
  523. :log_encoding => 'ISO-8859-1' )
  524. assert r
  525. c = Changeset.new(:repository => r,
  526. :committed_on => Time.now,
  527. :revision => '123',
  528. :scmid => '12345',
  529. :comments => "",
  530. :committer => "")
  531. assert( c.save )
  532. assert_equal "", c.comments
  533. assert_equal "", c.committer
  534. assert_equal "UTF-8", c.comments.encoding.to_s
  535. assert_equal "UTF-8", c.committer.encoding.to_s
  536. end
  537. def test_comments_should_accept_more_than_64k
  538. c = Changeset.new(:repository => Repository.first,
  539. :committed_on => Time.now,
  540. :revision => '123',
  541. :scmid => '12345',
  542. :comments => "a" * 500.kilobyte)
  543. assert c.save
  544. c.reload
  545. assert_equal 500.kilobyte, c.comments.size
  546. end
  547. def test_identifier
  548. c = Changeset.find_by_revision('1')
  549. assert_equal c.revision, c.identifier
  550. end
  551. end