updates method name to be more accurate
This commit is contained in:
@@ -19,7 +19,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController
|
||||
def valuate
|
||||
if valid_price_params? && @spending_proposal.update(valuation_params)
|
||||
|
||||
if @spending_proposal.marked_as_unfeasible?
|
||||
if @spending_proposal.unfeasible_email_pending?
|
||||
@spending_proposal.send_unfeasible_email
|
||||
end
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class SpendingProposal < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def marked_as_unfeasible?
|
||||
def unfeasible_email_pending?
|
||||
unfeasible_email_sent_at.blank? && unfeasible? && valuation_finished?
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ namespace :spending_proposals do
|
||||
desc "Sends an email to the authors of unfeasible spending proposals"
|
||||
task send_unfeasible_emails: :environment do
|
||||
SpendingProposal.find_each do |spending_propsal|
|
||||
if spending_propsal.marked_as_unfeasible?
|
||||
if spending_propsal.unfeasible_email_pending?
|
||||
spending_propsal.send_unfeasible_email
|
||||
puts "email sent for proposal #{spending_propsal.title}"
|
||||
else
|
||||
|
||||
@@ -72,27 +72,27 @@ describe SpendingProposal do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#marked_as_unfeasible?" do
|
||||
describe "#unfeasible_email_pending?" do
|
||||
let(:spending_proposal) { create(:spending_proposal) }
|
||||
|
||||
it "returns true when marked as unfeasibable and valuation_finished" do
|
||||
spending_proposal.update(feasible: false, valuation_finished: true)
|
||||
expect(spending_proposal.marked_as_unfeasible?).to eq true
|
||||
expect(spending_proposal.unfeasible_email_pending?).to eq true
|
||||
end
|
||||
|
||||
it "returns false when marked as feasible" do
|
||||
spending_proposal.update(feasible: true)
|
||||
expect(spending_proposal.marked_as_unfeasible?).to eq false
|
||||
expect(spending_proposal.unfeasible_email_pending?).to eq false
|
||||
end
|
||||
|
||||
it "returns false when marked as feasable and valuation_finished" do
|
||||
spending_proposal.update(feasible: true, valuation_finished: true)
|
||||
expect(spending_proposal.marked_as_unfeasible?).to eq false
|
||||
expect(spending_proposal.unfeasible_email_pending?).to eq false
|
||||
end
|
||||
|
||||
it "returns false when unfeasible email already sent" do
|
||||
spending_proposal.update(unfeasible_email_sent_at: 1.day.ago)
|
||||
expect(spending_proposal.marked_as_unfeasible?).to eq false
|
||||
expect(spending_proposal.unfeasible_email_pending?).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user