2019-03-16 15:03:47 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2011-04-29 13:27:50 +00:00
|
|
|
# Redmine - project management software
|
2024-02-26 22:55:54 +00:00
|
|
|
# Copyright (C) 2006- Jean-Philippe Lang
|
2010-09-28 20:20:00 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-17 01:16:04 +00:00
|
|
|
#
|
2010-09-28 20:20:00 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
2011-05-17 01:16:04 +00:00
|
|
|
#
|
2010-09-28 20:20:00 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
2023-01-01 07:13:39 +00:00
|
|
|
require_relative '../test_helper'
|
2010-09-28 20:20:00 +00:00
|
|
|
|
|
|
|
|
class JournalObserverTest < ActiveSupport::TestCase
|
|
|
|
|
def setup
|
2018-12-16 17:23:31 +00:00
|
|
|
User.current = nil
|
2010-09-28 20:20:00 +00:00
|
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# context: issue_updated notified_events
|
|
|
|
|
def test_create_should_send_email_notification_with_issue_updated
|
2012-12-03 18:21:32 +00:00
|
|
|
issue = Issue.first
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
journal = issue.init_journal(user, "some notes")
|
2010-09-28 20:20:00 +00:00
|
|
|
|
2012-07-08 12:23:47 +00:00
|
|
|
with_settings :notified_events => %w(issue_updated) do
|
|
|
|
|
assert journal.save
|
|
|
|
|
end
|
2018-10-06 13:08:52 +00:00
|
|
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
2010-09-28 20:20:00 +00:00
|
|
|
end
|
2011-05-17 01:16:04 +00:00
|
|
|
|
2011-04-29 13:27:50 +00:00
|
|
|
def test_create_should_not_send_email_notification_with_notify_set_to_false
|
2012-12-03 18:21:32 +00:00
|
|
|
issue = Issue.first
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
journal = issue.init_journal(user, "some notes")
|
2011-04-29 13:27:50 +00:00
|
|
|
journal.notify = false
|
2011-05-17 01:16:04 +00:00
|
|
|
|
2012-07-08 12:23:47 +00:00
|
|
|
with_settings :notified_events => %w(issue_updated) do
|
|
|
|
|
assert journal.save
|
|
|
|
|
end
|
2011-04-29 13:27:50 +00:00
|
|
|
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
2010-09-28 20:20:00 +00:00
|
|
|
|
|
|
|
|
def test_create_should_not_send_email_notification_without_issue_updated
|
2012-12-03 18:21:32 +00:00
|
|
|
issue = Issue.first
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
journal = issue.init_journal(user, "some notes")
|
2010-09-28 20:20:00 +00:00
|
|
|
|
2012-07-08 12:23:47 +00:00
|
|
|
with_settings :notified_events => [] do
|
|
|
|
|
assert journal.save
|
|
|
|
|
end
|
2010-09-28 20:20:00 +00:00
|
|
|
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_should_send_email_notification_with_issue_note_added
|
2012-12-03 18:21:32 +00:00
|
|
|
issue = Issue.first
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
journal = issue.init_journal(user)
|
2010-09-28 20:20:00 +00:00
|
|
|
journal.notes = 'This update has a note'
|
|
|
|
|
|
2012-07-08 12:23:47 +00:00
|
|
|
with_settings :notified_events => %w(issue_note_added) do
|
|
|
|
|
assert journal.save
|
|
|
|
|
end
|
2018-10-06 13:08:52 +00:00
|
|
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
2010-09-28 20:20:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_should_not_send_email_notification_without_issue_note_added
|
2012-12-03 18:21:32 +00:00
|
|
|
issue = Issue.first
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
journal = issue.init_journal(user)
|
2010-09-28 20:20:00 +00:00
|
|
|
journal.notes = 'This update has a note'
|
2011-05-17 01:16:04 +00:00
|
|
|
|
2012-07-08 12:23:47 +00:00
|
|
|
with_settings :notified_events => [] do
|
|
|
|
|
assert journal.save
|
|
|
|
|
end
|
2010-09-28 20:20:00 +00:00
|
|
|
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_should_send_email_notification_with_issue_status_updated
|
2012-12-03 18:21:32 +00:00
|
|
|
issue = Issue.first
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
issue.init_journal(user)
|
2010-09-28 20:20:00 +00:00
|
|
|
issue.status = IssueStatus.last
|
|
|
|
|
|
2012-07-08 12:23:47 +00:00
|
|
|
with_settings :notified_events => %w(issue_status_updated) do
|
|
|
|
|
assert issue.save
|
|
|
|
|
end
|
2018-10-06 13:08:52 +00:00
|
|
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
2010-09-28 20:20:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_should_not_send_email_notification_without_issue_status_updated
|
2012-12-03 18:21:32 +00:00
|
|
|
issue = Issue.first
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
issue.init_journal(user)
|
2010-09-28 20:20:00 +00:00
|
|
|
issue.status = IssueStatus.last
|
2011-05-17 01:16:04 +00:00
|
|
|
|
2012-07-08 12:23:47 +00:00
|
|
|
with_settings :notified_events => [] do
|
|
|
|
|
assert issue.save
|
|
|
|
|
end
|
2010-09-28 20:20:00 +00:00
|
|
|
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
|
|
|
|
|
2014-03-17 08:19:45 +00:00
|
|
|
def test_create_without_status_update_should_not_send_email_notification_with_issue_status_updated
|
|
|
|
|
issue = Issue.first
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
issue.init_journal(user)
|
2014-03-17 08:19:45 +00:00
|
|
|
issue.subject = "No status update"
|
|
|
|
|
|
|
|
|
|
with_settings :notified_events => %w(issue_status_updated) do
|
|
|
|
|
assert issue.save
|
|
|
|
|
end
|
|
|
|
|
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_should_send_email_notification_with_issue_assignee_updated
|
|
|
|
|
issue = Issue.generate!(:assigned_to_id => 2)
|
|
|
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
issue.init_journal(user)
|
2014-03-17 08:19:45 +00:00
|
|
|
issue.assigned_to = User.find(3)
|
|
|
|
|
|
|
|
|
|
with_settings :notified_events => %w(issue_assigned_to_updated) do
|
|
|
|
|
assert issue.save
|
|
|
|
|
end
|
2018-10-06 13:08:52 +00:00
|
|
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
2014-03-17 08:19:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_should_not_send_email_notification_without_issue_assignee_updated
|
|
|
|
|
issue = Issue.generate!(:assigned_to_id => 2)
|
|
|
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
issue.init_journal(user)
|
2014-03-17 08:19:45 +00:00
|
|
|
issue.assigned_to = User.find(3)
|
|
|
|
|
|
|
|
|
|
with_settings :notified_events => [] do
|
|
|
|
|
assert issue.save
|
|
|
|
|
end
|
|
|
|
|
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
|
|
|
|
|
2010-09-28 20:20:00 +00:00
|
|
|
def test_create_should_send_email_notification_with_issue_priority_updated
|
2012-12-03 18:21:32 +00:00
|
|
|
issue = Issue.first
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
issue.init_journal(user)
|
2010-09-28 20:20:00 +00:00
|
|
|
issue.priority = IssuePriority.last
|
|
|
|
|
|
2012-07-08 12:23:47 +00:00
|
|
|
with_settings :notified_events => %w(issue_priority_updated) do
|
|
|
|
|
assert issue.save
|
|
|
|
|
end
|
2018-10-06 13:08:52 +00:00
|
|
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
2010-09-28 20:20:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_should_not_send_email_notification_without_issue_priority_updated
|
2012-12-03 18:21:32 +00:00
|
|
|
issue = Issue.first
|
|
|
|
|
user = User.first
|
2014-03-17 08:23:07 +00:00
|
|
|
issue.init_journal(user)
|
2010-09-28 20:20:00 +00:00
|
|
|
issue.priority = IssuePriority.last
|
2011-05-17 01:16:04 +00:00
|
|
|
|
2012-07-08 12:23:47 +00:00
|
|
|
with_settings :notified_events => [] do
|
|
|
|
|
assert issue.save
|
|
|
|
|
end
|
2010-09-28 20:20:00 +00:00
|
|
|
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
2019-10-05 09:46:05 +00:00
|
|
|
|
|
|
|
|
def test_create_should_send_email_notification_with_issue_fixed_version_updated
|
|
|
|
|
with_settings :notified_events => %w(issue_fixed_version_updated) do
|
|
|
|
|
user = User.find_by_login('jsmith')
|
|
|
|
|
issue = issues(:issues_001)
|
|
|
|
|
issue.init_journal(user)
|
|
|
|
|
issue.fixed_version = versions(:versions_003)
|
|
|
|
|
|
|
|
|
|
assert issue.save
|
|
|
|
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_should_not_send_email_notification_without_issue_fixed_version_updated
|
|
|
|
|
with_settings :notified_events => [] do
|
|
|
|
|
user = User.find_by_login('jsmith')
|
|
|
|
|
issue = issues(:issues_001)
|
|
|
|
|
issue.init_journal(user)
|
|
|
|
|
issue.fixed_version = versions(:versions_003)
|
|
|
|
|
|
|
|
|
|
assert issue.save
|
|
|
|
|
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-04-28 06:40:12 +00:00
|
|
|
|
|
|
|
|
def test_create_should_send_email_notification_with_issue_attachment_added
|
|
|
|
|
set_tmp_attachments_directory
|
|
|
|
|
with_settings :notified_events => %w(issue_attachment_added) do
|
|
|
|
|
user = User.find_by_login('jsmith')
|
|
|
|
|
issue = issues(:issues_001)
|
|
|
|
|
issue.init_journal(user)
|
|
|
|
|
issue.save_attachments(
|
|
|
|
|
{ 'p0' => {'file' => mock_file_with_options(:original_filename => 'upload')} }
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert issue.save
|
|
|
|
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_should_not_send_email_notification_without_issue_attachment_added
|
|
|
|
|
set_tmp_attachments_directory
|
|
|
|
|
with_settings :notified_events => [] do
|
|
|
|
|
user = User.find_by_login('jsmith')
|
|
|
|
|
issue = issues(:issues_001)
|
|
|
|
|
issue.init_journal(user)
|
|
|
|
|
issue.save_attachments(
|
|
|
|
|
{ 'p0' => {'file' => mock_file_with_options(:original_filename => 'upload')} }
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert issue.save
|
|
|
|
|
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
|
|
|
end
|
|
|
|
|
end
|
2010-09-28 20:20:00 +00:00
|
|
|
end
|