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:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) }
|
||||
|
||||
Reference in New Issue
Block a user