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/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 5446e0a0a..8a817a805 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -188,7 +188,7 @@ feature 'Budget Investments' do expect(current_path).to eq(budget_investments_path(budget_id: budget.id)) end - scenario 'Create spending proposal too fast' do + scenario 'Create budget investment too fast' do allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(Float::INFINITY) login_as(author) @@ -263,26 +263,40 @@ feature 'Budget Investments' do end end - scenario "Show (feasible spending proposal)" do - user = create(:user) - login_as(user) + context "Show (feasible budget investment)" do + let(:investment) { create(:budget_investment, + :feasible, + :finished, + budget: budget, + group: group, + heading: heading, + price: 16, + price_explanation: 'Every wheel is 4 euros, so total is 16')} - investment = create(:budget_investment, - :feasible, - :finished, - budget: budget, - group: group, - heading: heading, - price: 16, - price_explanation: 'Every wheel is 4 euros, so total is 16') + background do + user = create(:user) + login_as(user) + end - visit budget_investment_path(budget_id: budget.id, id: investment.id) + scenario "Budget in selecting phase" do + budget.update(phase: "selecting") + visit budget_investment_path(budget_id: budget.id, id: investment.id) - expect(page).to have_content("Price explanation") - expect(page).to have_content(investment.price_explanation) + expect(page).to_not have_content("Unfeasibility explanation") + expect(page).to_not have_content("Price explanation") + expect(page).to_not have_content(investment.price_explanation) + end + + scenario "Budget in balloting phase" do + budget.update(phase: "balloting") + visit budget_investment_path(budget_id: budget.id, id: investment.id) + + expect(page).to have_content("Price explanation") + expect(page).to have_content(investment.price_explanation) + end end - scenario "Show (unfeasible spending proposal)" do + scenario "Show (unfeasible budget investment)" do user = create(:user) login_as(user) @@ -302,7 +316,7 @@ feature 'Budget Investments' do context "Destroy" do - scenario "Admin cannot destroy spending proposals" do + scenario "Admin cannot destroy budget investments" do admin = create(:administrator) user = create(:user, :level_two) investment = create(:budget_investment, heading: heading, author: user) diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index fa51f3cab..e9d5ccd13 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -144,6 +144,76 @@ describe Budget::Investment do end end + describe "#should_show_vote_count?" do + it "returns true in valuating phase" do + budget = create(:budget, phase: "valuating") + investment = create(:budget_investment, budget: budget) + + expect(investment.should_show_vote_count?).to eq(true) + end + + it "returns false in any other phase" do + Budget::PHASES.reject {|phase| phase == "valuating"}.each do |phase| + budget = create(:budget, phase: phase) + investment = create(:budget_investment, budget: budget) + + expect(investment.should_show_vote_count?).to eq(false) + end + end + end + + describe "#should_show_ballots?" do + it "returns true in balloting phase" do + budget = create(:budget, phase: "balloting") + investment = create(:budget_investment, budget: budget) + + expect(investment.should_show_ballots?).to eq(true) + end + + it "returns false in any other phase" do + Budget::PHASES.reject {|phase| phase == "balloting"}.each do |phase| + budget = create(:budget, phase: phase) + investment = create(:budget_investment, budget: budget) + + expect(investment.should_show_ballots?).to eq(false) + end + 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)