Port to Ruby 3, Mongoid 9, and Ransack 4.4 - #1
Merged
Conversation
- Replace removed Bignum/Fixnum with Integer in visitor - Guard ActiveRecord references with defined? checks - Remove polyamorous require and dead AR join methods - Wire gem entry point to load the Mongoid adapter - Skip Ransack::Context#initialize super call (references Polyamorous) - Fix evaluate to handle empty searches (nil from viz.accept) - Fix type_for to handle nil from bind_pair_for - Add visit_Ransack_Nodes_Sort override (Arel not loaded without AR) - Override escape_wildcards to use Regexp.escape instead of AR adapter - Re-register cont/start/end predicates with MongoDB regex formatters - Override formatted_values_for_attribute to skip Arel::Nodes::Quoted - Add ransackable_scopes_skip_sanitize_args (new in Ransack 4.4) - Remove Mongoid 3.2 dead branch from adapter loader
- Remove machinist, sham, faker dependencies from spec_helper - Delete blueprint files (articles, comments, notes, people, tags) - Rewrite Schema.create with direct create! calls, same data shape - Add optional: true to all belongs_to associations (required in Mongoid 7+) - Fix over_age scope: Symbol#gt removed, use MongoDB hash syntax - Fix ::Mongoid::Criteria constant lookup (namespace shadowed by Ransack::Mongoid) - Drop Mongoid 4 compatibility code from spec_helper
MongoDB requires field-scoped negation — $not cannot be a top-level
query operator. Fix does_not_match and not_in:
{ name => { '$not' => /regex/ } } (was: { '$not' => { name => /regex/ } })
{ name => { '$nin' => array } } (was: { '$not' => { name => { '$in' => ... } } })
Update predicate_spec expectations accordingly.
Add examples/ directory with five runnable scripts covering basic
search, comparisons, sorting, groupings, and scope integration.
Update README with an Examples section.
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.
Summary
Bignum/Fixnum, guardedActiveRecordreferences)create!callsWhat changed
Lib:
Bignum/Fixnum→Integer(removed in Ruby 2.4)polyamorousrequire and dead AR join methods from contextRansack::Context#initializesuper(pulls inPolyamorous::OuterJoin)visit_Ransack_Nodes_Sortandformatted_values_for_attributeto avoid Arel (not loaded without ActiveRecord)escape_wildcardswithRegexp.escapeinstead of AR adapter detectioncont/not_cont/start/endpredicates viaRansack.configurewith MongoDB regex formattersransackable_scopes_skip_sanitize_args(new method required by Ransack 4.4)lib/ransack/mongoid.rb) to load the adapterTests:
Schema.createwith plaincreate!calls (same data shape)optional: trueto allbelongs_to(required by default since Mongoid 7)over_agescope:Symbol#gtremoved, use{ 'age' => { '$gt' => y } }Test plan
docker compose up -d mongoto start MongoDB 7bundle exec rspec— 148 examples, 0 failures, 20 pending (pending = pre-existing AR-only stubs)