diff --git a/Gemfile b/Gemfile index 2334002..3dc13a4 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 7c10307..909e942 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 @@ -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) @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -286,7 +275,7 @@ DEPENDENCIES launchy poltergeist pry-rails - rails (~> 5.2) + rails (>= 5.2, < 6.1) ransack-mongoid! rspec-rails (~> 3.6) simplecov diff --git a/README.md b/README.md index 4258679..6097810 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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' ``` @@ -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" ``` diff --git a/activeadmin-mongoid.gemspec b/activeadmin-mongoid.gemspec index fcc1ad7..4e49952 100644 --- a/activeadmin-mongoid.gemspec +++ b/activeadmin-mongoid.gemspec @@ -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' diff --git a/lib/active_admin/mongoid.rb b/lib/active_admin/mongoid.rb index eea1cc0..fcf14c0 100644 --- a/lib/active_admin/mongoid.rb +++ b/lib/active_admin/mongoid.rb @@ -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' diff --git a/lib/active_admin/mongoid/association/relatable.rb b/lib/active_admin/mongoid/association/relatable.rb new file mode 100644 index 0000000..c3a4679 --- /dev/null +++ b/lib/active_admin/mongoid/association/relatable.rb @@ -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 \ No newline at end of file diff --git a/lib/active_admin/mongoid/filters/resource_extension.rb b/lib/active_admin/mongoid/filters/resource_extension.rb index 50d1e3a..015aca5 100644 --- a/lib/active_admin/mongoid/filters/resource_extension.rb +++ b/lib/active_admin/mongoid/filters/resource_extension.rb @@ -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 [] diff --git a/test_app/config/mongoid.6.yml b/test_app/config/mongoid.6.yml index e4a9498..0ecd0c6 100644 --- a/test_app/config/mongoid.6.yml +++ b/test_app/config/mongoid.6.yml @@ -1,10 +1,3 @@ -development: - clients: - default: - database: activeadmin_mongoid_development - hosts: - - localhost:27017 - test: clients: default: diff --git a/test_app/config/mongoid.7.yml b/test_app/config/mongoid.7.yml new file mode 100644 index 0000000..e4a9498 --- /dev/null +++ b/test_app/config/mongoid.7.yml @@ -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