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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/CONDUCT.md +13 -0
  4. data/Gemfile +9 -3
  5. data/README.md +30 -7
  6. data/activeadmin-mongoid.gemspec +7 -7
  7. data/lib/active_admin/mongoid.rb +6 -2
  8. data/lib/active_admin/mongoid/document.rb +54 -48
  9. data/lib/active_admin/mongoid/filter_form_builder.rb +9 -2
  10. data/lib/active_admin/mongoid/helpers/collection.rb +12 -2
  11. data/lib/active_admin/mongoid/order_clause.rb +12 -0
  12. data/lib/active_admin/mongoid/resource.rb +21 -51
  13. data/lib/active_admin/mongoid/version.rb +1 -1
  14. data/spec/features/smoke_spec.rb +52 -15
  15. data/spec/spec_helper.rb +5 -3
  16. data/spec/support/debug.rb +3 -0
  17. data/{test_app/config/_link_mongoid_config.rb → spec/support/mongoid.rb} +3 -1
  18. data/test_app/Gemfile +39 -0
  19. data/test_app/app/admin/posts.rb +34 -0
  20. data/test_app/app/assets/javascripts/active_admin.js +4 -4
  21. data/test_app/app/models/author.rb +9 -0
  22. data/test_app/app/models/city.rb +7 -0
  23. data/test_app/app/models/post.rb +3 -0
  24. data/test_app/config/application.rb +8 -14
  25. data/test_app/config/boot.rb +1 -1
  26. data/test_app/config/environment.rb +1 -1
  27. data/test_app/config/environments/development.rb +1 -1
  28. data/test_app/config/environments/production.rb +1 -1
  29. data/test_app/config/environments/test.rb +4 -2
  30. data/test_app/config/initializers/active_admin.rb +6 -3
  31. data/test_app/config/initializers/i18n.rb +1 -0
  32. data/test_app/config/initializers/mongoid.rb +1 -0
  33. data/test_app/config/initializers/secret_token.rb +1 -1
  34. data/test_app/config/initializers/session_store.rb +1 -1
  35. data/test_app/config/mongoid.4.yml +87 -0
  36. data/test_app/config/mongoid.5.yml +7 -0
  37. data/test_app/config/mongoid.6.yml +7 -0
  38. data/test_app/config/routes.rb +1 -1
  39. metadata +46 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9157f6b8aa66c4264bfb42bf5220ace2e7c79d30
4
- data.tar.gz: 3f67da796eb5c7b42c9ecc313c030315d452fe7c
3
+ metadata.gz: f252b1a213790dedb791b66a2371f0d22a25a479
4
+ data.tar.gz: 90e7f395fc61dc91bd66d9ccb8fa64243e740e2d
5
5
  SHA512:
6
- metadata.gz: f41834ee3606eff87869fcf5e741bc888fa8492329f19be35ea27a0526be6c76e9f745891a983d1c3a3befe644a1e80e56d780554f972ab81ca518b097fa99a5
7
- data.tar.gz: c1f54fe99d590b2346591b3a38f2b6d22f5c3097b3f881aa9bd2be342146f0700fc1f36d811438597c159771032d192622f7ea98dfe8653a7440fa7a15fc4b56
6
+ metadata.gz: a605334c710e2ad8471ded1fd48163035a9e86f9a667df83e41bfa0322c98f2f7afb68d33614423d5d3e852680efcac15e30bf509a73bceffbbbd4910184f8f6
7
+ data.tar.gz: 7fedb4c3668e2d7cc6154c341a9e6e24ed39e1dfbaf8fd9899196198cdc8493519791c19429fb04cbb251231859c189c0925ae921c289cba812240360061a4d6
@@ -2,5 +2,6 @@ language: ruby
2
2
  services:
3
3
  - mongodb
4
4
  rvm:
