From 1bfcfca2e2732f0c631101768b6cea4268157cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 16 Sep 2021 01:07:03 +0200 Subject: [PATCH] Move method to get available filters to the model We're naming the method `investments_filters`, with the word "investments" in plural, to be consistent with the method `investments_orders`. --- .../concerns/investment_filters.rb | 8 +------ app/models/budget.rb | 10 ++++++++ spec/models/budget_spec.rb | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/controllers/concerns/investment_filters.rb b/app/controllers/concerns/investment_filters.rb index 045dbba0d..159ac575f 100644 --- a/app/controllers/concerns/investment_filters.rb +++ b/app/controllers/concerns/investment_filters.rb @@ -16,12 +16,6 @@ module InvestmentFilters end def investment_filters - [ - "not_unfeasible", - "unfeasible", - ("unselected" if @budget.publishing_prices_or_later?), - ("selected" if @budget.publishing_prices_or_later?), - ("winners" if @budget.finished?) - ].compact + @budget.investments_filters end end diff --git a/app/models/budget.rb b/app/models/budget.rb index 9ea47bed7..1eb59f101 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -196,6 +196,16 @@ class Budget < ApplicationRecord end end + def investments_filters + [ + "not_unfeasible", + "unfeasible", + ("unselected" if publishing_prices_or_later?), + ("selected" if publishing_prices_or_later?), + ("winners" if finished?) + ].compact + end + def email_selected investments.selected.order(:id).each do |investment| Mailer.budget_investment_selected(investment).deliver_later diff --git a/spec/models/budget_spec.rb b/spec/models/budget_spec.rb index 11ca8e932..6d16ddc56 100644 --- a/spec/models/budget_spec.rb +++ b/spec/models/budget_spec.rb @@ -285,6 +285,30 @@ describe Budget do end end + describe "#investments_filters" do + it "returns feasibility filters before publishing prices" do + %w[informing accepting reviewing selecting valuating].each do |phase| + budget.phase = phase + + expect(budget.investments_filters).to eq(%w[not_unfeasible unfeasible]) + end + end + + it "returns feasibility and selection filters during the final voting phases" do + %w[publishing_prices balloting reviewing_ballots].each do |phase| + budget.phase = phase + + expect(budget.investments_filters).to eq(%w[not_unfeasible unfeasible unselected selected]) + end + end + + it "returns all filters after the budget has finished" do + budget.phase = "finished" + + expect(budget.investments_filters).to eq(%w[not_unfeasible unfeasible unselected selected winners]) + end + end + describe "#has_winning_investments?" do it "returns true if there is a winner investment" do budget.investments << build(:budget_investment, :winner, price: 3, ballot_lines_count: 2)