Added a check to ensure that an email was sent. Added a new email
template that sends the user the text of the reply.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/controllers/messages_controller.rb | 1 +
app/models/user_mailer.rb | 8 ++++++++
.../user_mailer/message_reply_notice.html.erb | 9 +++++++++
test/functional/messages_controller_test.rb | 16 +++++++++++++++-
4 files changed, 33 insertions(+), 1 deletions(-)
create mode 100644 app/views/user_mailer/message_reply_notice.html.erb
diff --git a/app/controllers/messages_controller.rb
b/app/controllers/messages_controller.rb
index 0cb02d5..5677d0e 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -47,6 +47,7 @@ class MessagesController < ApplicationController
respond_to do |format|
if @message.save
+ UserMailer.deliver_message_reply_notice(@reply)
flash[:message] = "Reply posted."
if @landing_page
format.html {redirect_to @landing_page}
diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb
index 9654c57..18afd18 100644
--- a/app/models/user_mailer.rb
+++ b/app/models/user_mailer.rb
@@ -109,4 +109,12 @@ class UserMailer < ActionMailer::Base
subject "Status of sprints"
body :user => user, :products => products
end
+
+ # Sends an email to a message posted that an reply was posted to their comment.
+ def message_reply_notice(reply)
+ recipients reply.reference.author.email
+ from MAIL_CONFIG[:from]
+ subject "Someone replied to your comment..."
+ body :reply => reply
+ end
end
diff --git a/app/views/user_mailer/message_reply_notice.html.erb
b/app/views/user_mailer/message_reply_notice.html.erb
new file mode 100644
index 0000000..d5e9ace
--- /dev/null
+++ b/app/views/user_mailer/message_reply_notice.html.erb
@@ -0,0 +1,9 @@
+<%= "#{@reply.reference.author.display_name}:" %>
+
+A reply has been posted in response to your posting:
+
+<%= "#{(a)reply.author.display_name} wrote:" %>
+<%= "#{(a)reply.body}" %>
+
+To view this reply, please go here: <%= message_url(@reply) %>
+To view your message, please go here: <%= message_url((a)reply.reference) %>
diff --git a/test/functional/messages_controller_test.rb
b/test/functional/messages_controller_test.rb
index 96fd2f4..1a3efb4 100644
--- a/test/functional/messages_controller_test.rb
+++ b/test/functional/messages_controller_test.rb
@@ -22,6 +22,13 @@ class MessagesControllerTest < ActionController::TestCase
@landing_page = dashboard_path
@new_reply = {:body => 'This is a reply', :reference_id =>
@message.id}
+
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+
+ @emails = ActionMailer::Base.deliveries
+ @emails.clear
end
# Ensures that viewing the list of messages works.
@@ -106,8 +113,11 @@ class MessagesControllerTest < ActionController::TestCase
assert_redirected_to @landing_page
result = Message.find_by_id((a)message.id).replies.last
- assert result, "Did not save the reply."
+ assert result, "Reply should have been saved."
assert_equal @new_reply[:body], result.body, "Did not save the message."
+ email = @emails.first
+ assert email, "An email should have been sent."
+ assert_equal @message.author.email, email.to[0], "Email was sent to the wrong
user."
end
# Ensures that a landing page is provided.
@@ -118,5 +128,9 @@ class MessagesControllerTest < ActionController::TestCase
result = Message.find_by_id((a)message.id).replies.last
assert result, "Did not save the reply."
assert_equal @new_reply[:body], result.body, "Did not save the message."
+ # ensures that emails were sent
+ email = @emails.first
+ assert email, "An email should have been sent."
+ assert_equal @message.author.email, email.to[0], "Email was sent to the wrong
user."
end
end
--
1.6.0.6
Show replies by thread