Add Budget.open scope

Before Budget.current could return multiple budgets, now there can only
be a single current_budget.

Adding the concept of open, which better reflects what the admin sees
in this page: A tab for open budgets and a tab for finished budgets
This commit is contained in:
rgarcia
2018-01-15 20:23:46 +01:00
parent be554a629c
commit 349780922d
3 changed files with 14 additions and 1 deletions

View File

@@ -2,7 +2,7 @@ class Admin::BudgetsController < Admin::BaseController
include FeatureFlags
feature_flag :budgets
has_filters %w{current finished}, only: :index
has_filters %w{open finished}, only: :index
load_and_authorize_resource

View File

@@ -30,6 +30,7 @@ class Budget < ActiveRecord::Base
scope :balloting, -> { where(phase: "balloting") }
scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") }
scope :finished, -> { where(phase: "finished") }
scope :open, -> { where.not(phase: "finished") }
def self.current
where.not(phase: "drafting").last

View File

@@ -123,6 +123,18 @@ describe Budget do
end
describe "#open" do
it "returns all budgets that are not in the finished phase" do
phases = Budget::PHASES - ["finished"]
phases.each do |phase|
budget = create(:budget, phase: phase)
expect(Budget.open).to include(budget)
end
end
end
describe "heading_price" do
let(:budget) { create(:budget) }
let(:group) { create(:budget_group, budget: budget) }