Fixes issue when evaluating feasible sps - the explanation should be required only for unfeasible ones
This commit is contained in:
@@ -16,7 +16,7 @@ class SpendingProposal < ActiveRecord::Base
|
||||
validates :title, presence: true
|
||||
validates :author, presence: true
|
||||
validates :description, presence: true
|
||||
validates_presence_of :feasible_explanation, if: :valuation_finished?
|
||||
validates_presence_of :feasible_explanation, if: :feasible_explanation_required?
|
||||
|
||||
validates :title, length: { in: 4..SpendingProposal.title_max_length }
|
||||
validates :description, length: { maximum: SpendingProposal.description_max_length }
|
||||
@@ -100,6 +100,10 @@ class SpendingProposal < ActiveRecord::Base
|
||||
valuation_finished
|
||||
end
|
||||
|
||||
def feasible_explanation_required?
|
||||
valuation_finished? && unfeasible?
|
||||
end
|
||||
|
||||
def total_votes
|
||||
cached_votes_up + physical_votes
|
||||
end
|
||||
@@ -139,4 +143,5 @@ class SpendingProposal < ActiveRecord::Base
|
||||
valuation_finished.feasible
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -49,8 +49,16 @@ describe SpendingProposal do
|
||||
expect(spending_proposal).to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid if valuation finished" do
|
||||
it "should be valid if valuation finished and feasible" do
|
||||
spending_proposal.feasible_explanation = ""
|
||||
spending_proposal.feasible = true
|
||||
spending_proposal.valuation_finished = true
|
||||
expect(spending_proposal).to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid if valuation finished and unfeasible" do
|
||||
spending_proposal.feasible_explanation = ""
|
||||
spending_proposal.feasible = false
|
||||
spending_proposal.valuation_finished = true
|
||||
expect(spending_proposal).to_not be_valid
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user