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