diff --git a/app/models/concerns/katalyst/tables/collection/core.rb b/app/models/concerns/katalyst/tables/collection/core.rb index 26a068b..788207f 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 442b017..c28fda5 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 3f056bb..5ab1d4b 100644 --- a/spec/models/katalyst/tables/collection/pagination_spec.rb +++ b/spec/models/katalyst/tables/collection/pagination_spec.rb @@ -11,6 +11,12 @@ 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 c01ac9f..0d7ec6b 100644 --- a/spec/support/collection_examples.rb +++ b/spec/support/collection_examples.rb @@ -83,4 +83,14 @@ def filter self.items = items.search(search) if search.present? end end + + class PaginatedCollection < Katalyst::Tables::Collection::Base + config.paginate = { limit: 10 } + end + + class InheritedPaginatedCollection < PaginatedCollection; end + + class OverriddenPaginatedCollection < PaginatedCollection + config.paginate = { limit: 20 } + end end