Skip to content
Browse files

Keep up with Mongoid master's change

  • Loading branch information...
1 parent 27a0f52 commit f948d6c5bd44155a623036805bace01dcf7b3209 @mshibuya mshibuya committed
View
1 Gemfile
@@ -38,7 +38,6 @@ group :mongoid do
gem 'mongoid-paperclip', :require => 'mongoid_paperclip', :git => 'git://github.com/mshibuya/mongoid-paperclip.git', :branch => 'fix-stop-patching-logger'
# For now, carrierwave-mongoid's mongoid dependency is restricted to '~> 2.1'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid', :git => 'git://github.com/tanordheim/carrierwave-mongoid.git', :branch => 'mongoid_3_0'
- gem 'database_cleaner', :git => 'git://github.com/potatosalad/database_cleaner.git'
else
gem 'bson', '1.6.2'
gem 'bson_ext', :platforms => [:ruby, :mswin, :mingw]
View
7 lib/rails_admin/adapters/mongoid.rb
@@ -7,6 +7,7 @@ module Adapters
module Mongoid
STRING_TYPE_COLUMN_NAMES = [:name, :title, :subject]
DISABLED_COLUMN_TYPES = ['Range']
+ ObjectId = (::Mongoid::VERSION >= '3' ? ::Moped::BSON::ObjectId : ::BSON::ObjectId)
def new(params = {})
AbstractObject.new(model.new)
@@ -141,6 +142,10 @@ def embedded?
@embedded ||= !!model.associations.values.find{|a| a.macro.to_sym == :embedded_in }
end
+ def object_id_from_string(str)
+ ObjectId.from_string(str)
+ end
+
private
def query_conditions(query, fields = config.list.fields.select(&:queryable?))
@@ -267,7 +272,7 @@ def build_statement(column, type, value, operator)
return if value.blank?
{ column => { "$in" => Array.wrap(value) } }
when :belongs_to_association, :bson_object_id
- object_id = (BSON::ObjectId.from_string(value) rescue nil)
+ object_id = (object_id_from_string(value) rescue nil)
{ column => object_id } if object_id
end
end
View
2 lib/rails_admin/config/fields/types/bson_object_id.rb
@@ -28,7 +28,7 @@ class BsonObjectId < RailsAdmin::Config::Fields::Types::String
def parse_input(params)
begin
- params[name] = (params[name].blank? ? nil : BSON::ObjectId.from_string(params[name])) if params[name].is_a?(::String)
+ params[name] = (params[name].blank? ? nil : abstract_model.object_id_from_string(params[name])) if params[name].is_a?(::String)
rescue => e
unless ['BSON::InvalidObjectId', 'Moped::Errors::InvalidObjectId'].include? e.class.to_s
raise e
View
2 rails_admin.gemspec
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'cancan'
gem.add_development_dependency 'capybara'
gem.add_development_dependency 'carrierwave'
- gem.add_development_dependency 'database_cleaner'
+ gem.add_development_dependency 'database_cleaner', '~> 0.8'
gem.add_development_dependency 'devise'
gem.add_development_dependency 'dragonfly'
gem.add_development_dependency 'factory_girl', '~> 2.6'
View
2 spec/dummy_app/app/mongoid/field_test.rb
@@ -10,7 +10,7 @@ class FieldTest
field :array_field, :type => Array
field :big_decimal_field, :type => BigDecimal
field :boolean_field, :type => Boolean
- field :bson_object_id_field, :type => BSON::ObjectId
+ field :bson_object_id_field, :type => RailsAdmin::Adapters::Mongoid::ObjectId
field :date_field, :type => Date
field :datetime_field, :type => DateTime
field :default_field

0 comments on commit f948d6c

Please sign in to comment.
Something went wrong with that request. Please try again.