Skip to content

Commit ad89eb0

Browse files
Jaymes Waters and Matt Gaugermathias
authored andcommitted
Use DatabaseCleaner properly with MongoMapper
- For both Cucumber and RSpec
1 parent df8c666 commit ad89eb0

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Given /^that someone has provided "([^"]*)" as an answer for my question$/ do |solution|
2-
other_user = Fabricate(:user)
2+
other_user = Fabricate(:user)
33
other_user.save!
44
@question.answers.build(:description => solution, :user => other_user).save!
55
end

features/support/env.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,11 @@
3131

3232
# Remove/comment out the lines below if your app doesn't have a database.
3333
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
34-
DatabaseCleaner.strategy = :truncation
34+
DatabaseCleaner.orm = "mongo_mapper"
35+
DatabaseCleaner[:mongo_mapper].strategy = :truncation
3536

3637
Before do
37-
MongoMapper.database.collections.each do |collection|
38-
unless collection.name.match(/^system\./)
39-
collection.remove
40-
end
41-
end
38+
DatabaseCleaner[:mongo_mapper].clean
4239
end
4340

4441
# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.

spec/spec_helper.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ENV["RAILS_ENV"] ||= 'test'
2+
require File.expand_path("../../config/environment", __FILE__)
3+
require 'rspec/rails'
4+
require 'database_cleaner'
5+
6+
# Requires supporting ruby files with custom matchers and macros, etc,
7+
# in spec/support/ and its subdirectories.
8+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
9+
10+
RSpec.configure do |config|
11+
# == Mock Framework
12+
#
13+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14+
#
15+
# config.mock_with :mocha
16+
# config.mock_with :flexmock
17+
# config.mock_with :rr
18+
config.mock_with :rspec
19+
20+
DatabaseCleaner.orm = "mongo_mapper"
21+
DatabaseCleaner[:mongo_mapper].strategy = :truncation
22+
23+
config.before(:each) do
24+
DatabaseCleaner[:mongo_mapper].clean
25+
end
26+
end

0 commit comments

Comments
 (0)