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

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