From 6c009f77144cf808e9a346b6f2ee062eba95a784 Mon Sep 17 00:00:00 2001 From: Alex Kibler Date: Wed, 29 Nov 2023 09:01:06 -0700 Subject: [PATCH 01/19] Ensure we aren't double populating relation attributes (cherry picked from commit 9911c6da07008055bee15d5f9266f24115aca126) --- lib/active_admin/mongoid/controllers/resource_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_admin/mongoid/controllers/resource_controller.rb b/lib/active_admin/mongoid/controllers/resource_controller.rb index 67a3d12..c5b510e 100644 --- a/lib/active_admin/mongoid/controllers/resource_controller.rb +++ b/lib/active_admin/mongoid/controllers/resource_controller.rb @@ -6,7 +6,7 @@ class ActiveAdmin::ResourceController def build_new_resource scoped_collection.send( method_for_build, - *resource_params + # *resource_params ) end end From f4fd5f71057ddfa9cf52538afa93ba4e1c300080 Mon Sep 17 00:00:00 2001 From: Nic Boie Date: Fri, 15 Dec 2023 11:23:46 -0600 Subject: [PATCH 02/19] Remove entries from count method (cherry picked from commit a66a6e06a8b52307793c0aaed1be59f44e1ba8f9) --- lib/active_admin/mongoid/helpers/collection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_admin/mongoid/helpers/collection.rb b/lib/active_admin/mongoid/helpers/collection.rb index 10e5fd8..483bafa 100644 --- a/lib/active_admin/mongoid/helpers/collection.rb +++ b/lib/active_admin/mongoid/helpers/collection.rb @@ -8,7 +8,7 @@ module Collection def collection_size(collection = nil) collection ||= self.collection if collection.is_a?(::Mongoid::Criteria) - collection.entries.count + collection.count else original_collection_size(collection) end From a09420c5dd3e3d39e7289181ecb5e96924be4580 Mon Sep 17 00:00:00 2001 From: Nic Boie Date: Wed, 15 Apr 2026 12:24:28 -0500 Subject: [PATCH 03/19] Fix bug with inheritance and primary_key (cherry picked from commit 796f8c50c871f65e87c82d8db884575c557459c2) --- lib/active_admin/mongoid/document.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/active_admin/mongoid/document.rb b/lib/active_admin/mongoid/document.rb index 8f89f92..7dbbc19 100644 --- a/lib/active_admin/mongoid/document.rb +++ b/lib/active_admin/mongoid/document.rb @@ -27,16 +27,12 @@ def quote_column_name name end end - # CLASS METHODS - included do - unless respond_to? :primary_key - class << self - attr_accessor :primary_key - end + unless respond_to?(:primary_key) && respond_to?(:primary_key=) + class_attribute :primary_key, instance_writer: false end - self.primary_key ||= :id + self.primary_key = :id if primary_key.nil? def column_for_attribute(name) self.class.fields[name.to_sym] From 799f03d246a458671160ba02dff2604f5dd30362 Mon Sep 17 00:00:00 2001 From: Nic Boie Date: Tue, 1 Dec 2026 17:07:24 +0000 Subject: [PATCH 04/19] Use the association key for select filters Mongoid associations expose their foreign key as reflection.key, so build the select filter's search method from it, and fall back to the method name. (From the riverock fork: 0c79f67, 6143325.) --- lib/active_admin/mongoid.rb | 1 + .../mongoid/inputs/filters/select_input.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 lib/active_admin/mongoid/inputs/filters/select_input.rb diff --git a/lib/active_admin/mongoid.rb b/lib/active_admin/mongoid.rb index 16e46df..fcf14c0 100644 --- a/lib/active_admin/mongoid.rb +++ b/lib/active_admin/mongoid.rb @@ -16,6 +16,7 @@ require 'active_admin/mongoid/association/relatable' require 'active_admin/mongoid/inputs/filters/check_boxes_input' +require 'active_admin/mongoid/inputs/filters/select_input' require 'active_admin/mongoid/filters/active_filter' require 'active_admin/mongoid/filters/resource_extension' require 'active_admin/mongoid/controllers/resource_controller' diff --git a/lib/active_admin/mongoid/inputs/filters/select_input.rb b/lib/active_admin/mongoid/inputs/filters/select_input.rb new file mode 100644 index 0000000..b2d46d6 --- /dev/null +++ b/lib/active_admin/mongoid/inputs/filters/select_input.rb @@ -0,0 +1,17 @@ +require 'active_admin/inputs/filters/select_input' + +class ActiveAdmin::Inputs::Filters::SelectInput + def searchable_method_name + if searchable_has_many_through? + "#{reflection.through_reflection.name}_#{reflection.foreign_key}" + else + reflection&.key || method + end + end + + def input_name + return method if seems_searchable? + + searchable_method_name&.to_s + (multiple? ? '_in' : '_eq') + end +end From 6a2079c5b250857d0cce8227ed115e013e498986 Mon Sep 17 00:00:00 2001 From: Nic Boie Date: Tue, 1 Dec 2026 17:07:41 +0000 Subject: [PATCH 05/19] Pass CSV options as keyword arguments Ruby 3 no longer converts a trailing hash to keyword arguments, so CSV.generate_line raised ArgumentError. (From the riverock fork: 1c73400.) --- lib/active_admin/mongoid/csv_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_admin/mongoid/csv_builder.rb b/lib/active_admin/mongoid/csv_builder.rb index 16fdcfd..2e91b57 100644 --- a/lib/active_admin/mongoid/csv_builder.rb +++ b/lib/active_admin/mongoid/csv_builder.rb @@ -11,13 +11,13 @@ def build(controller, csv) csv << bom if bom if column_names - csv << CSV.generate_line(columns.map { |c| encode c.name, options }, csv_options) + csv << CSV.generate_line(columns.map { |c| encode c.name, options }, **csv_options) end (1..paginated_collection.total_pages).each do |page| paginated_collection(page).each do |resource| resource = controller.send :apply_decorator, resource - csv << CSV.generate_line(build_row(resource, columns, options), csv_options) + csv << CSV.generate_line(build_row(resource, columns, options), **csv_options) end end From 538be2f2989ddfef3ea502b128865e6b45bfc3d1 Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 17:07:41 +0000 Subject: [PATCH 06/19] Support Rails 7.0 and ActiveAdmin 2.14 - 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.) --- .../controllers/resource_controller.rb | 19 ++++++++++--------- lib/active_admin/mongoid/csv_builder.rb | 7 ++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/active_admin/mongoid/controllers/resource_controller.rb b/lib/active_admin/mongoid/controllers/resource_controller.rb index c5b510e..4d4e5a4 100644 --- a/lib/active_admin/mongoid/controllers/resource_controller.rb +++ b/lib/active_admin/mongoid/controllers/resource_controller.rb @@ -1,14 +1,15 @@ require 'active_admin/engine' -ActiveAdmin::Engine.module_eval do - initializer 'active_admin.mongoid.resource_controller' do - class ActiveAdmin::ResourceController - def build_new_resource - scoped_collection.send( - method_for_build, - # *resource_params - ) - end +# to_prepare, not an initializer: ResourceController inherits from InheritedResources::Base, +# which lives in that gem's app/controllers and can't be autoloaded during initialization +# on Rails 7. +ActiveAdmin::Engine.config.to_prepare do + ActiveAdmin::ResourceController.class_eval do + def build_new_resource + scoped_collection.send( + method_for_build, + # *resource_params + ) end end end diff --git a/lib/active_admin/mongoid/csv_builder.rb b/lib/active_admin/mongoid/csv_builder.rb index 2e91b57..4befec5 100644 --- a/lib/active_admin/mongoid/csv_builder.rb +++ b/lib/active_admin/mongoid/csv_builder.rb @@ -1,7 +1,6 @@ module ActiveAdmin class CSVBuilder def build(controller, csv) - @collection = controller.send :find_collection, except: :pagination columns = exec_columns controller.view_context options = ActiveAdmin.application.csv_options.merge self.options bom = options.delete :byte_order_mark @@ -14,8 +13,10 @@ def build(controller, csv) csv << CSV.generate_line(columns.map { |c| encode c.name, options }, **csv_options) end - (1..paginated_collection.total_pages).each do |page| - paginated_collection(page).each do |resource| + # Not ActiveAdmin's in_paginated_batches: it wraps the loop in ActiveRecord::Base.uncached, + # and ActiveRecord isn't loaded in a Mongoid app. + (1..controller.send(:paginated_collection).total_pages).each do |page| + controller.send(:paginated_collection, page).each do |resource| resource = controller.send :apply_decorator, resource csv << CSV.generate_line(build_row(resource, columns, options), **csv_options) end From f157d9b59c27c0aa3e1ca23b6460af933e14d46b Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 17:26:15 +0000 Subject: [PATCH 07/19] Fix select filters on has_many associations 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/inputs/filters/select_input.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/active_admin/mongoid/inputs/filters/select_input.rb b/lib/active_admin/mongoid/inputs/filters/select_input.rb index b2d46d6..84dea53 100644 --- a/lib/active_admin/mongoid/inputs/filters/select_input.rb +++ b/lib/active_admin/mongoid/inputs/filters/select_input.rb @@ -1,11 +1,19 @@ require 'active_admin/inputs/filters/select_input' class ActiveAdmin::Inputs::Filters::SelectInput + # ActiveAdmin builds this from reflection.association_primary_key, which Mongoid associations + # don't have. belongs_to filters search the foreign key on the document itself; other + # associations search the related document's id, which ransack-mongoid resolves through the + # association. def searchable_method_name if searchable_has_many_through? "#{reflection.through_reflection.name}_#{reflection.foreign_key}" + elsif reflection&.macro == :belongs_to + reflection.key + elsif reflection + "#{method}_id" else - reflection&.key || method + method end end From 8dda2502d44c8802bbfee0fa6bce42322cd9368c Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 17:26:15 +0000 Subject: [PATCH 08/19] Count only the current page in collection_size 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. --- lib/active_admin/mongoid/helpers/collection.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_admin/mongoid/helpers/collection.rb b/lib/active_admin/mongoid/helpers/collection.rb index 483bafa..09102ea 100644 --- a/lib/active_admin/mongoid/helpers/collection.rb +++ b/lib/active_admin/mongoid/helpers/collection.rb @@ -8,7 +8,9 @@ module Collection def collection_size(collection = nil) collection ||= self.collection if collection.is_a?(::Mongoid::Criteria) - collection.count + # Count in the database instead of loading the documents. Mongoid's count ignores the + # criteria's skip and limit, so pass them to get the size of the current page. + collection.count(collection.options.slice(:skip, :limit)) else original_collection_size(collection) end From 177e4ae0060aca71a53ccc8561dd0f7a794ca4b7 Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 17:26:15 +0000 Subject: [PATCH 09/19] Explain why build_new_resource doesn't pass params Replace the commented-out argument (and the trailing comma RuboCop flags) with the reason: ActiveAdmin assigns resource_params right after building. --- .../mongoid/controllers/resource_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/active_admin/mongoid/controllers/resource_controller.rb b/lib/active_admin/mongoid/controllers/resource_controller.rb index 4d4e5a4..bf8c0f3 100644 --- a/lib/active_admin/mongoid/controllers/resource_controller.rb +++ b/lib/active_admin/mongoid/controllers/resource_controller.rb @@ -5,11 +5,10 @@ # on Rails 7. ActiveAdmin::Engine.config.to_prepare do ActiveAdmin::ResourceController.class_eval do + # No params: ActiveAdmin assigns resource_params right after building, and passing them here + # too assigned relation attributes twice. def build_new_resource - scoped_collection.send( - method_for_build, - # *resource_params - ) + scoped_collection.send(method_for_build) end end end From cae6463c861bb79ce02fb2cf43541a03160db50a Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 17:26:15 +0000 Subject: [PATCH 10/19] Run the test suite on Rails 6.1/7.0 and Mongoid 7/8 - 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 --- .gitignore | 1 + Gemfile | 15 +- Gemfile.lock | 508 ++++++++++-------- activeadmin-mongoid.gemspec | 2 +- .../mongoid/filter_form_builder_spec.rb | 2 +- spec/support/capybara.rb | 2 - test_app/app/assets/config/manifest.js | 1 + test_app/app/models/post.rb | 5 + test_app/bin/rails | 4 + test_app/bin/rake | 4 + test_app/bin/setup | 25 + test_app/config/boot.rb | 7 +- test_app/config/environment.rb | 6 +- test_app/config/environments/development.rb | 2 + test_app/config/environments/test.rb | 2 + .../application_controller_renderer.rb | 8 + test_app/config/initializers/assets.rb | 12 + .../initializers/content_security_policy.rb | 28 + .../config/initializers/cookies_serializer.rb | 5 + .../initializers/filter_parameter_logging.rb | 4 + test_app/config/initializers/inflections.rb | 11 +- .../new_framework_defaults_6_0.rb | 45 ++ test_app/config/mongoid.6.yml | 2 +- test_app/config/mongoid.7.yml | 5 +- test_app/config/mongoid.8.yml | 13 + 25 files changed, 480 insertions(+), 239 deletions(-) create mode 100644 test_app/app/assets/config/manifest.js create mode 100755 test_app/bin/rails create mode 100755 test_app/bin/rake create mode 100755 test_app/bin/setup create mode 100644 test_app/config/initializers/application_controller_renderer.rb create mode 100644 test_app/config/initializers/assets.rb create mode 100644 test_app/config/initializers/content_security_policy.rb create mode 100644 test_app/config/initializers/cookies_serializer.rb create mode 100644 test_app/config/initializers/filter_parameter_logging.rb create mode 100644 test_app/config/initializers/new_framework_defaults_6_0.rb create mode 100644 test_app/config/mongoid.8.yml diff --git a/.gitignore b/.gitignore index d51e3c7..4ba66d4 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ spec/reports /test_app/config/mongoid.yml /spec/rails .ruby-version +Gemfile.lock diff --git a/Gemfile b/Gemfile index 6de200c..692e83f 100644 --- a/Gemfile +++ b/Gemfile @@ -2,21 +2,20 @@ source 'https://rubygems.org' gemspec -gem 'ransack-mongoid', git: 'https://github.com/activerecord-hackery/ransack-mongoid' +# ransack-mongoid 0.x was never released to RubyGems. Pinned to the last commit that supports +# ransack 2.x, which ActiveAdmin 2 requires. +gem 'ransack-mongoid', git: 'https://github.com/riverock/ransack-mongoid', ref: 'f83ae55ea67fc0a0bca30158f3e04c49362f4464' -gem 'rails', '>= 5.2', '< 6.1' - -gem 'devise' - -gem 'pry-rails' +# CI picks the versions; see .github/workflows/tests.yml. +gem 'rails', "~> #{ENV.fetch('RAILS_VERSION', '7.0')}.0" +gem 'mongoid', "~> #{ENV.fetch('MONGOID_VERSION', '8.1')}.0" +gem 'devise', '~> 4.0' # ActiveAdmin 2 requires < 5 gem 'jquery-rails' gem 'jquery-ui-rails' -gem 'jslint' group :test do gem 'capybara' - gem 'poltergeist' gem 'launchy' gem 'simplecov', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index f85a85e..5c7cd5d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,241 +1,321 @@ GIT - remote: https://github.com/activerecord-hackery/ransack-mongoid - revision: bd1935293d2f285fa7cf33d2c5c90d981bf67338 + remote: https://github.com/riverock/ransack-mongoid + revision: f83ae55ea67fc0a0bca30158f3e04c49362f4464 + ref: f83ae55ea67fc0a0bca30158f3e04c49362f4464 specs: - ransack-mongoid (0.1.0) + ransack-mongoid (0.1.2) PATH remote: . specs: activeadmin-mongoid (1.0.0) - activeadmin (>= 1.4.3) + activeadmin (~> 2.0) + csv jquery-rails kaminari-mongoid - mongoid (>= 6.0, < 8.a) + mongoid (>= 7.0, < 9) sass-rails (>= 3.1.4) GEM remote: https://rubygems.org/ specs: - actioncable (5.2.3) - actionpack (= 5.2.3) + actioncable (7.0.10) + actionpack (= 7.0.10) + activesupport (= 7.0.10) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) - activejob (= 5.2.3) + actionmailbox (7.0.10) + actionpack (= 7.0.10) + activejob (= 7.0.10) + activerecord (= 7.0.10) + activestorage (= 7.0.10) + activesupport (= 7.0.10) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.10) + actionpack (= 7.0.10) + actionview (= 7.0.10) + activejob (= 7.0.10) + activesupport (= 7.0.10) mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp rails-dom-testing (~> 2.0) - actionpack (5.2.3) - actionview (= 5.2.3) - activesupport (= 5.2.3) - rack (~> 2.0) + actionpack (7.0.10) + actionview (= 7.0.10) + activesupport (= 7.0.10) + racc + rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.3) - activesupport (= 5.2.3) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.10) + actionpack (= 7.0.10) + activerecord (= 7.0.10) + activestorage (= 7.0.10) + activesupport (= 7.0.10) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.0.10) + activesupport (= 7.0.10) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activeadmin (2.6.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activeadmin (2.14.0) arbre (~> 1.2, >= 1.2.1) - formtastic (~> 3.1) + formtastic (>= 3.1, < 5.0) formtastic_i18n (~> 0.4) inherited_resources (~> 1.7) jquery-rails (~> 4.2) - kaminari (~> 1.0, >= 1.0.1) - railties (>= 5.2, < 6.1) - ransack (~> 2.1, >= 2.1.1) - sassc-rails (~> 2.1) - sprockets (>= 3.0, < 4.1) - activejob (5.2.3) - activesupport (= 5.2.3) + kaminari (~> 1.0, >= 1.2.1) + railties (>= 6.1, < 7.1) + ransack (>= 2.1.1, < 4) + activejob (7.0.10) + activesupport (= 7.0.10) globalid (>= 0.3.6) - activemodel (5.2.3) - activesupport (= 5.2.3) - activerecord (5.2.3) - activemodel (= 5.2.3) - activesupport (= 5.2.3) - arel (>= 9.0) - activestorage (5.2.3) - actionpack (= 5.2.3) - activerecord (= 5.2.3) - marcel (~> 0.3.1) - activesupport (5.2.3) + activemodel (7.0.10) + activesupport (= 7.0.10) + activerecord (7.0.10) + activemodel (= 7.0.10) + activesupport (= 7.0.10) + activestorage (7.0.10) + actionpack (= 7.0.10) + activejob (= 7.0.10) + activerecord (= 7.0.10) + activesupport (= 7.0.10) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.10) + base64 + benchmark (>= 0.3) + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - arbre (1.2.1) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + mutex_m + securerandom (>= 0.3) + tzinfo (~> 2.0) + addressable (2.10.0) + public_suffix (>= 2.0.2, < 8.0) + arbre (1.7.0) activesupport (>= 3.0.0) - arel (9.0.0) - ast (2.4.0) - bcrypt (3.1.13) - bson (4.7.1) - builder (3.2.4) - capybara (3.12.0) + ruby2_keywords (>= 0.0.2) + ast (2.4.3) + base64 (0.3.0) + bcrypt (3.1.22) + benchmark (0.5.0) + bigdecimal (4.1.3) + bson (5.2.1) + base64 + bigdecimal + ostruct + builder (3.3.0) + capybara (3.40.0) addressable + matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) - regexp_parser (~> 1.2) + regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - cliver (0.3.2) - coderay (1.1.2) - concurrent-ruby (1.1.6) - crass (1.0.6) - devise (4.7.1) + childprocess (5.1.0) + logger (~> 1.5) + concurrent-ruby (1.3.8) + crass (1.0.8) + csv (3.3.7) + date (3.6.0) + devise (4.9.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.3) - docile (1.3.1) - erubi (1.9.0) - ffi (1.12.1) - formtastic (3.1.5) - actionpack (>= 3.2.13) - formtastic_i18n (0.6.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - has_scope (0.7.2) - actionpack (>= 4.1) - activesupport (>= 4.1) - i18n (1.8.2) + diff-lcs (1.6.2) + drb (2.2.3) + erubi (1.13.1) + ffi (1.17.4-aarch64-linux-gnu) + ffi (1.17.4-aarch64-linux-musl) + ffi (1.17.4-arm-linux-gnu) + ffi (1.17.4-arm-linux-musl) + ffi (1.17.4-arm64-darwin) + ffi (1.17.4-x86_64-darwin) + ffi (1.17.4-x86_64-linux-gnu) + ffi (1.17.4-x86_64-linux-musl) + formtastic (4.0.0) + actionpack (>= 5.2.0) + formtastic_i18n (0.7.0) + globalid (1.4.0) + activesupport (>= 6.1) + has_scope (0.8.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + i18n (1.15.2) concurrent-ruby (~> 1.0) - inherited_resources (1.11.0) - actionpack (>= 5.0, < 6.1) - has_scope (~> 0.6) - railties (>= 5.0, < 6.1) - responders (>= 2, < 4) - jaro_winkler (1.5.4) - jquery-rails (4.3.3) + inherited_resources (1.14.0) + actionpack (>= 6.0) + has_scope (>= 0.6) + railties (>= 6.0) + responders (>= 2) + jaro_winkler (1.5.6) + jquery-rails (4.6.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - jquery-ui-rails (6.0.1) + jquery-ui-rails (8.0.1) railties (>= 3.2.16) - jslint (1.2.0) - json - json (2.3.1) - kaminari (1.2.1) + kaminari (1.3.3) activesupport (>= 4.1.0) - kaminari-actionview (= 1.2.1) - kaminari-activerecord (= 1.2.1) - kaminari-core (= 1.2.1) - kaminari-actionview (1.2.1) + kaminari-actionview (= 1.3.3) + kaminari-activerecord (= 1.3.3) + kaminari-core (= 1.3.3) + kaminari-actionview (1.3.3) actionview - kaminari-core (= 1.2.1) - kaminari-activerecord (1.2.1) + kaminari-core (= 1.3.3) + kaminari-activerecord (1.3.3) activerecord - kaminari-core (= 1.2.1) - kaminari-core (1.2.1) - kaminari-mongoid (1.0.1) + kaminari-core (= 1.3.3) + kaminari-core (1.3.3) + kaminari-mongoid (1.0.2) kaminari-core (~> 1.0) mongoid - launchy (2.4.3) - addressable (~> 2.3) - loofah (2.5.0) + launchy (3.1.1) + addressable (~> 2.8) + childprocess (~> 5.0) + logger (~> 1.6) + logger (1.7.0) + loofah (2.25.3) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) + nokogiri (>= 1.19.5) + mail (2.9.1) + logger mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) - method_source (0.9.2) - mimemagic (0.3.10) - nokogiri (~> 1) - rake - mini_mime (1.0.1) - mini_portile2 (2.4.0) - minitest (5.14.1) - mongo (2.11.3) - bson (>= 4.4.2, < 5.0.0) - mongoid (7.0.5) - activemodel (>= 5.1, < 6.1) - mongo (>= 2.5.1, < 3.0.0) - nio4r (2.3.1) - nokogiri (1.10.9) - mini_portile2 (~> 2.4.0) + net-imap + net-pop + net-smtp + marcel (1.2.1) + matrix (0.4.3) + method_source (1.1.0) + mini_mime (1.1.5) + minitest (6.1.0) + drb (~> 2.0) + prism (>= 1.5, < 3) + mongo (2.26.2) + base64 + bson (>= 4.14.1, < 6.0.0) + mongoid (8.1.13) + activemodel (>= 5.1, < 8.1, != 7.0.0) + concurrent-ruby (>= 1.0.5, < 2.0) + mongo (>= 2.18.0, < 3.0.0) + ruby2_keywords (~> 0.0.5) + mutex_m (0.3.0) + net-imap (0.6.8) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.4.0) + timeout + net-smtp (0.5.2) + net-protocol + nio4r (2.7.5) + nokogiri (1.19.7-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.7-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.19.7-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.7-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.19.7-arm64-darwin) + racc (~> 1.4) + nokogiri (1.19.7-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.19.7-x86_64-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.7-x86_64-linux-musl) + racc (~> 1.4) orm_adapter (0.5.0) - parallel (1.19.1) - parser (2.7.0.2) - ast (~> 2.4.0) - poltergeist (1.18.1) - capybara (>= 2.1, < 4) - cliver (~> 0.3.1) - websocket-driver (>= 0.2.0) - polyamorous (2.3.2) - activerecord (>= 5.2.1) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - pry-rails (0.3.8) - pry (>= 0.10.4) - public_suffix (3.0.3) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.3) - actioncable (= 5.2.3) - actionmailer (= 5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) - activejob (= 5.2.3) - activemodel (= 5.2.3) - activerecord (= 5.2.3) - activestorage (= 5.2.3) - activesupport (= 5.2.3) - bundler (>= 1.3.0) - railties (= 5.2.3) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + ostruct (0.6.3) + parallel (1.28.0) + parser (3.3.14.0) + ast (~> 2.4.1) + racc + prism (2.1.0-aarch64-linux-gnu) + prism (2.1.0-aarch64-linux-musl) + prism (2.1.0-arm-linux-gnu) + prism (2.1.0-arm-linux-musl) + prism (2.1.0-arm64-darwin) + prism (2.1.0-x86_64-darwin) + prism (2.1.0-x86_64-linux-gnu) + prism (2.1.0-x86_64-linux-musl) + public_suffix (7.1.0) + racc (1.8.1) + rack (2.2.26) + rack-test (2.3.0) + rack (>= 1.3) + rails (7.0.10) + actioncable (= 7.0.10) + actionmailbox (= 7.0.10) + actionmailer (= 7.0.10) + actionpack (= 7.0.10) + actiontext (= 7.0.10) + actionview (= 7.0.10) + activejob (= 7.0.10) + activemodel (= 7.0.10) + activerecord (= 7.0.10) + activestorage (= 7.0.10) + activesupport (= 7.0.10) + bundler (>= 1.15.0) + railties (= 7.0.10) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) - loofah (~> 2.3) - railties (5.2.3) - actionpack (= 5.2.3) - activesupport (= 5.2.3) + rails-html-sanitizer (1.7.2) + loofah (~> 2.25, >= 2.25.3) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (7.0.10) + actionpack (= 7.0.10) + activesupport (= 7.0.10) method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rainbow (3.0.0) - rake (12.3.3) - ransack (2.3.2) - activerecord (>= 5.2.1) - activesupport (>= 5.2.1) + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) + rainbow (3.1.1) + rake (13.4.2) + ransack (3.2.1) + activerecord (>= 6.1.5) + activesupport (>= 6.1.5) i18n - polyamorous (= 2.3.2) - regexp_parser (1.3.0) - responders (2.4.1) - actionpack (>= 4.2.0, < 6.0) - railties (>= 4.2.0, < 6.0) - rexml (3.2.5) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + regexp_parser (2.13.4) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) + rexml (3.4.4) + rspec-core (3.13.7) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.6) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.9) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-rails (3.8.1) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) + rspec-support (~> 3.13.0) + rspec-rails (6.1.5) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.8) rubocop (0.80.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) @@ -244,10 +324,11 @@ GEM rexml ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) - ruby-progressbar (1.10.1) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.2.1) + sassc (2.4.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -255,50 +336,55 @@ GEM sprockets (> 3.0) sprockets-rails tilt - simplecov (0.16.1) - docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) + securerandom (0.4.1) + simplecov (1.3.2) + sprockets (4.4.1) + concurrent-ruby (~> 1.1) + logger + rack (>= 2.2.4, < 4) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) - thor (0.20.3) - thread_safe (0.3.6) - tilt (2.0.10) - tzinfo (1.2.7) - thread_safe (~> 0.1) + thor (1.5.0) + tilt (2.10.0) + timeout (0.6.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) unicode-display_width (1.6.1) - warden (1.2.8) - rack (>= 2.0.6) - websocket-driver (0.7.0) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) + warden (1.2.9) + rack (>= 2.0.9) + websocket-driver (0.9.1) + base64 + websocket-extensions (>= 0.2.0) + websocket-extensions (0.3.0) xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.8.3) PLATFORMS - ruby + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux-gnu + x86_64-linux-musl DEPENDENCIES activeadmin-mongoid! capybara - devise + devise (~> 4.0) jquery-rails jquery-ui-rails - jslint launchy - poltergeist - pry-rails - rails (>= 5.2, < 6.1) + mongoid (~> 8.1.0) + rails (~> 7.0.0) ransack-mongoid! - rspec-rails (~> 3.6) + rspec-rails (~> 6.1) rubocop (= 0.80.0) simplecov BUNDLED WITH - 1.17.3 + 2.5.22 diff --git a/activeadmin-mongoid.gemspec b/activeadmin-mongoid.gemspec index 9634269..154290e 100644 --- a/activeadmin-mongoid.gemspec +++ b/activeadmin-mongoid.gemspec @@ -25,5 +25,5 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'jquery-rails' gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4'] - gem.add_development_dependency 'rspec-rails', '~> 3.6' + gem.add_development_dependency 'rspec-rails', '~> 6.1' end diff --git a/spec/lib/active_admin/mongoid/filter_form_builder_spec.rb b/spec/lib/active_admin/mongoid/filter_form_builder_spec.rb index f900605..70e3660 100644 --- a/spec/lib/active_admin/mongoid/filter_form_builder_spec.rb +++ b/spec/lib/active_admin/mongoid/filter_form_builder_spec.rb @@ -2,7 +2,7 @@ describe ActiveAdmin::Filters::FormBuilder do describe '#default_input_type' do - let(:instance) { described_class.new({}, {}, {}, {}) } + let(:instance) { described_class.new('q', {}, {}, {}) } # object_name must be a String on Rails 6.1+ let(:column) { double(:column) } subject { instance.default_input_type(nil) } diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index f62bf7d..370d15f 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -1,3 +1 @@ require 'capybara/rails' -require 'capybara/poltergeist' -Capybara.javascript_driver = :poltergeist diff --git a/test_app/app/assets/config/manifest.js b/test_app/app/assets/config/manifest.js new file mode 100644 index 0000000..e2c3235 --- /dev/null +++ b/test_app/app/assets/config/manifest.js @@ -0,0 +1 @@ +//= link active_admin.js diff --git a/test_app/app/models/post.rb b/test_app/app/models/post.rb index 57b9704..357c9d9 100644 --- a/test_app/app/models/post.rb +++ b/test_app/app/models/post.rb @@ -10,4 +10,9 @@ class Post embeds_one :author field :'author.city.name' + + def self.ransack(*args) + super + end + end diff --git a/test_app/bin/rails b/test_app/bin/rails new file mode 100755 index 0000000..0739660 --- /dev/null +++ b/test_app/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/test_app/bin/rake b/test_app/bin/rake new file mode 100755 index 0000000..1724048 --- /dev/null +++ b/test_app/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/test_app/bin/setup b/test_app/bin/setup new file mode 100755 index 0000000..2e29ac1 --- /dev/null +++ b/test_app/bin/setup @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby +require 'fileutils' + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime and get an expectable outcome. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/test_app/config/boot.rb b/test_app/config/boot.rb index 4f49bfb..c6cc703 100644 --- a/test_app/config/boot.rb +++ b/test_app/config/boot.rb @@ -1,6 +1,5 @@ -require 'rubygems' - -# Set up gems listed in the Gemfile. +# Rails 6.1 relies on concurrent-ruby to load Logger, which concurrent-ruby 1.3.5 stopped doing. +require 'logger' ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/test_app/config/environment.rb b/test_app/config/environment.rb index ad9dd14..426333b 100644 --- a/test_app/config/environment.rb +++ b/test_app/config/environment.rb @@ -1,5 +1,5 @@ -# Load the rails application -require File.expand_path('application', __dir__) +# Load the Rails application. +require_relative 'application' -# Initialize the rails application +# Initialize the Rails application. Rails.application.initialize! diff --git a/test_app/config/environments/development.rb b/test_app/config/environments/development.rb index 8afe863..91850be 100644 --- a/test_app/config/environments/development.rb +++ b/test_app/config/environments/development.rb @@ -27,4 +27,6 @@ # Expands the lines which load the assets config.assets.debug = true + + config.eager_load = false end diff --git a/test_app/config/environments/test.rb b/test_app/config/environments/test.rb index 589d8a1..74e1057 100644 --- a/test_app/config/environments/test.rb +++ b/test_app/config/environments/test.rb @@ -33,4 +33,6 @@ # Print deprecation notices to the stderr config.active_support.deprecation = :stderr + + config.eager_load = false end diff --git a/test_app/config/initializers/application_controller_renderer.rb b/test_app/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000..89d2efa --- /dev/null +++ b/test_app/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/test_app/config/initializers/assets.rb b/test_app/config/initializers/assets.rb new file mode 100644 index 0000000..fe48fc3 --- /dev/null +++ b/test_app/config/initializers/assets.rb @@ -0,0 +1,12 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/test_app/config/initializers/content_security_policy.rb b/test_app/config/initializers/content_security_policy.rb new file mode 100644 index 0000000..41c4301 --- /dev/null +++ b/test_app/config/initializers/content_security_policy.rb @@ -0,0 +1,28 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Set the nonce only to specific directives +# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/test_app/config/initializers/cookies_serializer.rb b/test_app/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..1389e86 --- /dev/null +++ b/test_app/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :marshal diff --git a/test_app/config/initializers/filter_parameter_logging.rb b/test_app/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/test_app/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/test_app/config/initializers/inflections.rb b/test_app/config/initializers/inflections.rb index 5d8d9be..ac033bf 100644 --- a/test_app/config/initializers/inflections.rb +++ b/test_app/config/initializers/inflections.rb @@ -1,15 +1,16 @@ # Be sure to restart your server when you modify this file. -# Add new inflection rules using the following format -# (all these examples are active by default): -# ActiveSupport::Inflector.inflections do |inflect| +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end -# + # These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections do |inflect| +# ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym 'RESTful' # end diff --git a/test_app/config/initializers/new_framework_defaults_6_0.rb b/test_app/config/initializers/new_framework_defaults_6_0.rb new file mode 100644 index 0000000..92240ef --- /dev/null +++ b/test_app/config/initializers/new_framework_defaults_6_0.rb @@ -0,0 +1,45 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 6.0 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Don't force requests from old versions of IE to be UTF-8 encoded. +# Rails.application.config.action_view.default_enforce_utf8 = false + +# Embed purpose and expiry metadata inside signed and encrypted +# cookies for increased security. +# +# This option is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.0. +# Rails.application.config.action_dispatch.use_cookies_with_metadata = true + +# Change the return value of `ActionDispatch::Response#content_type` to Content-Type header without modification. +# Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false + +# Return false instead of self when enqueuing is aborted from a callback. +# Rails.application.config.active_job.return_false_on_aborted_enqueue = true + +# Send Active Storage analysis and purge jobs to dedicated queues. +# Rails.application.config.active_storage.queues.analysis = :active_storage_analysis +# Rails.application.config.active_storage.queues.purge = :active_storage_purge + +# When assigning to a collection of attachments declared via `has_many_attached`, replace existing +# attachments instead of appending. Use #attach to add new attachments without replacing existing ones. +# Rails.application.config.active_storage.replace_on_assign_to_many = true + +# Use ActionMailer::MailDeliveryJob for sending parameterized and normal mail. +# +# The default delivery jobs (ActionMailer::Parameterized::DeliveryJob, ActionMailer::DeliveryJob), +# will be removed in Rails 6.1. This setting is not backwards compatible with earlier Rails versions. +# If you send mail in the background, job workers need to have a copy of +# MailDeliveryJob to ensure all delivery jobs are processed properly. +# Make sure your entire app is migrated and stable on 6.0 before using this setting. +# Rails.application.config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" + +# Enable the same cache key to be reused when the object being cached of type +# `ActiveRecord::Relation` changes by moving the volatile information (max updated at and count) +# of the relation's cache key into the cache version to support recycling cache key. +# Rails.application.config.active_record.collection_cache_versioning = true diff --git a/test_app/config/mongoid.6.yml b/test_app/config/mongoid.6.yml index 0ecd0c6..b361124 100644 --- a/test_app/config/mongoid.6.yml +++ b/test_app/config/mongoid.6.yml @@ -3,5 +3,5 @@ test: default: database: activeadmin_mongoid_test hosts: - - localhost:27017 + - db:27017 #scope_overwrite_exception: true diff --git a/test_app/config/mongoid.7.yml b/test_app/config/mongoid.7.yml index e4a9498..2147dfd 100644 --- a/test_app/config/mongoid.7.yml +++ b/test_app/config/mongoid.7.yml @@ -3,12 +3,11 @@ development: default: database: activeadmin_mongoid_development hosts: - - localhost:27017 + - <%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %> test: clients: default: database: activeadmin_mongoid_test hosts: - - localhost:27017 -#scope_overwrite_exception: true + - <%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %> diff --git a/test_app/config/mongoid.8.yml b/test_app/config/mongoid.8.yml new file mode 100644 index 0000000..2147dfd --- /dev/null +++ b/test_app/config/mongoid.8.yml @@ -0,0 +1,13 @@ +development: + clients: + default: + database: activeadmin_mongoid_development + hosts: + - <%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %> + +test: + clients: + default: + database: activeadmin_mongoid_test + hosts: + - <%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %> From 6c58cec6d0149eb14e5f26cb8a358da80164aacb Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 17:26:15 +0000 Subject: [PATCH 11/19] Test Ruby 3.1-4.0, Rails 6.1/7.0 and Mongoid 7.5/8.1 in CI 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. --- .github/workflows/codecheck.yml | 4 ++-- .github/workflows/tests.yml | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/codecheck.yml b/.github/workflows/codecheck.yml index 74e9f03..36e110f 100644 --- a/.github/workflows/codecheck.yml +++ b/.github/workflows/codecheck.yml @@ -10,9 +10,9 @@ jobs: codecheck: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 + ruby-version: 3.3 bundler-cache: true - run: bundle exec rubocop \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bb6a602..fd648ef 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,18 +11,29 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest] - ruby: [2.5, 2.6, 2.7] - runs-on: ${{ matrix.os }} + ruby: ['3.1', '3.2', '3.3', '3.4', '4.0'] + rails: ['6.1', '7.0'] + mongoid: ['7.5', '8.1'] + exclude: + # Rails 6.1 doesn't support Ruby 3.4 or later. + - ruby: '3.4' + rails: '6.1' + - ruby: '4.0' + rails: '6.1' + runs-on: ubuntu-latest + name: Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }}, Mongoid ${{ matrix.mongoid }} + env: + RAILS_VERSION: ${{ matrix.rails }} + MONGOID_VERSION: ${{ matrix.mongoid }} services: mongodb: - image: mongo + image: mongo:7 ports: - 27017:27017 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} From e38463544b04d1e356c5b376cb692d6cca0b8ac0 Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 17:26:15 +0000 Subject: [PATCH 12/19] Release 2.0.0 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. --- CHANGELOG.md | 26 +++++++++++++++ Gemfile.lock | 52 ++++++++++------------------- README.md | 17 ++++++++-- activeadmin-mongoid.gemspec | 9 ++--- lib/active_admin/mongoid/version.rb | 2 +- 5 files changed, 65 insertions(+), 41 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5ce30ba --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,26 @@ +# Changelog + +## 2.0.0 + +Supports Ruby 3.1+, Rails 6.1 and 7.0, Mongoid 7 and 8, and ActiveAdmin 2.x. Use 1.0.0 for older +versions. + +### Breaking changes + +* Requires Ruby 3.1 or later, Mongoid 7.0 or later, and ActiveAdmin 2.x. +* `build_new_resource` no longer passes `resource_params` to the build method. ActiveAdmin assigns + them right after building, so they were being assigned twice. + +### Fixes + +* Rails 7.0: the resource controller patch is applied in `to_prepare`, since Rails 7 doesn't autoload + during initialization. +* ActiveAdmin 2.14: CSV export no longer goes through `in_paginated_batches`, which needs + ActiveRecord. +* Ruby 3: CSV options are passed as keyword arguments. +* Select filters on `belongs_to` associations search the foreign key, and filters on other + associations no longer raise. +* The index page's "Displaying X - Y" counts the current page in the database instead of loading + documents (and no longer counts the whole collection). +* `primary_key` works for subclasses of a document. +* Declares the `csv` dependency, which Ruby 3.4 no longer installs by default. diff --git a/Gemfile.lock b/Gemfile.lock index 5c7cd5d..06efa84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GIT PATH remote: . specs: - activeadmin-mongoid (1.0.0) + activeadmin-mongoid (2.0.0) activeadmin (~> 2.0) csv jquery-rails @@ -138,6 +138,7 @@ GEM responders warden (~> 1.2.3) diff-lcs (1.6.2) + docile (1.4.1) drb (2.2.3) erubi (1.13.1) ffi (1.17.4-aarch64-linux-gnu) @@ -190,9 +191,9 @@ GEM childprocess (~> 5.0) logger (~> 1.6) logger (1.7.0) - loofah (2.25.3) + loofah (2.25.2) crass (~> 1.0.2) - nokogiri (>= 1.19.5) + nokogiri (>= 1.12.0) mail (2.9.1) logger mini_mime (>= 0.1.1) @@ -203,9 +204,8 @@ GEM matrix (0.4.3) method_source (1.1.0) mini_mime (1.1.5) - minitest (6.1.0) - drb (~> 2.0) - prism (>= 1.5, < 3) + mini_portile2 (2.8.9) + minitest (5.27.0) mongo (2.26.2) base64 bson (>= 4.14.1, < 6.0.0) @@ -225,21 +225,8 @@ GEM net-smtp (0.5.2) net-protocol nio4r (2.7.5) - nokogiri (1.19.7-aarch64-linux-gnu) - racc (~> 1.4) - nokogiri (1.19.7-aarch64-linux-musl) - racc (~> 1.4) - nokogiri (1.19.7-arm-linux-gnu) - racc (~> 1.4) - nokogiri (1.19.7-arm-linux-musl) - racc (~> 1.4) - nokogiri (1.19.7-arm64-darwin) - racc (~> 1.4) - nokogiri (1.19.7-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.19.7-x86_64-linux-gnu) - racc (~> 1.4) - nokogiri (1.19.7-x86_64-linux-musl) + nokogiri (1.18.10) + mini_portile2 (~> 2.8.2) racc (~> 1.4) orm_adapter (0.5.0) ostruct (0.6.3) @@ -247,15 +234,7 @@ GEM parser (3.3.14.0) ast (~> 2.4.1) racc - prism (2.1.0-aarch64-linux-gnu) - prism (2.1.0-aarch64-linux-musl) - prism (2.1.0-arm-linux-gnu) - prism (2.1.0-arm-linux-musl) - prism (2.1.0-arm64-darwin) - prism (2.1.0-x86_64-darwin) - prism (2.1.0-x86_64-linux-gnu) - prism (2.1.0-x86_64-linux-musl) - public_suffix (7.1.0) + public_suffix (6.0.2) racc (1.8.1) rack (2.2.26) rack-test (2.3.0) @@ -278,8 +257,8 @@ GEM activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.7.2) - loofah (~> 2.25, >= 2.25.3) + rails-html-sanitizer (1.7.1) + loofah (~> 2.25, >= 2.25.2) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) railties (7.0.10) actionpack (= 7.0.10) @@ -337,7 +316,12 @@ GEM sprockets-rails tilt securerandom (0.4.1) - simplecov (1.3.2) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.13.2) + simplecov_json_formatter (0.1.4) sprockets (4.4.1) concurrent-ruby (~> 1.1) logger @@ -360,7 +344,7 @@ GEM websocket-extensions (0.3.0) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.8.3) + zeitwerk (2.6.18) PLATFORMS aarch64-linux-gnu diff --git a/README.md b/README.md index 60feb35..5ffc540 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,19 @@ ActiveAdmin is holding off on pulling Mongoid support into the core ActiveAdmin application. This repo was pulled into the ActiveAdmin org from previous work done by Elia Schito, and will be maintained by Grzegorz Jakubiak, Nic Boie, JD Guzman, Elia Schito and other ActiveAdmin and community members. +### Requirements for version 2.0.0 +* Ruby 3.1 or greater (Ruby 3.4 and later need Rails 7.0). +* Rails 6.1 or 7.0 +* Mongoid 7.x or 8.x +* ActiveAdmin 2.x (tested on 2.14) +* `ransack-mongoid` - declare it in your Gemfile from GitHub; it has no RubyGems release that supports ransack 2.x or 3.x, which ActiveAdmin 2 requires: + + ```ruby + gem 'ransack-mongoid', github: 'riverock/ransack-mongoid', ref: 'f83ae55ea67fc0a0bca30158f3e04c49362f4464' + ``` + +See [CHANGELOG.md](CHANGELOG.md) for the changes from 1.0.0. + ### Requirements for version 1.0.0 * Ruby 2.4.0 or greater. * Tested working on Rails 5.2.3 @@ -39,8 +52,8 @@ For more on Mongoid support in ActiveAdmin see [this issue](https://github.com/g Add the following gems to your application's Gemfile, and lock the version: ```ruby -gem 'activeadmin-mongoid', '1.0.0' -gem 'ransack-mongoid', github: 'activerecord-hackery/ransack-mongoid' +gem 'activeadmin-mongoid', '~> 2.0' +gem 'ransack-mongoid', github: 'riverock/ransack-mongoid', ref: 'f83ae55ea67fc0a0bca30158f3e04c49362f4464' ``` You can safely remove the following lines, since are already activeadmin-mongoid dependencies: diff --git a/activeadmin-mongoid.gemspec b/activeadmin-mongoid.gemspec index 154290e..b46f474 100644 --- a/activeadmin-mongoid.gemspec +++ b/activeadmin-mongoid.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |gem| gem.email = ['elia@schito.me'] gem.description = %q{ActiveAdmin hacks to support Mongoid (some ActiveAdmin features are disabled)} gem.summary = %q{ActiveAdmin hacks to support Mongoid} - gem.homepage = '' + gem.homepage = 'https://github.com/activeadmin/activeadmin-mongoid' gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } gem.files = `git ls-files`.split("\n") @@ -17,10 +17,11 @@ Gem::Specification.new do |gem| gem.version = ActiveAdmin::Mongoid::VERSION gem.license = 'MIT' - gem.required_ruby_version = '>= 2.4' + gem.required_ruby_version = '>= 3.1' - gem.add_runtime_dependency 'mongoid', '>= 6.0', '< 8.a' - gem.add_runtime_dependency 'activeadmin', '>= 1.4.3' + gem.add_runtime_dependency 'mongoid', '>= 7.0', '< 9' + gem.add_runtime_dependency 'activeadmin', '~> 2.0' + gem.add_runtime_dependency 'csv' # the CSV builder; no longer a default gem from Ruby 3.4 gem.add_runtime_dependency 'kaminari-mongoid' gem.add_runtime_dependency 'jquery-rails' gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4'] diff --git a/lib/active_admin/mongoid/version.rb b/lib/active_admin/mongoid/version.rb index c67e774..7a3c100 100644 --- a/lib/active_admin/mongoid/version.rb +++ b/lib/active_admin/mongoid/version.rb @@ -1,5 +1,5 @@ module ActiveAdmin module Mongoid - VERSION = '1.0.0' + VERSION = '2.0.0' end end From e44803c19badae0de61996178783abb7f9bb0f54 Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 17:40:38 +0000 Subject: [PATCH 13/19] Install gems in CI with bundle install, not setup-ruby's cache 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. --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fd648ef..63dee1b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,5 +37,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - bundler-cache: true + # Not setup-ruby's bundler-cache: it locks the Gemfile without this job's RAILS_VERSION and + # MONGOID_VERSION, then refuses to install the matrix versions against that frozen lockfile. + - run: bundle install - run: bundle exec rake From eb0c2b1c6eae8d9a5503bcc27fb265745f81f493 Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 17:53:10 +0000 Subject: [PATCH 14/19] Run CI on ubuntu-24.04 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. --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 63dee1b..02f195c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,7 +20,8 @@ jobs: rails: '6.1' - ruby: '4.0' rails: '6.1' - runs-on: ubuntu-latest + # ubuntu-latest (26.04) can't compile native extensions against Ruby 3.2's headers. + runs-on: ubuntu-24.04 name: Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }}, Mongoid ${{ matrix.mongoid }} env: RAILS_VERSION: ${{ matrix.rails }} From 9d1131ac8eea2db8917b434844e66b77dab627ee Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 17:56:50 +0000 Subject: [PATCH 15/19] Resolve gems from scratch in each CI job 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. --- .github/workflows/tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 02f195c..d2bd3cc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,6 +39,7 @@ jobs: with: ruby-version: ${{ matrix.ruby }} # Not setup-ruby's bundler-cache: it locks the Gemfile without this job's RAILS_VERSION and - # MONGOID_VERSION, then refuses to install the matrix versions against that frozen lockfile. - - run: bundle install + # MONGOID_VERSION. setup-ruby still writes that default lockfile, and moving it to this job's + # versions can fail to resolve, so resolve from scratch. + - run: rm -f Gemfile.lock && bundle install - run: bundle exec rake From e2400fbf609710c663bd16b45450e38e4f0dd71a Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Wed, 2 Dec 2026 00:35:15 +0000 Subject: [PATCH 16/19] Stop tracking Gemfile.lock The test suite commit meant to untrack it but committed a regenerated copy instead, so the .gitignore entry had no effect. --- Gemfile.lock | 374 --------------------------------------------------- 1 file changed, 374 deletions(-) delete mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 06efa84..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,374 +0,0 @@ -GIT - remote: https://github.com/riverock/ransack-mongoid - revision: f83ae55ea67fc0a0bca30158f3e04c49362f4464 - ref: f83ae55ea67fc0a0bca30158f3e04c49362f4464 - specs: - ransack-mongoid (0.1.2) - -PATH - remote: . - specs: - activeadmin-mongoid (2.0.0) - activeadmin (~> 2.0) - csv - jquery-rails - kaminari-mongoid - mongoid (>= 7.0, < 9) - sass-rails (>= 3.1.4) - -GEM - remote: https://rubygems.org/ - specs: - actioncable (7.0.10) - actionpack (= 7.0.10) - activesupport (= 7.0.10) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (7.0.10) - actionpack (= 7.0.10) - activejob (= 7.0.10) - activerecord (= 7.0.10) - activestorage (= 7.0.10) - activesupport (= 7.0.10) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.0.10) - actionpack (= 7.0.10) - actionview (= 7.0.10) - activejob (= 7.0.10) - activesupport (= 7.0.10) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.10) - actionview (= 7.0.10) - activesupport (= 7.0.10) - racc - rack (~> 2.0, >= 2.2.4) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.10) - actionpack (= 7.0.10) - activerecord (= 7.0.10) - activestorage (= 7.0.10) - activesupport (= 7.0.10) - globalid (>= 0.6.0) - nokogiri (>= 1.8.5) - actionview (7.0.10) - activesupport (= 7.0.10) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activeadmin (2.14.0) - arbre (~> 1.2, >= 1.2.1) - formtastic (>= 3.1, < 5.0) - formtastic_i18n (~> 0.4) - inherited_resources (~> 1.7) - jquery-rails (~> 4.2) - kaminari (~> 1.0, >= 1.2.1) - railties (>= 6.1, < 7.1) - ransack (>= 2.1.1, < 4) - activejob (7.0.10) - activesupport (= 7.0.10) - globalid (>= 0.3.6) - activemodel (7.0.10) - activesupport (= 7.0.10) - activerecord (7.0.10) - activemodel (= 7.0.10) - activesupport (= 7.0.10) - activestorage (7.0.10) - actionpack (= 7.0.10) - activejob (= 7.0.10) - activerecord (= 7.0.10) - activesupport (= 7.0.10) - marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.10) - base64 - benchmark (>= 0.3) - bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) - drb - i18n (>= 1.6, < 2) - logger (>= 1.4.2) - minitest (>= 5.1) - mutex_m - securerandom (>= 0.3) - tzinfo (~> 2.0) - addressable (2.10.0) - public_suffix (>= 2.0.2, < 8.0) - arbre (1.7.0) - activesupport (>= 3.0.0) - ruby2_keywords (>= 0.0.2) - ast (2.4.3) - base64 (0.3.0) - bcrypt (3.1.22) - benchmark (0.5.0) - bigdecimal (4.1.3) - bson (5.2.1) - base64 - bigdecimal - ostruct - builder (3.3.0) - capybara (3.40.0) - addressable - matrix - mini_mime (>= 0.1.3) - nokogiri (~> 1.11) - rack (>= 1.6.0) - rack-test (>= 0.6.3) - regexp_parser (>= 1.5, < 3.0) - xpath (~> 3.2) - childprocess (5.1.0) - logger (~> 1.5) - concurrent-ruby (1.3.8) - crass (1.0.8) - csv (3.3.7) - date (3.6.0) - devise (4.9.4) - bcrypt (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 4.1.0) - responders - warden (~> 1.2.3) - diff-lcs (1.6.2) - docile (1.4.1) - drb (2.2.3) - erubi (1.13.1) - ffi (1.17.4-aarch64-linux-gnu) - ffi (1.17.4-aarch64-linux-musl) - ffi (1.17.4-arm-linux-gnu) - ffi (1.17.4-arm-linux-musl) - ffi (1.17.4-arm64-darwin) - ffi (1.17.4-x86_64-darwin) - ffi (1.17.4-x86_64-linux-gnu) - ffi (1.17.4-x86_64-linux-musl) - formtastic (4.0.0) - actionpack (>= 5.2.0) - formtastic_i18n (0.7.0) - globalid (1.4.0) - activesupport (>= 6.1) - has_scope (0.8.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - i18n (1.15.2) - concurrent-ruby (~> 1.0) - inherited_resources (1.14.0) - actionpack (>= 6.0) - has_scope (>= 0.6) - railties (>= 6.0) - responders (>= 2) - jaro_winkler (1.5.6) - jquery-rails (4.6.1) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - jquery-ui-rails (8.0.1) - railties (>= 3.2.16) - kaminari (1.3.3) - activesupport (>= 4.1.0) - kaminari-actionview (= 1.3.3) - kaminari-activerecord (= 1.3.3) - kaminari-core (= 1.3.3) - kaminari-actionview (1.3.3) - actionview - kaminari-core (= 1.3.3) - kaminari-activerecord (1.3.3) - activerecord - kaminari-core (= 1.3.3) - kaminari-core (1.3.3) - kaminari-mongoid (1.0.2) - kaminari-core (~> 1.0) - mongoid - launchy (3.1.1) - addressable (~> 2.8) - childprocess (~> 5.0) - logger (~> 1.6) - logger (1.7.0) - loofah (2.25.2) - crass (~> 1.0.2) - nokogiri (>= 1.12.0) - mail (2.9.1) - logger - mini_mime (>= 0.1.1) - net-imap - net-pop - net-smtp - marcel (1.2.1) - matrix (0.4.3) - method_source (1.1.0) - mini_mime (1.1.5) - mini_portile2 (2.8.9) - minitest (5.27.0) - mongo (2.26.2) - base64 - bson (>= 4.14.1, < 6.0.0) - mongoid (8.1.13) - activemodel (>= 5.1, < 8.1, != 7.0.0) - concurrent-ruby (>= 1.0.5, < 2.0) - mongo (>= 2.18.0, < 3.0.0) - ruby2_keywords (~> 0.0.5) - mutex_m (0.3.0) - net-imap (0.6.8) - date - net-protocol - net-pop (0.1.2) - net-protocol - net-protocol (0.4.0) - timeout - net-smtp (0.5.2) - net-protocol - nio4r (2.7.5) - nokogiri (1.18.10) - mini_portile2 (~> 2.8.2) - racc (~> 1.4) - orm_adapter (0.5.0) - ostruct (0.6.3) - parallel (1.28.0) - parser (3.3.14.0) - ast (~> 2.4.1) - racc - public_suffix (6.0.2) - racc (1.8.1) - rack (2.2.26) - rack-test (2.3.0) - rack (>= 1.3) - rails (7.0.10) - actioncable (= 7.0.10) - actionmailbox (= 7.0.10) - actionmailer (= 7.0.10) - actionpack (= 7.0.10) - actiontext (= 7.0.10) - actionview (= 7.0.10) - activejob (= 7.0.10) - activemodel (= 7.0.10) - activerecord (= 7.0.10) - activestorage (= 7.0.10) - activesupport (= 7.0.10) - bundler (>= 1.15.0) - railties (= 7.0.10) - rails-dom-testing (2.3.0) - activesupport (>= 5.0.0) - minitest - nokogiri (>= 1.6) - rails-html-sanitizer (1.7.1) - loofah (~> 2.25, >= 2.25.2) - nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) - railties (7.0.10) - actionpack (= 7.0.10) - activesupport (= 7.0.10) - method_source - rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) - rainbow (3.1.1) - rake (13.4.2) - ransack (3.2.1) - activerecord (>= 6.1.5) - activesupport (>= 6.1.5) - i18n - regexp_parser (2.13.4) - responders (3.1.1) - actionpack (>= 5.2) - railties (>= 5.2) - rexml (3.4.4) - rspec-core (3.13.7) - rspec-support (~> 3.13.0) - rspec-expectations (3.13.6) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.13.0) - rspec-mocks (3.13.9) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.13.0) - rspec-rails (6.1.5) - actionpack (>= 6.1) - activesupport (>= 6.1) - railties (>= 6.1) - rspec-core (~> 3.13) - rspec-expectations (~> 3.13) - rspec-mocks (~> 3.13) - rspec-support (~> 3.13) - rspec-support (3.13.8) - rubocop (0.80.0) - jaro_winkler (~> 1.5.1) - parallel (~> 1.10) - parser (>= 2.7.0.1) - rainbow (>= 2.2.2, < 4.0) - rexml - ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.7) - ruby-progressbar (1.13.0) - ruby2_keywords (0.0.5) - sass-rails (6.0.0) - sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.4.0) - ffi (~> 1.9) - sassc-rails (2.1.2) - railties (>= 4.0.0) - sassc (>= 2.0) - sprockets (> 3.0) - sprockets-rails - tilt - securerandom (0.4.1) - simplecov (0.22.0) - docile (~> 1.1) - simplecov-html (~> 0.11) - simplecov_json_formatter (~> 0.1) - simplecov-html (0.13.2) - simplecov_json_formatter (0.1.4) - sprockets (4.4.1) - concurrent-ruby (~> 1.1) - logger - rack (>= 2.2.4, < 4) - sprockets-rails (3.5.2) - actionpack (>= 6.1) - activesupport (>= 6.1) - sprockets (>= 3.0.0) - thor (1.5.0) - tilt (2.10.0) - timeout (0.6.1) - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) - unicode-display_width (1.6.1) - warden (1.2.9) - rack (>= 2.0.9) - websocket-driver (0.9.1) - base64 - websocket-extensions (>= 0.2.0) - websocket-extensions (0.3.0) - xpath (3.2.0) - nokogiri (~> 1.8) - zeitwerk (2.6.18) - -PLATFORMS - aarch64-linux-gnu - aarch64-linux-musl - arm-linux-gnu - arm-linux-musl - arm64-darwin - x86_64-darwin - x86_64-linux-gnu - x86_64-linux-musl - -DEPENDENCIES - activeadmin-mongoid! - capybara - devise (~> 4.0) - jquery-rails - jquery-ui-rails - launchy - mongoid (~> 8.1.0) - rails (~> 7.0.0) - ransack-mongoid! - rspec-rails (~> 6.1) - rubocop (= 0.80.0) - simplecov - -BUNDLED WITH - 2.5.22 From 9f869b1d4920f9a71cfe06fa637250ba883da13e Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Wed, 2 Dec 2026 00:40:53 +0000 Subject: [PATCH 17/19] Drop test app boilerplate and old Mongoid configs - 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. --- test_app/app/models/post.rb | 4 - .../application_controller_renderer.rb | 8 -- test_app/config/initializers/assets.rb | 12 --- .../initializers/content_security_policy.rb | 28 ------ .../config/initializers/cookies_serializer.rb | 5 - .../initializers/filter_parameter_logging.rb | 4 - .../new_framework_defaults_6_0.rb | 45 --------- test_app/config/mongoid.2.yml | 20 ---- test_app/config/mongoid.3.yml | 96 ------------------- test_app/config/mongoid.4.yml | 87 ----------------- test_app/config/mongoid.5.yml | 7 -- test_app/config/mongoid.6.yml | 7 -- 12 files changed, 323 deletions(-) delete mode 100644 test_app/config/initializers/application_controller_renderer.rb delete mode 100644 test_app/config/initializers/assets.rb delete mode 100644 test_app/config/initializers/content_security_policy.rb delete mode 100644 test_app/config/initializers/cookies_serializer.rb delete mode 100644 test_app/config/initializers/filter_parameter_logging.rb delete mode 100644 test_app/config/initializers/new_framework_defaults_6_0.rb delete mode 100644 test_app/config/mongoid.2.yml delete mode 100644 test_app/config/mongoid.3.yml delete mode 100644 test_app/config/mongoid.4.yml delete mode 100644 test_app/config/mongoid.5.yml delete mode 100644 test_app/config/mongoid.6.yml diff --git a/test_app/app/models/post.rb b/test_app/app/models/post.rb index 357c9d9..fb905dd 100644 --- a/test_app/app/models/post.rb +++ b/test_app/app/models/post.rb @@ -11,8 +11,4 @@ class Post embeds_one :author field :'author.city.name' - def self.ransack(*args) - super - end - end diff --git a/test_app/config/initializers/application_controller_renderer.rb b/test_app/config/initializers/application_controller_renderer.rb deleted file mode 100644 index 89d2efa..0000000 --- a/test_app/config/initializers/application_controller_renderer.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# ActiveSupport::Reloader.to_prepare do -# ApplicationController.renderer.defaults.merge!( -# http_host: 'example.org', -# https: false -# ) -# end diff --git a/test_app/config/initializers/assets.rb b/test_app/config/initializers/assets.rb deleted file mode 100644 index fe48fc3..0000000 --- a/test_app/config/initializers/assets.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Version of your assets, change this if you want to expire all your assets. -Rails.application.config.assets.version = '1.0' - -# Add additional assets to the asset load path. -# Rails.application.config.assets.paths << Emoji.images_path - -# Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in the app/assets -# folder are already added. -# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/test_app/config/initializers/content_security_policy.rb b/test_app/config/initializers/content_security_policy.rb deleted file mode 100644 index 41c4301..0000000 --- a/test_app/config/initializers/content_security_policy.rb +++ /dev/null @@ -1,28 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Define an application-wide content security policy -# For further information see the following documentation -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy - -# Rails.application.config.content_security_policy do |policy| -# policy.default_src :self, :https -# policy.font_src :self, :https, :data -# policy.img_src :self, :https, :data -# policy.object_src :none -# policy.script_src :self, :https -# policy.style_src :self, :https - -# # Specify URI for violation reports -# # policy.report_uri "/csp-violation-report-endpoint" -# end - -# If you are using UJS then enable automatic nonce generation -# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } - -# Set the nonce only to specific directives -# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) - -# Report CSP violations to a specified URI -# For further information see the following documentation: -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only -# Rails.application.config.content_security_policy_report_only = true diff --git a/test_app/config/initializers/cookies_serializer.rb b/test_app/config/initializers/cookies_serializer.rb deleted file mode 100644 index 1389e86..0000000 --- a/test_app/config/initializers/cookies_serializer.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Specify a serializer for the signed and encrypted cookie jars. -# Valid options are :json, :marshal, and :hybrid. -Rails.application.config.action_dispatch.cookies_serializer = :marshal diff --git a/test_app/config/initializers/filter_parameter_logging.rb b/test_app/config/initializers/filter_parameter_logging.rb deleted file mode 100644 index 4a994e1..0000000 --- a/test_app/config/initializers/filter_parameter_logging.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password] diff --git a/test_app/config/initializers/new_framework_defaults_6_0.rb b/test_app/config/initializers/new_framework_defaults_6_0.rb deleted file mode 100644 index 92240ef..0000000 --- a/test_app/config/initializers/new_framework_defaults_6_0.rb +++ /dev/null @@ -1,45 +0,0 @@ -# Be sure to restart your server when you modify this file. -# -# This file contains migration options to ease your Rails 6.0 upgrade. -# -# Once upgraded flip defaults one by one to migrate to the new default. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. - -# Don't force requests from old versions of IE to be UTF-8 encoded. -# Rails.application.config.action_view.default_enforce_utf8 = false - -# Embed purpose and expiry metadata inside signed and encrypted -# cookies for increased security. -# -# This option is not backwards compatible with earlier Rails versions. -# It's best enabled when your entire app is migrated and stable on 6.0. -# Rails.application.config.action_dispatch.use_cookies_with_metadata = true - -# Change the return value of `ActionDispatch::Response#content_type` to Content-Type header without modification. -# Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false - -# Return false instead of self when enqueuing is aborted from a callback. -# Rails.application.config.active_job.return_false_on_aborted_enqueue = true - -# Send Active Storage analysis and purge jobs to dedicated queues. -# Rails.application.config.active_storage.queues.analysis = :active_storage_analysis -# Rails.application.config.active_storage.queues.purge = :active_storage_purge - -# When assigning to a collection of attachments declared via `has_many_attached`, replace existing -# attachments instead of appending. Use #attach to add new attachments without replacing existing ones. -# Rails.application.config.active_storage.replace_on_assign_to_many = true - -# Use ActionMailer::MailDeliveryJob for sending parameterized and normal mail. -# -# The default delivery jobs (ActionMailer::Parameterized::DeliveryJob, ActionMailer::DeliveryJob), -# will be removed in Rails 6.1. This setting is not backwards compatible with earlier Rails versions. -# If you send mail in the background, job workers need to have a copy of -# MailDeliveryJob to ensure all delivery jobs are processed properly. -# Make sure your entire app is migrated and stable on 6.0 before using this setting. -# Rails.application.config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" - -# Enable the same cache key to be reused when the object being cached of type -# `ActiveRecord::Relation` changes by moving the volatile information (max updated at and count) -# of the relation's cache key into the cache version to support recycling cache key. -# Rails.application.config.active_record.collection_cache_versioning = true diff --git a/test_app/config/mongoid.2.yml b/test_app/config/mongoid.2.yml deleted file mode 100644 index 8355f4c..0000000 --- a/test_app/config/mongoid.2.yml +++ /dev/null @@ -1,20 +0,0 @@ -development: - host: localhost - database: test_app_development - -test: - host: localhost - database: test_app_test - -# set these environment variables on your prod server -production: - host: <%= ENV['MONGOID_HOST'] %> - port: <%= ENV['MONGOID_PORT'] %> - username: <%= ENV['MONGOID_USERNAME'] %> - password: <%= ENV['MONGOID_PASSWORD'] %> - database: <%= ENV['MONGOID_DATABASE'] %> - # slaves: - # - host: slave1.local - # port: 27018 - # - host: slave2.local - # port: 27019 diff --git a/test_app/config/mongoid.3.yml b/test_app/config/mongoid.3.yml deleted file mode 100644 index dcd09db..0000000 --- a/test_app/config/mongoid.3.yml +++ /dev/null @@ -1,96 +0,0 @@ -test: - # Configure available database sessions. (required) - sessions: - # Defines the default session. (required) - default: - # Defines the name of the default database that Mongoid can connect to. - # (required). - database: activeadmin_mongoid_test - # Provides the hosts the default session can connect to. Must be an array - # of host:port pairs. (required) - hosts: - - localhost:27017 - options: - # Change whether the session persists in safe mode by default. - # (default: false) - # safe: false - - # Change the default consistency model to :eventual or :strong. - # :eventual will send reads to secondaries, :strong sends everything - # to master. (default: :eventual) - # consistency: :eventual - - # How many times Moped should attempt to retry an operation after - # failure. (default: 30) - # max_retries: 30 - - # The time in seconds that Moped should wait before retrying an - # operation on failure. (default: 1) - # retry_interval: 1 - # Configure Mongoid specific options. (optional) - options: &default_options - # Configuration for whether or not to allow access to fields that do - # not have a field definition on the model. (default: true) - # allow_dynamic_fields: true - allow_dynamic_fields: false - - # Enable the identity map, needed for eager loading. (default: false) - # identity_map_enabled: false - identity_map_enabled: true - - # Includes the root model name in json serialization. (default: false) - # include_root_in_json: false - - # Include the _type field in serializaion. (default: false) - # include_type_for_serialization: false - - # Preload all models in development, needed when models use - # inheritance. (default: false) - # preload_models: false - - # Protect id and type from mass assignment. (default: true) - # protect_sensitive_fields: true - - # Raise an error when performing a #find and the document is not found. - # (default: true) - # raise_not_found_error: true - - # Raise an error when defining a scope with the same name as an - # existing method. (default: false) - scope_overwrite_exception: true - - # Skip the database version check, used when connecting to a db without - # admin access. (default: false) - # skip_version_check: false - - # User Active Support's time zone in conversions. (default: true) - # use_activesupport_time_zone: true - - # Ensure all times are UTC in the app side. (default: false) - # use_utc: false - -# production: -# sessions: -# default: -# uri: <%= ENV['MONGOLAB_URI'] %> -# options: -# skip_version_check: true -# identity_map_enabled: true -# safe: true -# options: -# *default_options -# -# development: -# sessions: -# default: -# database: activeadmin_mongoid_development -# hosts: -# - localhost:27017 -# options: -# consistency: :strong -# # In the test environment we lower the retries and retry interval to -# # low amounts for fast failures. -# max_retries: 1 -# retry_interval: 0 -# options: -# *default_options diff --git a/test_app/config/mongoid.4.yml b/test_app/config/mongoid.4.yml deleted file mode 100644 index 4433c91..0000000 --- a/test_app/config/mongoid.4.yml +++ /dev/null @@ -1,87 +0,0 @@ -test: - # Configure available database sessions. (required) - sessions: - # Defines the default session. (required) - default: - # Defines the name of the default database that Mongoid can connect to. - # (required). - database: activeadmin_mongoid_test - # Provides the hosts the default session can connect to. Must be an array - # of host:port pairs. (required) - hosts: - - localhost:27017 - options: - # Change whether the session persists in safe mode by default. - # (default: false) - # safe: false - - # Change the default consistency model to :eventual or :strong. - # :eventual will send reads to secondaries, :strong sends everything - # to master. (default: :eventual) - # consistency: :eventual - - # How many times Moped should attempt to retry an operation after - # failure. (default: 30) - # max_retries: 30 - - # The time in seconds that Moped should wait before retrying an - # operation on failure. (default: 1) - # retry_interval: 1 - # Configure Mongoid specific options. (optional) - options: &default_options - # Includes the root model name in json serialization. (default: false) - # include_root_in_json: false - - # Include the _type field in serializaion. (default: false) - # include_type_for_serialization: false - - # Preload all models in development, needed when models use - # inheritance. (default: false) - # preload_models: false - - # Protect id and type from mass assignment. (default: true) - # protect_sensitive_fields: true - - # Raise an error when performing a #find and the document is not found. - # (default: true) - # raise_not_found_error: true - - # Raise an error when defining a scope with the same name as an - # existing method. (default: false) - scope_overwrite_exception: true - - # Skip the database version check, used when connecting to a db without - # admin access. (default: false) - # skip_version_check: false - - # User Active Support's time zone in conversions. (default: true) - # use_activesupport_time_zone: true - - # Ensure all times are UTC in the app side. (default: false) - # use_utc: false - -# production: -# sessions: -# default: -# uri: <%= ENV['MONGOLAB_URI'] %> -# options: -# skip_version_check: true -# identity_map_enabled: true -# safe: true -# options: -# *default_options -# -# development: -# sessions: -# default: -# database: activeadmin_mongoid_development -# hosts: -# - localhost:27017 -# options: -# consistency: :strong -# # In the test environment we lower the retries and retry interval to -# # low amounts for fast failures. -# max_retries: 1 -# retry_interval: 0 -# options: -# *default_options diff --git a/test_app/config/mongoid.5.yml b/test_app/config/mongoid.5.yml deleted file mode 100644 index 0ecd0c6..0000000 --- a/test_app/config/mongoid.5.yml +++ /dev/null @@ -1,7 +0,0 @@ -test: - clients: - default: - database: activeadmin_mongoid_test - hosts: - - localhost:27017 -#scope_overwrite_exception: true diff --git a/test_app/config/mongoid.6.yml b/test_app/config/mongoid.6.yml deleted file mode 100644 index b361124..0000000 --- a/test_app/config/mongoid.6.yml +++ /dev/null @@ -1,7 +0,0 @@ -test: - clients: - default: - database: activeadmin_mongoid_test - hosts: - - db:27017 -#scope_overwrite_exception: true From 8a2317530fc1d83da1e154fa4ca156374a40ac7b Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Wed, 2 Dec 2026 00:40:53 +0000 Subject: [PATCH 18/19] Skip the query cache during CSV export 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. --- CHANGELOG.md | 2 +- lib/active_admin/mongoid/csv_builder.rb | 14 +++++++++----- spec/features/smoke_spec.rb | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ce30ba..4510dde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ versions. * Rails 7.0: the resource controller patch is applied in `to_prepare`, since Rails 7 doesn't autoload during initialization. * ActiveAdmin 2.14: CSV export no longer goes through `in_paginated_batches`, which needs - ActiveRecord. + ActiveRecord. Like it, the export skips the query cache. * Ruby 3: CSV options are passed as keyword arguments. * Select filters on `belongs_to` associations search the foreign key, and filters on other associations no longer raise. diff --git a/lib/active_admin/mongoid/csv_builder.rb b/lib/active_admin/mongoid/csv_builder.rb index 4befec5..c9da6bc 100644 --- a/lib/active_admin/mongoid/csv_builder.rb +++ b/lib/active_admin/mongoid/csv_builder.rb @@ -14,11 +14,15 @@ def build(controller, csv) end # Not ActiveAdmin's in_paginated_batches: it wraps the loop in ActiveRecord::Base.uncached, - # and ActiveRecord isn't loaded in a Mongoid app. - (1..controller.send(:paginated_collection).total_pages).each do |page| - controller.send(:paginated_collection, page).each do |resource| - resource = controller.send :apply_decorator, resource - csv << CSV.generate_line(build_row(resource, columns, options), **csv_options) + # and ActiveRecord isn't loaded in a Mongoid app. Skip Mongo's query cache the same way, so a + # large export doesn't keep every page cached until the request ends. + query_cache = defined?(::Mongo::QueryCache) ? ::Mongo::QueryCache : ::Mongoid::QueryCache + query_cache.uncached do + (1..controller.send(:paginated_collection).total_pages).each do |page| + controller.send(:paginated_collection, page).each do |resource| + resource = controller.send :apply_decorator, resource + csv << CSV.generate_line(build_row(resource, columns, options), **csv_options) + end end end diff --git a/spec/features/smoke_spec.rb b/spec/features/smoke_spec.rb index 0c04ad2..362070e 100644 --- a/spec/features/smoke_spec.rb +++ b/spec/features/smoke_spec.rb @@ -311,8 +311,10 @@ end it "builds csv" do + expect(Mongo::QueryCache).to receive(:uncached).and_call_original visit '/admin/admin_users.csv' expect(page.status_code).to eq(200) or eq(304) + expect(page.body).to include(email, other_email) end end end From 50c742f46faaa49be10a9c598554d4c34dd516e5 Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Wed, 2 Dec 2026 00:40:53 +0000 Subject: [PATCH 19/19] Filter only on association keys the document stores 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. --- CHANGELOG.md | 6 ++++-- .../mongoid/association/relatable.rb | 6 ++++++ .../mongoid/filters/resource_extension.rb | 6 ++++-- .../mongoid/inputs/filters/select_input.rb | 20 ++++++++----------- spec/features/smoke_spec.rb | 16 +++++++++++++++ .../filters/resource_extension_spec.rb | 19 ++++++++++++++++++ test_app/app/admin/admin_users.rb | 1 - test_app/app/admin/posts.rb | 1 + test_app/app/models/post.rb | 1 + 9 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 spec/lib/active_admin/mongoid/filters/resource_extension_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 4510dde..9242280 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,10 @@ versions. * ActiveAdmin 2.14: CSV export no longer goes through `in_paginated_batches`, which needs ActiveRecord. Like it, the export skips the query cache. * Ruby 3: CSV options are passed as keyword arguments. -* Select filters on `belongs_to` associations search the foreign key, and filters on other - associations no longer raise. +* Select filters search the key the document stores, so filters on `belongs_to` and + `has_and_belongs_to_many` associations work. +* `has_many` and `has_one` associations are no longer default filters, since their keys are in the + related documents. Declaring one explicitly raises an error that says so. * The index page's "Displaying X - Y" counts the current page in the database instead of loading documents (and no longer counts the whole collection). * `primary_key` works for subclasses of a document. diff --git a/lib/active_admin/mongoid/association/relatable.rb b/lib/active_admin/mongoid/association/relatable.rb index 6f17a87..8186bf4 100644 --- a/lib/active_admin/mongoid/association/relatable.rb +++ b/lib/active_admin/mongoid/association/relatable.rb @@ -7,6 +7,12 @@ def embeds? [:embeds_one, :embeds_many].include?(macro) end + # Whether the association's key is stored in this document, so it can be filtered on. + # has_many and has_one keep theirs in the related document. + def key_stored_on_document? + [:belongs_to, :has_and_belongs_to_many].include?(macro) + end + def foreign_key return if embeds? foreign_key.to_sym rescue nil diff --git a/lib/active_admin/mongoid/filters/resource_extension.rb b/lib/active_admin/mongoid/filters/resource_extension.rb index ae5b0bf..5dcd447 100644 --- a/lib/active_admin/mongoid/filters/resource_extension.rb +++ b/lib/active_admin/mongoid/filters/resource_extension.rb @@ -3,8 +3,10 @@ module ActiveAdmin::Filters::ResourceExtension def default_association_filters if resource_class.respond_to?(:reflect_on_all_associations) - without_embedded = resource_class.reflect_on_all_associations.reject { |e| e.embeds? } - poly, not_poly = without_embedded.partition { |r| r.macro == :belongs_to && r.options[:polymorphic] } + # Only associations whose key this document stores can be filtered (not embedded ones, + # has_many or has_one). + filterable = resource_class.reflect_on_all_associations.select(&:key_stored_on_document?) + poly, not_poly = filterable.partition { |r| r.macro == :belongs_to && r.options[:polymorphic] } filters = poly.map(&:foreign_key) + not_poly.map(&:name) filters.map &:to_sym diff --git a/lib/active_admin/mongoid/inputs/filters/select_input.rb b/lib/active_admin/mongoid/inputs/filters/select_input.rb index 84dea53..7300b0c 100644 --- a/lib/active_admin/mongoid/inputs/filters/select_input.rb +++ b/lib/active_admin/mongoid/inputs/filters/select_input.rb @@ -2,19 +2,15 @@ class ActiveAdmin::Inputs::Filters::SelectInput # ActiveAdmin builds this from reflection.association_primary_key, which Mongoid associations - # don't have. belongs_to filters search the foreign key on the document itself; other - # associations search the related document's id, which ransack-mongoid resolves through the - # association. + # don't have. Filter on the key the document stores instead (belongs_to and + # has_and_belongs_to_many). has_many and has_one keep their keys in the related documents, so + # a filter on them can't match anything. def searchable_method_name - if searchable_has_many_through? - "#{reflection.through_reflection.name}_#{reflection.foreign_key}" - elsif reflection&.macro == :belongs_to - reflection.key - elsif reflection - "#{method}_id" - else - method - end + return method unless reflection + return reflection.key if reflection.key_stored_on_document? + + raise ArgumentError, "Can't filter #{@object.klass} by #{method}: Mongoid #{reflection.macro} " \ + "associations aren't stored in the document. Remove `filter :#{method}`." end def input_name diff --git a/spec/features/smoke_spec.rb b/spec/features/smoke_spec.rb index 362070e..7f6d030 100644 --- a/spec/features/smoke_spec.rb +++ b/spec/features/smoke_spec.rb @@ -180,6 +180,22 @@ end end + describe 'select on a has_and_belongs_to_many association' do + it 'selects by editor' do + Post.first.update!(editors: [other_user]) + + select other_email, from: 'Editors' + click_on 'Filter' + within '#index_table_posts' do + expect(page).to have_content('Quick Brown Fox') + end + + select email, from: 'Editors' + click_on 'Filter' + expect(page).to_not have_content('Quick Brown Fox') + end + end + describe 'check_boxes' do it 'checks by other_user' do check email diff --git a/spec/lib/active_admin/mongoid/filters/resource_extension_spec.rb b/spec/lib/active_admin/mongoid/filters/resource_extension_spec.rb new file mode 100644 index 0000000..a47e7b3 --- /dev/null +++ b/spec/lib/active_admin/mongoid/filters/resource_extension_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe ActiveAdmin::Filters::ResourceExtension do + def default_association_filters(klass) + ActiveAdmin.application.namespace(:admin).resource_for(klass).send(:default_association_filters) + end + + it 'includes associations whose key the document stores' do + expect(default_association_filters(Post)).to include(:admin_user, :other_user, :editors) + end + + it 'leaves out has_many associations, whose keys are in the related documents' do + expect(default_association_filters(AdminUser)).not_to include(:posts) + end + + it 'leaves out embedded associations' do + expect(default_association_filters(Post)).not_to include(:author) + end +end diff --git a/test_app/app/admin/admin_users.rb b/test_app/app/admin/admin_users.rb index 69ef56c..1d1c1ab 100644 --- a/test_app/app/admin/admin_users.rb +++ b/test_app/app/admin/admin_users.rb @@ -8,7 +8,6 @@ end filter :email - filter :posts form do |f| f.inputs "Admin Details" do diff --git a/test_app/app/admin/posts.rb b/test_app/app/admin/posts.rb index 0a46ffa..73f8ac3 100644 --- a/test_app/app/admin/posts.rb +++ b/test_app/app/admin/posts.rb @@ -9,6 +9,7 @@ filter :view_count, as: :numeric filter :admin_user, as: :select filter :other_user, as: :check_boxes + filter :editors, as: :select index do selectable_column diff --git a/test_app/app/models/post.rb b/test_app/app/models/post.rb index fb905dd..4322462 100644 --- a/test_app/app/models/post.rb +++ b/test_app/app/models/post.rb @@ -7,6 +7,7 @@ class Post field :view_count, type: ::Integer, default: 0 belongs_to :admin_user belongs_to :other_user, class_name: 'AdminUser' + has_and_belongs_to_many :editors, class_name: 'AdminUser', inverse_of: nil embeds_one :author field :'author.city.name'