Merge pull request #1470 from consul/price-validation

Validation for price when investment is feasible
This commit is contained in:
Raimond Garcia
2017-03-27 13:23:12 +02:00
committed by GitHub
2 changed files with 29 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ class Budget
validates :description, presence: true
validates :heading_id, presence: true
validates_presence_of :unfeasibility_explanation, if: :unfeasibility_explanation_required?
validates_presence_of :price, if: :price_required?
validates :title, length: { in: 4..Budget::Investment.title_max_length }
validates :description, length: { maximum: Budget::Investment.description_max_length }
@@ -136,6 +137,10 @@ class Budget
unfeasible? && valuation_finished?
end
def price_required?
feasible? && valuation_finished?
end
def unfeasible_email_pending?
unfeasible_email_sent_at.blank? && unfeasible? && valuation_finished?
end

View File

@@ -54,7 +54,7 @@ describe Budget::Investment do
expect(investment.group_id).to eq group_2.id
end
describe "#unfeasibility_explanation" do
describe "#unfeasibility_explanation blank" do
it "should be valid if valuation not finished" do
investment.unfeasibility_explanation = ""
investment.valuation_finished = false
@@ -76,6 +76,29 @@ describe Budget::Investment do
end
end
describe "#price blank" do
it "should be valid if valuation not finished" do
investment.price = ""
investment.valuation_finished = false
expect(investment).to be_valid
end
it "should be valid if valuation finished and unfeasible" do
investment.price = ""
investment.unfeasibility_explanation = "reason"
investment.feasibility = "unfeasible"
investment.valuation_finished = true
expect(investment).to be_valid
end
it "should not be valid if valuation finished and feasible" do
investment.price = ""
investment.feasibility = "feasible"
investment.valuation_finished = true
expect(investment).to_not be_valid
end
end
describe "#code" do
let(:investment) { create(:budget_investment) }