activeadmin-mongoid 0.0.2.jpmckinney.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -4
  3. data/.rspec +2 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +27 -1
  6. data/README.md +0 -5
  7. data/Rakefile +6 -1
  8. data/activeadmin-mongoid.gemspec +8 -4
  9. data/lib/active_admin/mongoid.rb +26 -17
  10. data/lib/active_admin/mongoid/adaptor.rb +65 -0
  11. data/lib/active_admin/mongoid/comments.rb +12 -5
  12. data/lib/active_admin/mongoid/criteria.rb +10 -0
  13. data/lib/active_admin/mongoid/document.rb +43 -2
  14. data/lib/active_admin/mongoid/filter_form_builder.rb +31 -0
  15. data/lib/active_admin/mongoid/generators/install.rb +7 -0
  16. data/lib/active_admin/mongoid/helpers/collection.rb +10 -0
  17. data/lib/active_admin/mongoid/resource.rb +51 -33
  18. data/lib/active_admin/mongoid/version.rb +1 -1
  19. data/lib/tasks/activeadmin-mongoid_tasks.rake +4 -0
  20. data/spec/features/smoke_spec.rb +60 -0
  21. data/spec/spec_helper.rb +42 -0
  22. data/spec/support/capybara.rb +1 -0
  23. data/tasks/js.rake +32 -0
  24. data/tasks/test.rake +75 -0
  25. data/test_app/.gitignore +15 -0
  26. data/test_app/.rspec +1 -0
  27. data/test_app/README.rdoc +261 -0
  28. data/test_app/Rakefile +7 -0
  29. data/test_app/app/admin/admin_users.rb +20 -0
  30. data/test_app/app/admin/dashboard.rb +33 -0
  31. data/test_app/app/admin/posts.rb +3 -0
  32. data/test_app/app/assets/images/rails.png +0 -0
  33. data/test_app/app/assets/javascripts/active_admin.js +1 -0
  34. data/test_app/app/assets/javascripts/application.js +15 -0
  35. data/test_app/app/assets/stylesheets/active_admin.css.scss +29 -0
  36. data/test_app/app/assets/stylesheets/application.css +13 -0
  37. data/test_app/app/controllers/application_controller.rb +3 -0
  38. data/test_app/app/helpers/application_helper.rb +2 -0
  39. data/test_app/app/mailers/.gitkeep +0 -0
  40. data/test_app/app/models/.gitkeep +0 -0
  41. data/test_app/app/models/admin_user.rb +40 -0
  42. data/test_app/app/models/post.rb +6 -0
  43. data/test_app/app/views/layouts/application.html.erb +14 -0
  44. data/test_app/config.ru +4 -0
  45. data/test_app/config/_link_mongoid_config.rb +7 -0
  46. data/test_app/config/application.rb +70 -0
  47. data/test_app/config/boot.rb +6 -0
  48. data/test_app/config/database.yml +25 -0
  49. data/test_app/config/environment.rb +5 -0
  50. data/test_app/config/environments/development.rb +31 -0
  51. data/test_app/config/environments/production.rb +64 -0
  52. data/test_app/config/environments/test.rb +35 -0
  53. data/test_app/config/initializers/active_admin.rb +210 -0
  54. data/test_app/config/initializers/backtrace_silencers.rb +7 -0
  55. data/test_app/config/initializers/devise.rb +246 -0
  56. data/test_app/config/initializers/inflections.rb +15 -0
  57. data/test_app/config/initializers/mime_types.rb +5 -0
  58. data/test_app/config/initializers/secret_token.rb +7 -0
  59. data/test_app/config/initializers/session_store.rb +8 -0
  60. data/test_app/config/initializers/wrap_parameters.rb +10 -0
  61. data/test_app/config/locales/devise.en.yml +59 -0
  62. data/test_app/config/locales/en.yml +5 -0
  63. data/test_app/config/mongoid.2.yml +20 -0
  64. data/test_app/config/mongoid.3.yml +96 -0
  65. data/test_app/config/routes.rb +4 -0
  66. data/test_app/db/migrate/20130514223107_create_admin_notes.rb +17 -0
  67. data/test_app/db/migrate/20130514223108_move_admin_notes_to_comments.rb +26 -0
  68. data/test_app/db/seeds.rb +7 -0
  69. data/test_app/lib/assets/.gitkeep +0 -0
  70. data/test_app/lib/tasks/.gitkeep +0 -0
  71. data/test_app/log/.gitkeep +0 -0
  72. data/test_app/public/404.html +26 -0
  73. data/test_app/public/422.html +26 -0
  74. data/test_app/public/500.html +25 -0
  75. data/test_app/public/favicon.ico +0 -0
  76. data/test_app/public/index.html +241 -0
  77. data/test_app/public/robots.txt +5 -0
  78. data/test_app/script/rails +6 -0
  79. data/test_app/spec/models/admin_user_spec.rb +5 -0
  80. data/test_app/test/fixtures/.gitkeep +0 -0
  81. data/test_app/test/functional/.gitkeep +0 -0
  82. data/test_app/test/integration/.gitkeep +0 -0
  83. data/test_app/test/performance/browsing_test.rb +12 -0
  84. data/test_app/test/test_helper.rb +7 -0
  85. data/test_app/test/unit/.gitkeep +0 -0
  86. data/test_app/vendor/assets/javascripts/.gitkeep +0 -0
  87. data/test_app/vendor/assets/stylesheets/.gitkeep +0 -0
  88. data/test_app/vendor/plugins/.gitkeep +0 -0
  89. metadata +136 -29
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f4ee2f7bcc78891d91481ee20bdaa7ab082fba8
4
+ data.tar.gz: eb4fdbb0600638727f75187488434b6377ef44a1
5
+ SHA512:
6
+ metadata.gz: 15256821b3a1a2ce7fde50128a55690b4f1e004772ba0a0b273cd77c70f3fd54a9f789934b9825f36f6bbb0fe6441c1f77c672f04b82894baf73cb3ee3c0e3e5
7
+ data.tar.gz: 500cf07724202dd9f078334c893d7788ff0540a2771580e9fa52edf726ac9d8b4be848012e0446820cdc8033f08039e4a8e6bc1b339ff2f49d3e4e202ec97565
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  *.gem
2
2
  *.rbc
