Merge pull request #2570 from consul/unfeasibility-explanation

Display unfeasibility explanation only when valuation has finished
This commit is contained in:
Raimond Garcia
2018-04-05 00:21:31 +02:00
committed by GitHub
4 changed files with 70 additions and 3 deletions

View File

@@ -303,6 +303,10 @@ class Budget
should_show_price? && price_explanation.present?
end
def should_show_unfeasibility_explanation?
unfeasible? && valuation_finished? && unfeasibility_explanation.present?
end
def formatted_price
budget.formatted_amount(price)
end

View File

@@ -63,7 +63,7 @@
</div>
<% end %>
<% if investment.unfeasible? && investment.unfeasibility_explanation.present? %>
<% if investment.should_show_unfeasibility_explanation? %>
<h2><%= t('budgets.investments.show.unfeasibility_explanation') %></h2>
<p><%= investment.unfeasibility_explanation %></p>
<% end %>

View File

@@ -921,7 +921,25 @@ feature 'Budget Investments' do
visit budget_investment_path(budget_id: budget.id, id: investment.id)
expect(page).to have_content("Unfeasibility explanation")
expect(page).to have_content(investment.unfeasibility_explanation)
expect(page).to have_content("Local government is not competent in this matter")
end
scenario "Show (unfeasible budget investment with valuation not finished)" do
user = create(:user)
login_as(user)
investment = create(:budget_investment,
:unfeasible,
valuation_finished: false,
budget: budget,
group: group,
heading: heading,
unfeasibility_explanation: 'Local government is not competent in this matter')
visit budget_investment_path(budget_id: budget.id, id: investment.id)
expect(page).not_to have_content("Unfeasibility explanation")
expect(page).not_to have_content("Local government is not competent in this matter")
end
scenario "Show milestones", :js do

View File

@@ -263,7 +263,52 @@ describe Budget::Investment do
end
end
describe "by_admin" do
describe "#should_show_unfeasibility_explanation?" do
let(:budget) { create(:budget) }
let(:investment) do
create(:budget_investment, budget: budget,
unfeasibility_explanation: "because of reasons",
valuation_finished: true,
feasibility: "unfeasible")
end
it "returns true for unfeasible investments with unfeasibility explanation and valuation finished" do
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
budget.update(phase: phase)
expect(investment.should_show_unfeasibility_explanation?).to eq(true)
end
end
it "returns false in valuation has not finished" do
investment.update(valuation_finished: false)
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
budget.update(phase: phase)
expect(investment.should_show_unfeasibility_explanation?).to eq(false)
end
end
it "returns false if not unfeasible" do
investment.update(feasibility: "undecided")
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
budget.update(phase: phase)
expect(investment.should_show_unfeasibility_explanation?).to eq(false)
end
end
it "returns false if unfeasibility explanation blank" do
investment.update(unfeasibility_explanation: "")
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
budget.update(phase: phase)
expect(investment.should_show_unfeasibility_explanation?).to eq(false)
end
end
end
describe "#by_admin" do
it "returns investments assigned to specific administrator" do
investment1 = create(:budget_investment, administrator_id: 33)
create(:budget_investment)