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_test.rb 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # redMine - project management software
  2. # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
  18. class RepositoryTest < Test::Unit::TestCase
  19. fixtures :projects,
  20. :trackers,
  21. :projects_trackers,
  22. :repositories,
  23. :issues,
  24. :issue_statuses,
  25. :changesets,
  26. :changes,
  27. :users,
  28. :enumerations
  29. def setup
  30. @repository = Project.find(1).repository
  31. end
  32. def test_create
  33. repository = Repository::Subversion.new(:project => Project.find(3))
  34. assert !repository.save
  35. repository.url = "svn://localhost"
  36. assert repository.save
  37. repository.reload
  38. project = Project.find(3)
  39. assert_equal repository, project.repository
  40. end
  41. def test_scan_changesets_for_issue_ids
  42. # choosing a status to apply to fix issues
  43. Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
  44. Setting.commit_fix_done_ratio = "90"
  45. Setting.commit_ref_keywords = 'refs , references, IssueID'
  46. Setting.commit_fix_keywords = 'fixes , closes'
  47. Setting.default_language = 'en'
  48. ActionMailer::Base.deliveries.clear
  49. # make sure issue 1 is not already closed
  50. fixed_issue = Issue.find(1)
  51. assert !fixed_issue.status.is_closed?
  52. old_status = fixed_issue.status
  53. Repository.scan_changesets_for_issue_ids
  54. assert_equal [101, 102], Issue.find(3).changeset_ids
  55. # fixed issues
  56. fixed_issue.reload
  57. assert fixed_issue.status.is_closed?
  58. assert_equal 90, fixed_issue.done_ratio
  59. assert_equal [101], fixed_issue.changeset_ids
  60. # issue change
  61. journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
  62. assert_equal User.find_by_login('dlopper'), journal.user
  63. assert_equal 'Applied in changeset r2.', journal.notes
  64. # 2 email notifications
  65. assert_equal 2, ActionMailer::Base.deliveries.size
  66. mail = ActionMailer::Base.deliveries.first
  67. assert_kind_of TMail::Mail, mail
  68. assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
  69. assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}")
  70. # ignoring commits referencing an issue of another project
  71. assert_equal [], Issue.find(4).changesets
  72. end
  73. def test_for_changeset_comments_strip
  74. repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' )
  75. comment = <<-COMMENT
  76. This is a loooooooooooooooooooooooooooong comment
  77. COMMENT
  78. changeset = Changeset.new(
  79. :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c',
  80. :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository )
  81. assert( changeset.save )
  82. assert_not_equal( comment, changeset.comments )
  83. assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments )
  84. end
  85. end