Fix filters for investments without admin/valuator

These filters were only returning investments with valuation open, but
we don't want to do that since the time we changed the interface in
order to allow users to apply several filters at the same time.
This commit is contained in:
Javi Martín
2020-02-05 22:49:31 +01:00
parent 2b87b9ed19
commit f223b3945f
2 changed files with 8 additions and 17 deletions

View File

@@ -71,9 +71,9 @@ class Budget
scope :sort_by_supports, -> { order("cached_votes_up DESC") } scope :sort_by_supports, -> { order("cached_votes_up DESC") }
scope :valuation_open, -> { where(valuation_finished: false) } scope :valuation_open, -> { where(valuation_finished: false) }
scope :without_admin, -> { valuation_open.where(administrator_id: nil) } scope :without_admin, -> { where(administrator_id: nil) }
scope :without_valuator_group, -> { where(valuator_group_assignments_count: 0) } scope :without_valuator_group, -> { where(valuator_group_assignments_count: 0) }
scope :without_valuator, -> { valuation_open.without_valuator_group.where(valuator_assignments_count: 0) } scope :without_valuator, -> { without_valuator_group.where(valuator_assignments_count: 0) }
scope :under_valuation, -> { valuation_open.valuating.where("administrator_id IS NOT ?", nil) } scope :under_valuation, -> { valuation_open.valuating.where("administrator_id IS NOT ?", nil) }
scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).where("administrator_id IS NOT ?", nil) } scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).where("administrator_id IS NOT ?", nil) }
scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0 OR valuator_group_assignments_count > 0") } scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0 OR valuator_group_assignments_count > 0") }

View File

@@ -459,19 +459,13 @@ describe Budget::Investment do
end end
describe "without_admin" do describe "without_admin" do
it "returns open investments without assigned admin" do it "returns investments without an admin" do
investment = create(:budget_investment, :open, administrator: nil) investment = create(:budget_investment, :finished, administrator: nil)
expect(Budget::Investment.without_admin).to eq [investment] expect(Budget::Investment.without_admin).to eq [investment]
end end
it "does not return investments with valuation finished" do it "does not return investments with an admin" do
create(:budget_investment, :finished)
expect(Budget::Investment.without_admin).to be_empty
end
it "does not return investment with an admin" do
create(:budget_investment, :with_administrator) create(:budget_investment, :with_administrator)
expect(Budget::Investment.without_admin).to be_empty expect(Budget::Investment.without_admin).to be_empty
@@ -1212,15 +1206,12 @@ describe Budget::Investment do
describe "with without_admin filter" do describe "with without_admin filter" do
let(:params) { { advanced_filters: ["without_admin"], budget_id: budget.id } } let(:params) { { advanced_filters: ["without_admin"], budget_id: budget.id } }
it "returns only investment without admin" do it "returns only investment without admin" do
create(:budget_investment,
:finished,
budget: budget)
create(:budget_investment, create(:budget_investment,
:with_administrator, :with_administrator,
budget: budget) budget: budget)
investment3 = create(:budget_investment, budget: budget) investment2 = create(:budget_investment, budget: budget)
expect(Budget::Investment.scoped_filter(params, "all")).to eq([investment3]) expect(Budget::Investment.scoped_filter(params, "all")).to eq([investment2])
end end
end end
@@ -1228,7 +1219,7 @@ describe Budget::Investment do
let(:params) { { advanced_filters: ["without_valuator"], budget_id: budget.id } } let(:params) { { advanced_filters: ["without_valuator"], budget_id: budget.id } }
it "returns only investment without valuator" do it "returns only investment without valuator" do
create(:budget_investment, create(:budget_investment,
:finished, :with_valuator,
budget: budget) budget: budget)
investment2 = create(:budget_investment, investment2 = create(:budget_investment,
:with_administrator, :with_administrator,