Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 2a3b6a96d6e09e5748aea3061110a9071852ffbb 1 parent a78f183
Mitsuhiro Shibuya mshibuya authored
4 Gemfile
@@ -36,13 +36,15 @@ group :mongoid do
36 36 case ENV['CI_ORM_VERSION']
37 37 when 'head'
38 38 gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
  39 + gem 'mongoid-paperclip', :require => 'mongoid_paperclip', :git => 'git://github.com/mshibuya/mongoid-paperclip.git', :branch => 'fix-stop-patching-logger'
39 40 # For now, carrierwave-mongoid's mongoid dependency is restricted to '~> 2.1'
40 41 gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid', :git => 'git://github.com/tanordheim/carrierwave-mongoid.git', :branch => 'mongoid_3_0'
  42 + gem 'database_cleaner', :git => 'git://github.com/potatosalad/database_cleaner.git'
41 43 else
42 44 gem 'mongoid'
  45 + gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
43 46 gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
44 47 end
45   - gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
46 48 end
47 49
48 50 group :debug do
2  app/views/rails_admin/main/index.html.haml
@@ -132,7 +132,7 @@
132 132 %td.last.links
133 133 %ul.inline= menu_for :member, @abstract_model, object, true
134 134 - if @objects.respond_to?(:total_count)
135   - - total_count = @objects.total_count
  135 + - total_count = @objects.total_count.to_i
136 136 = paginate(@objects, :theme => 'twitter-bootstrap', :remote => true)
137 137 = 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
138 138 .clearfix.total-count= "#{total_count} #{@model_config.label_plural.downcase}"
14 lib/rails_admin/adapters/mongoid.rb
@@ -15,8 +15,13 @@ def new(params = {})
15 15 def get(id)
16 16 begin
17 17 AbstractObject.new(model.find(id))
18   - rescue BSON::InvalidObjectId, ::Mongoid::Errors::DocumentNotFound
19   - nil
  18 + rescue => e
  19 + if ['BSON::InvalidObjectId', 'Mongoid::Errors::DocumentNotFound',
  20 + 'Mongoid::Errors::InvalidFind', 'Moped::Errors::InvalidObjectId'].include? e.class.to_s
  21 + nil
  22 + else
  23 + raise e
  24 + end
20 25 end
21 26 end
22 27
@@ -82,6 +87,7 @@ def properties
82 87 "BigDecimal" => { :type => :decimal },
83 88 "Boolean" => { :type => :boolean },
84 89 "BSON::ObjectId" => { :type => :bson_object_id, :serial? => (name == primary_key) },
  90 + "Moped::BSON::ObjectId" => { :type => :bson_object_id, :serial? => (name == primary_key) },
85 91 "Date" => { :type => :date },
86 92 "DateTime" => { :type => :datetime },
87 93 "Float" => { :type => :float },
@@ -118,7 +124,7 @@ def properties
118 124 end
119 125
120 126 def table_name
121   - model.collection.name
  127 + model.collection.name.to_s
122 128 end
123 129
124 130 def serialized_attributes
@@ -261,7 +267,7 @@ def build_statement(column, type, value, operator)
261 267 return if value.blank?
262 268 { column => { "$in" => Array.wrap(value) } }
263 269 when :belongs_to_association, :bson_object_id
264   - object_id = (BSON::ObjectId(value) rescue nil)
  270 + object_id = (BSON::ObjectId.from_string(value) rescue nil)
265 271 { column => object_id } if object_id
266 272 end
267 273 end
7 lib/rails_admin/config/fields/types/bson_object_id.rb
@@ -28,8 +28,11 @@ class BsonObjectId < RailsAdmin::Config::Fields::Types::String
28 28
29 29 def parse_input(params)
30 30 begin
31   - params[name] = (params[name].blank? ? nil : BSON::ObjectId(params[name])) if params[name].is_a?(::String)
32   - rescue BSON::InvalidObjectId
  31 + params[name] = (params[name].blank? ? nil : BSON::ObjectId.from_string(params[name])) if params[name].is_a?(::String)
  32 + rescue => e
  33 + unless ['BSON::InvalidObjectId', 'Moped::Errors::InvalidObjectId'].include? e.class.to_s
  34 + raise e
  35 + end
33 36 end
34 37 end
35 38 end
2  spec/controllers/main_controller_spec.rb
@@ -67,7 +67,7 @@
67 67 end
68 68
69 69 it "scopes associated collection records according to bindings" do
70   - @team.revenue = 3
  70 + @team.revenue = BigDecimal.new('3')