3
- .bundle
4
3
  .config
5
4
  .yardoc
6
5
  Gemfile.lock
@@ -12,6 +11,14 @@ lib/bundler/man
12
11
  pkg
13
12
  rdoc
14
13
  spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
14
+ /spec/tmp
15
+ /spec/version_tmp
16
+ /tmp
17
+ /.bundle
18
+ /log/*.log
19
+ /test_app/db/*.sqlite3
20
+ /test_app/log/*.log
21
+ /test_app/tmp/
22
+ /test_app/.sass-cache
23
+ /test_app/config/mongoid.yml
24
+ /spec/rails
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ services:
3
+ - mongodb
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
data/Gemfile CHANGED
@@ -1,4 +1,30 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in activeadmin-mongoid.gemspec
3
+ # Declare your gem's dependencies in activeadmin-mongoid.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
4
6
  gemspec
7
+
8
+
9
+ # Test app stuff
10
+
11
+ gem 'rails', '~> 3.2.6'
12
+
13
+ # Gems used only for assets and not required
14
+ # in production environments by default.
15
+ group :assets do
16
+ gem 'sass-rails', '~> 3.2.3'
17
+ gem 'coffee-rails', '~> 3.2.1'
18
+
19
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
20
+ # gem 'therubyracer', :platforms => :ruby
21
+ gem 'uglifier', '>= 1.0.3'
22
+ end
23
+
24
+ gem 'jquery-rails'
25
+ gem 'jslint'
26
+
27
+ group :test do
28
+ gem 'capybara'
29
+ gem 'launchy'
30
+ end
data/README.md CHANGED
@@ -4,7 +4,6 @@ ActiveAdmin hacks to support Mongoid.
4
4
  Some ActiveAdmin features are disabled:
5
5
 
6
6
  - comments
7
- - sidebar filters
8
7
 
9
8
  For more on Mongoid support in ActiveAdmin see [this issue](https://github.com/gregbell/active_admin/issues/26).
10
9
 
@@ -15,11 +14,7 @@ Add the following gems to your application's Gemfile:
15
14
 
16
15
  ```ruby
17
16
  gem 'activeadmin-mongoid'
18
- gem 'devise'
19
17
  ```
20
- Devise is the gem used to managed admin authentication.
21
- The gem is required to force itself ORM configuration.
22
- Else the gem will try to use by default ActiveRecord ORM.
23
18
 
24
19
  You can safely remove the following lines, since are already activeadmin-mongoid dependencies:
25
20
 
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+
3
+ require 'bundler/setup'
4
+ require 'bundler/gem_tasks'
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new :default
@@ -1,5 +1,7 @@
1
1
  # coding: utf-8
2
- require File.expand_path('../lib/active_admin/mongoid/version', __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_admin/mongoid/version'
3
5
 
4
6
  Gem::Specification.new do |gem|
5
7
  gem.authors = ['Elia Schito']
@@ -15,9 +17,11 @@ Gem::Specification.new do |gem|
15
17
  gem.require_paths = ['lib']
16
18
  gem.version = ActiveAdmin::Mongoid::VERSION
17
19
  gem.license = 'MIT'
18
-
19
- gem.add_runtime_dependency 'mongoid', '>= 2.0'
20
- gem.add_runtime_dependency 'activeadmin', '~> 0.4'
20
+
21
+ gem.add_runtime_dependency 'mongoid', '~> 3.0'
22
+ gem.add_runtime_dependency 'activeadmin', '~> 0.6'
21
23
  gem.add_runtime_dependency 'meta_search', '>= 1.1.0.pre'
22
24
  gem.add_runtime_dependency 'sass-rails', ['~> 3.1', '>= 3.1.4']
25
+
26
+ gem.add_development_dependency 'rspec-rails', '~> 2.7'
23
27
  end
@@ -1,20 +1,29 @@
1
+ require 'active_admin/mongoid/version'
2
+ # require 'active_admin/mongoid/engine'
1
3
  require 'active_admin'
4
+ require 'devise'
5
+ require 'rails'
2
6
  require 'mongoid'
3
7
 
4
- module ActiveAdmin
5
- module Mongoid
6
- end
7
-
8
- class << self
9
- alias setup_without_mongoid setup
10
-
11
- # Load monkey patches *after* the setup process
12
- def setup *args, &block
13
- setup_without_mongoid *args, &block
14
-
15
- require 'active_admin/mongoid/comments'
16
- require 'active_admin/mongoid/resource'
17
- require 'active_admin/mongoid/document'
18
- end
19
- end
20
- end
8
+ require 'active_admin/mongoid/comments'
9
+ require 'active_admin/mongoid/adaptor'
10
+ require 'active_admin/mongoid/filter_form_builder'
11
+ require 'active_admin/mongoid/resource'
12
+ require 'active_admin/mongoid/document'
13
+ require 'active_admin/mongoid/helpers/collection'
14
+ require 'active_admin/mongoid/criteria'
15
+
16
+ # module ActiveAdmin
17
+ # module Mongoid
18
+ # end
19
+ #
20
+ # class << self
21
+ # alias setup_without_mongoid setup
22
+ #
23
+ # # Load monkey patches *after* the setup process
24
+ # def setup *args, &block
25
+ # setup_without_mongoid *args, &block
26
+ #
27
+ # end
28
+ # end
29
+ # end
@@ -0,0 +1,65 @@
1
+ module ActiveAdmin
2
+ module Mongoid
3
+ class Search
4
+ attr_reader :base, :query, :query_hash, :search_params
5
+
6
+ def initialize(object, search_params = {}, per_page = 30, page = 1)
7
+ @base = object
8
+ @search_params = search_params
9
+ @query_hash = get_query_hash(search_params)
10
+ vpage = page.to_i > 0 ? page.to_i : 1
11
+ @query = @base.where(@query_hash).limit(per_page).skip(per_page * (vpage - 1))
12
+ end
13
+
14
+ def respond_to?(method_id)
15
+ @query.send(:respond_to?, method_id)
16
+ end
17
+
18
+ def method_missing(method_id, *args, &block)
19
+ if is_query(method_id)
20
+ @search_params[method_id.to_s]
21
+ else
22
+ @query.send(method_id, *args, &block)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def is_query(method_id)
29
+ method_id.to_s =~ /_(contains|eq|in|gt|lt|gte|lte)$/
30
+ end
31
+
32
+ def get_query_hash(search_params)
33
+ searches = search_params.map do|k, v|
34
+ mongoidify_search(k,v)
35
+ end
36
+ Hash[searches]
37
+ end
38
+
39
+ def mongoidify_search(k, v)
40
+ case k
41
+ when /_contains$/
42
+ [get_attribute(k, '_contains'), Regexp.new(Regexp.escape("#{v}"), Regexp::IGNORECASE)]
43
+ when /_eq$/
44
+ [get_attribute(k, '_eq'), v]
45
+ when /_in$/
46
+ [get_attribute(k, '_in').to_sym.in, v]
47
+ when /_gt$/
48
+ [get_attribute(k, "_gt").to_sym.gt, v]
49
+ when /_lt$/
50
+ [get_attribute(k, "_lt").to_sym.lt, v]
51
+ when /_gte$/
52
+ [get_attribute(k, "_gte").to_sym.gte, v]
53
+ when /_lte$/
54
+ [get_attribute(k, "_lte").to_sym.lte, v]
55
+ else
56
+ [k, v]
57
+ end
58
+ end
59
+
60
+ def get_attribute(k, postfix)
61
+ k.match(/^(.*)#{postfix}$/)[1]
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,7 +1,14 @@
1
- ActiveAdmin::Namespace # autoload
2
- class ActiveAdmin::Namespace
3
- # Disable comments
4
- def comments?
5
- false
1
+ require 'active_admin/comments/namespace_helper'
2
+ # ActiveAdmin::Application.allow_comments = false
3
+
4
+ module ActiveAdmin
5
+ module Comments
6
+
7
+ module NamespaceHelper
8
+ def comments?
9
+ false
10
+ end
11
+ end
12
+
6
13
  end
7
14
  end
@@ -0,0 +1,10 @@
1
+ Mongoid::Criteria.class_eval do
2
+ def relation *args, &block
3
+ self
4
+ end
5
+
6
+ def base
7
+ klass
8
+ end
9
+ end
10
+
@@ -1,18 +1,59 @@
1
1
  module ActiveAdmin::Mongoid::Document
2
2
  extend ActiveSupport::Concern
3
-
3
+
4
+ included do
5
+ unless respond_to? :primary_key
6
+ class << self
7
+ attr_accessor :primary_key
8
+ end
9
+ end
10
+
11
+ self.primary_key ||= [:_id]
12
+ end
13
+
14
+ class Connection
15
+ def initialize model
16
+ @model = model
17
+ end
18
+
19
+ def quote_column_name name
20
+ name
21
+ end
22
+ end
23
+
4
24
  module ClassMethods
5
25
  def content_columns
6
26
  @content_columns ||= fields.map(&:second).select {|f| f.name !~ /(^_|^(created|updated)_at)/}
7
27
  end
8
28
 
29
+ def metasearch *args, &block
30
+ scoped
31
+ end
32
+
9
33
  def columns
10
34
  @columns ||= fields.map(&:second)
11
35
  end
12
-
36
+
37
+ def column_names
38
+ @column_names ||= fields.map(&:first)
39
+ end
40
+
13
41
  def reorder *args
14
42
  scoped
15
43
  end
44
+
45
+ def connection
46
+ @connection ||= Connection.new(self)
47
+ end
48
+
49
+ def find_by_id id
50
+ find_by(:_id => id)
51
+ end
52
+
53
+ def quoted_table_name
54
+ collection_name.to_s.inspect
55
+ end
56
+
16
57
  end
17
58
  end
18
59
 
@@ -0,0 +1,31 @@
1
+ class ActiveAdmin::FilterFormBuilder
2
+ def default_input_type(method, options = {})
3
+ if column = column_for(method)
4
+ case column.type.name.downcase.to_sym
5
+ when :date, :datetime, :time; :date_range
6
+ when :string, :text, :objectl; :string
7
+ when :float, :decimal; :numeric
8
+ when :integer
9
+ return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
10
+ return :numeric
11
+ end
12
+ elsif is_association?(method)
13
+ return :select
14
+ else
15
+ # dirty but allows to create filters for hashes
16
+ return :string
17
+ end
18
+ end
19
+
20
+ def is_association?(method)
21
+ @object.klass.associations.to_a.map(&:first).include?(method.to_s)
22
+ end
23
+
24
+ def column_for(method)
25
+ @object.klass.fields[method.to_s] if @object.klass.respond_to?(:fields)
26
+ end
27
+
28
+ def reflection_for(method)
29
+ @object.klass.reflect_on_association(method) if @object.klass.respond_to?(:reflect_on_association)
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ require 'generators/active_admin/install/install_generator'
2
+
3
+ class ActiveAdmin::Generators::InstallGenerator
4
+ def create_migrations
5
+ # do nothing
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # module ActiveAdmin
2
+ # module Helpers
3
+ # module Collection
4
+ # def collection_size(collection=collection)
5
+ # raise collection.inspect
6
+ # collection.count
7
+ # end
8
+ # end
9
+ # end
10
+ # end
@@ -1,34 +1,52 @@
1
- ActiveAdmin::Resource # autoload
2
- class ActiveAdmin::Resource
3
- def resource_table_name
4
- resource_class.collection_name
5
- end
6
- end
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
7
22
 
8
- ActiveAdmin::ResourceController # autoload
9
- class ActiveAdmin::ResourceController
10
- before_filter :skip_sidebar!
11
-
12
- protected
13
-
14
- # @todo remove once https://github.com/gregbell/active_admin/pull/1454 is merged
15
- def skip_sidebar!
16
- @skip_sidebar = true
17
- end
18
-
19
- # Use #desc and #asc for sorting.
20
- def sort_order(chain)
21
- params[:order] ||= active_admin_config.sort_order
22
- # @todo remove once https://github.com/mongoid/mongoid/pull/2175 is fixed
23
- if params[:order] && params[:order] != 'id_desc' && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
24
- chain.send($2, $1)
25
- else
26
- chain # just return the chain
27
- end
28
- end
29
-
30
- # Disable filters
31
- def search(chain)
32
- chain
33
- end
34
- end
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