Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 4 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ 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 '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'

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
9 changes: 4 additions & 5 deletions activeadmin-mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ 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
gem.license = 'MIT'

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 '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'
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/mongoid.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
10 changes: 10 additions & 0 deletions lib/active_admin/mongoid/controllers/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions lib/active_admin/mongoid/resource/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/active_admin/mongoid/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveAdmin
module Mongoid
VERSION = '2.0.0'
VERSION = '3.0.0'
end
end
16 changes: 8 additions & 8 deletions spec/features/smoke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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'
Expand All @@ -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'

Expand All @@ -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')
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading