Index: app/controllers/settings_controller.rb
===================================================================
--- app/controllers/settings_controller.rb (revision 1524)
+++ app/controllers/settings_controller.rb (working copy)
@@ -25,7 +25,7 @@
end
def edit
- @notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted)
+ @notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted message_edited)
if request.post? && params[:settings] && params[:settings].is_a?(Hash)
settings = (params[:settings] || {}).dup.symbolize_keys
settings.each do |name, value|
Index: app/models/message_observer.rb
===================================================================
--- app/models/message_observer.rb (revision 1524)
+++ app/models/message_observer.rb (working copy)
@@ -17,6 +17,14 @@
class MessageObserver < ActiveRecord::Observer
def after_create(message)
+ send_for_event(message,'posted')
+ end
+
+ def after_save(message)
+ send_for_event(message,'edited')
+ end
+
+ def send_for_event(message,event)
# send notification to the authors of the thread
recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author && m.author.active?}
# send notification to the board watchers
@@ -24,6 +32,6 @@
# send notification to project members who want to be notified
recipients += message.board.project.recipients
recipients = recipients.compact.uniq
- Mailer.deliver_message_posted(message, recipients) if !recipients.empty? && Setting.notified_events.include?('message_posted')
+ Mailer.deliver_message_posted(message, recipients) if !recipients.empty? && Setting.notified_events.include?("message_#{event}")
end
end
Index: test/functional/messages_controller_test.rb
===================================================================
--- test/functional/messages_controller_test.rb (revision 1524)
+++ test/functional/messages_controller_test.rb (working copy)
@@ -86,6 +86,8 @@
def test_post_edit
@request.session[:user_id] = 2
+ Setting.notified_events << 'message_edited'
+
post :edit, :board_id => 1, :id => 1,
:message => { :subject => 'New subject',
:content => 'New body'}
@@ -93,6 +95,19 @@
message = Message.find(1)
assert_equal 'New subject', message.subject
assert_equal 'New body', message.content
+
+
+
+
+ mail = ActionMailer::Base.deliveries.last
+ assert_kind_of TMail::Mail, mail
+ assert_equal "[#{message.board.project.name} - #{message.board.name}] New subject", mail.subject
+ assert mail.body.include?('New body')
+ # author
+ assert mail.bcc.include?('jsmith@somenet.foo')
+ # project member
+ assert mail.bcc.include?('dlopper@somenet.foo')
+
end
def test_reply