diff --git a/app/components/admin/budgets/index_component.rb b/app/components/admin/budgets/index_component.rb index 1bf411989..58203a206 100644 --- a/app/components/admin/budgets/index_component.rb +++ b/app/components/admin/budgets/index_component.rb @@ -19,7 +19,11 @@ class Admin::Budgets::IndexComponent < ApplicationComponent end def current_enabled_phase_number(budget) - budget.phases.enabled.order(:id).pluck(:kind).index(budget.phase) + 1 + current_enabled_phase_index(budget) + 1 + end + + def current_enabled_phase_index(budget) + budget.phases.enabled.order(:id).pluck(:kind).index(budget.phase) || -1 end def dates(budget) diff --git a/spec/components/admin/budgets/index_component_spec.rb b/spec/components/admin/budgets/index_component_spec.rb new file mode 100644 index 000000000..c6da3183a --- /dev/null +++ b/spec/components/admin/budgets/index_component_spec.rb @@ -0,0 +1,18 @@ +require "rails_helper" + +describe Admin::Budgets::IndexComponent, type: :component do + before do + allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BudgetsController") + allow_any_instance_of(Admin::BudgetsController).to receive(:valid_filters).and_return(["all"]) + allow_any_instance_of(Admin::BudgetsController).to receive(:current_filter).and_return("all") + end + + it "displays current phase zero for budgets with no current phase" do + budget = create(:budget, :accepting, name: "Not enabled phase") + budget.phases.accepting.update!(enabled: false) + + render_inline Admin::Budgets::IndexComponent.new(Budget.page(1)) + + expect(page.find("tr", text: "Not enabled phase")).to have_content "0/8" + end +end