activeadmin-mongoid 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/README.md +4 -0
- data/activeadmin-mongoid.gemspec +4 -3
- data/lib/active_admin/mongoid.rb +19 -14
- data/lib/active_admin/mongoid/criteria.rb +12 -0
- data/lib/active_admin/mongoid/document.rb +98 -12
- data/lib/active_admin/mongoid/helpers/collection.rb +9 -10
- data/lib/active_admin/mongoid/version.rb +1 -1
- data/lib/meta_search/searches/mongoid.rb +117 -0
- data/spec/features/smoke_spec.rb +223 -33
- data/spec/spec_helper.rb +9 -0
- data/spec/support/capybara.rb +3 -1
- data/test_app/app/admin/posts.rb +8 -0
- data/test_app/app/assets/javascripts/active_admin.js +7 -1
- data/test_app/app/models/admin_user.rb +4 -0
- data/test_app/app/models/post.rb +4 -0
- data/test_app/config/_link_mongoid_config.rb +1 -0
- data/test_app/config/initializers/devise.rb +2 -0
- metadata +37 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9157f6b8aa66c4264bfb42bf5220ace2e7c79d30
|
4
|
+
data.tar.gz: 3f67da796eb5c7b42c9ecc313c030315d452fe7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f41834ee3606eff87869fcf5e741bc888fa8492329f19be35ea27a0526be6c76e9f745891a983d1c3a3befe644a1e80e56d780554f972ab81ca518b097fa99a5
|
7
|
+
data.tar.gz: c1f54fe99d590b2346591b3a38f2b6d22f5c3097b3f881aa9bd2be342146f0700fc1f36d811438597c159771032d192622f7ea98dfe8653a7440fa7a15fc4b56
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# ActiveAdmin::Mongoid
|
2
2
|
|
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)
|
5
|
+
|
6
|
+
|
3
7
|
ActiveAdmin hacks to support Mongoid.
|
4
8
|
Some ActiveAdmin features are disabled:
|
5
9
|
|
data/activeadmin-mongoid.gemspec
CHANGED
@@ -18,10 +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', '
|
21
|
+
gem.add_runtime_dependency 'mongoid', ['> 3.0', '< 5.0']
|
22
22
|
gem.add_runtime_dependency 'activeadmin', '~> 0.6'
|
23
|
-
gem.add_runtime_dependency '
|
24
|
-
gem.add_runtime_dependency 'sass-rails', ['
|
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'
|
25
26
|
|
26
27
|
gem.add_development_dependency 'rspec-rails', '~> 2.7'
|
27
28
|
end
|
data/lib/active_admin/mongoid.rb
CHANGED
@@ -13,17 +13,22 @@ require 'active_admin/mongoid/document'
|
|
13
13
|
require 'active_admin/mongoid/helpers/collection'
|
14
14
|
require 'active_admin/mongoid/criteria'
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
16
|
+
module ActiveAdmin
|
17
|
+
module Mongoid
|
18
|
+
class Railtie < ::Rails::Railtie
|
19
|
+
config.after_initialize do
|
20
|
+
I18n.backend.reload!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# class << self
|
26
|
+
# alias setup_without_mongoid setup
|
27
|
+
#
|
28
|
+
# # Load monkey patches *after* the setup process
|
29
|
+
# def setup *args, &block
|
30
|
+
# setup_without_mongoid *args, &block
|
31
|
+
#
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
1
3
|
Mongoid::Criteria.class_eval do
|
2
4
|
def relation *args, &block
|
3
5
|
self
|
@@ -6,5 +8,15 @@ Mongoid::Criteria.class_eval do
|
|
6
8
|
def base
|
7
9
|
klass
|
8
10
|
end
|
11
|
+
|
12
|
+
def table
|
13
|
+
CollectionTable.new(klass.collection)
|
14
|
+
end
|
15
|
+
|
16
|
+
class CollectionTable < SimpleDelegator
|
17
|
+
def from(*a)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
9
21
|
end
|
10
22
|
|
@@ -1,14 +1,24 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'meta_search/searches/mongoid'
|
3
|
+
|
1
4
|
module ActiveAdmin::Mongoid::Document
|
2
5
|
extend ActiveSupport::Concern
|
3
6
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
# PROXY CLASSES
|
11
|
+
|
12
|
+
class ColumnWrapper < SimpleDelegator
|
13
|
+
def type
|
14
|
+
_super = super
|
15
|
+
case _super
|
16
|
+
when Moped::BSON::ObjectId, Object
|
17
|
+
:string
|
18
|
+
else
|
19
|
+
_super.name.underscore.to_sym
|
8
20
|
end
|
9
21
|
end
|
10
|
-
|
11
|
-
self.primary_key ||= [:_id]
|
12
22
|
end
|
13
23
|
|
14
24
|
class Connection
|
@@ -21,25 +31,94 @@ module ActiveAdmin::Mongoid::Document
|
|
21
31
|
end
|
22
32
|
end
|
23
33
|
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
# CLASS METHODS
|
38
|
+
|
39
|
+
included do
|
40
|
+
include MetaSearch::Searches::Mongoid
|
41
|
+
|
42
|
+
unless respond_to? :primary_key
|
43
|
+
class << self
|
44
|
+
attr_accessor :primary_key
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
self.primary_key ||= [:_id]
|
49
|
+
|
50
|
+
end
|
51
|
+
|
24
52
|
module ClassMethods
|
25
|
-
|
26
|
-
|
53
|
+
|
54
|
+
# Metasearch
|
55
|
+
|
56
|
+
def joins_values *args
|
57
|
+
criteria
|
27
58
|
end
|
28
59
|
|
29
|
-
def
|
60
|
+
def group_by *args, &block
|
61
|
+
criteria
|
62
|
+
end
|
63
|
+
|
64
|
+
def ransack *args
|
65
|
+
scoped
|
66
|
+
|
67
|
+
scoped.class.class_eval do
|
68
|
+
def result
|
69
|
+
self
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
30
73
|
scoped
|
31
74
|
end
|
32
75
|
|
76
|
+
|
77
|
+
# Cache
|
78
|
+
|
79
|
+
def [] name
|
80
|
+
raise name.inspect
|
81
|
+
cache[name]
|
82
|
+
end
|
83
|
+
|
84
|
+
def []= name, value
|
85
|
+
cache[name]= value
|
86
|
+
end
|
87
|
+
|
88
|
+
def cache
|
89
|
+
@cache ||= {}
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
# Columns
|
94
|
+
|
95
|
+
def content_columns
|
96
|
+
# cannot cache this, since changes in time (while defining fields)
|
97
|
+
fields.map(&:second).reject do |f|
|
98
|
+
f.name =~ /(^_|^(created|updated)_at)/ or Mongoid::Fields::ForeignKey === f
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
33
102
|
def columns
|
34
|
-
@columns ||= fields.map(&:second)
|
103
|
+
@columns ||= fields.map(&:second).map{ |c| ColumnWrapper.new(c) }
|
35
104
|
end
|
36
105
|
|
37
106
|
def column_names
|
38
107
|
@column_names ||= fields.map(&:first)
|
39
108
|
end
|
40
109
|
|
41
|
-
def
|
42
|
-
|
110
|
+
def columns_hash
|
111
|
+
columns.index_by(&:name)
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
|
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)
|
43
122
|
end
|
44
123
|
|
45
124
|
def connection
|
@@ -54,7 +133,14 @@ module ActiveAdmin::Mongoid::Document
|
|
54
133
|
collection_name.to_s.inspect
|
55
134
|
end
|
56
135
|
|
136
|
+
|
137
|
+
def reflections *a
|
138
|
+
relations *a
|
139
|
+
end
|
57
140
|
end
|
58
141
|
end
|
59
142
|
|
60
143
|
Mongoid::Document.send :include, ActiveAdmin::Mongoid::Document
|
144
|
+
Mongoid::Document.send :include, MetaSearch::Searches::Mongoid
|
145
|
+
|
146
|
+
|
@@ -1,10 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# end
|
1
|
+
module ActiveAdmin
|
2
|
+
module Helpers
|
3
|
+
module Collection
|
4
|
+
def collection_size(collection=collection)
|
5
|
+
collection.count(true)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'meta_search/method'
|
3
|
+
require 'meta_search/builder'
|
4
|
+
|
5
|
+
module MetaSearch
|
6
|
+
module Searches
|
7
|
+
|
8
|
+
require 'delegate'
|
9
|
+
class MongoidSearchBuilder < SimpleDelegator
|
10
|
+
def initialize relation, params, options
|
11
|
+
super(relation)
|
12
|
+
@relation = relation
|
13
|
+
@params, @options = params, options
|
14
|
+
end
|
15
|
+
|
16
|
+
def build
|
17
|
+
params.each_pair do |field_query, value|
|
18
|
+
field, query = field_query.to_s.scan(metasearch_regexp).first
|
19
|
+
case query.to_sym
|
20
|
+
when :equals, :eq
|
21
|
+
@relation = relation.where(field => value)
|
22
|
+
when :does_not_equal, :ne, :not_eq
|
23
|
+
@relation = relation.where(field.to_sym.ne => value)
|
24
|
+
when :contains, :like, :matches
|
25
|
+
@relation = relation.where(field => /#{value}/i)
|
26
|
+
when :does_not_contain, :nlike, :not_matches
|
27
|
+
@relation = relation.where(field.to_sym.not => /#{value}/i)
|
28
|
+
when :starts_with, :sw
|
29
|
+
@relation = relation.where(field.to_sym => /\A#{Regexp.quote(value)}/i)
|
30
|
+
when :does_not_start_with, :dnsw
|
31
|
+
@relation = relation.where(field.to_sym.not => /\A#{Regexp.quote(value)}/i)
|
32
|
+
when :ends_with, :ew
|
33
|
+
@relation = relation.where(field.to_sym => /#{Regexp.quote(value)}\z/i)
|
34
|
+
when :does_not_end_with, :dnew
|
35
|
+
@relation = relation.where(field.to_sym.not => /#{Regexp.quote(value)}\z/i)
|
36
|
+
when :greater_than, :gt
|
37
|
+
@relation = relation.where(field.to_sym.gt => value)
|
38
|
+
when :less_than, :lt
|
39
|
+
@relation = relation.where(field.to_sym.lt => value)
|
40
|
+
when :greater_than_or_equal_to, :gte, :gteq
|
41
|
+
@relation = relation.where(field.to_sym.gte => value)
|
42
|
+
when :less_than_or_equal_to, :lte, :lteq
|
43
|
+
@relation = relation.where(field.to_sym.lte => value)
|
44
|
+
when :in
|
45
|
+
@relation = relation.where(field.to_sym.in => Array.wrap(value))
|
46
|
+
when :not_in, :ni
|
47
|
+
@relation = relation.where(field.to_sym.nin => Array.wrap(value))
|
48
|
+
when :is_true
|
49
|
+
@relation = relation.where(field => true)
|
50
|
+
when :is_false
|
51
|
+
@relation = relation.where(field => false)
|
52
|
+
when :is_present
|
53
|
+
@relation = relation.where(field.to_sym.exists => true)
|
54
|
+
when :is_blank
|
55
|
+
@relation = relation.where(field.to_sym.exists => false)
|
56
|
+
when :is_null
|
57
|
+
@relation = relation.where(field => nil)
|
58
|
+
when :is_not_null
|
59
|
+
@relation = relation.where(field.to_sym.ne => nil)
|
60
|
+
else
|
61
|
+
raise [field_query, value].inspect
|
62
|
+
end
|
63
|
+
end
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
attr_reader :relation, :params, :options
|
68
|
+
|
69
|
+
def base
|
70
|
+
self
|
71
|
+
end
|
72
|
+
|
73
|
+
def klass
|
74
|
+
relation
|
75
|
+
end
|
76
|
+
|
77
|
+
def method_missing name, *attrs, &block
|
78
|
+
relation.send(name, *attrs, &block)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def respond_to? name, include_private = false
|
83
|
+
name.to_s =~ metasearch_regexp or super
|
84
|
+
end
|
85
|
+
|
86
|
+
def method_missing name, *args, &block
|
87
|
+
if name =~ metasearch_regexp
|
88
|
+
params[name]
|
89
|
+
else
|
90
|
+
super
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def metasearch_regexp
|
95
|
+
field_names = klass.fields.map(&:second).map(&:name)
|
96
|
+
conditions = MetaSearch::DEFAULT_WHERES.map {|condition| condition[0...-1]} # pop tail options
|
97
|
+
|
98
|
+
/\A(#{field_names.join('|')})_(#{conditions.join('|')})\z/
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
module Mongoid
|
104
|
+
extend ActiveSupport::Concern
|
105
|
+
|
106
|
+
module ClassMethods
|
107
|
+
def metasearch(params = nil, options = nil)
|
108
|
+
options ||= {}
|
109
|
+
params ||= {}
|
110
|
+
MongoidSearchBuilder.new(criteria, params, options).build
|
111
|
+
end
|
112
|
+
alias_method :search, :metasearch unless respond_to?(:search)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/spec/features/smoke_spec.rb
CHANGED
@@ -5,56 +5,246 @@ require 'activeadmin'
|
|
5
5
|
describe 'browse the test app' do
|
6
6
|
let(:password) { 'foobar•secret' }
|
7
7
|
let(:email) { 'john@doe.com' }
|
8
|
+
let(:admin_user) do
|
9
|
+
AdminUser.where(email: email).first || AdminUser.create!(email: email, password: password)
|
10
|
+
end
|
11
|
+
let(:other_email) { 'jane@doe.com' }
|
12
|
+
let(:other_user) do
|
13
|
+
AdminUser.where(email: other_email).first || AdminUser.create!(email: other_email, password: password)
|
14
|
+
end
|
8
15
|
|
9
16
|
before do
|
10
17
|
Mongoid.purge!
|
11
|
-
|
18
|
+
expect(admin_user).to be_persisted
|
19
|
+
expect(other_user).to be_persisted
|
12
20
|
end
|
13
|
-
before { visit '/admin' }
|
14
21
|
|
15
|
-
|
16
|
-
|
22
|
+
context 'when authorized' do
|
23
|
+
before do
|
24
|
+
visit '/admin'
|
25
|
+
|
26
|
+
I18n.t('active_admin.devise.login.submit').should eq('Login')
|
17
27
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
28
|
+
# Auth
|
29
|
+
fill_in 'Email', with: email
|
30
|
+
fill_in 'Password', with: password
|
31
|
+
click_on 'Login'
|
32
|
+
end
|
22
33
|
|
23
|
-
|
24
|
-
|
25
|
-
|
34
|
+
it 'creates and edits a new post' do
|
35
|
+
# New
|
36
|
+
click_on 'Posts'
|
37
|
+
click_on 'New Post'
|
38
|
+
fill_in 'Title', with: 'dhh screencast'
|
39
|
+
fill_in 'Body', with: 'is still the best intro to rails'
|
26
40
|
|
27
|
-
|
28
|
-
|
41
|
+
# Create
|
42
|
+
click_on 'Create Post'
|
29
43
|
|
30
|
-
|
31
|
-
|
44
|
+
within '.attributes_table.post' do
|
45
|
+
page.should have_content('dhh screencast')
|
46
|
+
page.should have_content('is still the best intro to rails')
|
47
|
+
end
|
32
48
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
49
|
+
# Edit
|
50
|
+
click_on 'Edit Post'
|
51
|
+
fill_in 'Title', with: 'DHH original screencast'
|
37
52
|
|
38
|
-
|
39
|
-
|
40
|
-
fill_in 'Title', with: 'DHH original screencast'
|
53
|
+
# Update
|
54
|
+
click_on 'Update Post'
|
41
55
|
|
42
|
-
|
43
|
-
|
56
|
+
within '.attributes_table.post' do
|
57
|
+
page.should have_content('DHH original screencast')
|
58
|
+
page.should have_content('is still the best intro to rails')
|
59
|
+
end
|
44
60
|
|
45
|
-
|
46
|
-
|
47
|
-
|
61
|
+
# List
|
62
|
+
within('.breadcrumb') { click_on 'Posts' }
|
63
|
+
within '#index_table_posts' do
|
64
|
+
page.should have_content('DHH original screencast')
|
65
|
+
page.should have_content('is still the best intro to rails')
|
66
|
+
end
|
48
67
|
end
|
49
68
|
|
50
|
-
|
51
|
-
|
69
|
+
context 'with 1 post' do
|
70
|
+
|
71
|
+
before do
|
72
|
+
Post.create!(title: 'Quick Brown Fox', body: 'The quick brown fox jumps over the lazy dog.', view_count: 5, admin_user: admin_user, other_user: other_user)
|
73
|
+
|
74
|
+
click_on 'Posts'
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'filters' do
|
78
|
+
describe 'string' do
|
79
|
+
it 'searches by title' do
|
80
|
+
fill_in 'Title', with: 'Brown'
|
81
|
+
click_on 'Filter'
|
82
|
+
|
83
|
+
within '#index_table_posts' do
|
84
|
+
page.should have_content('Quick Brown Fox')
|
85
|
+
end
|
86
|
+
|
87
|
+
fill_in 'Title', with: 'dog'
|
88
|
+
click_on 'Filter'
|
89
|
+
page.should_not have_content('Quick Brown Fox')
|
90
|
+
|
91
|
+
fill_in 'Title', with: ''
|
92
|
+
click_on 'Filter'
|
93
|
+
|
94
|
+
page.should have_content('Displaying 1 Post')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'date_range' do
|
99
|
+
it 'searches by created_at range' do
|
100
|
+
fill_in 'q[created_at_gte]', with: 1.day.ago.to_datetime.strftime("%Y-%m-%d")
|
101
|
+
fill_in 'q[created_at_lte]', with: 2.days.from_now.to_datetime.strftime("%Y-%m-%d")
|
102
|
+
click_on 'Filter'
|
103
|
+
|
104
|
+
within '#index_table_posts' do
|
105
|
+
page.should have_content('Quick Brown Fox')
|
106
|
+
end
|
107
|
+
|
108
|
+
fill_in 'q[created_at_gte]', with: 1.day.from_now.to_datetime.strftime("%Y-%m-%d")
|
109
|
+
click_on 'Filter'
|
110
|
+
page.should_not have_content('Quick Brown Fox')
|
111
|
+
|
112
|
+
fill_in 'q[created_at_gte]', with: ''
|
113
|
+
fill_in 'q[created_at_lte]', with: ''
|
114
|
+
click_on 'Filter'
|
115
|
+
|
116
|
+
page.should have_content('Displaying 1 Post')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'numeric' do
|
121
|
+
it 'searches by created_at range', js: true do
|
122
|
+
within '.filter_numeric' do
|
123
|
+
find(:select).find('option[value=view_count_equals]').select_option
|
124
|
+
end
|
125
|
+
fill_in 'View count', with: '5'
|
126
|
+
click_on 'Filter'
|
127
|
+
|
128
|
+
within '#index_table_posts' do
|
129
|
+
page.should have_content('Quick Brown Fox')
|
130
|
+
end
|
131
|
+
|
132
|
+
fill_in 'View count', with: '6'
|
133
|
+
click_on 'Filter'
|
134
|
+
page.should_not have_content('Quick Brown Fox')
|
135
|
+
|
136
|
+
within '.filter_numeric' do
|
137
|
+
find(:select).find('option[value=view_count_less_than]').select_option
|
138
|
+
end
|
139
|
+
click_on 'Filter'
|
140
|
+
|
141
|
+
within '#index_table_posts' do
|
142
|
+
page.should have_content('Quick Brown Fox')
|
143
|
+
end
|
144
|
+
|
145
|
+
within '.filter_numeric' do
|
146
|
+
find(:select).find('option[value=view_count_greater_than]').select_option
|
147
|
+
end
|
148
|
+
click_on 'Filter'
|
149
|
+
page.should_not have_content('Quick Brown Fox')
|
52
150
|
|
53
|
-
|
54
|
-
|
55
|
-
|
151
|
+
fill_in 'View count', with: '4'
|
152
|
+
click_on 'Filter'
|
153
|
+
|
154
|
+
within '#index_table_posts' do
|
155
|
+
page.should have_content('Quick Brown Fox')
|
156
|
+
end
|
157
|
+
|
158
|
+
fill_in 'View count', with: ''
|
159
|
+
click_on 'Filter'
|
160
|
+
|
161
|
+
page.should have_content('Displaying 1 Post')
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'select' do
|
167
|
+
it 'selects by admin_user' do
|
168
|
+
select email, from: 'Admin user'
|
169
|
+
click_on 'Filter'
|
170
|
+
|
171
|
+
within '#index_table_posts' do
|
172
|
+
page.should have_content('Quick Brown Fox')
|
173
|
+
end
|
174
|
+
|
175
|
+
select other_email, from: 'Admin user'
|
176
|
+
click_on 'Filter'
|
177
|
+
page.should_not have_content('Quick Brown Fox')
|
178
|
+
|
179
|
+
select 'Any', from: 'Admin user'
|
180
|
+
click_on 'Filter'
|
181
|
+
|
182
|
+
page.should have_content('Displaying 1 Post')
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe 'check_boxes' do
|
187
|
+
it 'checks by other_user' do
|
188
|
+
check email
|
189
|
+
click_on 'Filter'
|
190
|
+
page.should_not have_content('Quick Brown Fox')
|
191
|
+
|
192
|
+
check other_email
|
193
|
+
click_on 'Filter'
|
194
|
+
|
195
|
+
within '#index_table_posts' do
|
196
|
+
page.should have_content('Quick Brown Fox')
|
197
|
+
end
|
198
|
+
|
199
|
+
uncheck email
|
200
|
+
uncheck other_email
|
201
|
+
click_on 'Filter'
|
202
|
+
|
203
|
+
page.should have_content('Displaying 1 Post')
|
204
|
+
end
|
205
|
+
end
|
56
206
|
end
|
57
207
|
|
58
|
-
|
208
|
+
context 'with 100 posts' do
|
209
|
+
let(:per_page) { 30 }
|
210
|
+
let(:posts_size) { 100 }
|
211
|
+
|
212
|
+
before do
|
213
|
+
posts_size.times { |n|
|
214
|
+
Post.create!(title: "Quick Brown Fox #{n}", body: 'The quick brown fox jumps over the lazy dog.', view_count: 5, admin_user: admin_user, other_user: other_user)
|
215
|
+
}
|
216
|
+
|
217
|
+
click_on 'Posts'
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "paginator" do
|
221
|
+
it "must have paginator with 4 pages" do
|
222
|
+
page.should have_css('.pagination > .page.current')
|
223
|
+
page.all(:css, '.pagination > .page').size.should == 4
|
224
|
+
end
|
225
|
+
|
226
|
+
it "must show each page correctly" do
|
227
|
+
# temprorary go to page 2
|
228
|
+
page.find('.pagination > .page > a', text: '2').click
|
229
|
+
|
230
|
+
(1..4).each do |page_number|
|
231
|
+
page.find('.pagination > .page > a', text: page_number).click
|
232
|
+
page.find('.pagination_information').should have_content('Displaying Posts')
|
233
|
+
|
234
|
+
offset = (page_number - 1) * per_page
|
235
|
+
collection_size = [per_page, posts_size - (page_number - 1) * per_page].min
|
236
|
+
|
237
|
+
display_total_text = I18n.t 'active_admin.pagination.multiple',
|
238
|
+
model: 'Posts', total: posts_size,
|
239
|
+
from: offset + 1, to: offset + collection_size
|
240
|
+
display_total_text = Nokogiri::HTML(display_total_text).text.gsub(' ', ' ')
|
241
|
+
pagination_information = page.find('.pagination_information').text
|
242
|
+
pagination_information.should include(display_total_text)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end # context 'with 100 posts'
|
247
|
+
|
59
248
|
end
|
249
|
+
|
60
250
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
ENV['RAILS_ENV'] ||= 'test'
|
3
3
|
require 'rubygems'
|
4
4
|
require 'bundler'
|
5
|
+
|
6
|
+
if %w(true 1).include?(ENV['COVERAGE'])
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter '/test_app/'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
5
13
|
Bundler.require
|
6
14
|
|
7
15
|
require File.expand_path("../../test_app/config/environment", __FILE__)
|
@@ -10,6 +18,7 @@ require 'rspec/autorun'
|
|
10
18
|
|
11
19
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
12
20
|
# in spec/support/ and its subdirectories.
|
21
|
+
Dir[File.join(File.expand_path("../../", __FILE__), "spec/support/**/*.rb")].each {|f| require f}
|
13
22
|
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
14
23
|
|
15
24
|
RSpec.configure do |config|
|
data/spec/support/capybara.rb
CHANGED
data/test_app/app/admin/posts.rb
CHANGED
data/test_app/app/models/post.rb
CHANGED
@@ -6,6 +6,8 @@ Devise.setup do |config|
|
|
6
6
|
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
7
7
|
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
|
8
8
|
|
9
|
+
config.secret_key = '8c57910ca9a61008a2566fc337a67ddc043b91d64e0420ca8dd691e80cf362bc8a480ecb1465bd4ae958e715d354264a97934c058c3e14f5d552012ff5755122'
|
10
|
+
|
9
11
|
# Configure the class responsible to send e-mails.
|
10
12
|
# config.mailer = "Devise::Mailer"
|
11
13
|
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin-mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>'
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - '>'
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '3.0'
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: activeadmin
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,39 +45,53 @@ dependencies:
|
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: '0.6'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: jquery-rails
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - <
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
53
|
+
version: '3.0'
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- -
|
58
|
+
- - <
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
60
|
+
version: '3.0'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: sass-rails
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.1'
|
62
65
|
- - '>='
|
63
66
|
- !ruby/object:Gem::Version
|
64
67
|
version: 3.1.4
|
68
|
+
- - <
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '5.0'
|
65
71
|
type: :runtime
|
66
72
|
prerelease: false
|
67
73
|
version_requirements: !ruby/object:Gem::Requirement
|
68
74
|
requirements:
|
69
|
-
- - ~>
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '3.1'
|
72
75
|
- - '>='
|
73
76
|
- !ruby/object:Gem::Version
|
74
77
|
version: 3.1.4
|
78
|
+
- - <
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '5.0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: meta_search
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.1.3
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.1.3
|
75
95
|
- !ruby/object:Gem::Dependency
|
76
96
|
name: rspec-rails
|
77
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,6 +133,7 @@ files:
|
|
113
133
|
- lib/active_admin/mongoid/resource.rb
|
114
134
|
- lib/active_admin/mongoid/version.rb
|
115
135
|
- lib/activeadmin-mongoid.rb
|
136
|
+
- lib/meta_search/searches/mongoid.rb
|
116
137
|
- lib/tasks/activeadmin-mongoid_tasks.rake
|
117
138
|
- spec/features/smoke_spec.rb
|
118
139
|
- spec/spec_helper.rb
|
@@ -204,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
225
|
version: '0'
|
205
226
|
requirements: []
|
206
227
|
rubyforge_project:
|
207
|
-
rubygems_version: 2.
|
228
|
+
rubygems_version: 2.1.2
|
208
229
|
signing_key:
|
209
230
|
specification_version: 4
|
210
231
|
summary: ActiveAdmin hacks to support Mongoid
|