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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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, :members, :member_roles
  22. def setup
  23. User.current = nil
  24. ActionMailer::Base.deliveries.clear
  25. @journal = Journal.find 1
  26. end
  27. # context: issue_updated notified_events
  28. def test_create_should_send_email_notification_with_issue_updated
  29. issue = Issue.first
  30. user = User.first
  31. journal = issue.init_journal(user, "some notes")
  32. with_settings :notified_events => %w(issue_updated) do
  33. assert journal.save
  34. end
  35. assert_equal 2, ActionMailer::Base.deliveries.size
  36. end
  37. def test_create_should_not_send_email_notification_with_notify_set_to_false
  38. issue = Issue.first
  39. user = User.first
  40. journal = issue.init_journal(user, "some notes")
  41. journal.notify = false
  42. with_settings :notified_events => %w(issue_updated) do
  43. assert journal.save
  44. end
  45. assert_equal 0, ActionMailer::Base.deliveries.size
  46. end
  47. def test_create_should_not_send_email_notification_without_issue_updated
  48. issue = Issue.first
  49. user = User.first
  50. journal = issue.init_journal(user, "some notes")
  51. with_settings :notified_events => [] do
  52. assert journal.save
  53. end
  54. assert_equal 0, ActionMailer::Base.deliveries.size
  55. end
  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)
  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 2, 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)
  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. def test_create_should_send_email_notification_with_issue_status_updated
  77. issue = Issue.first
  78. user = User.first
  79. issue.init_journal(user)
  80. issue.status = IssueStatus.last
  81. with_settings :notified_events => %w(issue_status_updated) do
  82. assert issue.save
  83. end
  84. assert_equal 2, ActionMailer::Base.deliveries.size
  85. end
  86. def test_create_should_not_send_email_notification_without_issue_status_updated
  87. issue = Issue.first
  88. user = User.first
  89. issue.init_journal(user)
  90. issue.status = IssueStatus.last
  91. with_settings :notified_events => [] do
  92. assert issue.save
  93. end
  94. assert_equal 0, ActionMailer::Base.deliveries.size
  95. end
  96. def test_create_without_status_update_should_not_send_email_notification_with_issue_status_updated
  97. issue = Issue.first
  98. user = User.first
  99. issue.init_journal(user)
  100. issue.subject = "No status update"
  101. with_settings :notified_events => %w(issue_status_updated) do
  102. assert issue.save
  103. end
  104. assert_equal 0, ActionMailer::Base.deliveries.size
  105. end
  106. def test_create_should_send_email_notification_with_issue_assignee_updated
  107. issue = Issue.generate!(:assigned_to_id => 2)
  108. ActionMailer::Base.deliveries.clear
  109. user = User.first
  110. issue.init_journal(user)
  111. issue.assigned_to = User.find(3)
  112. with_settings :notified_events => %w(issue_assigned_to_updated) do
  113. assert issue.save
  114. end
  115. assert_equal 2, ActionMailer::Base.deliveries.size
  116. end
  117. def test_create_should_not_send_email_notification_without_issue_assignee_updated
  118. issue = Issue.generate!(:assigned_to_id => 2)
  119. ActionMailer::Base.deliveries.clear
  120. user = User.first
  121. issue.init_journal(user)
  122. issue.assigned_to = User.find(3)
  123. with_settings :notified_events => [] do
  124. assert issue.save
  125. end
  126. assert_equal 0, ActionMailer::Base.deliveries.size
  127. end
  128. def test_create_should_send_email_notification_with_issue_priority_updated
  129. issue = Issue.first
  130. user = User.first
  131. issue.init_journal(user)
  132. issue.priority = IssuePriority.last
  133. with_settings :notified_events => %w(issue_priority_updated) do
  134. assert issue.save
  135. end
  136. assert_equal 2, ActionMailer::Base.deliveries.size
  137. end
  138. def test_create_should_not_send_email_notification_without_issue_priority_updated
  139. issue = Issue.first
  140. user = User.first
  141. issue.init_journal(user)
  142. issue.priority = IssuePriority.last
  143. with_settings :notified_events => [] do
  144. assert issue.save
  145. end
  146. assert_equal 0, ActionMailer::Base.deliveries.size
  147. end
  148. end