Skip to content

Commit

Permalink
All green against latest rev on AA, fix pagination counts, fix dateti…
Browse files Browse the repository at this point in the history
…me filters
  • Loading branch information
boie0025 committed Mar 17, 2017
1 parent 7097652 commit b7e1cc9
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem 'activeadmin', github: 'activeadmin'
# Test app stuff

gem 'rails', '~> 4.0'
gem 'kaminari', '= 0.15.0'

gem 'devise'

Expand All @@ -31,6 +32,7 @@ gem 'jquery-ui-rails'
gem 'jslint'

group :test do
gem 'pry-rails'
gem 'capybara'
gem 'poltergeist'
gem 'launchy'
Expand Down
2 changes: 1 addition & 1 deletion activeadmin-mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
gem.license = 'MIT'

gem.add_runtime_dependency 'mongoid', ['>= 5.0']
gem.add_runtime_dependency 'activeadmin', ['>= 1.0.0.pre', '< 2']
gem.add_runtime_dependency 'activeadmin', ['>= 1.0.0.pre5', '< 2']
gem.add_runtime_dependency 'jquery-rails'
gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4', '< 5.0']
# gem.add_runtime_dependency 'meta_search', '~> 1.1.3'
Expand Down
11 changes: 9 additions & 2 deletions lib/active_admin/mongoid/filter_form_builder.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
class ActiveAdmin::FilterFormBuilder
class ActiveAdmin::Filters::FormBuilder

def filter(method, options = {})
if method.present? && options[:as] ||= default_input_type(method)
template.concat input(method, options)
end
end

def default_input_type(method, options = {})
if column = column_for(method)
case column.type.name.downcase.to_sym
when :date, :datetime, :time; :date_range
when :string, :text, :objectl; :string
when :string, :text, :object; :string
when :float, :decimal; :numeric
when :integer
return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/mongoid/helpers/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Collection
def collection_size(collection = nil)
collection ||= self.collection
if collection.is_a?(::Mongoid::Criteria)
collection.count
collection.entries.count
else
original_collection_size(collection)
end
Expand Down
10 changes: 5 additions & 5 deletions spec/features/smoke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@

describe 'date_range' do
it 'searches by created_at range' do
fill_in 'q[created_at_gteq]', with: 1.day.ago.to_datetime.strftime("%Y-%m-%d")
fill_in 'q[created_at_lteq]', with: 2.days.from_now.to_datetime.strftime("%Y-%m-%d")
fill_in 'q[created_at_gteq_datetime]', with: 1.day.ago.to_datetime.strftime("%Y-%m-%d")
fill_in 'q[created_at_lteq_datetime]', with: 2.days.from_now.to_datetime.strftime("%Y-%m-%d")
click_on 'Filter'

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

fill_in 'q[created_at_gteq]', with: 1.day.from_now.to_datetime.strftime("%Y-%m-%d")
fill_in 'q[created_at_gteq_datetime]', with: 1.day.from_now.to_datetime.strftime("%Y-%m-%d")
click_on 'Filter'
page.should_not have_content('Quick Brown Fox')

fill_in 'q[created_at_gteq]', with: ''
fill_in 'q[created_at_lteq]', with: ''
fill_in 'q[created_at_gteq_datetime]', with: ''
fill_in 'q[created_at_lteq_datetime]', with: ''
click_on 'Filter'

page.should have_content('Displaying 1 Post')
Expand Down
1 change: 1 addition & 0 deletions test_app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem 'pry'
gem 'devise'

gem 'mongoid', '~> 4.0'
gem 'kaminari', '= 0.15.0'

# Gems used only for assets and not required
# in production environments by default.
Expand Down
2 changes: 0 additions & 2 deletions test_app/app/assets/javascripts/active_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
//# require jquery.ui.datepicker

//= require jquery-ui

//= require active_admin/application
7 changes: 4 additions & 3 deletions test_app/config/initializers/active_admin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Rails.application.config.assets.precompile += ['active_admin.js']
ActiveAdmin.setup do |config|

config.load_paths = ["#{Rails.root}/app/admin"]
Expand Down Expand Up @@ -156,9 +157,9 @@
# == Menu System
#
# You can add a navigation menu to be used in your application, or configure a provided menu
#
#
# To change the default utility navigation to show a link to your website & a logout btn
#
#
# config.namespace :admin do |admin|
# admin.build_menu :utility_navigation do |menu|
# menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank }
Expand Down Expand Up @@ -202,7 +203,7 @@

# == Filters
#
# By default the index screen includes a “Filters” sidebar on the right
# By default the index screen includes a “Filters” sidebar on the right
# hand side with a filter for each attribute of the registered model.
# You can enable or disable them for all resources here.
#
Expand Down
7 changes: 7 additions & 0 deletions test_app/config/mongoid.5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test:
clients:
default:
database: activeadmin_mongoid_test
hosts:
- localhost:27017
#scope_overwrite_exception: true

0 comments on commit b7e1cc9

Please sign in to comment.