activeadmin-mongoid 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/CONDUCT.md +13 -0
- data/Gemfile +9 -3
- data/README.md +30 -7
- data/activeadmin-mongoid.gemspec +7 -7
- data/lib/active_admin/mongoid.rb +6 -2
- data/lib/active_admin/mongoid/document.rb +54 -48
- data/lib/active_admin/mongoid/filter_form_builder.rb +9 -2
- data/lib/active_admin/mongoid/helpers/collection.rb +12 -2
- data/lib/active_admin/mongoid/order_clause.rb +12 -0
- data/lib/active_admin/mongoid/resource.rb +21 -51
- data/lib/active_admin/mongoid/version.rb +1 -1
- data/spec/features/smoke_spec.rb +52 -15
- data/spec/spec_helper.rb +5 -3
- data/spec/support/debug.rb +3 -0
- data/{test_app/config/_link_mongoid_config.rb → spec/support/mongoid.rb} +3 -1
- data/test_app/Gemfile +39 -0
- data/test_app/app/admin/posts.rb +34 -0
- data/test_app/app/assets/javascripts/active_admin.js +4 -4
- data/test_app/app/models/author.rb +9 -0
- data/test_app/app/models/city.rb +7 -0
- data/test_app/app/models/post.rb +3 -0
- data/test_app/config/application.rb +8 -14
- data/test_app/config/boot.rb +1 -1
- data/test_app/config/environment.rb +1 -1
- data/test_app/config/environments/development.rb +1 -1
- data/test_app/config/environments/production.rb +1 -1
- data/test_app/config/environments/test.rb +4 -2
- data/test_app/config/initializers/active_admin.rb +6 -3
- data/test_app/config/initializers/i18n.rb +1 -0
- data/test_app/config/initializers/mongoid.rb +1 -0
- data/test_app/config/initializers/secret_token.rb +1 -1
- data/test_app/config/initializers/session_store.rb +1 -1
- data/test_app/config/mongoid.4.yml +87 -0
- data/test_app/config/mongoid.5.yml +7 -0
- data/test_app/config/mongoid.6.yml +7 -0
- data/test_app/config/routes.rb +1 -1
- metadata +46 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f252b1a213790dedb791b66a2371f0d22a25a479
|
4
|
+
data.tar.gz: 90e7f395fc61dc91bd66d9ccb8fa64243e740e2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a605334c710e2ad8471ded1fd48163035a9e86f9a667df83e41bfa0322c98f2f7afb68d33614423d5d3e852680efcac15e30bf509a73bceffbbbd4910184f8f6
|
7
|
+
data.tar.gz: 7fedb4c3668e2d7cc6154c341a9e6e24ed39e1dfbaf8fd9899196198cdc8493519791c19429fb04cbb251231859c189c0925ae921c289cba812240360061a4d6
|
data/.travis.yml
CHANGED
data/CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
This document provides community guidelines for a safe, respectful, productive,
|
2
|
+
and collaborative place for any person who is willing to contribute to the project
|
3
|
+
community. It applies to all “collaborative space”, which is defined as
|
4
|
+
community communications channels (such as mailing lists, submitted patches,
|
5
|
+
commit comments, etc.).
|
6
|
+
|
7
|
+
* Participants will be tolerant of opposing views.
|
8
|
+
* Participants must ensure that their language and actions are free of personal
|
9
|
+
attacks and disparaging personal remarks.
|
10
|
+
* When interpreting the words and actions of others, participants should always
|
11
|
+
assume good intentions.
|
12
|
+
* Behaviour which can be reasonably considered harassment will not be
|
13
|
+
tolerated.
|
data/Gemfile
CHANGED
@@ -5,16 +5,21 @@ source 'https://rubygems.org'
|
|
5
5
|
# development dependencies will be added by default to the :development group.
|
6
6
|
gemspec
|
7
7
|
|
8
|
+
gem 'ransack', github: 'activerecord-hackery/ransack'
|
8
9
|
|
9
10
|
# Test app stuff
|
10
11
|
|
11
|
-
gem 'rails', '~>
|
12
|
+
gem 'rails', '~> 5.0'
|
13
|
+
gem 'kaminari', '~> 1.0'
|
14
|
+
gem 'kaminari-mongoid'
|
15
|
+
|
16
|
+
gem 'devise'
|
12
17
|
|
13
18
|
# Gems used only for assets and not required
|
14
19
|
# in production environments by default.
|
15
20
|
group :assets do
|
16
|
-
gem 'sass-rails', '
|
17
|
-
gem 'coffee-rails', '~>
|
21
|
+
gem 'sass-rails', '>= 5.0.6'
|
22
|
+
gem 'coffee-rails', '~> 4.0'
|
18
23
|
|
19
24
|
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
20
25
|
# gem 'therubyracer', :platforms => :ruby
|
@@ -26,6 +31,7 @@ gem 'jquery-ui-rails'
|
|
26
31
|
gem 'jslint'
|
27
32
|
|
28
33
|
group :test do
|
34
|
+
gem 'pry-rails'
|
29
35
|
gem 'capybara'
|
30
36
|
gem 'poltergeist'
|
31
37
|
gem 'launchy'
|
data/README.md
CHANGED
@@ -1,23 +1,46 @@
|
|
1
|
-
# ActiveAdmin
|
1
|
+
# ActiveAdmin-Mongoid
|
2
|
+
|
3
|
+
## Updates
|
4
|
+
|
5
|
+
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 Nic Boie, JD Guzman, Elia Schito and other ActiveAdmin and community members.
|
6
|
+
|
7
|
+
### Requirements for version 0.4.0
|
8
|
+
* Ruby 2.2.2 or greater. (Note, ruby-2.4.0 fails specs, see [this issue](https://github.com/DatabaseCleaner/database_cleaner/issues/466))
|
9
|
+
* Requires Rails 5.0.x
|
10
|
+
* Mongoid 6.0.x
|
11
|
+
* ActiveAdmin 1.x
|
12
|
+
|
13
|
+
## Previous versions
|
14
|
+
* Rails 4.x with Mongoid 5.x use branch rails4-mongoid5
|
15
|
+
* Rails 4.x with Mongoid 4.x branch rails4
|
16
|
+
* Mongoid 3.x with older versions of rails use v 0.3.0
|
2
17
|
|
3
|
-
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/activeadmin-mongoid.png)](http://badge.fury.io/rb/activeadmin-mongoid)
|
18
|
+
#### Rails 4 with
|
5
19
|
|
20
|
+
## ♻️ INFO
|
21
|
+
|
22
|
+
This gem has been brought into the ActiveAdmin org for support and maintenance.
|
23
|
+
|
24
|
+
<!-- [![Build Status](https://secure.travis-ci.org/elia/activeadmin-mongoid.svg?branch=master)](http://travis-ci.org/elia/activeadmin-mongoid)
|
25
|
+
[![Gem Version](https://badge.fury.io/rb/activeadmin-mongoid.svg)](http://badge.fury.io/rb/activeadmin-mongoid) -->
|
26
|
+
|
27
|
+
# ActiveAdmin::Mongoid
|
6
28
|
|
7
29
|
ActiveAdmin hacks to support Mongoid.
|
8
|
-
Some ActiveAdmin features are disabled:
|
30
|
+
Some ActiveAdmin features are disabled or not working properly:
|
9
31
|
|
10
|
-
- comments
|
32
|
+
- comments are disabled by default
|
33
|
+
- filters are somewhat broken
|
11
34
|
|
12
35
|
For more on Mongoid support in ActiveAdmin see [this issue](https://github.com/gregbell/active_admin/issues/26).
|
13
36
|
|
14
37
|
## Installation
|
15
38
|
|
16
39
|
### Some Gems
|
17
|
-
Add the following gems to your application's Gemfile:
|
40
|
+
Add the following gems to your application's Gemfile, and lock the version:
|
18
41
|
|
19
42
|
```ruby
|
20
|
-
gem 'activeadmin-mongoid'
|
43
|
+
gem 'activeadmin-mongoid', '0.4.0'
|
21
44
|
```
|
22
45
|
|
23
46
|
You can safely remove the following lines, since are already activeadmin-mongoid dependencies:
|
data/activeadmin-mongoid.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'active_admin/mongoid/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.authors = ['Elia Schito']
|
7
|
+
gem.authors = ['Elia Schito', 'Nic Boie', 'JD Guzman']
|
8
8
|
gem.email = ['elia@schito.me']
|
9
9
|
gem.description = %q{ActiveAdmin hacks to support Mongoid (some ActiveAdmin features are disabled)}
|
10
10
|
gem.summary = %q{ActiveAdmin hacks to support Mongoid}
|
@@ -18,11 +18,11 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.version = ActiveAdmin::Mongoid::VERSION
|
19
19
|
gem.license = 'MIT'
|
20
20
|
|
21
|
-
gem.add_runtime_dependency 'mongoid', ['
|
22
|
-
gem.add_runtime_dependency 'activeadmin', '~> 0
|
23
|
-
gem.add_runtime_dependency 'jquery-rails'
|
24
|
-
gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4', '
|
25
|
-
gem.add_runtime_dependency 'meta_search', '~> 1.1.3'
|
21
|
+
gem.add_runtime_dependency 'mongoid', ['~> 6.0.3']
|
22
|
+
gem.add_runtime_dependency 'activeadmin', ['~> 1.0']
|
23
|
+
gem.add_runtime_dependency 'jquery-rails'
|
24
|
+
gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4', '<= 5.0.6']
|
25
|
+
# gem.add_runtime_dependency 'meta_search', '~> 1.1.3'
|
26
26
|
|
27
|
-
gem.add_development_dependency 'rspec-rails', '~>
|
27
|
+
gem.add_development_dependency 'rspec-rails', '~> 3.6'
|
28
28
|
end
|
data/lib/active_admin/mongoid.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'active_admin/mongoid/version'
|
2
|
+
require 'active_model'
|
3
|
+
require 'mongoid'
|
4
|
+
require 'ransack'
|
2
5
|
# require 'active_admin/mongoid/engine'
|
3
6
|
require 'active_admin'
|
4
7
|
require 'devise'
|
5
8
|
require 'rails'
|
6
|
-
require 'mongoid'
|
7
9
|
|
8
|
-
require 'active_admin/mongoid/comments'
|
10
|
+
# require 'active_admin/mongoid/comments'
|
9
11
|
require 'active_admin/mongoid/adaptor'
|
10
12
|
require 'active_admin/mongoid/filter_form_builder'
|
11
13
|
require 'active_admin/mongoid/resource'
|
@@ -13,6 +15,8 @@ require 'active_admin/mongoid/document'
|
|
13
15
|
require 'active_admin/mongoid/helpers/collection'
|
14
16
|
require 'active_admin/mongoid/criteria'
|
15
17
|
|
18
|
+
require 'active_admin/mongoid/order_clause'
|
19
|
+
|
16
20
|
module ActiveAdmin
|
17
21
|
module Mongoid
|
18
22
|
class Railtie < ::Rails::Railtie
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'delegate'
|
2
|
-
require 'meta_search/searches/mongoid'
|
2
|
+
# require 'meta_search/searches/mongoid'
|
3
3
|
|
4
4
|
module ActiveAdmin::Mongoid::Document
|
5
5
|
extend ActiveSupport::Concern
|
@@ -13,7 +13,7 @@ module ActiveAdmin::Mongoid::Document
|
|
13
13
|
def type
|
14
14
|
_super = super
|
15
15
|
case _super
|
16
|
-
when
|
16
|
+
when BSON::ObjectId, Object
|
17
17
|
:string
|
18
18
|
else
|
19
19
|
_super.name.underscore.to_sym
|
@@ -37,7 +37,7 @@ module ActiveAdmin::Mongoid::Document
|
|
37
37
|
# CLASS METHODS
|
38
38
|
|
39
39
|
included do
|
40
|
-
include MetaSearch::Searches::Mongoid
|
40
|
+
# include MetaSearch::Searches::Mongoid
|
41
41
|
|
42
42
|
unless respond_to? :primary_key
|
43
43
|
class << self
|
@@ -45,7 +45,11 @@ module ActiveAdmin::Mongoid::Document
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
self.primary_key ||=
|
48
|
+
self.primary_key ||= :id
|
49
|
+
|
50
|
+
def column_for_attribute(name)
|
51
|
+
self.class.fields[name.to_sym]
|
52
|
+
end
|
49
53
|
|
50
54
|
end
|
51
55
|
|
@@ -53,41 +57,41 @@ module ActiveAdmin::Mongoid::Document
|
|
53
57
|
|
54
58
|
# Metasearch
|
55
59
|
|
56
|
-
def joins_values *args
|
57
|
-
|
58
|
-
end
|
60
|
+
# def joins_values *args
|
61
|
+
# criteria
|
62
|
+
# end
|
59
63
|
|
60
|
-
def group_by *args, &block
|
61
|
-
|
62
|
-
end
|
64
|
+
# def group_by *args, &block
|
65
|
+
# criteria
|
66
|
+
# end
|
63
67
|
|
64
|
-
def ransack *args
|
65
|
-
|
68
|
+
# def ransack *args
|
69
|
+
# scoped
|
66
70
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
71
|
+
# scoped.class.class_eval do
|
72
|
+
# def result
|
73
|
+
# self
|
74
|
+
# end
|
75
|
+
# end
|
72
76
|
|
73
|
-
|
74
|
-
end
|
77
|
+
# scoped
|
78
|
+
# end
|
75
79
|
|
76
80
|
|
77
81
|
# Cache
|
78
82
|
|
79
|
-
def [] name
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
+
# def [] name
|
84
|
+
# raise name.inspect
|
85
|
+
# cache[name]
|
86
|
+
# end
|
83
87
|
|
84
|
-
def []= name, value
|
85
|
-
|
86
|
-
end
|
88
|
+
# def []= name, value
|
89
|
+
# cache[name]= value
|
90
|
+
# end
|
87
91
|
|
88
|
-
def cache
|
89
|
-
|
90
|
-
end
|
92
|
+
# def cache
|
93
|
+
# @cache ||= {}
|
94
|
+
# end
|
91
95
|
|
92
96
|
|
93
97
|
# Columns
|
@@ -99,27 +103,31 @@ module ActiveAdmin::Mongoid::Document
|
|
99
103
|
end
|
100
104
|
end
|
101
105
|
|
102
|
-
def columns
|
103
|
-
|
104
|
-
end
|
106
|
+
# def columns
|
107
|
+
# @columns ||= fields.map(&:second).map{ |c| ColumnWrapper.new(c) }
|
108
|
+
# end
|
105
109
|
|
106
|
-
def column_names
|
107
|
-
|
108
|
-
end
|
110
|
+
# def column_names
|
111
|
+
# @column_names ||= fields.map(&:first)
|
112
|
+
# end
|
109
113
|
|
110
|
-
def columns_hash
|
111
|
-
|
112
|
-
end
|
114
|
+
# def columns_hash
|
115
|
+
# columns.index_by(&:name)
|
116
|
+
# end
|
113
117
|
|
114
118
|
|
115
119
|
|
116
|
-
def reorder sorting
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
120
|
+
# def reorder sorting
|
121
|
+
# return unscoped if sorting.blank?
|
122
|
+
# if sorting.match /\".*\".*/
|
123
|
+
# options = sorting.split(/ |\./)
|
124
|
+
# options.shift if options.count == 3
|
125
|
+
# else
|
126
|
+
# options = sorting.split(' ')
|
127
|
+
# end
|
128
|
+
# field, order = *options
|
129
|
+
# unscoped.order_by(field => order)
|
130
|
+
# end
|
123
131
|
|
124
132
|
def connection
|
125
133
|
@connection ||= Connection.new(self)
|
@@ -141,6 +149,4 @@ module ActiveAdmin::Mongoid::Document
|
|
141
149
|
end
|
142
150
|
|
143
151
|
Mongoid::Document.send :include, ActiveAdmin::Mongoid::Document
|
144
|
-
Mongoid::Document.send :include, MetaSearch::Searches::Mongoid
|
145
|
-
|
146
|
-
|
152
|
+
# Mongoid::Document.send :include, MetaSearch::Searches::Mongoid
|
@@ -1,9 +1,16 @@
|
|
1
|
-
class ActiveAdmin::
|
1
|
+
class ActiveAdmin::Filters::FormBuilder
|
2
|
+
|
3
|
+
def filter(method, options = {})
|
4
|
+
if method.present? && options[:as] ||= default_input_type(method)
|
5
|
+
template.concat input(method, options)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
2
9
|
def default_input_type(method, options = {})
|
3
10
|
if column = column_for(method)
|
4
11
|
case column.type.name.downcase.to_sym
|
5
12
|
when :date, :datetime, :time; :date_range
|
6
|
-
when :string, :text, :
|
13
|
+
when :string, :text, :object; :string
|
7
14
|
when :float, :decimal; :numeric
|
8
15
|
when :integer
|
9
16
|
return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
|
@@ -1,9 +1,19 @@
|
|
1
1
|
module ActiveAdmin
|
2
2
|
module Helpers
|
3
3
|
module Collection
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
alias original_collection_size collection_size
|
6
|
+
original_collection_size = instance_method(:collection_size)
|
7
|
+
|
8
|
+
def collection_size(collection = nil)
|
9
|
+
collection ||= self.collection
|
10
|
+
if collection.is_a?(::Mongoid::Criteria)
|
11
|
+
collection.entries.count
|
12
|
+
else
|
13
|
+
original_collection_size(collection)
|
14
|
+
end
|
6
15
|
end
|
16
|
+
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
@@ -1,52 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
# module Naming
|
5
|
-
#
|
6
|
-
# # Returns a name used to uniquely identify this resource
|
7
|
-
# # this should be an instance of ActiveAdmin:Resource::Name, which responds to
|
8
|
-
# # #singular, #plural, #route_key, #human etc.
|
9
|
-
# def resource_name
|
10
|
-
# custom_name = @options[:as] && @options[:as].gsub(/\s/,'')
|
11
|
-
# @resource_name ||= if custom_name || !resource_class.respond_to?(:model_name)
|
12
|
-
# Resource::Name.new(resource_class, custom_name)
|
13
|
-
# else
|
14
|
-
# Resource::Name.new(resource_class)
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# end
|
21
|
-
# end
|
1
|
+
module ActiveAdmin
|
2
|
+
class Resource
|
22
3
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
|
43
|
-
# chain.send($2, $1)
|
44
|
-
# else
|
45
|
-
# chain # just return the chain
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# def search(chain)
|
50
|
-
# @search = ActiveAdmin::Mongoid::Search.new(chain, clean_search_params(params[:q]), active_admin_config.mongoid_per_page, params[:page])
|
51
|
-
# end
|
52
|
-
# end
|
4
|
+
# the commit: https://github.com/activeadmin/activeadmin/commit/1ef08af5044814c336917fa93aea607dce16dcb7
|
5
|
+
# adds in the _id field, which doesn't work with ransack for some reason or
|
6
|
+
# another. I'm not going to investigate any deeper, let's just remove the
|
7
|
+
# underscore prefixed fields as was the prior behavior
|
8
|
+
def default_filters
|
9
|
+
super.reject { |filter| filter == :_id }
|
10
|
+
end
|
11
|
+
|
12
|
+
module Attributes
|
13
|
+
|
14
|
+
# Hardcode mongoid STI column name
|
15
|
+
# see https://github.com/activeadmin/activeadmin/commit/1ef08af5044814c336917fa93aea607dce16dcb7#diff-e15d78c0b6b12c8bffec0de0ffcf735bR34
|
16
|
+
def sti_col?(c)
|
17
|
+
c.name == '_type'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|