Integration
Carrierwave
Support for Mongoid exists in
Carrierwave
for doing file attachments, and you may specify them to be files or
S3 currently. If no :mount_on option is provided to the uploader,
the filename will get stored in a field with "_filename" appended
to the name of the uploader.
class User
include Mongoid::Document
mount_uploader :avatar, AvatarUploader #field is avatar_filename
end
Cucumber
Since MongoDB does not support transactions, you will want to add a
hook to Cucumber
that ensures the database is clean before each feature.
In features/support/hooks.rb:
Mongoid.master.collections.select do |collection|
collection.name !~ /system/
end.each(&:drop)
If you are using the database_cleaner gem,
instead just create a file called features/support/database_cleaner.rb with the content:
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid"
Before { DatabaseCleaner.clean }
RSpec
Similar to Cucumber, Rspec's
use_transactional_fixtures option will have no affect on Mongoid,
so you can clean up your specs after the suite.
In spec/spec_helper.rb:
Rspec.configure do |config|
config.after :suite do
Mongoid.master.collections.select do |collection|
collection.name !~ /system/
end.each(&:drop)
end
end
You may also do this after :each as well if you have a lot of
integration spec, but note it will be slower.
If you are using the database_cleaner gem,
you can instead add these lines to your RSpec configure block spec/spec_helper.rb:
Rspec.configure do |config|
require 'database_cleaner'
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid"
end
config.before(:each) do
DatabaseCleaner.clean
end
end
Devise
In order to get Devise
set up to work with Mongoid, all you will need to do is remove the
ActiveRecord require and replace it with the Mongoid one.
In config/initializers/devise.rb:
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default),
# :mongoid (bson_ext recommended) and :data_mapper (experimental).
require "devise/orm/mongoid"
Passenger
The MongoDB wiki will alert you of an initializer that you need to include
if you are using Passenger
with smart spawning enabled. (Conservative spawning is the default.)
In the case of Mongoid you will NOT need to do this as Mongoid detects
if Passenger is running in this mode and will reconnect for you when
a worker is forked.
Unicorn
No extra configuration is needed for Mongoid if you are using
Unicorn
with preload_app set to true. Mongoid will detect if
Unicorn has forked a child worker and will reconnect to the database
on the next query.