##// END OF EJS Templates
Notify project members when a message is posted if they want to receive notifications for everything on the project (#1079)....
Jean-Philippe Lang -
r1353:e55c1d82e633
parent child
Show More
@@ -1,27 +1,29
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 class MessageObserver < ActiveRecord::Observer
19 19 def after_create(message)
20 20 # send notification to the authors of the thread
21 21 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author && m.author.active?}
22 22 # send notification to the board watchers
23 23 recipients += message.board.watcher_recipients
24 # send notification to project members who want to be notified
25 recipients += message.board.project.recipients
24 26 recipients = recipients.compact.uniq
25 27 Mailer.deliver_message_posted(message, recipients) if !recipients.empty? && Setting.notified_events.include?('message_posted')
26 28 end
27 29 end
@@ -1,99 +1,111
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'messages_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class MessagesController; def rescue_action(e) raise e end; end
23 23
24 24 class MessagesControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :users, :members, :roles, :boards, :messages, :enabled_modules
26 26
27 27 def setup
28 28 @controller = MessagesController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_show
35 35 get :show, :board_id => 1, :id => 1
36 36 assert_response :success
37 37 assert_template 'show'
38 38 assert_not_nil assigns(:board)
39 39 assert_not_nil assigns(:project)
40 40 assert_not_nil assigns(:topic)
41 41 end
42 42
43 43 def test_show_message_not_found
44 44 get :show, :board_id => 1, :id => 99999
45 45 assert_response 404
46 46 end
47 47
48 48 def test_get_new
49 49 @request.session[:user_id] = 2
50 50 get :new, :board_id => 1
51 51 assert_response :success
52 52 assert_template 'new'
53 53 end
54 54
55 55 def test_post_new
56 56 @request.session[:user_id] = 2
57 ActionMailer::Base.deliveries.clear
58 Setting.notified_events << 'message_posted'
59
57 60 post :new, :board_id => 1,
58 61 :message => { :subject => 'Test created message',
59 62 :content => 'Message body'}
60 63 assert_redirected_to 'messages/show'
61 64 message = Message.find_by_subject('Test created message')
62 65 assert_not_nil message
63 66 assert_equal 'Message body', message.content
64 67 assert_equal 2, message.author_id
65 68 assert_equal 1, message.board_id
69
70 mail = ActionMailer::Base.deliveries.last
71 assert_kind_of TMail::Mail, mail
72 assert_equal "[#{message.board.project.name} - #{message.board.name}] Test created message", mail.subject
73 assert mail.body.include?('Message body')
74 # author
75 assert mail.bcc.include?('jsmith@somenet.foo')
76 # project member
77 assert mail.bcc.include?('dlopper@somenet.foo')
66 78 end
67 79
68 80 def test_get_edit
69 81 @request.session[:user_id] = 2
70 82 get :edit, :board_id => 1, :id => 1
71 83 assert_response :success
72 84 assert_template 'edit'
73 85 end
74 86
75 87 def test_post_edit
76 88 @request.session[:user_id] = 2
77 89 post :edit, :board_id => 1, :id => 1,
78 90 :message => { :subject => 'New subject',
79 91 :content => 'New body'}
80 92 assert_redirected_to 'messages/show'
81 93 message = Message.find(1)
82 94 assert_equal 'New subject', message.subject
83 95 assert_equal 'New body', message.content
84 96 end
85 97
86 98 def test_reply
87 99 @request.session[:user_id] = 2
88 100 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
89 101 assert_redirected_to 'messages/show'
90 102 assert Message.find_by_subject('Test reply')
91 103 end
92 104
93 105 def test_destroy_topic
94 106 @request.session[:user_id] = 2
95 107 post :destroy, :board_id => 1, :id => 1
96 108 assert_redirected_to 'boards/show'
97 109 assert_nil Message.find_by_id(1)
98 110 end
99 111 end
General Comments 0
You need to be logged in to leave comments. Login now