sends a copy of the direct message to the sender

This commit is contained in:
rgarcia
2016-06-14 18:55:28 +02:00
parent fd67294075
commit ce6072d17b
9 changed files with 86 additions and 15 deletions

View File

@@ -12,7 +12,8 @@ class DirectMessagesController < ApplicationController
@direct_message = DirectMessage.new(parsed_params) @direct_message = DirectMessage.new(parsed_params)
if @direct_message.save if @direct_message.save
Mailer.direct_message(@direct_message).deliver_later Mailer.direct_message_for_receiver(@direct_message).deliver_later
Mailer.direct_message_for_sender(@direct_message).deliver_later
redirect_to [@receiver, @direct_message], notice: I18n.t("flash.actions.create.direct_message") redirect_to [@receiver, @direct_message], notice: I18n.t("flash.actions.create.direct_message")
else else
render :new render :new

View File

@@ -50,12 +50,21 @@ class Mailer < ApplicationMailer
end end
end end
def direct_message(direct_message) def direct_message_for_receiver(direct_message)
@direct_message = direct_message @direct_message = direct_message
@receiver = @direct_message.receiver @receiver = @direct_message.receiver
with_user(@receiver) do with_user(@receiver) do
mail(to: @receiver.email, subject: "Has recibido un nuevo mensaje privado") mail(to: @receiver.email, subject: t('mailers.direct_message_for_receiver.subject'))
end
end
def direct_message_for_sender(direct_message)
@direct_message = direct_message
@sender = @direct_message.sender
with_user(@sender) do
mail(to: @sender.email, subject: t('mailers.direct_message_for_sender.subject'))
end end
end end

View File

@@ -11,7 +11,7 @@
<tbody> <tbody>
<tr> <tr>
<td style="padding-bottom: 12px; padding-top: 24px; text-align: center;"> <td style="padding-bottom: 12px; padding-top: 24px; text-align: center;">
<%= link_to user_url(@direct_message.sender_id), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;", target: "_blank" do %> <%= link_to user_url(@direct_message.sender), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;", target: "_blank" do %>
<%= image_tag('icon_mailer_reply.png', style: "border: 0; display: inline-block; width: 100%; max-width: 12px; vertical-align: sub;", alt: "") %> <%= image_tag('icon_mailer_reply.png', style: "border: 0; display: inline-block; width: 100%; max-width: 12px; vertical-align: sub;", alt: "") %>
<%= t('mailers.direct_message.reply', <%= t('mailers.direct_message.reply',
sender: @direct_message.sender.name) %> sender: @direct_message.sender.name) %>

View File

@@ -0,0 +1,11 @@
<td style="padding-bottom: 20px; padding-left: 10px;">
<p><%= @direct_message.receiver.name %></p>
<h1 style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;">
<%= @direct_message.title %>
</h1>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= @direct_message.body %>
</p>
</td>

View File

@@ -37,5 +37,8 @@ en:
title: You received the following notifications title: You received the following notifications
share: Share share: Share
comment: Comment proposal comment: Comment proposal
direct_message: direct_message_for_receiver:
reply: Reply to %{sender} subject: "You have received a new private message"
reply: Reply to %{sender}
direct_message_for_sender:
subject: "You have send a new private message"

View File

@@ -37,5 +37,8 @@ es:
title: Has recibido las siguientes notificaciones title: Has recibido las siguientes notificaciones
share: Compartir share: Compartir
comment: Comentar propuesta comment: Comentar propuesta
direct_message: direct_message_for_receiver:
reply: Responder a %{sender} subject: "Has recibido un nuevo mensaje privado"
reply: Responder a %{sender}
direct_message_for_sender:
subject: "Has enviado un nuevo mensaje privado"

View File

@@ -61,11 +61,4 @@ feature 'Direct messages' do
expect(page).to have_content error_message expect(page).to have_content error_message
end end
context "Limits" do
pending "Cannot send more than one notification within established interval"
pending "use timecop to make sure notifications can be sent after time interval"
end
end end

View File

@@ -148,6 +148,41 @@ feature 'Emails' do
expect(email).to have_body_text(spending_proposal.feasible_explanation) expect(email).to have_body_text(spending_proposal.feasible_explanation)
end end
context "Direct Message" do
scenario "Receiver email" do
sender = create(:user, :level_two)
receiver = create(:user, :level_two)
direct_message = create_direct_message(sender, receiver)
email = unread_emails_for(receiver.email).first
expect(email).to have_subject("You have received a new private message")
expect(email).to have_body_text(direct_message.title)
expect(email).to have_body_text(direct_message.body)
expect(email).to have_body_text(direct_message.sender.name)
expect(email).to have_body_text(/#{user_path(direct_message.sender_id)}/)
end
scenario "Sender email" do
sender = create(:user, :level_two)
receiver = create(:user, :level_two)
direct_message = create_direct_message(sender, receiver)
email = unread_emails_for(sender.email).first
expect(email).to have_subject("You have send a new private message")
expect(email).to have_body_text(direct_message.title)
expect(email).to have_body_text(direct_message.body)
expect(email).to have_body_text(direct_message.receiver.name)
end
pending "In the copy sent to the sender, display the receiver's name"
end
context "Proposal notifications" do context "Proposal notifications" do
scenario "Proposal notification" do scenario "Proposal notification" do

View File

@@ -214,4 +214,20 @@ module CommonActions
Notification.last Notification.last
end end
def create_direct_message(sender, receiver)
login_as(sender)
visit user_path(receiver)
click_link "Send private message"
expect(page).to have_content "Send private message to #{receiver.name}"
fill_in 'direct_message_title', with: "Hey #{receiver.name}!"
fill_in 'direct_message_body', with: "How are you doing? This is #{sender.name}"
click_button "Send message"
expect(page).to have_content "You message has been sent successfully."
DirectMessage.last
end
end end