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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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, :email_addresses, :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, "some notes")
  31. with_settings :notified_events => %w(issue_updated) do
  32. assert journal.save
  33. end
  34. assert_equal 2, 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, "some notes")
  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, "some notes")
  50. with_settings :notified_events => [] do
  51. assert journal.save
  52. end
  53. assert_equal 0, ActionMailer::Base.deliveries.size
  54. end
  55. def test_create_should_send_email_notification_with_issue_note_added
  56. issue = Issue.first
  57. user = User.first
  58. journal = issue.init_journal(user)
  59. journal.notes = 'This update has a note'
  60. with_settings :notified_events => %w(issue_note_added) do
  61. assert journal.save
  62. end
  63. assert_equal 2, ActionMailer::Base.deliveries.size
  64. end
  65. def test_create_should_not_send_email_notification_without_issue_note_added
  66. issue = Issue.first
  67. user = User.first
  68. journal = issue.init_journal(user)
  69. journal.notes = 'This update has a note'
  70. with_settings :notified_events => [] do
  71. assert journal.save
  72. end
  73. assert_equal 0, ActionMailer::Base.deliveries.size
  74. end
  75. def test_create_should_send_email_notification_with_issue_status_updated
  76. issue = Issue.first
  77. user = User.first
  78. issue.init_journal(user)
  79. issue.status = IssueStatus.last
  80. with_settings :notified_events => %w(issue_status_updated) do
  81. assert issue.save
  82. end
  83. assert_equal 2, ActionMailer::Base.deliveries.size
  84. end
  85. def test_create_should_not_send_email_notification_without_issue_status_updated
  86. issue = Issue.first
  87. user = User.first
  88. issue.init_journal(user)
  89. issue.status = IssueStatus.last
  90. with_settings :notified_events => [] do
  91. assert issue.save
  92. end
  93. assert_equal 0, ActionMailer::Base.deliveries.size
  94. end
  95. def test_create_without_status_update_should_not_send_email_notification_with_issue_status_updated
  96. issue = Issue.first
  97. user = User.first
  98. issue.init_journal(user)
  99. issue.subject = "No status update"
  100. with_settings :notified_events => %w(issue_status_updated) do
  101. assert issue.save
  102. end
  103. assert_equal 0, ActionMailer::Base.deliveries.size
  104. end
  105. def test_create_should_send_email_notification_with_issue_assignee_updated
  106. issue = Issue.generate!(:assigned_to_id => 2)
  107. ActionMailer::Base.deliveries.clear
  108. user = User.first
  109. issue.init_journal(user)
  110. issue.assigned_to = User.find(3)
  111. with_settings :notified_events => %w(issue_assigned_to_updated) do
  112. assert issue.save
  113. end
  114. assert_equal 2, ActionMailer::Base.deliveries.size
  115. end
  116. def test_create_should_not_send_email_notification_without_issue_assignee_updated
  117. issue = Issue.generate!(:assigned_to_id => 2)
  118. ActionMailer::Base.deliveries.clear
  119. user = User.first
  120. issue.init_journal(user)
  121. issue.assigned_to = User.find(3)
  122. with_settings :notified_events => [] do
  123. assert issue.save
  124. end
  125. assert_equal 0, ActionMailer::Base.deliveries.size
  126. end
  127. def test_create_should_send_email_notification_with_issue_priority_updated
  128. issue = Issue.first
  129. user = User.first
  130. issue.init_journal(user)
  131. issue.priority = IssuePriority.last
  132. with_settings :notified_events => %w(issue_priority_updated) do
  133. assert issue.save
  134. end
  135. assert_equal 2, ActionMailer::Base.deliveries.size
  136. end
  137. def test_create_should_not_send_email_notification_without_issue_priority_updated
  138. issue = Issue.first
  139. user = User.first
  140. issue.init_journal(user)
  141. issue.priority = IssuePriority.last
  142. with_settings :notified_events => [] do
  143. assert issue.save
  144. end
  145. assert_equal 0, ActionMailer::Base.deliveries.size
  146. end
  147. end