From 1d36f81c756fc3558ef1bcacb1bd6e072fa846af Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 27 Jan 2026 12:07:52 +1030 Subject: [PATCH 1/2] Add test for config subclass inheritance --- spec/models/katalyst/tables/collection/pagination_spec.rb | 2 ++ spec/support/collection_examples.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/spec/models/katalyst/tables/collection/pagination_spec.rb b/spec/models/katalyst/tables/collection/pagination_spec.rb index 3f056bbc..472ff6ab 100644 --- a/spec/models/katalyst/tables/collection/pagination_spec.rb +++ b/spec/models/katalyst/tables/collection/pagination_spec.rb @@ -11,6 +11,8 @@ it { is_expected.not_to be_filtered } it { is_expected.to have_attributes(to_params: {}) } + it { expect(Examples::PaginatedCollection.new).to be_paginate } + it { expect(Examples::InheritedPaginatedCollection.new).to be_paginate } it "does not paginate by default" do expect(collection.apply(items)).to have_attributes(count: 0, pagination: nil) diff --git a/spec/support/collection_examples.rb b/spec/support/collection_examples.rb index c01ac9fb..dec4b479 100644 --- a/spec/support/collection_examples.rb +++ b/spec/support/collection_examples.rb @@ -83,4 +83,10 @@ def filter self.items = items.search(search) if search.present? end end + + class PaginatedCollection < Katalyst::Tables::Collection::Base + config.paginate = true + end + + class InheritedPaginatedCollection < PaginatedCollection; end end From 6a27476caa89bdc4ea6f2d54372dbcd8371262ae Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 27 Jan 2026 12:08:17 +1030 Subject: [PATCH 2/2] Fix config inheritance for subclasses --- app/models/concerns/katalyst/tables/collection/core.rb | 6 ++++-- lib/katalyst/tables/config.rb | 2 -- spec/models/katalyst/tables/collection/pagination_spec.rb | 4 ++++ spec/support/collection_examples.rb | 6 +++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/models/concerns/katalyst/tables/collection/core.rb b/app/models/concerns/katalyst/tables/collection/core.rb index 26a068bc..788207f6 100644 --- a/app/models/concerns/katalyst/tables/collection/core.rb +++ b/app/models/concerns/katalyst/tables/collection/core.rb @@ -18,8 +18,9 @@ module Core # :nodoc: include Reducers class_methods do - def config - @config ||= Config.new + def inherited(subclass) + super + subclass.config = config.dup end def permitted_params @@ -53,6 +54,7 @@ def resolve_type_name(name, **) end included do + class_attribute :config, instance_accessor: false, default: Config.new attr_accessor :items, :unscoped_items delegate :each, :count, :empty?, to: :items, allow_nil: true diff --git a/lib/katalyst/tables/config.rb b/lib/katalyst/tables/config.rb index 442b017e..c28fda52 100644 --- a/lib/katalyst/tables/config.rb +++ b/lib/katalyst/tables/config.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "active_support/configurable" - module Katalyst module Tables class Config diff --git a/spec/models/katalyst/tables/collection/pagination_spec.rb b/spec/models/katalyst/tables/collection/pagination_spec.rb index 472ff6ab..5ab1d4b2 100644 --- a/spec/models/katalyst/tables/collection/pagination_spec.rb +++ b/spec/models/katalyst/tables/collection/pagination_spec.rb @@ -12,7 +12,11 @@ it { is_expected.not_to be_filtered } it { is_expected.to have_attributes(to_params: {}) } it { expect(Examples::PaginatedCollection.new).to be_paginate } + it { expect(Examples::PaginatedCollection.config).to have_attributes(paginate: { limit: 10 }) } it { expect(Examples::InheritedPaginatedCollection.new).to be_paginate } + it { expect(Examples::InheritedPaginatedCollection.config).to have_attributes(paginate: { limit: 10 }) } + it { expect(Examples::OverriddenPaginatedCollection.new).to be_paginate } + it { expect(Examples::OverriddenPaginatedCollection.config).to have_attributes(paginate: { limit: 20 }) } it "does not paginate by default" do expect(collection.apply(items)).to have_attributes(count: 0, pagination: nil) diff --git a/spec/support/collection_examples.rb b/spec/support/collection_examples.rb index dec4b479..0d7ec6ba 100644 --- a/spec/support/collection_examples.rb +++ b/spec/support/collection_examples.rb @@ -85,8 +85,12 @@ def filter end class PaginatedCollection < Katalyst::Tables::Collection::Base - config.paginate = true + config.paginate = { limit: 10 } end class InheritedPaginatedCollection < PaginatedCollection; end + + class OverriddenPaginatedCollection < PaginatedCollection + config.paginate = { limit: 20 } + end end