Skip to content

Mongoid 7 support #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 29, 2020
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ gemspec

gem 'ransack-mongoid', git: 'https://github.com/activerecord-hackery/ransack-mongoid'

gem 'rails', '~> 5.2'
gem 'rails', '>= 5.2', '< 6.1'

gem 'devise'

Expand Down
89 changes: 39 additions & 50 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ GIT
PATH
remote: .
specs:
activeadmin-mongoid (0.9.0)
activeadmin-mongoid (1.0.0)
activeadmin (>= 1.4.3)
jquery-rails
kaminari-mongoid
mongoid (~> 6.0)
mongoid (>= 6.0, < 8.a)
sass-rails (>= 3.1.4)

GEM
Expand Down Expand Up @@ -40,18 +40,17 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activeadmin (1.4.3)
arbre (>= 1.1.1)
coffee-rails
activeadmin (2.6.0)
arbre (~> 1.2, >= 1.2.1)
formtastic (~> 3.1)
formtastic_i18n
inherited_resources (>= 1.9.0)
jquery-rails (>= 4.2.0)
kaminari (>= 0.15)
railties (>= 4.2, < 5.3)
ransack (>= 1.8.7)
sass (~> 3.1)
sprockets (< 4.1)
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)
globalid (>= 0.3.6)
Expand All @@ -76,7 +75,7 @@ GEM
activesupport (>= 3.0.0)
arel (9.0.0)
bcrypt (3.1.13)
bson (4.4.2)
bson (4.7.1)
builder (3.2.3)
capybara (3.12.0)
addressable
Expand All @@ -88,13 +87,6 @@ GEM
xpath (~> 3.2)
cliver (0.3.2)
coderay (1.1.2)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.1.5)
crass (1.0.5)
devise (4.7.1)
Expand All @@ -106,8 +98,7 @@ GEM
diff-lcs (1.3)
docile (1.3.1)
erubi (1.8.0)
execjs (2.7.0)
ffi (1.10.0)
ffi (1.12.1)
formtastic (3.1.5)
actionpack (>= 3.2.13)
formtastic_i18n (0.6.0)
Expand All @@ -118,11 +109,11 @@ GEM
activesupport (>= 4.1)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
inherited_resources (1.10.0)
actionpack (>= 5.0, < 6.0)
inherited_resources (1.11.0)
actionpack (>= 5.0, < 6.1)
has_scope (~> 0.6)
railties (>= 5.0, < 6.0)
responders (~> 2.0)
railties (>= 5.0, < 6.1)
responders (>= 2, < 4)
jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
Expand Down Expand Up @@ -161,10 +152,10 @@ GEM
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
mongo (2.8.0)
mongo (2.11.3)
bson (>= 4.4.2, < 5.0.0)
mongoid (6.4.2)
activemodel (>= 5.1, < 6.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.5)
Expand All @@ -174,6 +165,8 @@ GEM
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)
Expand Down Expand Up @@ -208,14 +201,11 @@ GEM
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rake (12.3.3)
ransack (2.1.1)
actionpack (>= 5.0)
activerecord (>= 5.0)
activesupport (>= 5.0)
ransack (2.3.2)
activerecord (>= 5.2.1)
activesupport (>= 5.2.1)
i18n
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
polyamorous (= 2.3.2)
regexp_parser (1.3.0)
responders (2.4.1)
actionpack (>= 4.2.0, < 6.0)
Expand All @@ -237,17 +227,16 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (5.0.7)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.2.1)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
Expand All @@ -262,7 +251,7 @@ GEM
sprockets (>= 3.0.0)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.9)
tilt (2.0.10)
tzinfo (1.2.5)
thread_safe (~> 0.1)
warden (1.2.8)
Expand All @@ -286,7 +275,7 @@ DEPENDENCIES
launchy
poltergeist
pry-rails
rails (~> 5.2)
rails (>= 5.2, < 6.1)
ransack-mongoid!
rspec-rails (~> 3.6)
simplecov
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ActiveAdmin is holding off on pulling Mongoid support into the core ActiveAdmin
* Ruby 2.4.0 or greater.
* Tested working on Rails 5.2.3
* Mongoid 6.x (**WARNING**:, using a Mongoid version >= 6.1.x has resulted in a fair amount of errors seen in the wild. Test your upgrade very carefully with any apps in which you're using this gem with Mongoid >= 6.1.x!)
* ActiveAdmin 1.4.3
* ActiveAdmin 1.4.3 or greater
* `ransack-mongoid` - it needs to be explicitly declared in Gemfile, pointing to github's master since it has no releases on rubygems yet.

## Previous versions
Expand Down Expand Up @@ -38,7 +38,7 @@ 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', '0.9.0'
gem 'activeadmin-mongoid', '1.0.0'
gem 'ransack-mongoid', github: 'activerecord-hackery/ransack-mongoid'
```

Expand All @@ -61,6 +61,7 @@ with:
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
```
Expand Down
2 changes: 1 addition & 1 deletion activeadmin-mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |gem|

gem.required_ruby_version = '>= 2.4'

gem.add_runtime_dependency 'mongoid', ['~> 6.0']
gem.add_runtime_dependency 'mongoid', '>= 6.0', '< 8.a'
gem.add_runtime_dependency 'activeadmin', '>= 1.4.3'
gem.add_runtime_dependency 'kaminari-mongoid'
gem.add_runtime_dependency 'jquery-rails'
Expand Down
1 change: 1 addition & 0 deletions lib/active_admin/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'active_admin/mongoid/helpers/collection'
require 'active_admin/mongoid/criteria'
require 'active_admin/mongoid/order_clause'
require 'active_admin/mongoid/association/relatable'

require 'active_admin/mongoid/inputs/filters/check_boxes_input'
require 'active_admin/mongoid/inputs/filters/select_input'
Expand Down
14 changes: 14 additions & 0 deletions lib/active_admin/mongoid/association/relatable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Mongoid::Association::Relatable.module_eval do
def macro
self.class.name.split('::').last.underscore.to_sym
end

def embeds?
[:embeds_one, :embeds_many].include?(macro)
end

def foreign_key
return if embeds?
foreign_key.to_sym rescue nil
end
end
4 changes: 2 additions & 2 deletions lib/active_admin/mongoid/filters/resource_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +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| [:embeds_many, :embeds_one].include? e.macro }
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] }

filters = poly.map(&:foreign_type) + not_poly.map(&:name)
filters = poly.map(&:foreign_key) + not_poly.map(&:name)
filters.map &:to_sym
else
[]
Expand Down
7 changes: 0 additions & 7 deletions test_app/config/mongoid.6.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
development:
clients:
default:
database: activeadmin_mongoid_development
hosts:
- localhost:27017

test:
clients:
default:
Expand Down
14 changes: 14 additions & 0 deletions test_app/config/mongoid.7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
development:
clients:
default:
database: activeadmin_mongoid_development
hosts:
- localhost:27017

test:
clients:
default:
database: activeadmin_mongoid_test
hosts:
- localhost:27017
#scope_overwrite_exception: true