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)
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)
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')
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
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
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