@@ -0,0 +1,118 | |||||
|
1 | # redMine - project management software | |||
|
2 | # Copyright (C) 2006-2009 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 | ||||
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |||
|
19 | ||||
|
20 | class JournalObserverTest < ActiveSupport::TestCase | |||
|
21 | fixtures :issues, :issue_statuses, :journals, :journal_details | |||
|
22 | ||||
|
23 | def setup | |||
|
24 | ActionMailer::Base.deliveries.clear | |||
|
25 | @journal = Journal.find 1 | |||
|
26 | end | |||
|
27 | ||||
|
28 | # context: issue_updated notified_events | |||
|
29 | def test_create_should_send_email_notification_with_issue_updated | |||
|
30 | Setting.notified_events = ['issue_updated'] | |||
|
31 | issue = Issue.find(:first) | |||
|
32 | user = User.find(:first) | |||
|
33 | journal = issue.init_journal(user, issue) | |||
|
34 | ||||
|
35 | assert journal.save | |||
|
36 | assert_equal 1, ActionMailer::Base.deliveries.size | |||
|
37 | end | |||
|
38 | ||||
|
39 | def test_create_should_not_send_email_notification_without_issue_updated | |||
|
40 | Setting.notified_events = [] | |||
|
41 | issue = Issue.find(:first) | |||
|
42 | user = User.find(:first) | |||
|
43 | journal = issue.init_journal(user, issue) | |||
|
44 | ||||
|
45 | assert journal.save | |||
|
46 | assert_equal 0, ActionMailer::Base.deliveries.size | |||
|
47 | end | |||
|
48 | ||||
|
49 | # context: issue_note_added notified_events | |||
|
50 | def test_create_should_send_email_notification_with_issue_note_added | |||
|
51 | Setting.notified_events = ['issue_note_added'] | |||
|
52 | issue = Issue.find(:first) | |||
|
53 | user = User.find(:first) | |||
|
54 | journal = issue.init_journal(user, issue) | |||
|
55 | journal.notes = 'This update has a note' | |||
|
56 | ||||
|
57 | assert journal.save | |||
|
58 | assert_equal 1, ActionMailer::Base.deliveries.size | |||
|
59 | end | |||
|
60 | ||||
|
61 | def test_create_should_not_send_email_notification_without_issue_note_added | |||
|
62 | Setting.notified_events = [] | |||
|
63 | issue = Issue.find(:first) | |||
|
64 | user = User.find(:first) | |||
|
65 | journal = issue.init_journal(user, issue) | |||
|
66 | journal.notes = 'This update has a note' | |||
|
67 | ||||
|
68 | assert journal.save | |||
|
69 | assert_equal 0, ActionMailer::Base.deliveries.size | |||
|
70 | end | |||
|
71 | ||||
|
72 | # context: issue_status_updated notified_events | |||
|
73 | def test_create_should_send_email_notification_with_issue_status_updated | |||
|
74 | Setting.notified_events = ['issue_status_updated'] | |||
|
75 | issue = Issue.find(:first) | |||
|
76 | user = User.find(:first) | |||
|
77 | issue.init_journal(user, issue) | |||
|
78 | issue.status = IssueStatus.last | |||
|
79 | ||||
|
80 | assert issue.save | |||
|
81 | assert_equal 1, ActionMailer::Base.deliveries.size | |||
|
82 | end | |||
|
83 | ||||
|
84 | def test_create_should_not_send_email_notification_without_issue_status_updated | |||
|
85 | Setting.notified_events = [] | |||
|
86 | issue = Issue.find(:first) | |||
|
87 | user = User.find(:first) | |||
|
88 | issue.init_journal(user, issue) | |||
|
89 | issue.status = IssueStatus.last | |||
|
90 | ||||
|
91 | assert issue.save | |||
|
92 | assert_equal 0, ActionMailer::Base.deliveries.size | |||
|
93 | end | |||
|
94 | ||||
|
95 | # context: issue_priority_updated notified_events | |||
|
96 | def test_create_should_send_email_notification_with_issue_priority_updated | |||
|
97 | Setting.notified_events = ['issue_priority_updated'] | |||
|
98 | issue = Issue.find(:first) | |||
|
99 | user = User.find(:first) | |||
|
100 | issue.init_journal(user, issue) | |||
|
101 | issue.priority = IssuePriority.last | |||
|
102 | ||||
|
103 | assert issue.save | |||
|
104 | assert_equal 1, ActionMailer::Base.deliveries.size | |||
|
105 | end | |||
|
106 | ||||
|
107 | def test_create_should_not_send_email_notification_without_issue_priority_updated | |||
|
108 | Setting.notified_events = [] | |||
|
109 | issue = Issue.find(:first) | |||
|
110 | user = User.find(:first) | |||
|
111 | issue.init_journal(user, issue) | |||
|
112 | issue.priority = IssuePriority.last | |||
|
113 | ||||
|
114 | assert issue.save | |||
|
115 | assert_equal 0, ActionMailer::Base.deliveries.size | |||
|
116 | end | |||
|
117 | ||||
|
118 | end |
@@ -17,6 +17,11 | |||||
17 |
|
17 | |||
18 | class JournalObserver < ActiveRecord::Observer |
|
18 | class JournalObserver < ActiveRecord::Observer | |
19 | def after_create(journal) |
|
19 | def after_create(journal) | |
20 |
|
|
20 | if Setting.notified_events.include?('issue_updated') || | |
|
21 | (Setting.notified_events.include?('issue_note_added') && journal.notes.present?) || | |||
|
22 | (Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) || | |||
|
23 | (Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?) | |||
|
24 | Mailer.deliver_issue_edit(journal) | |||
|
25 | end | |||
21 | end |
|
26 | end | |
22 | end |
|
27 | end |
@@ -3,6 +3,9 module Redmine | |||||
3 | CoreNotifications = [ |
|
3 | CoreNotifications = [ | |
4 | 'issue_added', |
|
4 | 'issue_added', | |
5 | 'issue_updated', |
|
5 | 'issue_updated', | |
|
6 | 'issue_note_added', | |||
|
7 | 'issue_status_updated', | |||
|
8 | 'issue_priority_updated', | |||
6 | 'news_added', |
|
9 | 'news_added', | |
7 | 'document_added', |
|
10 | 'document_added', | |
8 | 'file_added', |
|
11 | 'file_added', |
@@ -22,10 +22,10 class Redmine::NotifiableTest < ActiveSupport::TestCase | |||||
22 | end |
|
22 | end | |
23 |
|
23 | |||
24 | def test_included_core_notifications |
|
24 | def test_included_core_notifications | |
25 |
assert_equal |
|
25 | assert_equal 11, Redmine::Notifiable::CoreNotifications.length | |
26 | Redmine::Notifiable::CoreNotifications.length |
|
26 | Redmine::Notifiable::CoreNotifications.length | |
27 |
|
27 | |||
28 | %w(issue_added issue_updated news_added document_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable| |
|
28 | %w(issue_added issue_updated issue_note_added issue_status_updated issue_priority_updated news_added document_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable| | |
29 | assert Redmine::Notifiable::CoreNotifications.include?(notifiable), "missing #{notifiable}" |
|
29 | assert Redmine::Notifiable::CoreNotifications.include?(notifiable), "missing #{notifiable}" | |
30 | end |
|
30 | end | |
31 | end |
|
31 | end |
@@ -240,6 +240,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
240 | end |
|
240 | end | |
241 |
|
241 | |||
242 | def test_add_issue_should_send_email_notification |
|
242 | def test_add_issue_should_send_email_notification | |
|
243 | Setting.notified_events = ['issue_added'] | |||
243 | ActionMailer::Base.deliveries.clear |
|
244 | ActionMailer::Base.deliveries.clear | |
244 | # This email contains: 'Project: onlinestore' |
|
245 | # This email contains: 'Project: onlinestore' | |
245 | issue = submit_email('ticket_on_given_project.eml') |
|
246 | issue = submit_email('ticket_on_given_project.eml') |
@@ -67,6 +67,7 class RepositoryTest < ActiveSupport::TestCase | |||||
67 |
|
67 | |||
68 | def test_scan_changesets_for_issue_ids |
|
68 | def test_scan_changesets_for_issue_ids | |
69 | Setting.default_language = 'en' |
|
69 | Setting.default_language = 'en' | |
|
70 | Setting.notified_events = ['issue_added','issue_updated'] | |||
70 |
|
71 | |||
71 | # choosing a status to apply to fix issues |
|
72 | # choosing a status to apply to fix issues | |
72 | Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id |
|
73 | Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id |
General Comments 0
You need to be logged in to leave comments.
Login now