From 90bb06e68461d413f8877003d80d0abf4ddf7149 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sun, 4 Mar 2018 22:29:40 +0100 Subject: [PATCH 1/3] Fix display of unfeasibility explanation We were missing a check to make sure valuation had finished before displaying the unfeasibility explanation --- spec/features/budgets/investments_spec.rb | 18 +++++++++++ spec/models/budget/investment_spec.rb | 38 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 51445bccc..4347fb212 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -991,6 +991,24 @@ feature 'Budget Investments' do expect(page).not_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(investment.unfeasibility_explanation) + end + scenario "Show milestones", :js do user = create(:user) investment = create(:budget_investment) diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index a4e1d246d..e9081cf34 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -308,6 +308,44 @@ describe Budget::Investment do end end + describe "#by_budget" do + + 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) From b3978908b2e5cd791c9e159a559de7a7f6d3cd0e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 5 Mar 2018 01:05:36 +0100 Subject: [PATCH 2/3] Use strings instead of method calls in expectations --- spec/features/budgets/investments_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 4347fb212..dbc82ba31 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -1006,7 +1006,7 @@ feature 'Budget Investments' do 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(investment.unfeasibility_explanation) + expect(page).not_to have_content("Local government is not competent in this matter") end scenario "Show milestones", :js do From ab5f78120a3cd5a71bcb0ae24d6ba3bde8f5711a Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 26 Jul 2018 12:52:51 +0200 Subject: [PATCH 3/3] Fix specs Git seems to have gotten confused and some specs where duplicated and others missing This commits restructures commits to sync them with Madrid's fork --- spec/models/budget/investment_spec.rb | 42 +++++++++------------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index e9081cf34..c81ada18a 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -310,39 +310,25 @@ describe Budget::Investment do describe "#by_budget" do - 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) + it "returns investments scoped by budget" do + budget1 = create(:budget) + budget2 = create(:budget) - expect(investment.should_show_unfeasibility_explanation?).to eq(true) - end - end + group1 = create(:budget_group, budget: budget1) + group2 = create(:budget_group, budget: budget2) - 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) + heading1 = create(:budget_heading, group: group1) + heading2 = create(:budget_heading, group: group2) - expect(investment.should_show_unfeasibility_explanation?).to eq(false) - end - end + investment1 = create(:budget_investment, heading: heading1) + investment2 = create(:budget_investment, heading: heading1) + investment3 = create(:budget_investment, heading: heading2) - it "returns false if not unfeasible" do - investment.update(feasibility: "undecided") - Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase| - budget.update(phase: phase) + investments_by_budget = Budget::Investment.by_budget(budget1) - 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 + expect(investments_by_budget).to include investment1 + expect(investments_by_budget).to include investment2 + expect(investments_by_budget).to_not include investment3 end end