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 23KB

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