shows investment price info only if phase is balloting or later

This commit is contained in:
Juanjo Bazán
2017-04-17 13:15:17 +02:00
parent 83e7911c11
commit 61e5c187da
3 changed files with 41 additions and 1 deletions

View File

@@ -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

View File

@@ -47,7 +47,7 @@
<p><%= investment.unfeasibility_explanation %></p>
<% end %>
<% if investment.feasible? && investment.price_explanation.present? %>
<% if investment.should_show_price_info? %>
<h2><%= t('budgets.investments.show.price_explanation') %></h2>
<p><%= investment.price_explanation %></p>
<% end %>

View File

@@ -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)