Skip to content
Browse files

Keep up with the recent changes of Mongoid master. Fixes #1136

  • Loading branch information...
1 parent a78f183 commit 2a3b6a96d6e09e5748aea3061110a9071852ffbb @mshibuya mshibuya committed May 17, 2012
View
4 Gemfile
@@ -36,13 +36,15 @@ group :mongoid do
case ENV['CI_ORM_VERSION']
when 'head'
gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
+ 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 'mongoid'
+ gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
end
- gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
end
group :debug do
View
2 app/views/rails_admin/main/index.html.haml
@@ -132,7 +132,7 @@
%td.last.links
%ul.inline= menu_for :member, @abstract_model, object, true
- if @objects.respond_to?(:total_count)
- - total_count = @objects.total_count
+ - total_count = @objects.total_count.to_i
= paginate(@objects, :theme => 'twitter-bootstrap', :remote => true)
= link_to(t("admin.misc.show_all"), index_path(params.merge(:all => true)), :class => "show-all btn clearfix pjax") unless total_count > 100 || total_count <= @objects.to_a.size
.clearfix.total-count= "#{total_count} #{@model_config.label_plural.downcase}"
View
14 lib/rails_admin/adapters/mongoid.rb
@@ -15,8 +15,13 @@ def new(params = {})
def get(id)
begin
AbstractObject.new(model.find(id))
- rescue BSON::InvalidObjectId, ::Mongoid::Errors::DocumentNotFound
- nil
+ rescue => e
+ if ['BSON::InvalidObjectId', 'Mongoid::Errors::DocumentNotFound',
+ 'Mongoid::Errors::InvalidFind', 'Moped::Errors::InvalidObjectId'].include? e.class.to_s
+ nil
+ else
+ raise e
+ end
end
end
@@ -82,6 +87,7 @@ def properties
"BigDecimal" => { :type => :decimal },
"Boolean" => { :type => :boolean },
"BSON::ObjectId" => { :type => :bson_object_id, :serial? => (name == primary_key) },
+ "Moped::BSON::ObjectId" => { :type => :bson_object_id, :serial? => (name == primary_key) },
"Date" => { :type => :date },
"DateTime" => { :type => :datetime },
"Float" => { :type => :float },
@@ -118,7 +124,7 @@ def properties
end
def table_name
- model.collection.name
+ model.collection.name.to_s
end
def serialized_attributes
@@ -261,7 +267,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(value) rescue nil)
+ object_id = (BSON::ObjectId.from_string(value) rescue nil)
{ column => object_id } if object_id
end
end
View
7 lib/rails_admin/config/fields/types/bson_object_id.rb
@@ -28,8 +28,11 @@ class BsonObjectId < RailsAdmin::Config::Fields::Types::String
def parse_input(params)
begin
- params[name] = (params[name].blank? ? nil : BSON::ObjectId(params[name])) if params[name].is_a?(::String)
- rescue BSON::InvalidObjectId
+ params[name] = (params[name].blank? ? nil : BSON::ObjectId.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
+ end
end
end
end
View
2 spec/controllers/main_controller_spec.rb
@@ -67,7 +67,7 @@
end
it "scopes associated collection records according to bindings" do
- @team.revenue = 3
+ @team.revenue = BigDecimal.new('3')
@team.save
@players = 5.times.map do
View
2 spec/dummy_app/.gitignore
@@ -13,3 +13,5 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
+
+/public/system
View
2 spec/dummy_app/Gemfile
@@ -44,7 +44,7 @@ group :mongoid do
gem 'mongoid'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
end
- gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
+ gem 'mongoid-paperclip', :require => 'mongoid_paperclip', :git => 'git://github.com/mshibuya/mongoid-paperclip.git', :branch => 'fix-stop-patching-logger'
gem 'paperclip', '~> 2.4'
gem 'dragonfly'
end
View
2 spec/dummy_app/app/mongoid/team.rb
@@ -20,7 +20,7 @@ class Team
attr_accessible :name, :division_id, :logo_url, :manager, :ballpark, :mascot, :founded, :wins, :losses, :win_percentage, :revenue, :color, :custom_field, :fan_ids, :player_ids, :comment_ids
- has_many :players, :inverse_of => :team, :order => :_id
+ has_many :players, :inverse_of => :team, :order => :_id.asc
has_and_belongs_to_many :fans
has_many :comments, :as => :commentable
View
11 spec/dummy_app/config/initializers/devise.rb
@@ -9,9 +9,6 @@
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
- # Automatically apply schema changes in tableless databases
- config.apply_schema = false
-
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
@@ -95,7 +92,7 @@
# the user cannot access the website without confirming his account.
# config.allow_unconfirmed_access_for = 2.days
- # If true, requires any email changes to be confirmed (exctly the same way as
+ # If true, requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed new email is stored in
# unconfirmed email column, and copied to email column on successful confirmation.
@@ -111,13 +108,9 @@
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false
- # If true, uses the password salt as remember token. This should be turned
- # to false if you are not using database authenticatable.
- config.use_salt_as_remember_token = true
-
# Options to be passed to the created cookie. For instance, you can set
# :secure => true in order to force SSL only cookies.
- # config.cookie_options = {}
+ # config.rememberable_options = {}
# ==> Configuration for :validatable
# Range for password length. Default is 6..128.
View
5 spec/dummy_app/config/initializers/dragonfly.rb
@@ -3,11 +3,8 @@
app = Dragonfly[:images]
- # Configure to use ImageMagick, Rails defaults, and the Mongo data store
+ # Configure to use ImageMagick, Rails defaults
app.configure_with(:imagemagick)
- app.configure_with(:rails) do |c|
- c.datastore = Dragonfly::DataStorage::MongoDataStore.new :db => Mongoid.database
- end
# Allow all mongoid models to use the macro 'image_accessor'
app.define_macro_on_include(Mongoid::Document, :image_accessor)
View
11 spec/dummy_app/config/mongoid.yml
@@ -5,7 +5,18 @@ defaults: &defaults
development:
<<: *defaults
database: dummy_app_development
+ sessions:
+ default:
+ database: dummy_app_development
+ hosts:
+ - localhost:27017
+
test:
<<: *defaults
database: dummy_app_test
+ sessions:
+ default:
+ database: dummy_app_test
+ hosts:
+ - localhost:27017
View
2 spec/orm/mongoid.rb
@@ -1,5 +1,7 @@
require 'rails_admin/adapters/mongoid'
+Paperclip.logger = Logger.new(nil)
+
class Tableless
include Mongoid::Document

0 comments on commit 2a3b6a9

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