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.

journal_observer_test.rb 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2014 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 JournalObserverTest < ActiveSupport::TestCase
  19. fixtures :issues, :issue_statuses, :journals, :journal_details, :projects,
  20. :projects_trackers, :trackers, :enabled_modules, :enumerations,
  21. :users, :roles
  22. def setup
  23. ActionMailer::Base.deliveries.clear
  24. @journal = Journal.find 1
  25. end
  26. # context: issue_updated notified_events
  27. def test_create_should_send_email_notification_with_issue_updated
  28. issue = Issue.first
  29. user = User.first
  30. journal = issue.init_journal(user, issue)
  31. with_settings :notified_events => %w(issue_updated) do
  32. assert journal.save
  33. end
  34. assert_equal 1, ActionMailer::Base.deliveries.size
  35. end
  36. def test_create_should_not_send_email_notification_with_notify_set_to_false
  37. issue = Issue.first
  38. user = User.first
  39. journal = issue.init_journal(user, issue)
  40. journal.notify = false
  41. with_settings :notified_events => %w(issue_updated) do
  42. assert journal.save
  43. end
  44. assert_equal 0, ActionMailer::Base.deliveries.size
  45. end
  46. def test_create_should_not_send_email_notification_without_issue_updated
  47. issue = Issue.first
  48. user = User.first
  49. journal = issue.init_journal(user, issue)
  50. with_settings :notified_events => [] do
  51. assert journal.save
  52. end
  53. assert_equal 0, ActionMailer::Base.deliveries.size
  54. end
  55. # context: issue_note_added notified_events
  56. def test_create_should_send_email_notification_with_issue_note_added
  57. issue = Issue.first
  58. user = User.first
  59. journal = issue.init_journal(user, issue)
  60. journal.notes = 'This update has a note'
  61. with_settings :notified_events => %w(issue_note_added) do
  62. assert journal.save
  63. end
  64. assert_equal 1, ActionMailer::Base.deliveries.size
  65. end
  66. def test_create_should_not_send_email_notification_without_issue_note_added
  67. issue = Issue.first
  68. user = User.first
  69. journal = issue.init_journal(user, issue)
  70. journal.notes = 'This update has a note'
  71. with_settings :notified_events => [] do
  72. assert journal.save
  73. end
  74. assert_equal 0, ActionMailer::Base.deliveries.size
  75. end
  76. # context: issue_status_updated notified_events
  77. def test_create_should_send_email_notification_with_issue_status_updated
  78. issue = Issue.first
  79. user = User.first
  80. issue.init_journal(user, issue)
  81. issue.status = IssueStatus.last
  82. with_settings :notified_events => %w(issue_status_updated) do
  83. assert issue.save
  84. end
  85. assert_equal 1, ActionMailer::Base.deliveries.size
  86. end
  87. def test_create_should_not_send_email_notification_without_issue_status_updated
  88. issue = Issue.first
  89. user = User.first
  90. issue.init_journal(user, issue)
  91. issue.status = IssueStatus.last
  92. with_settings :notified_events => [] do
  93. assert issue.save
  94. end
  95. assert_equal 0, ActionMailer::Base.deliveries.size
  96. end
  97. # context: issue_priority_updated notified_events
  98. def test_create_should_send_email_notification_with_issue_priority_updated
  99. issue = Issue.first
  100. user = User.first
  101. issue.init_journal(user, issue)
  102. issue.priority = IssuePriority.last
  103. with_settings :notified_events => %w(issue_priority_updated) do
  104. assert issue.save
  105. end
  106. assert_equal 1, ActionMailer::Base.deliveries.size
  107. end
  108. def test_create_should_not_send_email_notification_without_issue_priority_updated
  109. issue = Issue.first
  110. user = User.first
  111. issue.init_journal(user, issue)
  112. issue.priority = IssuePriority.last
  113. with_settings :notified_events => [] do
  114. assert issue.save
  115. end
  116. assert_equal 0, ActionMailer::Base.deliveries.size
  117. end
  118. end