journal_observer_test.rb
139 lines
| 4.4 KiB
| text/x-ruby
|
RubyLexer
|
r5482 | # Redmine - project management software | ||
|
r9453 | # Copyright (C) 2006-2012 Jean-Philippe Lang | ||
|
r4107 | # | ||
# 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. | ||||
|
r5687 | # | ||
|
r4107 | # 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. | ||||
|
r5687 | # | ||
|
r4107 | # 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. | ||||
|
r4395 | require File.expand_path('../../test_helper', __FILE__) | ||
|
r4107 | |||
class JournalObserverTest < ActiveSupport::TestCase | ||||
|
r10564 | fixtures :issues, :issue_statuses, :journals, :journal_details, :projects, | ||
:projects_trackers, :trackers, :enabled_modules, :enumerations, | ||||
:users, :roles | ||||
|
r4107 | |||
def setup | ||||
ActionMailer::Base.deliveries.clear | ||||
@journal = Journal.find 1 | ||||
end | ||||
# context: issue_updated notified_events | ||||
def test_create_should_send_email_notification_with_issue_updated | ||||
|
r10701 | issue = Issue.first | ||
user = User.first | ||||
|
r4107 | journal = issue.init_journal(user, issue) | ||
|
r9766 | with_settings :notified_events => %w(issue_updated) do | ||
assert journal.save | ||||
end | ||||
|
r4107 | assert_equal 1, ActionMailer::Base.deliveries.size | ||
end | ||||
|
r5687 | |||
|
r5482 | def test_create_should_not_send_email_notification_with_notify_set_to_false | ||
|
r10701 | issue = Issue.first | ||
user = User.first | ||||
|
r5482 | journal = issue.init_journal(user, issue) | ||
journal.notify = false | ||||
|
r5687 | |||
|
r9766 | with_settings :notified_events => %w(issue_updated) do | ||
assert journal.save | ||||
end | ||||
|
r5482 | assert_equal 0, ActionMailer::Base.deliveries.size | ||
end | ||||
|
r4107 | |||
def test_create_should_not_send_email_notification_without_issue_updated | ||||
|
r10701 | issue = Issue.first | ||
user = User.first | ||||
|
r4107 | journal = issue.init_journal(user, issue) | ||
|
r9766 | with_settings :notified_events => [] do | ||
assert journal.save | ||||
end | ||||
|
r4107 | assert_equal 0, ActionMailer::Base.deliveries.size | ||
end | ||||
# context: issue_note_added notified_events | ||||
def test_create_should_send_email_notification_with_issue_note_added | ||||
|
r10701 | issue = Issue.first | ||
user = User.first | ||||
|
r4107 | journal = issue.init_journal(user, issue) | ||
journal.notes = 'This update has a note' | ||||
|
r9766 | with_settings :notified_events => %w(issue_note_added) do | ||
assert journal.save | ||||
end | ||||
|
r4107 | assert_equal 1, ActionMailer::Base.deliveries.size | ||
end | ||||
def test_create_should_not_send_email_notification_without_issue_note_added | ||||
|
r10701 | issue = Issue.first | ||
user = User.first | ||||
|
r4107 | journal = issue.init_journal(user, issue) | ||
journal.notes = 'This update has a note' | ||||
|
r5687 | |||
|
r9766 | with_settings :notified_events => [] do | ||
assert journal.save | ||||
end | ||||
|
r4107 | assert_equal 0, ActionMailer::Base.deliveries.size | ||
end | ||||
# context: issue_status_updated notified_events | ||||
def test_create_should_send_email_notification_with_issue_status_updated | ||||
|
r10701 | issue = Issue.first | ||
user = User.first | ||||
|
r4107 | issue.init_journal(user, issue) | ||
issue.status = IssueStatus.last | ||||
|
r9766 | with_settings :notified_events => %w(issue_status_updated) do | ||
assert issue.save | ||||
end | ||||
|
r4107 | assert_equal 1, ActionMailer::Base.deliveries.size | ||
end | ||||
def test_create_should_not_send_email_notification_without_issue_status_updated | ||||
|
r10701 | issue = Issue.first | ||
user = User.first | ||||
|
r4107 | issue.init_journal(user, issue) | ||
issue.status = IssueStatus.last | ||||
|
r5687 | |||
|
r9766 | with_settings :notified_events => [] do | ||
assert issue.save | ||||
end | ||||
|
r4107 | assert_equal 0, ActionMailer::Base.deliveries.size | ||
end | ||||
# context: issue_priority_updated notified_events | ||||
def test_create_should_send_email_notification_with_issue_priority_updated | ||||
|
r10701 | issue = Issue.first | ||
user = User.first | ||||
|
r4107 | issue.init_journal(user, issue) | ||
issue.priority = IssuePriority.last | ||||
|
r9766 | with_settings :notified_events => %w(issue_priority_updated) do | ||
assert issue.save | ||||
end | ||||
|
r4107 | assert_equal 1, ActionMailer::Base.deliveries.size | ||
end | ||||
def test_create_should_not_send_email_notification_without_issue_priority_updated | ||||
|
r10701 | issue = Issue.first | ||
user = User.first | ||||
|
r4107 | issue.init_journal(user, issue) | ||
issue.priority = IssuePriority.last | ||||
|
r5687 | |||
|
r9766 | with_settings :notified_events => [] do | ||
assert issue.save | ||||
end | ||||
|
r4107 | assert_equal 0, ActionMailer::Base.deliveries.size | ||
end | ||||
end | ||||