Skip to content

Make filter rendering nil-safe for non-AR resources#9039

Open
Fivell wants to merge 1 commit into
masterfrom
non-ar-filter-rendering
Open

Make filter rendering nil-safe for non-AR resources#9039
Fivell wants to merge 1 commit into
masterfrom
non-ar-filter-rendering

Conversation

@Fivell

@Fivell Fivell commented Jun 1, 2026

Copy link
Copy Markdown
Member

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#build_filters

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.

@Fivell Fivell self-assigned this Jun 1, 2026
@Fivell Fivell force-pushed the non-ar-filter-rendering branch 6 times, most recently from 6e44e3d to 227cf28 Compare June 1, 2026 07:59
@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.08%. Comparing base (9045e76) to head (083333b).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Fivell Fivell force-pushed the non-ar-filter-rendering branch from 227cf28 to 6b82510 Compare June 1, 2026 08:16
@Fivell Fivell requested a review from javierjulio June 1, 2026 08:58
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.
@Fivell Fivell force-pushed the non-ar-filter-rendering branch from 6b82510 to 083333b Compare June 1, 2026 09:04
@Fivell Fivell requested a review from tagliala June 13, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant