@@ -1,175 +1,174 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class JournalObserverTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :issues, :issue_statuses, :journals, :journal_details, :projects, |
|
22 | 22 | :projects_trackers, :trackers, :enabled_modules, :enumerations, |
|
23 | 23 | :users, :roles |
|
24 | 24 | |
|
25 | 25 | def setup |
|
26 | 26 | ActionMailer::Base.deliveries.clear |
|
27 | 27 | @journal = Journal.find 1 |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | # context: issue_updated notified_events |
|
31 | 31 | def test_create_should_send_email_notification_with_issue_updated |
|
32 | 32 | issue = Issue.first |
|
33 | 33 | user = User.first |
|
34 |
journal = issue.init_journal(user, |
|
|
34 | journal = issue.init_journal(user, "some notes") | |
|
35 | 35 | |
|
36 | 36 | with_settings :notified_events => %w(issue_updated) do |
|
37 | 37 | assert journal.save |
|
38 | 38 | end |
|
39 | 39 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def test_create_should_not_send_email_notification_with_notify_set_to_false |
|
43 | 43 | issue = Issue.first |
|
44 | 44 | user = User.first |
|
45 |
journal = issue.init_journal(user, |
|
|
45 | journal = issue.init_journal(user, "some notes") | |
|
46 | 46 | journal.notify = false |
|
47 | 47 | |
|
48 | 48 | with_settings :notified_events => %w(issue_updated) do |
|
49 | 49 | assert journal.save |
|
50 | 50 | end |
|
51 | 51 | assert_equal 0, ActionMailer::Base.deliveries.size |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def test_create_should_not_send_email_notification_without_issue_updated |
|
55 | 55 | issue = Issue.first |
|
56 | 56 | user = User.first |
|
57 |
journal = issue.init_journal(user, |
|
|
57 | journal = issue.init_journal(user, "some notes") | |
|
58 | 58 | |
|
59 | 59 | with_settings :notified_events => [] do |
|
60 | 60 | assert journal.save |
|
61 | 61 | end |
|
62 | 62 | assert_equal 0, ActionMailer::Base.deliveries.size |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | # context: issue_note_added notified_events | |
|
66 | 65 | def test_create_should_send_email_notification_with_issue_note_added |
|
67 | 66 | issue = Issue.first |
|
68 | 67 | user = User.first |
|
69 |
journal = issue.init_journal(user |
|
|
68 | journal = issue.init_journal(user) | |
|
70 | 69 | journal.notes = 'This update has a note' |
|
71 | 70 | |
|
72 | 71 | with_settings :notified_events => %w(issue_note_added) do |
|
73 | 72 | assert journal.save |
|
74 | 73 | end |
|
75 | 74 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
76 | 75 | end |
|
77 | 76 | |
|
78 | 77 | def test_create_should_not_send_email_notification_without_issue_note_added |
|
79 | 78 | issue = Issue.first |
|
80 | 79 | user = User.first |
|
81 |
journal = issue.init_journal(user |
|
|
80 | journal = issue.init_journal(user) | |
|
82 | 81 | journal.notes = 'This update has a note' |
|
83 | 82 | |
|
84 | 83 | with_settings :notified_events => [] do |
|
85 | 84 | assert journal.save |
|
86 | 85 | end |
|
87 | 86 | assert_equal 0, ActionMailer::Base.deliveries.size |
|
88 | 87 | end |
|
89 | 88 | |
|
90 | 89 | def test_create_should_send_email_notification_with_issue_status_updated |
|
91 | 90 | issue = Issue.first |
|
92 | 91 | user = User.first |
|
93 |
issue.init_journal(user |
|
|
92 | issue.init_journal(user) | |
|
94 | 93 | issue.status = IssueStatus.last |
|
95 | 94 | |
|
96 | 95 | with_settings :notified_events => %w(issue_status_updated) do |
|
97 | 96 | assert issue.save |
|
98 | 97 | end |
|
99 | 98 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
100 | 99 | end |
|
101 | 100 | |
|
102 | 101 | def test_create_should_not_send_email_notification_without_issue_status_updated |
|
103 | 102 | issue = Issue.first |
|
104 | 103 | user = User.first |
|
105 |
issue.init_journal(user |
|
|
104 | issue.init_journal(user) | |
|
106 | 105 | issue.status = IssueStatus.last |
|
107 | 106 | |
|
108 | 107 | with_settings :notified_events => [] do |
|
109 | 108 | assert issue.save |
|
110 | 109 | end |
|
111 | 110 | assert_equal 0, ActionMailer::Base.deliveries.size |
|
112 | 111 | end |
|
113 | 112 | |
|
114 | 113 | def test_create_without_status_update_should_not_send_email_notification_with_issue_status_updated |
|
115 | 114 | issue = Issue.first |
|
116 | 115 | user = User.first |
|
117 |
issue.init_journal(user |
|
|
116 | issue.init_journal(user) | |
|
118 | 117 | issue.subject = "No status update" |
|
119 | 118 | |
|
120 | 119 | with_settings :notified_events => %w(issue_status_updated) do |
|
121 | 120 | assert issue.save |
|
122 | 121 | end |
|
123 | 122 | assert_equal 0, ActionMailer::Base.deliveries.size |
|
124 | 123 | end |
|
125 | 124 | |
|
126 | 125 | def test_create_should_send_email_notification_with_issue_assignee_updated |
|
127 | 126 | issue = Issue.generate!(:assigned_to_id => 2) |
|
128 | 127 | ActionMailer::Base.deliveries.clear |
|
129 | 128 | user = User.first |
|
130 |
issue.init_journal(user |
|
|
129 | issue.init_journal(user) | |
|
131 | 130 | issue.assigned_to = User.find(3) |
|
132 | 131 | |
|
133 | 132 | with_settings :notified_events => %w(issue_assigned_to_updated) do |
|
134 | 133 | assert issue.save |
|
135 | 134 | end |
|
136 | 135 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
137 | 136 | end |
|
138 | 137 | |
|
139 | 138 | def test_create_should_not_send_email_notification_without_issue_assignee_updated |
|
140 | 139 | issue = Issue.generate!(:assigned_to_id => 2) |
|
141 | 140 | ActionMailer::Base.deliveries.clear |
|
142 | 141 | user = User.first |
|
143 |
issue.init_journal(user |
|
|
142 | issue.init_journal(user) | |
|
144 | 143 | issue.assigned_to = User.find(3) |
|
145 | 144 | |
|
146 | 145 | with_settings :notified_events => [] do |
|
147 | 146 | assert issue.save |
|
148 | 147 | end |
|
149 | 148 | assert_equal 0, ActionMailer::Base.deliveries.size |
|
150 | 149 | end |
|
151 | 150 | |
|
152 | 151 | def test_create_should_send_email_notification_with_issue_priority_updated |
|
153 | 152 | issue = Issue.first |
|
154 | 153 | user = User.first |
|
155 |
issue.init_journal(user |
|
|
154 | issue.init_journal(user) | |
|
156 | 155 | issue.priority = IssuePriority.last |
|
157 | 156 | |
|
158 | 157 | with_settings :notified_events => %w(issue_priority_updated) do |
|
159 | 158 | assert issue.save |
|
160 | 159 | end |
|
161 | 160 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
162 | 161 | end |
|
163 | 162 | |
|
164 | 163 | def test_create_should_not_send_email_notification_without_issue_priority_updated |
|
165 | 164 | issue = Issue.first |
|
166 | 165 | user = User.first |
|
167 |
issue.init_journal(user |
|
|
166 | issue.init_journal(user) | |
|
168 | 167 | issue.priority = IssuePriority.last |
|
169 | 168 | |
|
170 | 169 | with_settings :notified_events => [] do |
|
171 | 170 | assert issue.save |
|
172 | 171 | end |
|
173 | 172 | assert_equal 0, ActionMailer::Base.deliveries.size |
|
174 | 173 | end |
|
175 | 174 | end |
General Comments 0
You need to be logged in to leave comments.
Login now