To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 7e / 7e2f3b607d692519463808260150f029a9664509.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (4.48 KB)

1 1296:038ba2d95de8 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2012  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.expand_path('../../test_helper', __FILE__)
19
20
class JournalObserverTest < ActiveSupport::TestCase
21
  fixtures :issues, :issue_statuses, :journals, :journal_details, :projects,
22
           :projects_trackers, :trackers, :enabled_modules, :enumerations,
23
           :users, :roles
24
25
  def setup
26
    ActionMailer::Base.deliveries.clear
27
    @journal = Journal.find 1
28
  end
29
30
  # context: issue_updated notified_events
31
  def test_create_should_send_email_notification_with_issue_updated
32
    issue = Issue.find(:first)
33
    user = User.find(:first)
34
    journal = issue.init_journal(user, issue)
35
36
    with_settings :notified_events => %w(issue_updated) do
37
      assert journal.save
38
    end
39
    assert_equal 1, ActionMailer::Base.deliveries.size
40
  end
41
42
  def test_create_should_not_send_email_notification_with_notify_set_to_false
43
    issue = Issue.find(:first)
44
    user = User.find(:first)
45
    journal = issue.init_journal(user, issue)
46
    journal.notify = false
47
48
    with_settings :notified_events => %w(issue_updated) do
49
      assert journal.save
50
    end
51
    assert_equal 0, ActionMailer::Base.deliveries.size
52
  end
53
54
  def test_create_should_not_send_email_notification_without_issue_updated
55
    issue = Issue.find(:first)
56
    user = User.find(:first)
57
    journal = issue.init_journal(user, issue)
58
59
    with_settings :notified_events => [] do
60
      assert journal.save
61
    end
62
    assert_equal 0, ActionMailer::Base.deliveries.size
63
  end
64
65
  # context: issue_note_added notified_events
66
  def test_create_should_send_email_notification_with_issue_note_added
67
    issue = Issue.find(:first)
68
    user = User.find(:first)
69
    journal = issue.init_journal(user, issue)
70
    journal.notes = 'This update has a note'
71
72
    with_settings :notified_events => %w(issue_note_added) do
73
      assert journal.save
74
    end
75
    assert_equal 1, ActionMailer::Base.deliveries.size
76
  end
77
78
  def test_create_should_not_send_email_notification_without_issue_note_added
79
    issue = Issue.find(:first)
80
    user = User.find(:first)
81
    journal = issue.init_journal(user, issue)
82
    journal.notes = 'This update has a note'
83
84
    with_settings :notified_events => [] do
85
      assert journal.save
86
    end
87
    assert_equal 0, ActionMailer::Base.deliveries.size
88
  end
89
90
  # context: issue_status_updated notified_events
91
  def test_create_should_send_email_notification_with_issue_status_updated
92
    issue = Issue.find(:first)
93
    user = User.find(:first)
94
    issue.init_journal(user, issue)
95
    issue.status = IssueStatus.last
96
97
    with_settings :notified_events => %w(issue_status_updated) do
98
      assert issue.save
99
    end
100
    assert_equal 1, ActionMailer::Base.deliveries.size
101
  end
102
103
  def test_create_should_not_send_email_notification_without_issue_status_updated
104
    issue = Issue.find(:first)
105
    user = User.find(:first)
106
    issue.init_journal(user, issue)
107
    issue.status = IssueStatus.last
108
109
    with_settings :notified_events => [] do
110
      assert issue.save
111
    end
112
    assert_equal 0, ActionMailer::Base.deliveries.size
113
  end
114
115
  # context: issue_priority_updated notified_events
116
  def test_create_should_send_email_notification_with_issue_priority_updated
117
    issue = Issue.find(:first)
118
    user = User.find(:first)
119
    issue.init_journal(user, issue)
120
    issue.priority = IssuePriority.last
121
122
    with_settings :notified_events => %w(issue_priority_updated) do
123
      assert issue.save
124
    end
125
    assert_equal 1, ActionMailer::Base.deliveries.size
126
  end
127
128
  def test_create_should_not_send_email_notification_without_issue_priority_updated
129
    issue = Issue.find(:first)
130
    user = User.find(:first)
131
    issue.init_journal(user, issue)
132
    issue.priority = IssuePriority.last
133
134
    with_settings :notified_events => [] do
135
      assert issue.save
136
    end
137
    assert_equal 0, ActionMailer::Base.deliveries.size
138
  end
139
end