Skip to content

Port to Ruby 3, Mongoid 9, and Ransack 4.4 - #1

Merged
BeubeuCode merged 9 commits into
masterfrom
port/ruby3-mongoid9
May 8, 2026
Merged

Port to Ruby 3, Mongoid 9, and Ransack 4.4#1
BeubeuCode merged 9 commits into
masterfrom
port/ruby3-mongoid9

Conversation

@BeubeuCode

Copy link
Copy Markdown
Owner

Summary

  • Update all dependencies: Mongoid 9, Ransack 4.4, Ruby 3.3 (via RVM + Docker)
  • Fix Ruby 3 incompatibilities in the adapter (removed Bignum/Fixnum, guarded ActiveRecord references)
  • Rewrite adapter internals for Ransack 4.4 compatibility: visitor, context, constants, condition node, predicate registration
  • Replace Machinist/Faker/Sham test infrastructure with direct Mongoid create! calls

What changed

Lib:

  • Bignum/FixnumInteger (removed in Ruby 2.4)
  • Remove polyamorous require and dead AR join methods from context
  • Skip Ransack::Context#initialize super (pulls in Polyamorous::OuterJoin)
  • Override visit_Ransack_Nodes_Sort and formatted_values_for_attribute to avoid Arel (not loaded without ActiveRecord)
  • Override escape_wildcards with Regexp.escape instead of AR adapter detection
  • Re-register cont/not_cont/start/end predicates via Ransack.configure with MongoDB regex formatters
  • Add ransackable_scopes_skip_sanitize_args (new method required by Ransack 4.4)
  • Wire gem entry point (lib/ransack/mongoid.rb) to load the adapter

Tests:

  • Drop Machinist, Sham, Faker — replace Schema.create with plain create! calls (same data shape)
  • Add optional: true to all belongs_to (required by default since Mongoid 7)
  • Fix over_age scope: Symbol#gt removed, use { 'age' => { '$gt' => y } }

Test plan

  • docker compose up -d mongo to start MongoDB 7
  • bundle exec rspec — 148 examples, 0 failures, 20 pending (pending = pre-existing AR-only stubs)

BeubeuCode added 9 commits May 4, 2026 22:50
- 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.
@BeubeuCode
BeubeuCode merged commit d30b223 into master May 8, 2026
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