Added a new column to the notifications table, email_on_replies. If set
to true then replies are emailed to the user.
The email notice is only sent if the author of the message being replied
to has email notices enabled for replies.
Added a configuration box to the user's preferences page to
enable/disable email noticies on replies.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/controllers/messages_controller.rb | 2 +-
app/views/users/_notifications.html.erb | 6 ++++++
db/migrate/017_create_notifications.rb | 1 +
doc/ChangeLog | 1 +
test/functional/messages_controller_test.rb | 15 +++++++++++++++
5 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/app/controllers/messages_controller.rb
b/app/controllers/messages_controller.rb
index 5677d0e..b1e5ff3 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -47,7 +47,7 @@ class MessagesController < ApplicationController
respond_to do |format|
if @message.save
- UserMailer.deliver_message_reply_notice(@reply)
+ UserMailer.deliver_message_reply_notice(@reply) if
@message.author.notifications.email_on_replies
flash[:message] = "Reply posted."
if @landing_page
format.html {redirect_to @landing_page}
diff --git a/app/views/users/_notifications.html.erb
b/app/views/users/_notifications.html.erb
index 89a5dfd..905c480 100644
--- a/app/views/users/_notifications.html.erb
+++ b/app/views/users/_notifications.html.erb
@@ -28,6 +28,12 @@
</tr>
<tr>
+ <td class="value">
+ <%= form.check_box :email_on_replies %>
+ <%= form.label :email_on_replies, "Send an email when some replies to a
message you posted." %>
+ </tr>
+
+ <tr>
<td class="buttons">
<%= submit_tag "Update" %>
</td>
diff --git a/db/migrate/017_create_notifications.rb
b/db/migrate/017_create_notifications.rb
index 8304a36..edfa008 100644
--- a/db/migrate/017_create_notifications.rb
+++ b/db/migrate/017_create_notifications.rb
@@ -22,6 +22,7 @@ class CreateNotifications < ActiveRecord::Migration
t.boolean :task_reminders, :null => false, :default => true
t.boolean :daily_updates, :null => false, :default => true
t.boolean :updates_to_product_list, :null => false, :default => false
+ t.boolean :email_on_replies, :null => false, :default => true
t.timestamps
end
diff --git a/doc/ChangeLog b/doc/ChangeLog
index e12f4b9..ff6368e 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -34,6 +34,7 @@ Change Log (0.3.0):
* #208 - Blocker history is shown for backlog items.
* #209 - A blocked item is shown in a different color on the item list page.
* #210 - Epics with no user stories should only be deleted. (BUG)
+ * #213 - Users can disable receiving emails when replies are posted.
* #216 - The user's most recent postings are displayed on their details page.
* #217 - All of a user's posts can be viewed.
diff --git a/test/functional/messages_controller_test.rb
b/test/functional/messages_controller_test.rb
index 1a3efb4..d5287ac 100644
--- a/test/functional/messages_controller_test.rb
+++ b/test/functional/messages_controller_test.rb
@@ -133,4 +133,19 @@ class MessagesControllerTest < ActionController::TestCase
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.
+ def test_post_reply_with_emails_on_replies_disabled
+ @message.author.notifications.email_on_replies = false
+ @message.author.notifications.save!
+
+ post :post_reply, {:id => @message.id, :reply => @new_reply}, {:user_id =>
@user.id}
+
+ assert_redirected_to message_path(@message)
+ 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
+ assert @emails.empty?, "No emails should have been sent."
+ end
end
--
1.6.0.6
Show replies by thread