mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
finish merge, all specs, all features pass
This commit is contained in:
parent
6250a1e7a7
commit
8dcbb697b1
15 changed files with 175 additions and 79 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,5 +4,6 @@ coverage
|
|||
pkg
|
||||
.bundle
|
||||
bundled_gems/
|
||||
vendor/
|
||||
examples/db/*.db
|
||||
examples/config/database.yml
|
||||
|
|
14
Gemfile
Normal file → Executable file
14
Gemfile
Normal file → Executable file
|
@ -1,20 +1,20 @@
|
|||
source "http://rubygems.org"
|
||||
group :development do
|
||||
gem "mysql"
|
||||
gem "json_pure", "1.2.0"
|
||||
gem "json_pure", "1.4.3"
|
||||
gem "rspec", "1.3.0"
|
||||
gem "cucumber"
|
||||
gem "cucumber", "0.8.1"
|
||||
|
||||
gem "activerecord"
|
||||
|
||||
gem "datamapper", "0.10.2"
|
||||
gem "data_objects"
|
||||
gem "do_sqlite3"
|
||||
gem "datamapper", "1.0.0"
|
||||
gem "dm-migrations", "1.0.0"
|
||||
gem "dm-sqlite-adapter", "1.0.0"
|
||||
|
||||
# mongo requirements
|
||||
gem "mongo", "1.0.2"
|
||||
gem "mongo", "1.0.1"
|
||||
gem "mongo_ext", "0.19.3"
|
||||
gem "bson", "1.0.2"
|
||||
gem "bson_ext", "1.0.1"
|
||||
|
||||
gem "mongoid", "1.9.0"
|
||||
#mongoid requires active support <= 2.3.5
|
||||
|
|
82
Gemfile.lock
82
Gemfile.lock
|
@ -11,11 +11,15 @@ dependencies:
|
|||
datamapper:
|
||||
group:
|
||||
- :development
|
||||
version: = 0.10.2
|
||||
version: = 1.0.0
|
||||
mongo:
|
||||
group:
|
||||
- :development
|
||||
version: = 1.0.2
|
||||
version: = 1.0.1
|
||||
bson_ext:
|
||||
group:
|
||||
- :development
|
||||
version: = 1.0.1
|
||||
ZenTest:
|
||||
group:
|
||||
- :development
|
||||
|
@ -36,10 +40,6 @@ dependencies:
|
|||
group:
|
||||
- :development
|
||||
version: ">= 0"
|
||||
data_objects:
|
||||
group:
|
||||
- :development
|
||||
version: ">= 0"
|
||||
rake:
|
||||
group:
|
||||
- :development
|
||||
|
@ -56,14 +56,14 @@ dependencies:
|
|||
group:
|
||||
- :development
|
||||
version: = 1.3.0
|
||||
bson:
|
||||
group:
|
||||
- :development
|
||||
version: = 1.0.2
|
||||
jeweler:
|
||||
group:
|
||||
- :development
|
||||
version: ">= 0"
|
||||
dm-sqlite-adapter:
|
||||
group:
|
||||
- :development
|
||||
version: = 1.0.0
|
||||
bundler:
|
||||
group:
|
||||
- :development
|
||||
|
@ -75,19 +75,19 @@ dependencies:
|
|||
cucumber:
|
||||
group:
|
||||
- :development
|
||||
version: ">= 0"
|
||||
version: = 0.8.1
|
||||
json_pure:
|
||||
group:
|
||||
- :development
|
||||
version: = 1.2.0
|
||||
version: = 1.4.3
|
||||
dm-migrations:
|
||||
group:
|
||||
- :development
|
||||
version: = 1.0.0
|
||||
activesupport:
|
||||
group:
|
||||
- :development
|
||||
version: <= 2.3.5
|
||||
do_sqlite3:
|
||||
group:
|
||||
- :development
|
||||
version: ">= 0"
|
||||
specs:
|
||||
- rake:
|
||||
version: 0.8.7
|
||||
|
@ -99,10 +99,10 @@ specs:
|
|||
version: 2.3.5
|
||||
- addressable:
|
||||
version: 2.1.2
|
||||
- bcrypt-ruby:
|
||||
version: 2.1.2
|
||||
- bson:
|
||||
version: 1.0.2
|
||||
version: 1.0.1
|
||||
- bson_ext:
|
||||
version: 1.0.1
|
||||
- builder:
|
||||
version: 2.1.2
|
||||
- bundler:
|
||||
|
@ -121,46 +121,52 @@ specs:
|
|||
version: 0.2.31
|
||||
- diff-lcs:
|
||||
version: 1.1.2
|
||||
- trollop:
|
||||
version: 1.16.2
|
||||
- gherkin:
|
||||
version: 2.0.1
|
||||
- json_pure:
|
||||
version: 1.2.0
|
||||
- polyglot:
|
||||
version: 0.3.1
|
||||
version: 1.4.3
|
||||
- term-ansicolor:
|
||||
version: 1.0.5
|
||||
- treetop:
|
||||
version: 1.4.8
|
||||
- cucumber:
|
||||
version: 0.6.4
|
||||
version: 0.8.1
|
||||
- data_objects:
|
||||
version: 0.10.2
|
||||
- extlib:
|
||||
version: 0.9.15
|
||||
- dm-core:
|
||||
version: 0.10.2
|
||||
version: 1.0.0
|
||||
- dm-aggregates:
|
||||
version: 0.10.2
|
||||
- dm-constraints:
|
||||
version: 0.10.2
|
||||
version: 1.0.0
|
||||
- dm-migrations:
|
||||
version: 0.10.2
|
||||
version: 1.0.0
|
||||
- dm-constraints:
|
||||
version: 1.0.0
|
||||
- fastercsv:
|
||||
version: 1.5.3
|
||||
- dm-serializer:
|
||||
version: 0.10.2
|
||||
version: 1.0.0
|
||||
- dm-timestamps:
|
||||
version: 0.10.2
|
||||
version: 1.0.0
|
||||
- dm-transactions:
|
||||
version: 1.0.0
|
||||
- stringex:
|
||||
version: 1.1.0
|
||||
- uuidtools:
|
||||
version: 2.1.1
|
||||
- dm-types:
|
||||
version: 0.10.2
|
||||
version: 1.0.0
|
||||
- dm-validations:
|
||||
version: 0.10.2
|
||||
version: 1.0.0
|
||||
- datamapper:
|
||||
version: 0.10.2
|
||||
version: 1.0.0
|
||||
- dm-do-adapter:
|
||||
version: 1.0.0
|
||||
- do_sqlite3:
|
||||
version: 0.10.2
|
||||
- dm-sqlite-adapter:
|
||||
version: 1.0.0
|
||||
- durran-validatable:
|
||||
version: 2.0.1
|
||||
- gemcutter:
|
||||
|
@ -176,7 +182,7 @@ specs:
|
|||
- linecache:
|
||||
version: "0.43"
|
||||
- mongo:
|
||||
version: 1.0.2
|
||||
version: 1.0.1
|
||||
- mongo_ext:
|
||||
version: 0.19.3
|
||||
- plucky:
|
||||
|
@ -200,11 +206,11 @@ specs:
|
|||
version: 1.3.0
|
||||
- tzinfo:
|
||||
version: 0.3.22
|
||||
hash: 8e87490eff1e76efe5e75a0c7380657e6d50ed93
|
||||
hash: dabca3250327bd882a442aa36e3708f62eed0a76
|
||||
sources:
|
||||
- Git:
|
||||
uri: git://github.com/JonRowe/mongomapper.git
|
||||
git: git://github.com/JonRowe/mongomapper.git
|
||||
ref: c93703c266085ad021a0d9987f7efa0ebd82b5ea
|
||||
ref: 1bae62df3aea1870a948972c95d7198ddd8f39aa
|
||||
- Rubygems:
|
||||
uri: http://rubygems.org
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
Feature: example
|
||||
In order to test DataBase Cleaner
|
||||
Here are some scenarios that rely on the DB being clean!
|
||||
|
||||
Background:
|
||||
Given I have setup database cleaner to clean multiple databases using datamapper
|
||||
|
||||
Scenario: dirty the db
|
||||
When I create a widget in one db using datamapper
|
||||
And I create a widget in another db using datamapper
|
||||
Then I should see 1 widget in one db using datamapper
|
||||
And I should see 1 widget in another db using datamapper
|
||||
|
||||
Scenario: assume a clean db
|
||||
When I create a widget in one db using datamapper
|
||||
Then I should see 1 widget in one db using datamapper
|
||||
And I should see 0 widget in another db using datamapper
|
||||
|
||||
Scenario: assume a clean db
|
||||
When I create a widget in another db using datamapper
|
||||
Then I should see 0 widget in one db using datamapper
|
||||
And I should see 1 widget in another db using datamapper
|
||||
|
23
examples/features/step_definitions/mongoid_steps.rb
Normal file
23
examples/features/step_definitions/mongoid_steps.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
When /^I create a widget using mongoid$/ do
|
||||
MongoidWidget.create!( :id => rand(1000)+1000)
|
||||
end
|
||||
|
||||
Then /^I should see ([\d]+) widget using mongoid$/ do |widget_count|
|
||||
MongoidWidget.count.should == widget_count.to_i
|
||||
end
|
||||
|
||||
When /^I create a widget in one db using mongoid$/ do
|
||||
MongoidWidgetUsingDatabaseOne.create!
|
||||
end
|
||||
|
||||
When /^I create a widget in another db using mongoid$/ do
|
||||
MongoidWidgetUsingDatabaseTwo.create!
|
||||
end
|
||||
|
||||
Then /^I should see ([\d]+) widget in one db using mongoid$/ do |widget_count|
|
||||
MongoidWidgetUsingDatabaseOne.count.should == widget_count.to_i
|
||||
end
|
||||
|
||||
Then /^I should see ([\d]+) widget in another db using mongoid$/ do |widget_count|
|
||||
MongoidWidgetUsingDatabaseTwo.count.should == widget_count.to_i
|
||||
end
|
|
@ -1,5 +1,9 @@
|
|||
#Hilarious as it seems, this is necessary so bundle exec cucumber works for mongoid cukeage (I'm assuming mongomapper is automatically present because its a git repo)
|
||||
Object.send(:remove_const, 'MongoMapper') if defined?(::MongoMapper)
|
||||
|
||||
require 'rubygems'
|
||||
require 'bundler'
|
||||
|
||||
Bundler.setup
|
||||
require 'spec/expectations'
|
||||
require 'ruby-debug'
|
||||
|
@ -34,10 +38,7 @@ if orm && strategy
|
|||
|
||||
|
||||
|
||||
if multiple_db && another_orm
|
||||
DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym, {:connection => :one} ].strategy = strategy.to_sym
|
||||
DatabaseCleaner[ another_orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym, {:connection => :two} ].strategy = strategy.to_sym
|
||||
elsif multiple_db
|
||||
if multiple_db
|
||||
DatabaseCleaner.app_root = "#{File.dirname(__FILE__)}/../.."
|
||||
orm_sym = orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'couch_potato'
|
||||
require 'json/pure'
|
||||
require 'json/pure' unless defined? ::JSON
|
||||
::CouchPotato::Config.database_name = 'couch_potato_test'
|
||||
|
||||
class CouchPotatoWidget
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
require "dm-core"
|
||||
require "dm-transactions"
|
||||
|
||||
#Datamapper 1.0 requires you to require dm-migrations to automigrate
|
||||
require "dm-migrations"
|
||||
|
||||
# only to please activerecord API used in database_cleaner/examples/features/step_definitions
|
||||
# yes, i know that's lazy ...
|
||||
|
||||
require "dm-validations"
|
||||
require "dm-aggregates"
|
||||
|
||||
|
|
|
@ -9,15 +9,41 @@ end
|
|||
#::MongoMapper.connection = Mongo::Connection.new('127.0.0.1')
|
||||
#::MongoMapper.database = 'database_cleaner_test'
|
||||
|
||||
class Widget
|
||||
class MongoidWidget
|
||||
include Mongoid::Document
|
||||
field :id, :type => Integer
|
||||
field :name
|
||||
|
||||
class << self
|
||||
#mongomapper doesn't seem to provide this...
|
||||
#mongoid doesn't seem to provide this...
|
||||
def create!(*args)
|
||||
new(*args).save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class MongoidWidgetUsingDatabaseOne
|
||||
include Mongoid::Document
|
||||
field :id, :type => Integer
|
||||
field :name
|
||||
|
||||
class << self
|
||||
#mongoid doesn't seem to provide this...
|
||||
def create!(*args)
|
||||
new(*args).save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class MongoidWidgetUsingDatabaseTwo
|
||||
include Mongoid::Document
|
||||
field :id, :type => Integer
|
||||
field :name
|
||||
|
||||
class << self
|
||||
#mongoid doesn't seem to provide this...
|
||||
def create!(*args)
|
||||
new(*args).save!
|
||||
end
|
||||
end
|
||||
end
|
|
@ -13,7 +13,17 @@ Feature: database cleaning using multiple ORMs
|
|||
| ORM1 | ORM2 |
|
||||
| ActiveRecord | DataMapper |
|
||||
| ActiveRecord | MongoMapper |
|
||||
| ActiveRecord | Mongoid |
|
||||
| ActiveRecord | CouchPotato |
|
||||
| DataMapper | ActiveRecord |
|
||||
| DataMapper | MongoMapper |
|
||||
| DataMapper | Mongoid |
|
||||
| DataMapper | CouchPotato |
|
||||
| MongoMapper | ActiveRecord |
|
||||
| MongoMapper | DataMapper |
|
||||
| MongoMapper | Mongoid |
|
||||
| MongoMapper | CouchPotato |
|
||||
| CouchPotato | ActiveRecord |
|
||||
| CouchPotato | DataMapper |
|
||||
| CouchPotato | MongoMapper |
|
||||
| CouchPotato | Mongoid |
|
||||
|
|
|
@ -4,7 +4,7 @@ Given /^I am using (ActiveRecord|DataMapper|MongoMapper|Mongoid|CouchPotato)$/ d
|
|||
@feature_runner.orm = orm
|
||||
end
|
||||
|
||||
Given /^I am using (ActiveRecord|DataMapper|MongoMapper|CouchPotato) and (ActiveRecord|DataMapper|MongoMapper|CouchPotato)$/ do |orm1,orm2|
|
||||
Given /^I am using (ActiveRecord|DataMapper|MongoMapper|CouchPotato|Mongoid) and (ActiveRecord|DataMapper|MongoMapper|CouchPotato|Mongoid)$/ do |orm1,orm2|
|
||||
@feature_runner = FeatureRunner.new
|
||||
@feature_runner.orm = orm1
|
||||
@feature_runner.another_orm = orm2
|
||||
|
|
|
@ -13,11 +13,22 @@ class FeatureRunner
|
|||
def go(feature)
|
||||
full_dir ||= File.expand_path(File.dirname(__FILE__) + "/../../examples/")
|
||||
Dir.chdir(full_dir) do
|
||||
|
||||
|
||||
|
||||
ENV['ORM'] = orm
|
||||
ENV['ANOTHER_ORM'] = another_orm if another_orm
|
||||
ENV['MULTIPLE_DBS'] = "true" if multiple_databases
|
||||
ENV['STRATEGY'] = strategy
|
||||
|
||||
if another_orm
|
||||
ENV['ANOTHER_ORM'] = another_orm
|
||||
else
|
||||
ENV['ANOTHER_ORM'] = nil
|
||||
end
|
||||
|
||||
if multiple_databases
|
||||
ENV['MULTIPLE_DBS'] = "true"
|
||||
else
|
||||
ENV['MULTIPLE_DBS'] = nil
|
||||
end
|
||||
|
||||
self.output = `#{"jruby -S " if defined?(JRUBY_VERSION)}cucumber features/#{feature}.feature`
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ module DataMapper
|
|||
|
||||
end
|
||||
|
||||
|
||||
class Sqlite3Adapter < DataObjectsAdapter
|
||||
|
||||
# taken from http://github.com/godfat/dm-mapping/tree/master
|
||||
|
@ -62,7 +63,32 @@ module DataMapper
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
class SqliteAdapter < DataObjectsAdapter
|
||||
# taken from http://github.com/godfat/dm-mapping/tree/master
|
||||
def storage_names(repository = :default)
|
||||
# activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 177
|
||||
sql = <<-SQL.compress_lines
|
||||
SELECT name
|
||||
FROM sqlite_master
|
||||
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
||||
SQL
|
||||
# activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 181
|
||||
select(sql)
|
||||
end
|
||||
|
||||
def truncate_table(table_name)
|
||||
execute("DELETE FROM #{quote_name(table_name)};")
|
||||
end
|
||||
|
||||
# this is a no-op copied from activerecord
|
||||
# i didn't find out if/how this is possible
|
||||
# activerecord also doesn't do more here
|
||||
def disable_referential_integrity
|
||||
yield
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# FIXME
|
||||
# i don't know if this works
|
||||
|
|
|
@ -58,6 +58,7 @@ module DatabaseCleaner
|
|||
Object.const_set('ActiveRecord','Actively mocking records.')
|
||||
Object.const_set('DataMapper', 'Mapping data mocks')
|
||||
Object.const_set('MongoMapper', 'Mapping mock mongos')
|
||||
Object.const_set('Mongoid', 'Mongoid mock')
|
||||
Object.const_set('CouchPotato', 'Couching mock potatos')
|
||||
|
||||
cleaner.orm.should == :active_record
|
||||
|
@ -66,6 +67,7 @@ module DatabaseCleaner
|
|||
it "should detect DataMapper second" do
|
||||
Object.const_set('DataMapper', 'Mapping data mocks')
|
||||
Object.const_set('MongoMapper', 'Mapping mock mongos')
|
||||
Object.const_set('Mongoid', 'Mongoid mock')
|
||||
Object.const_set('CouchPotato', 'Couching mock potatos')
|
||||
|
||||
cleaner.orm.should == :data_mapper
|
||||
|
@ -73,11 +75,19 @@ module DatabaseCleaner
|
|||
|
||||
it "should detect MongoMapper third" do
|
||||
Object.const_set('MongoMapper', 'Mapping mock mongos')
|
||||
Object.const_set('Mongoid', 'Mongoid mock')
|
||||
Object.const_set('CouchPotato', 'Couching mock potatos')
|
||||
|
||||
cleaner.orm.should == :mongo_mapper
|
||||
end
|
||||
|
||||
it "should detect Mongoid fourth" do
|
||||
Object.const_set('Mongoid', 'Mongoid mock')
|
||||
Object.const_set('CouchPotato', 'Couching mock potatos')
|
||||
|
||||
cleaner.orm.should == :mongoid
|
||||
end
|
||||
|
||||
it "should detect CouchPotato last" do
|
||||
Object.const_set('CouchPotato', 'Couching mock potatos')
|
||||
|
||||
|
|
Loading…
Reference in a new issue