Make filter rendering nil-safe for non-AR resources#9039
Open
Fivell wants to merge 1 commit into
Open
Conversation
6e44e3d to
227cf28
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9039 +/- ##
=======================================
Coverage 99.08% 99.08%
=======================================
Files 139 139
Lines 4040 4043 +3
=======================================
+ Hits 4003 4006 +3
Misses 37 37 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
227cf28 to
6b82510
Compare
ActiveAdmin's filter pipeline assumed an ActiveRecord-backed resource and
a Ransack::Search-shaped @search in six spots that raised for resources
backed by ActiveResource, API client wrappers, ActiveModel, or POROs:
* FormtasticAddons#klass, #scope?
* Resource::Attributes#default_attributes
* Resource#resource_column_names
* Views::TableFor::Column#sortable?
* Filters::Active#initialize
Each now short-circuits when the resource/search doesn't respond to the
AR/Ransack-specific method, returning nil / [] / {} / false instead of
raising. The AR path is byte-identical; no rescues, no monkey-patches.
Covered by features/index/non_ar_filters.feature: a PORO ApiPost resource
with find_collection override and a small Struct-based @search hydrated
from params[:q], demonstrating server-side pagination, filter narrowing,
and "Clear Filters" — all without monkey-patches.
Known limitation: the "Active Search" chips sidebar is tightly coupled
to Ransack::Condition (predicate / attributes / klass / reflect_on_all_
associations). It no longer raises but renders "No filters applied" for
non-Ransack searches. Hide it with config.current_filters = false or
provide a Ransack-shaped wrapper.
6b82510 to
083333b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ActiveAdmin's filter pipeline assumed an ActiveRecord-backed resource and a Ransack::Search-shaped @search in six spots that raised for resources backed by ActiveResource, API client wrappers, ActiveModel, or POROs:
Each now short-circuits when the resource/search doesn't respond to the AR/Ransack-specific method, returning nil / [] / {} / false instead of raising. The AR path is byte-identical; no rescues, no monkey-patches.
Covered by features/index/non_ar_filters.feature: a PORO ApiPost resource with find_collection override and @search = OpenStruct.new(params[:q]), demonstrating server-side pagination, filter narrowing, and "Clear Filters" — all without monkey-patches.
Known limitation: the "Active Search" chips sidebar is tightly coupled to Ransack::Condition (predicate / attributes / klass / reflect_on_all_ associations). It no longer raises but renders "No filters applied" for non-Ransack searches. Hide it with config.current_filters = false or provide a Ransack-shaped wrapper.