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`.
This commit is contained in:
Javi Martín
2021-09-16 01:07:03 +02:00
parent 36d795f69c
commit 1bfcfca2e2
3 changed files with 35 additions and 7 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)