summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/journal.rb14
-rw-r--r--lib/redmine/notifiable.rb1
-rw-r--r--test/unit/journal_observer_test.rb40
-rw-r--r--test/unit/lib/redmine/notifiable_test.rb2
4 files changed, 50 insertions, 7 deletions
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 10ebf8ee6..5d10ef83f 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -80,15 +80,20 @@ class Journal < ActiveRecord::Base
end
end
+ # Returns the JournalDetail for the given attribute, or nil if the attribute
+ # was not updated
+ def detail_for_attribute(attribute)
+ details.detect {|detail| detail.prop_key == attribute}
+ end
+
# Returns the new status if the journal contains a status change, otherwise nil
def new_status
- c = details.detect {|detail| detail.prop_key == 'status_id'}
- (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
+ s = new_value_for('status_id')
+ s ? IssueStatus.find_by_id(s.to_i) : nil
end
def new_value_for(prop)
- c = details.detect {|detail| detail.prop_key == prop}
- c ? c.value : nil
+ detail_for_attribute(prop).try(:value)
end
def editable_by?(usr)
@@ -185,6 +190,7 @@ class Journal < ActiveRecord::Base
if notify? && (Setting.notified_events.include?('issue_updated') ||
(Setting.notified_events.include?('issue_note_added') && notes.present?) ||
(Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
+ (Setting.notified_events.include?('issue_assigned_to_updated') && new_value_for('assigned_to_id').present?) ||
(Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?)
)
Mailer.deliver_issue_edit(self)
diff --git a/lib/redmine/notifiable.rb b/lib/redmine/notifiable.rb
index 88ca9d776..41fd736e6 100644
--- a/lib/redmine/notifiable.rb
+++ b/lib/redmine/notifiable.rb
@@ -12,6 +12,7 @@ module Redmine
notifications << Notifiable.new('issue_updated')
notifications << Notifiable.new('issue_note_added', 'issue_updated')
notifications << Notifiable.new('issue_status_updated', 'issue_updated')
+ notifications << Notifiable.new('issue_assigned_to_updated', 'issue_updated')
notifications << Notifiable.new('issue_priority_updated', 'issue_updated')
notifications << Notifiable.new('news_added')
notifications << Notifiable.new('news_comment_added')
diff --git a/test/unit/journal_observer_test.rb b/test/unit/journal_observer_test.rb
index 50c76028e..eabd2779d 100644
--- a/test/unit/journal_observer_test.rb
+++ b/test/unit/journal_observer_test.rb
@@ -87,7 +87,6 @@ class JournalObserverTest < ActiveSupport::TestCase
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
issue = Issue.first
user = User.first
@@ -112,7 +111,44 @@ class JournalObserverTest < ActiveSupport::TestCase
assert_equal 0, ActionMailer::Base.deliveries.size
end
- # context: issue_priority_updated notified_events
+ def test_create_without_status_update_should_not_send_email_notification_with_issue_status_updated
+ issue = Issue.first
+ user = User.first
+ issue.init_journal(user, issue)
+ 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
+ issue.init_journal(user, issue)
+ issue.assigned_to = User.find(3)
+
+ with_settings :notified_events => %w(issue_assigned_to_updated) do
+ assert issue.save
+ end
+ assert_equal 1, ActionMailer::Base.deliveries.size
+ 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
+ issue.init_journal(user, issue)
+ issue.assigned_to = User.find(3)
+
+ with_settings :notified_events => [] do
+ assert issue.save
+ end
+ assert_equal 0, ActionMailer::Base.deliveries.size
+ end
+
def test_create_should_send_email_notification_with_issue_priority_updated
issue = Issue.first
user = User.first
diff --git a/test/unit/lib/redmine/notifiable_test.rb b/test/unit/lib/redmine/notifiable_test.rb
index f1d9149c7..18e4de04e 100644
--- a/test/unit/lib/redmine/notifiable_test.rb
+++ b/test/unit/lib/redmine/notifiable_test.rb
@@ -24,7 +24,7 @@ class Redmine::NotifiableTest < ActiveSupport::TestCase
def test_all
assert_equal 12, Redmine::Notifiable.all.length
- %w(issue_added issue_updated issue_note_added issue_status_updated issue_priority_updated news_added news_comment_added document_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable|
+ %w(issue_added issue_updated issue_note_added issue_status_updated issue_status_updated issue_priority_updated news_added news_comment_added document_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable|
assert Redmine::Notifiable.all.collect(&:name).include?(notifiable), "missing #{notifiable}"
end
end