adds email delivery of selected and unselected investments
This commit is contained in:
@@ -91,6 +91,24 @@ class Mailer < ApplicationMailer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def budget_investment_selected(investment)
|
||||||
|
@investment = investment
|
||||||
|
@author = investment.author
|
||||||
|
|
||||||
|
with_user(@author) do
|
||||||
|
mail(to: @author.email, subject: t('mailers.budget_investment_selected.subject', code: @investment.code))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def budget_investment_unselected(investment)
|
||||||
|
@investment = investment
|
||||||
|
@author = investment.author
|
||||||
|
|
||||||
|
with_user(@author) do
|
||||||
|
mail(to: @author.email, subject: t('mailers.budget_investment_unselected.subject', code: @investment.code))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def with_user(user, &block)
|
def with_user(user, &block)
|
||||||
|
|||||||
@@ -113,6 +113,18 @@ class Budget < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def email_selected
|
||||||
|
investments.selected.each do |investment|
|
||||||
|
Mailer.budget_investment_selected(investment).deliver_later
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def email_unselected
|
||||||
|
investments.unselected.each do |investment|
|
||||||
|
Mailer.budget_investment_unselected(investment).deliver_later
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def sanitize_descriptions
|
def sanitize_descriptions
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||||
<%= t("mailers.budget_investment_selected.share",
|
<%= t("mailers.budget_investment_selected.share",
|
||||||
url: link_to(t("mailers.budget_investment_selected.share_url"),
|
url: link_to(t("mailers.budget_investment_selected.share_url"),
|
||||||
namespaced_budget_investment_path(@investment), style: "color: #2895F1; text-decoration: underline;")) %>
|
budget_url(@investment.budget), style: "color: #2895F1; text-decoration: underline;")) %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<table style="width: 100%;">
|
<table style="width: 100%;">
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||||
<%= t("mailers.budget_investment_unselected.participate",
|
<%= t("mailers.budget_investment_unselected.participate",
|
||||||
url: link_to(t("mailers.budget_investment_unselected.participate_url"),
|
url: link_to(t("mailers.budget_investment_unselected.participate_url"),
|
||||||
new_budget_investment_url(@investment.budget), style: "color: #2895F1; text-decoration: underline;")) %>
|
budget_url(@investment.budget), style: "color: #2895F1; text-decoration: underline;")) %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||||
|
|||||||
@@ -84,21 +84,21 @@ en:
|
|||||||
subject: "Your investment project '%{code}' has been marked as unfeasible"
|
subject: "Your investment project '%{code}' has been marked as unfeasible"
|
||||||
unfeasible_html: "From the City Council we want to thank you for your participation in the <strong>participatory budgets</strong>. We regret to inform you that your investment <strong>'%{title}'</strong> will be excluded from this participatory process for the following reason:"
|
unfeasible_html: "From the City Council we want to thank you for your participation in the <strong>participatory budgets</strong>. We regret to inform you that your investment <strong>'%{title}'</strong> will be excluded from this participatory process for the following reason:"
|
||||||
budget_investment_selected:
|
budget_investment_selected:
|
||||||
subject: "Tu propuesta de inversión '%{code}' ha sido seleccionada"
|
subject: "Your investment project '%{code}' has been selected"
|
||||||
hi: "Estimado usuario,"
|
hi: "Dear user,"
|
||||||
selected_html: "Desde el Ayuntamiento queremos agradecer tu participación en los <strong>Presupuestos Participativos</strong>. Queremos informarte de que tu proyecto <strong>'%{title}'</strong> ha sido seleccionado y pasa a la fase de votación final que tiene lugar desde el <strong>15 de mayo hasta el 30 de junio</strong>."
|
selected_html: "From the City Council we want to thank you for your participation in the <strong>participatory budgets</strong>. We would like to inform you that your investment project <strong>'%{title}'</strong> has been selected for the final voting phase that will happen from <strong>May 15th to June 30th</strong>."
|
||||||
share: "Te invitamos a que %{url} en redes sociales para promocionarlo y conseguir más votos."
|
share: "We invite you to %{url} in social networks to promote it and achieve more votes."
|
||||||
share_url: "compartas tu proyecto de gasto"
|
share_url: "share your investment project"
|
||||||
share_button: "Comparte tu proyecto"
|
share_button: "Share your investment project"
|
||||||
thanks: "Gracias de nuevo por tu participación."
|
thanks: "Thank you again for participating."
|
||||||
sincerely: "Atentamente"
|
sincerely: "Sincererly"
|
||||||
signatory: "DIRECCIÓN GENERAL DE PARTICIPACIÓN CIUDADANA"
|
signatory: "DEPARTMENT OF PUBLIC PARTICIPATION"
|
||||||
budget_investment_unselected:
|
budget_investment_unselected:
|
||||||
subject: "Tu propuesta de inversión '%{code}' no ha sido seleccionada"
|
subject: "Your investment project '%{code}' has not been selected"
|
||||||
hi: "Estimado usuario,"
|
hi: "Dear user,"
|
||||||
unselected_html: "Desde el Ayuntamiento queremos agradecer tu participación en los <strong>Presupuestos Participativos</strong>. Lamentamos informarte de que tu proyecto <strong>'%{title}'</strong> no ha sido seleccionado para la fase de votación final."
|
unselected_html: "From the City Council we want to thank you for your participation in the <strong>participatory budgets</strong>. We regret to inform you that your investment project <strong>'%{title}'</strong> has not been selected for the final voting phase."
|
||||||
participate: "De todas formas te invitamos a que %{url} votando otros proyectos desde el <strong>15 de mayo hasta el 30 de junio</strong>."
|
participate: "You can continue participating in the final voting phase voting for investments projects from <strong>May 15th to June 30th</strong>."
|
||||||
participate_url: "participes en la votación final"
|
participate_url: "participate in the final voting"
|
||||||
thanks: "Gracias de nuevo por tu participación."
|
thanks: "Thank you again for participating."
|
||||||
sincerely: "Atentamente"
|
sincerely: "Sincererly"
|
||||||
signatory: "DIRECCIÓN GENERAL DE PARTICIPACIÓN CIUDADANA"
|
signatory: "DEPARTMENT OF PUBLIC PARTICIPATION"
|
||||||
@@ -75,8 +75,8 @@ es:
|
|||||||
unfeasible_html: "Desde el Ayuntamiento queremos agradecer tu participación en los <strong>Presupuestos Participativos</strong>. Lamentamos informarte de que tu proyecto <strong>'%{title}'</strong> quedará excluido de este proceso participativo por el siguiente motivo:"
|
unfeasible_html: "Desde el Ayuntamiento queremos agradecer tu participación en los <strong>Presupuestos Participativos</strong>. Lamentamos informarte de que tu proyecto <strong>'%{title}'</strong> quedará excluido de este proceso participativo por el siguiente motivo:"
|
||||||
budget_investment_selected:
|
budget_investment_selected:
|
||||||
subject: "Tu propuesta de inversión '%{code}' ha sido seleccionada"
|
subject: "Tu propuesta de inversión '%{code}' ha sido seleccionada"
|
||||||
hi: "Estimado usuario,"
|
hi: "Estimado/a usuario/a"
|
||||||
selected_html: "Desde el Ayuntamiento queremos agradecer tu participación en los <strong>Presupuestos Participativos</strong>. Queremos informarte de que tu proyecto <strong>'%{title}'</strong> ha sido seleccionado y pasa a la fase de votación final que tiene lugar desde el <strong>15 de mayo hasta el 30 de junio</strong>."
|
selected_html: "Desde el Ayuntamiento de Madrid agradecemos que hayas participado con tu idea en los <strong>Presupuestos Participativos</strong>. Te invitamos de que tu proyecto <strong>'%{title}'</strong> ha sido seleccionado y pasa a la fase de votación final que tiene lugar desde el <strong>15 de mayo hasta el 30 de junio de 2017</strong>. Empieza ya a conseguir votos, comparte tu proyecto de gasto en redes sociales. La difusión es fundamental para conseguir que se haga realidad."
|
||||||
share: "Te invitamos a que %{url} en redes sociales para promocionarlo y conseguir más votos."
|
share: "Te invitamos a que %{url} en redes sociales para promocionarlo y conseguir más votos."
|
||||||
share_url: "compartas tu proyecto de gasto"
|
share_url: "compartas tu proyecto de gasto"
|
||||||
share_button: "Comparte tu proyecto"
|
share_button: "Comparte tu proyecto"
|
||||||
@@ -85,9 +85,9 @@ es:
|
|||||||
signatory: "DIRECCIÓN GENERAL DE PARTICIPACIÓN CIUDADANA"
|
signatory: "DIRECCIÓN GENERAL DE PARTICIPACIÓN CIUDADANA"
|
||||||
budget_investment_unselected:
|
budget_investment_unselected:
|
||||||
subject: "Tu propuesta de inversión '%{code}' no ha sido seleccionada"
|
subject: "Tu propuesta de inversión '%{code}' no ha sido seleccionada"
|
||||||
hi: "Estimado usuario,"
|
hi: "Estimado/a usuario/a"
|
||||||
unselected_html: "Desde el Ayuntamiento queremos agradecer tu participación en los <strong>Presupuestos Participativos</strong>. Lamentamos informarte de que tu proyecto <strong>'%{title}'</strong> no ha sido seleccionado para la fase de votación final."
|
unselected_html: "Desde el Ayuntamiento de Madrid agradecemos que hayas participado con tu idea en los <strong>Presupuestos Participativos</strong>. Lamentamos informarte de que tu proyecto <strong>'%{title}'</strong> no ha sido seleccionado para la fase de votación final."
|
||||||
participate: "De todas formas te invitamos a que %{url} votando otros proyectos desde el <strong>15 de mayo hasta el 30 de junio</strong>."
|
participate: "Puedes continuar participando en la votación final votando proyectos para toda la ciudad y el distrito que elijas desde el <strong>15 de mayo hasta el 30 de junio de 2017.</strong>"
|
||||||
participate_url: "participes en la votación final"
|
participate_url: "participes en la votación final"
|
||||||
thanks: "Gracias de nuevo por tu participación."
|
thanks: "Gracias de nuevo por tu participación."
|
||||||
sincerely: "Atentamente"
|
sincerely: "Atentamente"
|
||||||
|
|||||||
16
lib/tasks/budgets.rake
Normal file
16
lib/tasks/budgets.rake
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
namespace :budgets do
|
||||||
|
namespace :email do
|
||||||
|
|
||||||
|
desc "Sends emails to authors of selected investments"
|
||||||
|
task selected: :environment do
|
||||||
|
Budget.last.email_selected
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Sends emails to authors of unselected investments"
|
||||||
|
task unselected: :environment do
|
||||||
|
Budget.last.email_unselected
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -321,5 +321,51 @@ feature 'Emails' do
|
|||||||
expect(email).to have_body_text(investment.unfeasibility_explanation)
|
expect(email).to have_body_text(investment.unfeasibility_explanation)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Selected investment" do
|
||||||
|
author1 = create(:user)
|
||||||
|
author2 = create(:user)
|
||||||
|
author3 = create(:user)
|
||||||
|
|
||||||
|
investment1 = create(:budget_investment, :selected, author: author1, budget: budget)
|
||||||
|
investment2 = create(:budget_investment, :selected, author: author2, budget: budget)
|
||||||
|
investment3 = create(:budget_investment, :unselected, author: author3, budget: budget)
|
||||||
|
|
||||||
|
reset_mailer
|
||||||
|
budget.email_selected
|
||||||
|
|
||||||
|
expect(find_email investment1.author.email).to be
|
||||||
|
expect(find_email investment2.author.email).to be
|
||||||
|
expect(find_email investment3.author.email).to_not be
|
||||||
|
|
||||||
|
email = open_last_email
|
||||||
|
investment = investment2
|
||||||
|
expect(email).to have_subject("Your investment project '#{investment.code}' has been selected")
|
||||||
|
expect(email).to deliver_to(investment.author.email)
|
||||||
|
expect(email).to have_body_text(investment.title)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Unselected investment" do
|
||||||
|
author1 = create(:user)
|
||||||
|
author2 = create(:user)
|
||||||
|
author3 = create(:user)
|
||||||
|
|
||||||
|
investment1 = create(:budget_investment, :unselected, author: author1, budget: budget)
|
||||||
|
investment2 = create(:budget_investment, :unselected, author: author2, budget: budget)
|
||||||
|
investment3 = create(:budget_investment, :selected, author: author3, budget: budget)
|
||||||
|
|
||||||
|
reset_mailer
|
||||||
|
budget.email_unselected
|
||||||
|
|
||||||
|
expect(find_email investment1.author.email).to be
|
||||||
|
expect(find_email investment2.author.email).to be
|
||||||
|
expect(find_email investment3.author.email).to_not be
|
||||||
|
|
||||||
|
email = open_last_email
|
||||||
|
investment = investment2
|
||||||
|
expect(email).to have_subject("Your investment project '#{investment.code}' has not been selected")
|
||||||
|
expect(email).to deliver_to(investment.author.email)
|
||||||
|
expect(email).to have_body_text(investment.title)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user