Skip to content

Make activeadmin-mongoid play nice with ActiveRecord Resources #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ActiveAdmin::Mongoid

[![Build Status](https://secure.travis-ci.org/elia/activeadmin-mongoid.png?branch=master)](http://travis-ci.org/elia/activeadmin-mongoid)
[![Gem Version](https://badge.fury.io/rb/activeadmin-mongoid.png)](http://badge.fury.io/rb/activeadmin-mongoid)


ActiveAdmin hacks to support Mongoid.
Some ActiveAdmin features are disabled:

Expand Down
4 changes: 2 additions & 2 deletions activeadmin-mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Gem::Specification.new do |gem|

gem.add_runtime_dependency 'mongoid', ['> 3.0', '< 5.0']
gem.add_runtime_dependency 'activeadmin', '~> 0.6'
gem.add_runtime_dependency 'jquery-rails', '>= 3.0.0'
gem.add_runtime_dependency 'jquery-ui-rails', '>= 4.0.0'
gem.add_runtime_dependency 'jquery-rails', '< 3.0' # in which they remove jquery-ui
gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4', '< 5.0']
gem.add_runtime_dependency 'meta_search', '~> 1.1.3'

gem.add_development_dependency 'rspec-rails', '~> 2.7'
end
2 changes: 1 addition & 1 deletion lib/active_admin/mongoid/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def type
when Moped::BSON::ObjectId, Object
:string
else
p _super.name.underscore.to_sym
_super.name.underscore.to_sym
end
end
end
Expand Down
9 changes: 8 additions & 1 deletion lib/active_admin/mongoid/helpers/collection.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
module ActiveAdmin
module Helpers
module Collection

alias original_collection_size collection_size
original_collection_size = instance_method(:collection_size)
def collection_size(collection=collection)
collection.count(true)
if(not collection.empty? and collection.first.class.included_modules.include?(Mongoid::Document))
collection.count(true)
else
original_collection_size(collection)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/mongoid/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveAdmin
module Mongoid
VERSION = '0.2.0'
VERSION = '0.3.0'
end
end
25 changes: 12 additions & 13 deletions spec/features/smoke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@
describe 'filters' do
describe 'string' do
it 'searches by title' do
fill_in 'Search Title', with: 'Brown'
fill_in 'Title', with: 'Brown'
click_on 'Filter'

within '#index_table_posts' do
page.should have_content('Quick Brown Fox')
end

fill_in 'Search Title', with: 'dog'
fill_in 'Title', with: 'dog'
click_on 'Filter'
page.should_not have_content('Quick Brown Fox')

fill_in 'Search Title', with: ''
fill_in 'Title', with: ''
click_on 'Filter'

page.should have_content('Displaying 1 Post')
Expand Down Expand Up @@ -120,7 +120,7 @@
describe 'numeric' do
it 'searches by created_at range', js: true do
within '.filter_numeric' do
find(:select).find('option[value=view_count_eq]').select_option
find(:select).find('option[value=view_count_equals]').select_option
end
fill_in 'View count', with: '5'
click_on 'Filter'
Expand All @@ -134,7 +134,7 @@
page.should_not have_content('Quick Brown Fox')

within '.filter_numeric' do
find(:select).find('option[value=view_count_lt]').select_option
find(:select).find('option[value=view_count_less_than]').select_option
end
click_on 'Filter'

Expand All @@ -143,7 +143,7 @@
end

within '.filter_numeric' do
find(:select).find('option[value=view_count_gt]').select_option
find(:select).find('option[value=view_count_greater_than]').select_option
end
click_on 'Filter'
page.should_not have_content('Quick Brown Fox')
Expand Down Expand Up @@ -227,20 +227,19 @@
# temprorary go to page 2
page.find('.pagination > .page > a', text: '2').click

nbsp = Nokogiri::HTML("&nbsp;").text

(1..4).each do |page_number|
page.find('.pagination > .page > a', text: page_number).click
page.find('.pagination_information').should have_content('Displaying Posts')

offset = (page_number - 1) * per_page
collection_size = [per_page, posts_size - (page_number - 1) * per_page].min

display_total_text = I18n.t 'active_admin.pagination.multiple', :model => 'Posts', :total => posts_size,
:from => offset + 1, :to => offset + collection_size

pagination_information = page.find('.pagination_information').native.to_s.gsub(nbsp,' ')
pagination_information.should include(display_total_text.gsub('&nbsp;', ' '))
display_total_text = I18n.t 'active_admin.pagination.multiple',
model: 'Posts', total: posts_size,
from: offset + 1, to: offset + collection_size
display_total_text = Nokogiri::HTML(display_total_text).text.gsub(' ', ' ')
pagination_information = page.find('.pagination_information').text
pagination_information.should include(display_total_text)
end
end
end
Expand Down