71 71 @team.save
72 72
73 73 @players = 5.times.map do
2  spec/dummy_app/.gitignore
@@ -13,3 +13,5 @@
13 13 # Ignore all logfiles and tempfiles.
14 14 /log/*.log
15 15 /tmp
  16 +
  17 +/public/system
2  spec/dummy_app/Gemfile
@@ -44,7 +44,7 @@ group :mongoid do
44 44 gem 'mongoid'
45 45 gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
46 46 end
47   - gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
  47 + gem 'mongoid-paperclip', :require => 'mongoid_paperclip', :git => 'git://github.com/mshibuya/mongoid-paperclip.git', :branch => 'fix-stop-patching-logger'
48 48 gem 'paperclip', '~> 2.4'
49 49 gem 'dragonfly'
50 50 end
2  spec/dummy_app/app/mongoid/team.rb
@@ -20,7 +20,7 @@ class Team
20 20
21 21 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
22 22
23   - has_many :players, :inverse_of => :team, :order => :_id
  23 + has_many :players, :inverse_of => :team, :order => :_id.asc
24 24 has_and_belongs_to_many :fans
25 25 has_many :comments, :as => :commentable
26 26
11 spec/dummy_app/config/initializers/devise.rb
@@ -9,9 +9,6 @@
9 9 # Configure the class responsible to send e-mails.
10 10 # config.mailer = "Devise::Mailer"
11 11
12   - # Automatically apply schema changes in tableless databases
13   - config.apply_schema = false
14   -
15 12 # ==> ORM configuration
16 13 # Load and configure the ORM. Supports :active_record (default) and
17 14 # :mongoid (bson_ext recommended) by default. Other ORMs may be
@@ -95,7 +92,7 @@
95 92 # the user cannot access the website without confirming his account.
96 93 # config.allow_unconfirmed_access_for = 2.days
97 94
98   - # If true, requires any email changes to be confirmed (exctly the same way as
  95 + # If true, requires any email changes to be confirmed (exactly the same way as
99 96 # initial account confirmation) to be applied. Requires additional unconfirmed_email
100 97 # db field (see migrations). Until confirmed new email is stored in
101 98 # unconfirmed email column, and copied to email column on successful confirmation.
@@ -111,13 +108,9 @@
111 108 # If true, extends the user's remember period when remembered via cookie.
112 109 # config.extend_remember_period = false
113 110
114   - # If true, uses the password salt as remember token. This should be turned
115   - # to false if you are not using database authenticatable.
116   - config.use_salt_as_remember_token = true
117   -
118 111 # Options to be passed to the created cookie. For instance, you can set
119 112 # :secure => true in order to force SSL only cookies.
120   - # config.cookie_options = {}
  113 + # config.rememberable_options = {}
121 114
122 115 # ==> Configuration for :validatable
123 116 # Range for password length. Default is 6..128.
5 spec/dummy_app/config/initializers/dragonfly.rb
@@ -3,11 +3,8 @@
3 3
4 4 app = Dragonfly[:images]
5 5
6   - # Configure to use ImageMagick, Rails defaults, and the Mongo data store
  6 + # Configure to use ImageMagick, Rails defaults
7 7 app.configure_with(:imagemagick)
8   - app.configure_with(:rails) do |c|
9   - c.datastore = Dragonfly::DataStorage::MongoDataStore.new :db => Mongoid.database
10   - end
11 8
12 9 # Allow all mongoid models to use the macro 'image_accessor'
13 10 app.define_macro_on_include(Mongoid::Document, :image_accessor)
11 spec/dummy_app/config/mongoid.yml
@@ -5,7 +5,18 @@ defaults: &defaults
5 5 development:
6 6 <<: *defaults
7 7 database: dummy_app_development
  8 + sessions:
  9 + default:
  10 + database: dummy_app_development
  11 + hosts:
  12 + - localhost:27017
  13 +
8 14
9 15 test:
10 16 <<: *defaults
11 17 database: dummy_app_test
  18 + sessions:
  19 + default:
  20 + database: dummy_app_test
  21 + hosts:
  22 + - localhost:27017
2  spec/orm/mongoid.rb
... ... @@ -1,5 +1,7 @@
1 1 require 'rails_admin/adapters/mongoid'
2 2
  3 +Paperclip.logger = Logger.new(nil)
  4 +
3 5 class Tableless
4 6 include Mongoid::Document
5 7

0 comments on commit 2a3b6a9

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