Database Cleaning with Cucumber, Machinist 2, Rails 3, DatabaseCleaner, Mysql2 and Mongoid

Created at: 23.08.2010 21:33, source: Momoro Machine

This combo does not work out of the box right now. At a minimum, in order to use mysql 2, you’ll have to get this commit, which currently involves using the git source for db cleaner in your Gemfile.

You’ll also want to comment out the db cleaner stuff in env.rb and switch it to support/database_cleaner.rb and do it like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# DB Cleaner currently being used for AR
Mongoid.master.collections.select do |collection|
  collection.name !~ /system/
end.each(&:drop)

DatabaseCleaner.strategy = :truncation

Before do
  DatabaseCleaner.start
end

After do
  DatabaseCleaner.clean
end

There may be a better way to do this, but I’m not aware of it.

This solves issues like:

1
2
3
4
5
6
7

deadlock 0x1001c1258: sleep:J(0x1072ed8f0) (main) - /Users/foo/.rvm/gems/ree-1.8.7-
2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/blueprint.rb:33
INTERNAL ERROR!!! Thread( ): deadlock
        /Users/foo/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-
2.0.0.beta2/lib/machinist/active_record/blueprint.rb:33:in `value'

and

1
2
3
4

NoMethodError Exception: undefined method `truncate_table' for #
<ActiveRecord::ConnectionAdapters::Mysql2Adapter:>