sends an email for unfeasible spending proposals
This commit is contained in:
@@ -18,6 +18,11 @@ class Valuation::SpendingProposalsController < Valuation::BaseController
|
|||||||
|
|
||||||
def valuate
|
def valuate
|
||||||
if valid_price_params? && @spending_proposal.update(valuation_params)
|
if valid_price_params? && @spending_proposal.update(valuation_params)
|
||||||
|
|
||||||
|
if @spending_proposal.marked_as_unfeasible?
|
||||||
|
Mailer.unfeasible_spending_proposal(@spending_proposal).deliver_later
|
||||||
|
end
|
||||||
|
|
||||||
redirect_to valuation_spending_proposal_path(@spending_proposal), notice: t('valuation.spending_proposals.notice.valuate')
|
redirect_to valuation_spending_proposal_path(@spending_proposal), notice: t('valuation.spending_proposals.notice.valuate')
|
||||||
else
|
else
|
||||||
render action: :edit
|
render action: :edit
|
||||||
|
|||||||
@@ -33,6 +33,15 @@ class Mailer < ApplicationMailer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unfeasible_spending_proposal(spending_proposal)
|
||||||
|
@spending_proposal = spending_proposal
|
||||||
|
@author = spending_proposal.author
|
||||||
|
|
||||||
|
with_user(@author) do
|
||||||
|
mail(to: @author.email, subject: t('mailers.unfeasible_spending_proposal.subject'))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def with_user(user, &block)
|
def with_user(user, &block)
|
||||||
|
|||||||
@@ -68,4 +68,12 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def marked_as_unfeasible?
|
||||||
|
previous_changes.has_key?("feasible") && unfeasible?
|
||||||
|
end
|
||||||
|
|
||||||
|
def unfeasible?
|
||||||
|
not feasible?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
16
app/views/mailer/unfeasible_spending_proposal.html.erb
Normal file
16
app/views/mailer/unfeasible_spending_proposal.html.erb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<p>
|
||||||
|
<%= @author.name %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= @spending_proposal.title %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= @spending_proposal.feasible_explanation %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= t("mailers.unfeasible_spending_proposal.responsible") %>
|
||||||
|
<%= @spending_proposal.administrator.id %>
|
||||||
|
</p>
|
||||||
@@ -20,3 +20,7 @@ en:
|
|||||||
new_reply_by_html: There is a new response from <b>%{commenter}</b> to your comment on
|
new_reply_by_html: There is a new response from <b>%{commenter}</b> to your comment on
|
||||||
subject: Someone has responded to your comment
|
subject: Someone has responded to your comment
|
||||||
title: New response to your comment
|
title: New response to your comment
|
||||||
|
unfeasible_spending_proposal:
|
||||||
|
hi: Hi
|
||||||
|
subject: Your spending proposal has been marked as not feasible
|
||||||
|
responsible: The responsible for the evaluation of your spending proposal is admin
|
||||||
@@ -20,3 +20,7 @@ es:
|
|||||||
new_reply_by_html: Hay una nueva respuesta de <b>%{commenter}</b> a tu comentario en
|
new_reply_by_html: Hay una nueva respuesta de <b>%{commenter}</b> a tu comentario en
|
||||||
subject: Alguien ha respondido a tu comentario
|
subject: Alguien ha respondido a tu comentario
|
||||||
title: Nueva respuesta a tu comentario
|
title: Nueva respuesta a tu comentario
|
||||||
|
unfeasible_spending_proposal:
|
||||||
|
hi: Hola
|
||||||
|
subject: Tu propuesta de inversión ha sido marcada como inviable
|
||||||
|
responsible: El responsable de la evaluación de tu respuesta es el administrator
|
||||||
@@ -122,4 +122,30 @@ feature 'Emails' do
|
|||||||
expect(email).to have_body_text(user_confirmation_path)
|
expect(email).to have_body_text(user_confirmation_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Email on unfeasible spending proposal", :focus do
|
||||||
|
spending_proposal = create(:spending_proposal)
|
||||||
|
administrator = create(:administrator)
|
||||||
|
valuator = create(:valuator)
|
||||||
|
spending_proposal.update(administrator: administrator)
|
||||||
|
spending_proposal.valuators << valuator
|
||||||
|
|
||||||
|
login_as(valuator.user)
|
||||||
|
visit edit_valuation_spending_proposal_path(spending_proposal)
|
||||||
|
|
||||||
|
choose 'spending_proposal_feasible_false'
|
||||||
|
fill_in 'spending_proposal_feasible_explanation', with: 'This is not legal as stated in Article 34.9'
|
||||||
|
click_button 'Save changes'
|
||||||
|
|
||||||
|
expect(page).to have_content "Dossier updated"
|
||||||
|
spending_proposal.reload
|
||||||
|
|
||||||
|
email = open_last_email
|
||||||
|
expect(email).to have_subject('Your spending proposal has been marked as not feasible')
|
||||||
|
expect(email).to deliver_to(spending_proposal.author.email)
|
||||||
|
expect(email).to have_body_text(spending_proposal.author.name)
|
||||||
|
expect(email).to have_body_text(spending_proposal.title)
|
||||||
|
expect(email).to have_body_text(spending_proposal.feasible_explanation)
|
||||||
|
expect(email).to have_body_text("admin #{spending_proposal.administrator.id}")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -59,6 +59,37 @@ describe SpendingProposal do
|
|||||||
expect(spending_proposal.feasibility).to eq "undefined"
|
expect(spending_proposal.feasibility).to eq "undefined"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#unfeasible?" do
|
||||||
|
it "returns true when not feasible" do
|
||||||
|
spending_proposal.feasible = false
|
||||||
|
expect(spending_proposal.unfeasible?).to eq true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false when feasible" do
|
||||||
|
spending_proposal.feasible = true
|
||||||
|
expect(spending_proposal.unfeasible?).to eq false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#marked_as_unfeasible?" do
|
||||||
|
let(:spending_proposal) { create(:spending_proposal) }
|
||||||
|
|
||||||
|
it "returns true when feasibility has changed and it is false" do
|
||||||
|
spending_proposal.update(feasible: false)
|
||||||
|
expect(spending_proposal.marked_as_unfeasible?).to eq true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false when feasibility has not changed" do
|
||||||
|
spending_proposal.update(price: 1000000)
|
||||||
|
expect(spending_proposal.marked_as_unfeasible?).to eq false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false when it is feasible" do
|
||||||
|
spending_proposal.update(feasible: true)
|
||||||
|
expect(spending_proposal.marked_as_unfeasible?).to eq false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "by_admin" do
|
describe "by_admin" do
|
||||||
|
|||||||
Reference in New Issue
Block a user