From 349780922d2dc1d132ac24fe2762645dddb82f54 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 15 Jan 2018 20:23:46 +0100 Subject: [PATCH] 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 --- app/controllers/admin/budgets_controller.rb | 2 +- app/models/budget.rb | 1 + spec/models/budget_spec.rb | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/budgets_controller.rb b/app/controllers/admin/budgets_controller.rb index d2f8706c0..7dbd66d7b 100644 --- a/app/controllers/admin/budgets_controller.rb +++ b/app/controllers/admin/budgets_controller.rb @@ -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 diff --git a/app/models/budget.rb b/app/models/budget.rb index 55c4de841..608599217 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -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 diff --git a/spec/models/budget_spec.rb b/spec/models/budget_spec.rb index 9bca092ea..f8ec2d5a5 100644 --- a/spec/models/budget_spec.rb +++ b/spec/models/budget_spec.rb @@ -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) }