From 3e75bd4dfd5849e40bb8bc77d68850e3e0cc8fc3 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Mar 2018 19:58:40 +0100 Subject: [PATCH] Fix Valuation Investment index heading filters Why: Heading filter where not being correctly displayed How: Increasing scenario to cover all possible combinations, and fixing the heading_filters method of the Valuation Budget Investment Controller to correctly: * Find how many investments the valuator can access * Count investments for each heading --- .../budget_investments_controller.rb | 4 ++- .../valuation/budget_investments_spec.rb | 36 +++++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/controllers/valuation/budget_investments_controller.rb b/app/controllers/valuation/budget_investments_controller.rb index bf70d657b..d8b832d47 100644 --- a/app/controllers/valuation/budget_investments_controller.rb +++ b/app/controllers/valuation/budget_investments_controller.rb @@ -73,7 +73,9 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController end def heading_filters - investments = @budget.investments.by_valuator(current_user.valuator.try(:id)).distinct + investments = @budget.investments.by_valuator(current_user.valuator.try(:id)) + .visible_to_valuators.distinct + investment_headings = Budget::Heading.where(id: investments.pluck(:heading_id).uniq) .order(name: :asc) diff --git a/spec/features/valuation/budget_investments_spec.rb b/spec/features/valuation/budget_investments_spec.rb index 5d9b4fa4a..b5b381779 100644 --- a/spec/features/valuation/budget_investments_spec.rb +++ b/spec/features/valuation/budget_investments_spec.rb @@ -93,25 +93,25 @@ feature 'Valuation budget investments' do valuating_finished_heading = create(:budget_heading, name: "Valuating&Finished", group: group) finished_heading = create(:budget_heading, name: "Only Finished", group: group) create(:budget_investment, :visible_to_valuators, title: "Valuating Investment ONE", - heading: valuating_heading, - group: group, - budget: budget, - valuators: [valuator]) + heading: valuating_heading, + group: group, + budget: budget, + valuators: [valuator]) create(:budget_investment, :visible_to_valuators, title: "Valuating Investment TWO", - heading: valuating_finished_heading, - group: group, - budget: budget, - valuators: [valuator]) - create(:budget_investment, :finished, :visible_to_valuators, title: "Finished ONE", - heading: valuating_finished_heading, - group: group, - budget: budget, - valuators: [valuator]) - create(:budget_investment, :finished, :visible_to_valuators, title: "Finished TWO", - heading: finished_heading, - group: group, - budget: budget, - valuators: [valuator]) + heading: valuating_finished_heading, + group: group, + budget: budget, + valuators: [valuator]) + create(:budget_investment, :visible_to_valuators, :finished, title: "Finished ONE", + heading: valuating_finished_heading, + group: group, + budget: budget, + valuators: [valuator]) + create(:budget_investment, :visible_to_valuators, :finished, title: "Finished TWO", + heading: finished_heading, + group: group, + budget: budget, + valuators: [valuator]) visit valuation_budget_budget_investments_path(budget)