From 288a94e25da6989f7d485748d104acf1a0e38dfa Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Tue, 1 Dec 2026 16:51:12 +0000 Subject: [PATCH 1/4] Support ActiveAdmin 3 - Require activeadmin ~> 3.0. - update_resource: ActiveAdmin 3 wraps the save in ActiveRecord::Base.transaction and raises ActiveRecord::Rollback, which don't exist without ActiveRecord. Save the way ActiveAdmin 2 did. - counter_cache_col?: ActiveAdmin 3 asks has_many associations for counter cache columns; Mongoid associations have none. - List gem files with Dir.glob instead of git ls-files, so the gem also loads when vendored without git (e.g. in a Docker build). --- activeadmin-mongoid.gemspec | 6 ++---- .../mongoid/controllers/resource_controller.rb | 10 ++++++++++ lib/active_admin/mongoid/resource/attributes.rb | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/activeadmin-mongoid.gemspec b/activeadmin-mongoid.gemspec index b46f474..2e78968 100644 --- a/activeadmin-mongoid.gemspec +++ b/activeadmin-mongoid.gemspec @@ -9,9 +9,7 @@ Gem::Specification.new do |gem| gem.summary = %q{ActiveAdmin hacks to support Mongoid} 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") - gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + gem.files = Dir.glob('lib/**/*') + %w[LICENSE README.md CHANGELOG.md] gem.name = 'activeadmin-mongoid' gem.require_paths = ['lib'] gem.version = ActiveAdmin::Mongoid::VERSION @@ -20,7 +18,7 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 3.1' gem.add_runtime_dependency 'mongoid', '>= 7.0', '< 9' - gem.add_runtime_dependency 'activeadmin', '~> 2.0' + gem.add_runtime_dependency 'activeadmin', '~> 3.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' diff --git a/lib/active_admin/mongoid/controllers/resource_controller.rb b/lib/active_admin/mongoid/controllers/resource_controller.rb index bf8c0f3..970c2b6 100644 --- a/lib/active_admin/mongoid/controllers/resource_controller.rb +++ b/lib/active_admin/mongoid/controllers/resource_controller.rb @@ -10,5 +10,15 @@ def build_new_resource scoped_collection.send(method_for_build) end + + # ActiveAdmin 3 wraps this in ActiveRecord::Base.transaction and raises + # ActiveRecord::Rollback, which don't exist without ActiveRecord. Same as ActiveAdmin 2. + def update_resource(object, attributes) + object = assign_attributes(object, attributes) + + run_update_callbacks object do + save_resource(object) + end + end end end diff --git a/lib/active_admin/mongoid/resource/attributes.rb b/lib/active_admin/mongoid/resource/attributes.rb index 2abc084..012e566 100644 --- a/lib/active_admin/mongoid/resource/attributes.rb +++ b/lib/active_admin/mongoid/resource/attributes.rb @@ -17,6 +17,11 @@ def primary_col?(c) def sti_col?(c) false end + + # ActiveAdmin 3 asks ActiveRecord associations for counter caches; Mongoid has none. + def counter_cache_col?(c) + false + end end end end From 6058e6ad421e7e496e0221e130ccf9990641dc69 Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Wed, 2 Dec 2026 11:28:20 +0000 Subject: [PATCH 2/4] Depend on ransack-mongoid 1.0 ActiveAdmin 3 requires Ransack 4. ransack-mongoid 1.0, now on RubyGems, provides Mongoid support for it, so make it a runtime dependency, require it instead of ransack, and drop the GitHub pin from the Gemfile. Mongoid 7.5 is the oldest version that supports Rails 7. --- Gemfile | 4 ---- activeadmin-mongoid.gemspec | 3 ++- lib/active_admin/mongoid.rb | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 692e83f..c2c05f7 100644 --- a/Gemfile +++ b/Gemfile @@ -2,10 +2,6 @@ source 'https://rubygems.org' gemspec -# 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' - # 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" diff --git a/activeadmin-mongoid.gemspec b/activeadmin-mongoid.gemspec index 2e78968..0ff08cd 100644 --- a/activeadmin-mongoid.gemspec +++ b/activeadmin-mongoid.gemspec @@ -17,8 +17,9 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 3.1' - gem.add_runtime_dependency 'mongoid', '>= 7.0', '< 9' + gem.add_runtime_dependency 'mongoid', '>= 7.5', '< 9' gem.add_runtime_dependency 'activeadmin', '~> 3.0' + gem.add_runtime_dependency 'ransack-mongoid', '~> 1.0' # Mongoid support for Ransack 4, which ActiveAdmin 3 requires 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' diff --git a/lib/active_admin/mongoid.rb b/lib/active_admin/mongoid.rb index fcf14c0..3866874 100644 --- a/lib/active_admin/mongoid.rb +++ b/lib/active_admin/mongoid.rb @@ -1,7 +1,7 @@ require 'active_admin/mongoid/version' require 'active_model' require 'mongoid' -require 'ransack' +require 'ransack-mongoid' require 'kaminari/mongoid' require 'active_admin' require 'devise' From 6b98242a14c5ca8e90341257e5d443f4a4fbb4cb Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Wed, 2 Dec 2026 11:28:20 +0000 Subject: [PATCH 3/4] Test ActiveAdmin 3 on Rails 7.0-8.0 - CI matrix: Ruby 3.1-4.0 with Rails 7.0 on Mongoid 7.5 and 8.1, and Rails 7.1, 7.2 and 8.0 on Mongoid 8.1 (Mongoid 7.5 stops at Rails 7.0; Rails 8.0 needs Ruby 3.2+). The Gemfile defaults to Rails 8.0. - Specs use ActiveAdmin 3's filter names: _eq, _gt and _lt instead of the removed MetaSearch aliases, and _gteq/_lteq for date ranges. - Rails 8 draws routes lazily, and ActiveAdmin registers its resources then, so the default-filter spec loads routes first. - Devise 4.9 on Rails 7.0 and 7.1. With Devise 5 there, sign-in in the test app fails because the password parameter reaches Devise's strategy empty; Devise 5 works on Rails 7.2 and 8.0. --- .github/workflows/tests.yml | 23 +++++++++++-------- Gemfile | 6 +++-- spec/features/smoke_spec.rb | 16 ++++++------- .../filters/resource_extension_spec.rb | 3 +++ 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d2bd3cc..52be2d2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,20 +12,23 @@ jobs: fail-fast: false matrix: ruby: ['3.1', '3.2', '3.3', '3.4', '4.0'] - rails: ['6.1', '7.0'] - mongoid: ['7.5', '8.1'] + # Mongoid 7.5 supports Rails up to 7.0; Mongoid 8.1 up to 8.0. + stack: + - { rails: '7.0', mongoid: '7.5' } + - { rails: '7.0', mongoid: '8.1' } + - { rails: '7.1', mongoid: '8.1' } + - { rails: '7.2', mongoid: '8.1' } + - { rails: '8.0', mongoid: '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' + # Rails 8.0 needs Ruby 3.2 or later. + - ruby: '3.1' + stack: { rails: '8.0', mongoid: '8.1' } # 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 }} + name: Ruby ${{ matrix.ruby }}, Rails ${{ matrix.stack.rails }}, Mongoid ${{ matrix.stack.mongoid }} env: - RAILS_VERSION: ${{ matrix.rails }} - MONGOID_VERSION: ${{ matrix.mongoid }} + RAILS_VERSION: ${{ matrix.stack.rails }} + MONGOID_VERSION: ${{ matrix.stack.mongoid }} services: mongodb: diff --git a/Gemfile b/Gemfile index c2c05f7..cb08d7e 100644 --- a/Gemfile +++ b/Gemfile @@ -3,10 +3,12 @@ source 'https://rubygems.org' gemspec # CI picks the versions; see .github/workflows/tests.yml. -gem 'rails', "~> #{ENV.fetch('RAILS_VERSION', '7.0')}.0" +gem 'rails', "~> #{ENV.fetch('RAILS_VERSION', '8.0')}.0" gem 'mongoid', "~> #{ENV.fetch('MONGOID_VERSION', '8.1')}.0" -gem 'devise', '~> 4.0' # ActiveAdmin 2 requires < 5 +# Devise 5 sign-in fails in the test app on Rails 7.0 and 7.1: the password parameter reaches +# Devise's strategy empty. Devise 4.9 works there, and Devise 5 works on Rails 7.2+. +gem 'devise', ENV.fetch('RAILS_VERSION', '8.0').to_f < 7.2 ? '~> 4.9' : '>= 4.9' gem 'jquery-rails' gem 'jquery-ui-rails' diff --git a/spec/features/smoke_spec.rb b/spec/features/smoke_spec.rb index 7f6d030..70e7199 100644 --- a/spec/features/smoke_spec.rb +++ b/spec/features/smoke_spec.rb @@ -94,20 +94,20 @@ describe 'date_range' do it 'searches by created_at range' do - fill_in 'q[created_at_gteq_datetime]', with: 1.day.ago.to_datetime.strftime("%Y-%m-%d") - fill_in 'q[created_at_lteq_datetime]', with: 2.days.from_now.to_datetime.strftime("%Y-%m-%d") + fill_in 'q[created_at_gteq]', with: 1.day.ago.to_datetime.strftime("%Y-%m-%d") + fill_in 'q[created_at_lteq]', with: 2.days.from_now.to_datetime.strftime("%Y-%m-%d") click_on 'Filter' within '#index_table_posts' do expect(page).to have_content('Quick Brown Fox') end - fill_in 'q[created_at_gteq_datetime]', with: 1.day.from_now.to_datetime.strftime("%Y-%m-%d") + fill_in 'q[created_at_gteq]', with: 1.day.from_now.to_datetime.strftime("%Y-%m-%d") click_on 'Filter' expect(page).to_not have_content('Quick Brown Fox') - fill_in 'q[created_at_gteq_datetime]', with: '' - fill_in 'q[created_at_lteq_datetime]', with: '' + fill_in 'q[created_at_gteq]', with: '' + fill_in 'q[created_at_lteq]', with: '' click_on 'Filter' expect(page).to have_content('Displaying 1 Post') @@ -117,7 +117,7 @@ describe 'numeric' do it 'searches by created_at range', js: false do within '.filter_numeric' do - find(:select).find('option[value=view_count_equals]').select_option + find(:select).find('option[value=view_count_eq]').select_option end fill_in 'View count', with: '5' click_on 'Filter' @@ -131,7 +131,7 @@ expect(page).to_not have_content('Quick Brown Fox') within '.filter_numeric' do - find(:select).find('option[value=view_count_less_than]').select_option + find(:select).find('option[value=view_count_lt]').select_option end click_on 'Filter' @@ -140,7 +140,7 @@ # end within '.filter_numeric' do - find(:select).find('option[value=view_count_greater_than]').select_option + find(:select).find('option[value=view_count_gt]').select_option end click_on 'Filter' expect(page).to_not have_content('Quick Brown Fox') diff --git a/spec/lib/active_admin/mongoid/filters/resource_extension_spec.rb b/spec/lib/active_admin/mongoid/filters/resource_extension_spec.rb index a47e7b3..af451b8 100644 --- a/spec/lib/active_admin/mongoid/filters/resource_extension_spec.rb +++ b/spec/lib/active_admin/mongoid/filters/resource_extension_spec.rb @@ -1,6 +1,9 @@ require 'spec_helper' describe ActiveAdmin::Filters::ResourceExtension do + # Rails 8 draws routes lazily, and ActiveAdmin registers its resources while drawing them. + before(:all) { Rails.application.try(:reload_routes_unless_loaded) } + def default_association_filters(klass) ActiveAdmin.application.namespace(:admin).resource_for(klass).send(:default_association_filters) end From e48b9d0c51d3e447704f0c6d2b2cdd3d86589f3a Mon Sep 17 00:00:00 2001 From: JD Guzman Date: Wed, 2 Dec 2026 11:28:20 +0000 Subject: [PATCH 4/4] Release 3.0.0 - README: 3.0.0 requirements, and how to install 2.x for ActiveAdmin 2. - CHANGELOG for 3.0.0, including ActiveAdmin 3's own filter changes. - Version 3.0.0. --- CHANGELOG.md | 23 +++++++++++++++++++++++ README.md | 15 +++++++++++++++ lib/active_admin/mongoid/version.rb | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9242280..cbf3c3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # Changelog +## 3.0.0 + +Supports ActiveAdmin 3 with Ransack 4, on Ruby 3.1+, Rails 7.0 to 8.0, and Mongoid 8 (or Mongoid 7.5 +on Rails 7.0). Use 2.x with ActiveAdmin 2. + +### Breaking changes + +* Requires ActiveAdmin 3.x, and Ransack 4 through + [ransack-mongoid](https://github.com/riverock/ransack-mongoid) 1.x, which is now a dependency. + Remove any `ransack-mongoid` line from your Gemfile. +* Requires Mongoid 7.5 or later. +* ActiveAdmin 3 itself drops the old MetaSearch filter names (`_equals`, `_greater_than`, + `_less_than`, `_contains`, ...; use `_eq`, `_gt`, `_lt`, `_cont`), and its date range filters + use `_gteq` / `_lteq`, so a date-time "to" date ends at the start of that day. + +### Fixes + +* `update_resource` saves the way ActiveAdmin 2 did. ActiveAdmin 3 wraps the save in an + ActiveRecord transaction and raises `ActiveRecord::Rollback`, which don't exist without + ActiveRecord. +* Index columns no longer ask associations for counter caches, which Mongoid doesn't have. +* The gem lists its files without git, so it also loads when vendored without a `.git` directory. + ## 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 diff --git a/README.md b/README.md index 5ffc540..51260da 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,15 @@ 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 3.0.0 +* Ruby 3.1 or greater (Rails 8.0 needs Ruby 3.2 or later). +* Rails 7.0, 7.1, 7.2 or 8.0 +* Mongoid 8.x, or Mongoid 7.5 on Rails 7.0 +* ActiveAdmin 3.x (tested on 3.5) +* Ransack 4.x, through [ransack-mongoid](https://github.com/riverock/ransack-mongoid) 1.x, which this gem depends on. Your application should use Mongoid only (see the ransack-mongoid README). + +See [CHANGELOG.md](CHANGELOG.md) for the changes from 2.0.0. Use 2.x with ActiveAdmin 2. + ### 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 @@ -51,6 +60,12 @@ For more on Mongoid support in ActiveAdmin see [this issue](https://github.com/g ### Some Gems Add the following gems to your application's Gemfile, and lock the version: +```ruby +gem 'activeadmin-mongoid', '~> 3.0' +``` + +For ActiveAdmin 2, use 2.x, which needs `ransack-mongoid` from GitHub: + ```ruby gem 'activeadmin-mongoid', '~> 2.0' gem 'ransack-mongoid', github: 'riverock/ransack-mongoid', ref: 'f83ae55ea67fc0a0bca30158f3e04c49362f4464' diff --git a/lib/active_admin/mongoid/version.rb b/lib/active_admin/mongoid/version.rb index 7a3c100..917ca2c 100644 --- a/lib/active_admin/mongoid/version.rb +++ b/lib/active_admin/mongoid/version.rb @@ -1,5 +1,5 @@ module ActiveAdmin module Mongoid - VERSION = '2.0.0' + VERSION = '3.0.0' end end