5
- - 1.9.3
6
- - 2.0.0
5
+ - 2.2.7
6
+ - 2.3.4
7
+ - 2.4.1
@@ -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', '~> 3.2.6'
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', '~> 3.2.3'
17
- gem 'coffee-rails', '~> 3.2.1'
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::Mongoid
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
- [![Build Status](https://secure.travis-ci.org/elia/activeadmin-mongoid.png?branch=master)](http://travis-ci.org/elia/activeadmin-mongoid)
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:
@@ -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', ['> 3.0', '< 5.0']
22
- gem.add_runtime_dependency 'activeadmin', '~> 0.6'
23
- gem.add_runtime_dependency 'jquery-rails', '< 3.0' # in which they remove jquery-ui
24
- gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4', '< 5.0']
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', '~> 2.7'
27
+ gem.add_development_dependency 'rspec-rails', '~> 3.6'
28
28
  end
@@ -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 Moped::BSON::ObjectId, Object
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 ||= [:_id]
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
- criteria
58
- end
60
+ # def joins_values *args
61
+ # criteria
62
+ # end
59
63
 
60
- def group_by *args, &block
61
- criteria
62
- end
64
+ # def group_by *args, &block
65
+ # criteria
66
+ # end
63
67
 
64
- def ransack *args
65
- scoped
68
+ # def ransack *args
69
+ # scoped
66
70
 
67
- scoped.class.class_eval do
68
- def result
69
- self
70
- end
71
- end
71
+ # scoped.class.class_eval do
72
+ # def result
73
+ # self
74
+ # end
75
+ # end
72
76
 
73
- scoped
74
- end
77
+ # scoped
78
+ # end
75
79
 
76
80
 
77
81
  # Cache
78
82
 
79
- def [] name
80
- raise name.inspect
81
- cache[name]
82
- end
83
+ # def [] name
84
+ # raise name.inspect
85
+ # cache[name]
86
+ # end
83
87
 
84
- def []= name, value
85
- cache[name]= value
86
- end
88
+ # def []= name, value
89
+ # cache[name]= value
90
+ # end
87
91
 
88
- def cache
89
- @cache ||= {}
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
- @columns ||= fields.map(&:second).map{ |c| ColumnWrapper.new(c) }
104
- end
106
+ # def columns
107
+ # @columns ||= fields.map(&:second).map{ |c| ColumnWrapper.new(c) }
108
+ # end
105
109
 
106
- def column_names
107
- @column_names ||= fields.map(&:first)
108
- end
110
+ # def column_names
111
+ # @column_names ||= fields.map(&:first)
112
+ # end
109
113
 
110
- def columns_hash
111
- columns.index_by(&:name)
112
- end
114
+ # def columns_hash
115
+ # columns.index_by(&:name)
116
+ # end
113
117
 
114
118
 
115
119
 
116
- def reorder sorting
117
- return unscoped if sorting.blank?
118
- options = sorting.split(/ |\./)
119
- options.shift if options.count == 3
120
- field, order = *options
121
- unscoped.order_by(field => order)
122
- end
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::FilterFormBuilder
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, :objectl; :string
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
- def collection_size(collection=collection)
5
- collection.count(true)
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
@@ -0,0 +1,12 @@
1
+ module ActiveAdmin
2
+ class OrderClause
3
+
4
+ def to_sql
5
+ to_mongo_options
6
+ end
7
+
8
+ def to_mongo_options
9
+ { @column => @order.downcase.to_sym }
10
+ end
11
+ end
12
+ end
@@ -1,52 +1,22 @@
1
- # module ActiveAdmin
2
- # class Resource
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
- # ActiveAdmin::Resource # autoload
24
- # class ActiveAdmin::Resource
25
- # def resource_table_name
26
- # resource_class.collection_name
27
- # end
28
- #
29
- # def mongoid_per_page
30
- # per_page
31
- # end
32
- # end
33
- #
34
- # ActiveAdmin::ResourceController # autoload
35
- # class ActiveAdmin::ResourceController
36
- #
37
- # protected
38
- #
39
- # # Use #desc and #asc for sorting.
40
- # def sort_order(chain)
41
- # params[:order] ||= active_admin_config.sort_order
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