Repository navigation
Conversation
(cherry picked from commit 9911c6d)
(cherry picked from commit a66a6e0)
(cherry picked from commit 796f8c5)
Ruby 3 no longer converts a trailing hash to keyword arguments, so CSV.generate_line raised ArgumentError. (From the riverock fork: 1c73400.)
- Define build_new_resource in to_prepare. ResourceController inherits from InheritedResources::Base, which lives in that gem's app/controllers, and Rails 7 doesn't autoload during initialization. - CSVBuilder: ActiveAdmin 2.14 builds CSVs with controller.in_paginated_batches, which wraps the loop in ActiveRecord::Base.uncached. Page through the controller's paginated_collection instead, and drop the unused @collection. (From the riverock fork: d6da61c.)
Mongoid's reflection.key is the foreign key for belongs_to, but _id for has_many, which built a _id_eq search that crashed the index page. Use the key only for belongs_to, and search other associations by the related document's id, which ransack-mongoid resolves through the association.
Mongoid's count ignores the criteria's skip and limit, so the index showed "Displaying 1 - 100 of 100" on a 30-per-page index. Pass skip and limit to count, which still counts in the database instead of loading the page.
Replace the commented-out argument (and the trailing comma RuboCop flags) with the reason: ActiveAdmin assigns resource_params right after building.
- Update test_app for Rails 6.1 and 7.0 (the Rails 6 files come from the riverock fork), and load Logger before Rails, which Rails 6.1 needs with concurrent-ruby 1.3.5. - Add Mongoid 8 config; read the Mongo host from MONGODB_HOST. - Pick Rails and Mongoid with RAILS_VERSION and MONGOID_VERSION, and stop committing Gemfile.lock, which can't cover the matrix. - Pin ransack-mongoid to the last commit that supports ransack < 4, and Devise to 4.x, which ActiveAdmin 2 requires. - Drop Poltergeist, whose PhantomJS is long discontinued. No spec needs JavaScript, so Capybara's default driver runs them. - rspec-rails 6.1; pass a String object name to FormBuilder in the filter form builder spec, as Rails 6.1+ requires. Co-authored-by: Nic Boie <boie0025@gmail.com>
Rails 6.1 doesn't support Ruby 3.4 or later, so those combinations are excluded. Run RuboCop on Ruby 3.3, since the gem now needs Ruby 3.1.
Supports Ruby 3.1+, Rails 6.1 and 7.0, Mongoid 7 and 8, and ActiveAdmin 2.x: - gemspec: Ruby >= 3.1, mongoid >= 7.0 and < 9, activeadmin ~> 2.0, and csv, which Ruby 3.4 no longer installs by default. - README: 2.0.0 requirements and how to install ransack-mongoid. - CHANGELOG with the breaking changes and fixes since 1.0.0.
setup-ruby's bundler-cache locked the Gemfile without the job's RAILS_VERSION and MONGOID_VERSION, so every job except the default Rails 7.0 / Mongoid 8.1 failed to install in frozen mode before any spec ran.
On ubuntu-latest, now 26.04, native extensions fail to build against Ruby 3.2's headers (unknown type name 'bool'). Pinning the image also keeps a future runner change from changing the results.
setup-ruby writes a Gemfile.lock for the default Rails 7.0 / Mongoid 8.1 even without bundler-cache. On Ruby 3.2 and 3.3, Bundler couldn't move that lock to Rails 6.1 with Mongoid 7.5, though a fresh resolve works.
boie0025
left a comment
There was a problem hiding this comment.
Nice work getting the suite running again. The fork changes, the to_prepare move and the collection_size count all look right to me. A few things before this merges:
-
Gemfile.lockis still committed. The description and the new.gitignoreentry say it's no longer committed, but the PR modifies it instead of removing it, and.gitignorehas no effect on a file that's already tracked. It needs agit rm --cached Gemfile.lock, or the description needs updating. -
has_manyselect filters may now match nothing instead of raising. Forhas_many,searchable_method_namereturns"#{method}_id", sofilter :postsonAdminUserbecomesposts_id_eq. As far as I can tell, ransack-mongoid's predicates build{ name => value }from the attribute name only, so this queriesAdminUserwhere_idequals the post id, which never matches. The smoke spec only renders/admin/admin_users; nothing submits that filter. Could you add a spec that filters admin users by a post? If it does return nothing, I think removing the filter, or leaving the error in place, is better than an empty result that looks real. -
CSV export and the query cache. ActiveAdmin's
in_paginated_batcheswraps the loop inActiveRecord::Base.uncachedso a large export doesn't keep every page in the query cache. The replacement drops that. With Mongoid's query cache enabled, a big export holds every batch in memory until the request ends. Wrapping the loop inMongo::QueryCache.uncached { ... }would keep the original behavior.
Smaller things:
test_app/config/mongoid.6.ymlchanges the host todb:27017. That looks like a local Docker setting, and Mongoid 6 isn't supported anymore, so the file could probably just be deleted.Post.ransack(*args) super endin the test app doesn't do anything. If it works around something, please say what; if not, it can go.- Most of the new
test_app/config/initializersfiles are generator boilerplate with everything commented out (CSP,application_controller_renderer,new_framework_defaults_6_0). Dropping them would keep the diff to what matters. searchable_has_many_through?can't be true for Mongoid associations, so that branch inselect_input.rbnever runs.
The test suite commit meant to untrack it but committed a regenerated copy instead, so the .gitignore entry had no effect.
- Initializers the Rails 6 generator added that the test app doesn't use (most are entirely commented out). - Mongoid 2-6 configs; 2.0 supports Mongoid 7 and 8, and spec/support picks the config by major version. - Post.ransack, which only called super.
ActiveAdmin's in_paginated_batches wraps the export in ActiveRecord::Base.uncached so a large export doesn't keep every page in the query cache. The replacement loop dropped that. Wrap it in Mongo's query cache uncached (Mongoid's on drivers without one). The CSV spec now also checks the rows are exported.
The has_many filter returned nothing: filter :posts on AdminUser searched posts_id_eq, which matched AdminUser _id against the post's id. Mongoid documents only store the keys of belongs_to and has_and_belongs_to_many associations; has_many and has_one keep theirs in the related documents. - Select filters use the stored key (reflection.key), as the fork did for belongs_to. That also covers has_and_belongs_to_many, which the previous change broke. - has_many and has_one are no longer default filters, and declaring one explicitly raises an error that says why, rather than showing an empty result. - Remove the has_many :through branch, which Mongoid associations never take. - Test app: drop filter :posts from admin users; add a has_and_belongs_to_many editors filter to posts, with a spec, and specs for the default association filters.
|
Thanks for the review. All addressed:
Smaller things (9f869b1, 50c742f):
Locally, 31 examples pass on Ruby 3.1, 3.3 and 4.0 across Rails 6.1/7.0 and Mongoid 7.5/8.1, and RuboCop is clean. |
boie0025
left a comment
There was a problem hiding this comment.
Approving. Thanks, all of it is addressed:
Gemfile.lockis untracked.- Filtering on the stored key (
reflection.key) is right for bothbelongs_toandhas_and_belongs_to_many, sinceeditor_ids_eqmatches documents whose array contains the id. Droppinghas_many/has_onefrom the default filters, and raising a clear error when one is declared explicitly, is better than an empty result. The new specs cover each case. - The CSV export skips the query cache, and the spec checks it.
Brings the changes that so far only lived in the riverock fork back into this repo, gets the test suite running on current Ruby/Rails/Mongoid, and prepares the 2.0.0 release.
2.0.0 supports Ruby 3.1+, Rails 6.1 and 7.0, Mongoid 7 and 8, and ActiveAdmin 2.x. 1.0.0 stays the release for older stacks. ActiveAdmin 3 support will follow in 3.0.0, after a
2-x-stablebranch is cut from the 2.0.0 tag for backports.Changes
From the riverock fork (cherry-picked with their original authors):
resource_paramstobuild_new_resource. ActiveAdmin assigns them right after building, so relation attributes were assigned twice.collection_sizestops loading the documents.primary_keyworks for subclasses of a document.reflection.keyinstead ofassociation_primary_key, which Mongoid associations don't have. On this repo's master, every association filter raisesundefined method 'association_primary_key'.to_prepare(Rails 7 doesn't autoload during initialization), and page through the controller's collection for CSV export instead ofin_paginated_batches, which needs ActiveRecord. Likein_paginated_batches, the export skips the query cache.Found by getting the suite running again:
has_manyassociations raisedundefined method '_id_eq':reflection.keyis_idforhas_many. Mongoid only stores the keys ofbelongs_toandhas_and_belongs_to_manyassociations in the document, so select filters use the stored key for those,has_manyandhas_oneare no longer default filters, and declaring one explicitly raises an error that says why.countignores skip and limit.collection_sizenow passes them, so it counts the current page in the database.Tests and CI:
test_appruns on Rails 6.1 and 7.0, with a Mongoid 8 config.RAILS_VERSIONandMONGOID_VERSIONpick the versions, andGemfile.lockis no longer committed, since one lockfile can't cover a matrix.ransack-mongoidis pinned to the last commit that supports ransack < 4, which ActiveAdmin 2 requires.Release 2.0.0: gemspec bounds (Ruby >= 3.1, mongoid >= 7.0 < 9, activeadmin ~> 2.0, plus
csv, which Ruby 3.4 no longer installs by default), the homepage, README requirements, and a CHANGELOG.Breaking changes
build_new_resourceno longer passesresource_params(see above).Testing
Locally, all 27 examples pass on Ruby 3.1, 3.3, 3.4 and 4.0, across the Rails 6.1/7.0 and Mongoid 7.5/8.1 combinations. RuboCop is clean, and
gem buildproduces activeadmin-mongoid-2.0.0.For comparison, this repo's current master fails most of the suite on the same stack (Ruby 3.3, Rails 6.1, Mongoid 7.5, ActiveAdmin 2.14), because of the
association_primary_keyerrors above.