diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 4bfd038c3..0a7e92344 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -245,6 +245,12 @@ class Budget budget.balloting? end + def should_show_price_info? + feasible? && + price_explanation.present? && + (budget.balloting? || budget.reviewing_ballots? || budget.finished?) + end + def formatted_price budget.formatted_amount(price) end diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index d97a1fbfb..f88869cb9 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -47,7 +47,7 @@
<%= investment.unfeasibility_explanation %>
<% end %> - <% if investment.feasible? && investment.price_explanation.present? %> + <% if investment.should_show_price_info? %><%= investment.price_explanation %>
<% end %> diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index fa51f3cab..47affc10c 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -144,6 +144,40 @@ describe Budget::Investment do end end + describe "#should_show_price_info?" do + it "returns true for feasibles if phase is balloting or later and price_explanation is present" do + ["balloting", "reviewing_ballots", "finished"].each do |phase| + budget = create(:budget, phase: phase) + investment = create(:budget_investment, :feasible, budget: budget, price_explanation: "price explanation") + + expect(investment.should_show_price_info?).to eq(true) + end + end + + it "returns false in any other phase" do + (Budget::PHASES - ["balloting", "reviewing_ballots", "finished"]).each do |phase| + budget = create(:budget, phase: phase) + investment = create(:budget_investment, :feasible, budget: budget, price_explanation: "price explanation") + + expect(investment.should_show_price_info?).to eq(false) + end + end + + it "returns false if investment is unfeasible" do + budget = create(:budget, phase: "balloting") + investment = create(:budget_investment, :unfeasible, budget: budget, price_explanation: "price explanation") + + expect(investment.should_show_price_info?).to eq(false) + end + + it "returns false if price_explanation is blank" do + budget = create(:budget, phase: "balloting") + investment = create(:budget_investment, :unfeasible, budget: budget, price_explanation: "") + + expect(investment.should_show_price_info?).to eq(false) + end + end + describe "by_admin" do it "should return investments assigned to specific administrator" do investment1 = create(:budget_investment, administrator_id: 33)