surgical_strike 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +163 -0
- data/History.txt +210 -0
- data/LICENSE +20 -0
- data/README.textile +229 -0
- data/TODO +3 -0
- data/VERSION.yml +5 -0
- data/cucumber.yml +1 -0
- data/examples/Gemfile +1 -0
- data/examples/Gemfile.lock +1 -0
- data/examples/config/database.yml.example +8 -0
- data/examples/db/sqlite_databases_go_here +0 -0
- data/examples/features/example.feature +11 -0
- data/examples/features/example_multiple_db.feature +23 -0
- data/examples/features/example_multiple_orm.feature +22 -0
- data/examples/features/step_definitions/activerecord_steps.rb +31 -0
- data/examples/features/step_definitions/couchpotato_steps.rb +31 -0
- data/examples/features/step_definitions/datamapper_steps.rb +37 -0
- data/examples/features/step_definitions/mongoid_steps.rb +23 -0
- data/examples/features/step_definitions/mongomapper_steps.rb +31 -0
- data/examples/features/step_definitions/translation_steps.rb +55 -0
- data/examples/features/support/env.rb +62 -0
- data/examples/lib/activerecord_models.rb +41 -0
- data/examples/lib/couchpotato_models.rb +61 -0
- data/examples/lib/datamapper_models.rb +50 -0
- data/examples/lib/mongoid_models.rb +49 -0
- data/examples/lib/mongomapper_models.rb +51 -0
- data/features/cleaning.feature +22 -0
- data/features/cleaning_default_strategy.feature +19 -0
- data/features/cleaning_multiple_dbs.feature +21 -0
- data/features/cleaning_multiple_orms.feature +29 -0
- data/features/step_definitions/database_cleaner_steps.rb +32 -0
- data/features/support/env.rb +7 -0
- data/features/support/feature_runner.rb +39 -0
- data/lib/database_cleaner/active_record/base.rb +53 -0
- data/lib/database_cleaner/active_record/deletion.rb +67 -0
- data/lib/database_cleaner/active_record/surgicalstrike.rb +65 -0
- data/lib/database_cleaner/active_record/transaction.rb +28 -0
- data/lib/database_cleaner/active_record/truncation.rb +152 -0
- data/lib/database_cleaner/base.rb +138 -0
- data/lib/database_cleaner/configuration.rb +94 -0
- data/lib/database_cleaner/couch_potato/base.rb +7 -0
- data/lib/database_cleaner/couch_potato/truncation.rb +28 -0
- data/lib/database_cleaner/cucumber.rb +11 -0
- data/lib/database_cleaner/data_mapper/base.rb +21 -0
- data/lib/database_cleaner/data_mapper/transaction.rb +26 -0
- data/lib/database_cleaner/data_mapper/truncation.rb +175 -0
- data/lib/database_cleaner/generic/base.rb +12 -0
- data/lib/database_cleaner/generic/surgicalstrike.rb +47 -0
- data/lib/database_cleaner/generic/truncation.rb +37 -0
- data/lib/database_cleaner/mongo/truncation.rb +22 -0
- data/lib/database_cleaner/mongo_mapper/base.rb +20 -0
- data/lib/database_cleaner/mongo_mapper/truncation.rb +19 -0
- data/lib/database_cleaner/mongoid/base.rb +20 -0
- data/lib/database_cleaner/mongoid/truncation.rb +20 -0
- data/lib/database_cleaner/null_strategy.rb +15 -0
- data/lib/database_cleaner/sequel/base.rb +22 -0
- data/lib/database_cleaner/sequel/transaction.rb +25 -0
- data/lib/database_cleaner/sequel/truncation.rb +50 -0
- data/lib/surgical_strike.rb +3 -0
- data/spec/database_cleaner/active_record/base_spec.rb +144 -0
- data/spec/database_cleaner/active_record/transaction_spec.rb +77 -0
- data/spec/database_cleaner/active_record/truncation_spec.rb +76 -0
- data/spec/database_cleaner/base_spec.rb +493 -0
- data/spec/database_cleaner/configuration_spec.rb +294 -0
- data/spec/database_cleaner/couch_potato/truncation_spec.rb +41 -0
- data/spec/database_cleaner/data_mapper/base_spec.rb +30 -0
- data/spec/database_cleaner/data_mapper/transaction_spec.rb +23 -0
- data/spec/database_cleaner/data_mapper/truncation_spec.rb +11 -0
- data/spec/database_cleaner/generic/base_spec.rb +22 -0
- data/spec/database_cleaner/generic/truncation_spec.rb +78 -0
- data/spec/database_cleaner/mongo_mapper/base_spec.rb +33 -0
- data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +8 -0
- data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +74 -0
- data/spec/database_cleaner/sequel/base_spec.rb +32 -0
- data/spec/database_cleaner/sequel/transaction_spec.rb +21 -0
- data/spec/database_cleaner/sequel/truncation_spec.rb +13 -0
- data/spec/database_cleaner/shared_strategy_spec.rb +13 -0
- data/spec/rcov.opts +1 -0
- data/spec/spec.opts +7 -0
- data/spec/spec_helper.rb +19 -0
- metadata +162 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
Feature: example
|
2
|
+
In order to test DataBase Cleaner
|
3
|
+
Here are some scenarios that rely on the DB being clean!
|
4
|
+
|
5
|
+
# Background:
|
6
|
+
# Given I have setup DatabaseCleaner to clean multiple orms
|
7
|
+
|
8
|
+
Scenario: dirty the db
|
9
|
+
When I create a widget in one orm
|
10
|
+
And I create a widget in another orm
|
11
|
+
Then I should see 1 widget in one orm
|
12
|
+
And I should see 1 widget in another orm
|
13
|
+
|
14
|
+
Scenario: assume a clean db
|
15
|
+
When I create a widget in one orm
|
16
|
+
Then I should see 1 widget in one orm
|
17
|
+
And I should see 0 widget in another orm
|
18
|
+
|
19
|
+
Scenario: assume a clean db
|
20
|
+
When I create a widget in another orm
|
21
|
+
Then I should see 0 widget in one orm
|
22
|
+
And I should see 1 widget in another orm
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Given /^I have setup database cleaner to clean multiple databases using activerecord$/ do
|
2
|
+
#DatabaseCleaner
|
3
|
+
# require "#{File.dirname(__FILE__)}/../../../lib/datamapper_models"
|
4
|
+
#
|
5
|
+
# DatabaseCleaner[:datamapper, {:connection => :one} ].strategy = :truncation
|
6
|
+
# DatabaseCleaner[:datamapper, {:connection => :two} ].strategy = :truncation
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I create a widget using activerecord$/ do
|
10
|
+
ActiveRecordWidget.create!
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^I should see ([\d]+) widget using activerecord$/ do |widget_count|
|
14
|
+
ActiveRecordWidget.count.should == widget_count.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^I create a widget in one db using activerecord$/ do
|
18
|
+
ActiveRecordWidgetUsingDatabaseOne.create!
|
19
|
+
end
|
20
|
+
|
21
|
+
When /^I create a widget in another db using activerecord$/ do
|
22
|
+
ActiveRecordWidgetUsingDatabaseTwo.create!
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^I should see ([\d]+) widget in one db using activerecord$/ do |widget_count|
|
26
|
+
ActiveRecordWidgetUsingDatabaseOne.count.should == widget_count.to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
Then /^I should see ([\d]+) widget in another db using activerecord$/ do |widget_count|
|
30
|
+
ActiveRecordWidgetUsingDatabaseTwo.count.should == widget_count.to_i
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Given /^I have setup database cleaner to clean multiple databases using couchpotato$/ do
|
2
|
+
#DatabaseCleaner
|
3
|
+
# require "#{File.dirname(__FILE__)}/../../../lib/couchpotato_models"
|
4
|
+
#
|
5
|
+
# DatabaseCleaner[:couchpotato, {:connection => :one} ].strategy = :truncation
|
6
|
+
# DatabaseCleaner[:couchpotato, {:connection => :two} ].strategy = :truncation
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I create a widget using couchpotato$/ do
|
10
|
+
CouchPotatoWidget.create!
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^I should see ([\d]+) widget using couchpotato$/ do |widget_count|
|
14
|
+
CouchPotatoWidget.count.should == widget_count.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^I create a widget in one db using couchpotato$/ do
|
18
|
+
CouchPotatoWidgetUsingDatabaseOne.create!
|
19
|
+
end
|
20
|
+
|
21
|
+
When /^I create a widget in another db using couchpotato$/ do
|
22
|
+
CouchPotatoWidgetUsingDatabaseTwo.create!
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^I should see ([\d]+) widget in one db using couchpotato$/ do |widget_count|
|
26
|
+
CouchPotatoWidgetUsingDatabaseOne.count.should == widget_count.to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
Then /^I should see ([\d]+) widget in another db using couchpotato$/ do |widget_count|
|
30
|
+
CouchPotatoWidgetUsingDatabaseTwo.count.should == widget_count.to_i
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Given /^I have setup database cleaner to clean multiple databases using datamapper$/ do
|
2
|
+
#DatabaseCleaner
|
3
|
+
# require "#{File.dirname(__FILE__)}/../../../lib/datamapper_models"
|
4
|
+
#
|
5
|
+
# DatabaseCleaner[:datamapper, {:connection => :one} ].strategy = :truncation
|
6
|
+
# DatabaseCleaner[:datamapper, {:connection => :two} ].strategy = :truncation
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I create a widget using datamapper$/ do
|
10
|
+
DataMapperWidget.create!
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^I should see ([\d]+) widget using datamapper$/ do |widget_count|
|
14
|
+
DataMapperWidget.count.should == widget_count.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^I create a widget in one db using datamapper$/ do
|
18
|
+
begin
|
19
|
+
DataMapperWidgetUsingDatabaseOne.create!
|
20
|
+
rescue StandardError => e
|
21
|
+
BREAK = e.backtrace
|
22
|
+
debugger
|
23
|
+
DataMapperWidgetUsingDatabaseOne.create!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
When /^I create a widget in another db using datamapper$/ do
|
28
|
+
DataMapperWidgetUsingDatabaseTwo.create!
|
29
|
+
end
|
30
|
+
|
31
|
+
Then /^I should see ([\d]+) widget in one db using datamapper$/ do |widget_count|
|
32
|
+
DataMapperWidgetUsingDatabaseOne.count.should == widget_count.to_i
|
33
|
+
end
|
34
|
+
|
35
|
+
Then /^I should see ([\d]+) widget in another db using datamapper$/ do |widget_count|
|
36
|
+
DataMapperWidgetUsingDatabaseTwo.count.should == widget_count.to_i
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
When /^I create a widget using mongoid$/ do
|
2
|
+
MongoidWidget.create!( :id => rand(1000)+1000)
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^I should see ([\d]+) widget using mongoid$/ do |widget_count|
|
6
|
+
MongoidWidget.count.should == widget_count.to_i
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I create a widget in one db using mongoid$/ do
|
10
|
+
MongoidWidgetUsingDatabaseOne.create!
|
11
|
+
end
|
12
|
+
|
13
|
+
When /^I create a widget in another db using mongoid$/ do
|
14
|
+
MongoidWidgetUsingDatabaseTwo.create!
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^I should see ([\d]+) widget in one db using mongoid$/ do |widget_count|
|
18
|
+
MongoidWidgetUsingDatabaseOne.count.should == widget_count.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
Then /^I should see ([\d]+) widget in another db using mongoid$/ do |widget_count|
|
22
|
+
MongoidWidgetUsingDatabaseTwo.count.should == widget_count.to_i
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Given /^I have setup database cleaner to clean multiple databases using mongomapper$/ do
|
2
|
+
#DatabaseCleaner
|
3
|
+
# require "#{File.dirname(__FILE__)}/../../../lib/datamapper_models"
|
4
|
+
#
|
5
|
+
# DatabaseCleaner[:datamapper, {:connection => :one} ].strategy = :truncation
|
6
|
+
# DatabaseCleaner[:datamapper, {:connection => :two} ].strategy = :truncation
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I create a widget using mongomapper$/ do
|
10
|
+
MongoMapperWidget.create!
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^I should see ([\d]+) widget using mongomapper$/ do |widget_count|
|
14
|
+
MongoMapperWidget.count.should == widget_count.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^I create a widget in one db using mongomapper$/ do
|
18
|
+
MongoMapperWidgetUsingDatabaseOne.create!
|
19
|
+
end
|
20
|
+
|
21
|
+
When /^I create a widget in another db using mongomapper$/ do
|
22
|
+
MongoMapperWidgetUsingDatabaseTwo.create!
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^I should see ([\d]+) widget in one db using mongomapper$/ do |widget_count|
|
26
|
+
MongoMapperWidgetUsingDatabaseOne.count.should == widget_count.to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
Then /^I should see ([\d]+) widget in another db using mongomapper$/ do |widget_count|
|
30
|
+
MongoMapperWidgetUsingDatabaseTwo.count.should == widget_count.to_i
|
31
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
When /^I create a widget$/ do
|
2
|
+
When "I create a widget using #{ENV['ORM'].downcase}"
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^I should see 1 widget$/ do
|
6
|
+
Then "I should see 1 widget using #{ENV['ORM'].downcase}"
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I create a widget in one orm$/ do
|
10
|
+
When "I create a widget using #{ENV['ORM'].downcase}"
|
11
|
+
end
|
12
|
+
|
13
|
+
When /^I create a widget in another orm$/ do
|
14
|
+
When "I create a widget using #{ENV['ANOTHER_ORM'].downcase}"
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^I should see 1 widget in one orm$/ do
|
18
|
+
When "I should see 1 widget using #{ENV['ORM'].downcase}"
|
19
|
+
end
|
20
|
+
|
21
|
+
Then /^I should see 1 widget in another orm$/ do
|
22
|
+
When "I should see 1 widget using #{ENV['ANOTHER_ORM'].downcase}"
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^I should see 0 widget in another orm$/ do
|
26
|
+
When "I should see 0 widget using #{ENV['ANOTHER_ORM'].downcase}"
|
27
|
+
end
|
28
|
+
|
29
|
+
Then /^I should see 0 widget in one orm$/ do
|
30
|
+
When "I should see 0 widget using #{ENV['ORM'].downcase}"
|
31
|
+
end
|
32
|
+
|
33
|
+
When /^I create a widget in one db$/ do
|
34
|
+
When "I create a widget in one db using #{ENV['ORM'].downcase}"
|
35
|
+
end
|
36
|
+
|
37
|
+
When /^I create a widget in another db$/ do
|
38
|
+
When "I create a widget in another db using #{ENV['ORM'].downcase}"
|
39
|
+
end
|
40
|
+
|
41
|
+
Then /^I should see 1 widget in one db$/ do
|
42
|
+
When "I should see 1 widget in one db using #{ENV['ORM'].downcase}"
|
43
|
+
end
|
44
|
+
|
45
|
+
Then /^I should see 1 widget in another db$/ do
|
46
|
+
When "I should see 1 widget in another db using #{ENV['ORM'].downcase}"
|
47
|
+
end
|
48
|
+
|
49
|
+
Then /^I should see 0 widget in another db$/ do
|
50
|
+
When "I should see 0 widget in another db using #{ENV['ORM'].downcase}"
|
51
|
+
end
|
52
|
+
|
53
|
+
Then /^I should see 0 widget in one db$/ do
|
54
|
+
When "I should see 0 widget in one db using #{ENV['ORM'].downcase}"
|
55
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#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)
|
2
|
+
Object.send(:remove_const, 'MongoMapper') if defined?(::MongoMapper)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler'
|
6
|
+
|
7
|
+
Bundler.setup
|
8
|
+
require 'spec/expectations'
|
9
|
+
require 'ruby-debug'
|
10
|
+
|
11
|
+
DB_DIR = "#{File.dirname(__FILE__)}/../../db"
|
12
|
+
|
13
|
+
orm = ENV['ORM']
|
14
|
+
another_orm = ENV['ANOTHER_ORM']
|
15
|
+
strategy = ENV['STRATEGY']
|
16
|
+
multiple_db = ENV['MULTIPLE_DBS']
|
17
|
+
|
18
|
+
|
19
|
+
if orm && strategy
|
20
|
+
$:.unshift(File.dirname(__FILE__) + '/../../../lib')
|
21
|
+
require 'database_cleaner'
|
22
|
+
require 'database_cleaner/cucumber'
|
23
|
+
|
24
|
+
begin
|
25
|
+
require "#{File.dirname(__FILE__)}/../../lib/#{orm.downcase}_models"
|
26
|
+
rescue LoadError => e
|
27
|
+
raise "You don't have the #{orm} ORM installed"
|
28
|
+
end
|
29
|
+
|
30
|
+
if another_orm
|
31
|
+
begin
|
32
|
+
require "#{File.dirname(__FILE__)}/../../lib/#{another_orm.downcase}_models"
|
33
|
+
rescue LoadError => e
|
34
|
+
raise "You don't have the #{another_orm} ORM installed"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
if multiple_db
|
42
|
+
DatabaseCleaner.app_root = "#{File.dirname(__FILE__)}/../.."
|
43
|
+
orm_sym = orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym
|
44
|
+
|
45
|
+
if orm_sym == :mongo_mapper
|
46
|
+
DatabaseCleaner[ orm_sym, {:connection => 'database_cleaner_test_one'} ].strategy = strategy.to_sym
|
47
|
+
DatabaseCleaner[ orm_sym, {:connection => 'database_cleaner_test_two'} ].strategy = strategy.to_sym
|
48
|
+
else
|
49
|
+
DatabaseCleaner[ orm_sym, {:connection => :one} ].strategy = strategy.to_sym
|
50
|
+
DatabaseCleaner[ orm_sym, {:connection => :two} ].strategy = strategy.to_sym
|
51
|
+
end
|
52
|
+
|
53
|
+
elsif another_orm
|
54
|
+
DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym ].strategy = strategy.to_sym
|
55
|
+
DatabaseCleaner[ another_orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym ].strategy = strategy.to_sym
|
56
|
+
else
|
57
|
+
DatabaseCleaner.strategy = strategy.to_sym unless strategy == "default"
|
58
|
+
end
|
59
|
+
|
60
|
+
else
|
61
|
+
raise "Run 'ORM=ActiveRecord|DataMapper|MongoMapper|CouchPotato [ANOTHER_ORM=...] [MULTIPLE_DBS=true] STRATEGY=transaction|truncation|default cucumber examples/features'"
|
62
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
databases_config = {
|
3
|
+
"one" => {"adapter" => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", "database" => "#{DB_DIR}/activerecord_one.db"},
|
4
|
+
"two" => {"adapter" => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", "database" => "#{DB_DIR}/activerecord_two.db"}
|
5
|
+
}
|
6
|
+
|
7
|
+
File.open("#{File.dirname(__FILE__)}/../config/database.yml", 'w') do |file|
|
8
|
+
file.write(YAML.dump(databases_config))
|
9
|
+
end
|
10
|
+
|
11
|
+
["two","one"].each do |db|
|
12
|
+
ActiveRecord::Base.establish_connection(databases_config[db])
|
13
|
+
ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widgets"')
|
14
|
+
ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widget_using_database_ones"')
|
15
|
+
ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widget_using_database_twos"')
|
16
|
+
|
17
|
+
ActiveRecord::Schema.define(:version => 1) do
|
18
|
+
create_table :active_record_widgets do |t|
|
19
|
+
t.string :name
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :active_record_widget_using_database_ones do |t|
|
23
|
+
t.string :name
|
24
|
+
end
|
25
|
+
|
26
|
+
create_table :active_record_widget_using_database_twos do |t|
|
27
|
+
t.string :name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class ActiveRecordWidget < ActiveRecord::Base
|
33
|
+
end
|
34
|
+
|
35
|
+
class ActiveRecordWidgetUsingDatabaseOne < ActiveRecord::Base
|
36
|
+
establish_connection(:adapter => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", :database => "#{DB_DIR}/activerecord_one.db")
|
37
|
+
end
|
38
|
+
|
39
|
+
class ActiveRecordWidgetUsingDatabaseTwo < ActiveRecord::Base
|
40
|
+
establish_connection(:adapter => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", :database => "#{DB_DIR}/activerecord_two.db")
|
41
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'couch_potato'
|
2
|
+
require 'json/pure' unless defined? ::JSON
|
3
|
+
::CouchPotato::Config.database_name = 'couch_potato_test'
|
4
|
+
|
5
|
+
class CouchPotatoWidget
|
6
|
+
include CouchPotato::Persistence
|
7
|
+
|
8
|
+
property :name
|
9
|
+
view :by_name, :key => :name
|
10
|
+
|
11
|
+
|
12
|
+
# mimic the AR interface used in example_steps
|
13
|
+
|
14
|
+
def self.create!(attrs = {})
|
15
|
+
CouchPotato.database.save(self.new)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.count
|
19
|
+
CouchPotato.database.view(self.by_name).size
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class CouchPotatoWidgetUsingDatabaseOne
|
24
|
+
include CouchPotato::Persistence
|
25
|
+
|
26
|
+
database_name = 'couch_potato_test_one'
|
27
|
+
|
28
|
+
property :name
|
29
|
+
view :by_name, :key => :name
|
30
|
+
|
31
|
+
|
32
|
+
# mimic the AR interface used in example_steps
|
33
|
+
|
34
|
+
def self.create!(attrs = {})
|
35
|
+
CouchPotato.database.save(self.new)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.count
|
39
|
+
CouchPotato.database.view(self.by_name).size
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class CouchPotatoWidgetUsingDatabaseTwo
|
44
|
+
include CouchPotato::Persistence
|
45
|
+
|
46
|
+
database_name = 'couch_potato_test_two'
|
47
|
+
|
48
|
+
property :name
|
49
|
+
view :by_name, :key => :name
|
50
|
+
|
51
|
+
|
52
|
+
# mimic the AR interface used in example_steps
|
53
|
+
|
54
|
+
def self.create!(attrs = {})
|
55
|
+
CouchPotato.database.save(self.new)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.count
|
59
|
+
CouchPotato.database.view(self.by_name).size
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "dm-core"
|
2
|
+
require "dm-transactions"
|
3
|
+
|
4
|
+
#Datamapper 1.0 requires you to require dm-migrations to automigrate
|
5
|
+
require "dm-migrations"
|
6
|
+
|
7
|
+
# only to please activerecord API used in database_cleaner/examples/features/step_definitions
|
8
|
+
# yes, i know that's lazy ...
|
9
|
+
|
10
|
+
require "dm-validations"
|
11
|
+
require "dm-aggregates"
|
12
|
+
|
13
|
+
DataMapper.setup(:default, "sqlite3:#{DB_DIR}/datamapper_default.db")
|
14
|
+
DataMapper.setup(:one, "sqlite3:#{DB_DIR}/datamapper_one.db")
|
15
|
+
DataMapper.setup(:two, "sqlite3:#{DB_DIR}/datamapper_two.db")
|
16
|
+
|
17
|
+
class DataMapperWidget
|
18
|
+
include DataMapper::Resource
|
19
|
+
|
20
|
+
property :id, Serial
|
21
|
+
property :name, String
|
22
|
+
end
|
23
|
+
|
24
|
+
class DataMapperWidgetUsingDatabaseOne
|
25
|
+
include DataMapper::Resource
|
26
|
+
|
27
|
+
def self.default_repository_name
|
28
|
+
:one
|
29
|
+
end
|
30
|
+
|
31
|
+
property :id, Serial
|
32
|
+
property :name, String
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
class DataMapperWidgetUsingDatabaseTwo
|
37
|
+
include DataMapper::Resource
|
38
|
+
|
39
|
+
def self.default_repository_name
|
40
|
+
:two
|
41
|
+
end
|
42
|
+
|
43
|
+
property :id, Serial
|
44
|
+
property :name, String
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
DataMapperWidget.auto_migrate!
|
49
|
+
DataMapperWidgetUsingDatabaseOne.auto_migrate!
|
50
|
+
DataMapperWidgetUsingDatabaseTwo.auto_migrate!
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
|
3
|
+
Mongoid.configure do |config|
|
4
|
+
name = 'database_cleaner_test'
|
5
|
+
config.master = Mongo::Connection.new.db(name)
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
#::MongoMapper.connection = Mongo::Connection.new('127.0.0.1')
|
10
|
+
#::MongoMapper.database = 'database_cleaner_test'
|
11
|
+
|
12
|
+
class MongoidWidget
|
13
|
+
include Mongoid::Document
|
14
|
+
field :id, :type => Integer
|
15
|
+
field :name
|
16
|
+
|
17
|
+
class << self
|
18
|
+
#mongoid doesn't seem to provide this...
|
19
|
+
def create!(*args)
|
20
|
+
new(*args).save!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class MongoidWidgetUsingDatabaseOne
|
26
|
+
include Mongoid::Document
|
27
|
+
field :id, :type => Integer
|
28
|
+
field :name
|
29
|
+
|
30
|
+
class << self
|
31
|
+
#mongoid doesn't seem to provide this...
|
32
|
+
def create!(*args)
|
33
|
+
new(*args).save!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class MongoidWidgetUsingDatabaseTwo
|
39
|
+
include Mongoid::Document
|
40
|
+
field :id, :type => Integer
|
41
|
+
field :name
|
42
|
+
|
43
|
+
class << self
|
44
|
+
#mongoid doesn't seem to provide this...
|
45
|
+
def create!(*args)
|
46
|
+
new(*args).save!
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
|
3
|
+
::MongoMapper.connection = Mongo::Connection.new('127.0.0.1')
|
4
|
+
::MongoMapper.database = 'database_cleaner_test'
|
5
|
+
|
6
|
+
class MongoMapperWidget
|
7
|
+
include MongoMapper::Document
|
8
|
+
key :id, Integer
|
9
|
+
key :name, String
|
10
|
+
|
11
|
+
class << self
|
12
|
+
#mongomapper doesn't seem to provide this...
|
13
|
+
def create!(*args)
|
14
|
+
new(*args).save!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class MongoMapperWidgetUsingDatabaseOne
|
20
|
+
include MongoMapper::Document
|
21
|
+
|
22
|
+
connection = Mongo::Connection.new('127.0.0.1')
|
23
|
+
set_database_name = 'database_cleaner_test_one'
|
24
|
+
|
25
|
+
key :id, Integer
|
26
|
+
key :name, String
|
27
|
+
|
28
|
+
class << self
|
29
|
+
#mongomapper doesn't seem to provide this...
|
30
|
+
def create!(*args)
|
31
|
+
new(*args).save!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class MongoMapperWidgetUsingDatabaseTwo
|
37
|
+
include MongoMapper::Document
|
38
|
+
|
39
|
+
connection = Mongo::Connection.new('127.0.0.1')
|
40
|
+
set_database_name = 'database_cleaner_test_two'
|
41
|
+
|
42
|
+
key :id, Integer
|
43
|
+
key :name, String
|
44
|
+
|
45
|
+
class << self
|
46
|
+
#mongomapper doesn't seem to provide this...
|
47
|
+
def create!(*args)
|
48
|
+
new(*args).save!
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Feature: database cleaning
|
2
|
+
In order to ease example and feature writing
|
3
|
+
As a developer
|
4
|
+
I want to have my database in a clean state
|
5
|
+
|
6
|
+
Scenario Outline: ruby app
|
7
|
+
Given I am using <ORM>
|
8
|
+
And the <Strategy> cleaning strategy
|
9
|
+
|
10
|
+
When I run my scenarios that rely on a clean database
|
11
|
+
Then I should see all green
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
| ORM | Strategy |
|
15
|
+
| ActiveRecord | transaction |
|
16
|
+
| ActiveRecord | truncation |
|
17
|
+
| ActiveRecord | deletion |
|
18
|
+
| DataMapper | transaction |
|
19
|
+
| DataMapper | truncation |
|
20
|
+
| MongoMapper | truncation |
|
21
|
+
| Mongoid | truncation |
|
22
|
+
| CouchPotato | truncation |
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: database cleaning
|
2
|
+
In order to ease example and feature writing
|
3
|
+
As a developer
|
4
|
+
I want to have my database in a clean state with default strategy
|
5
|
+
|
6
|
+
Scenario Outline: ruby app
|
7
|
+
Given I am using <ORM>
|
8
|
+
And the default cleaning strategy
|
9
|
+
|
10
|
+
When I run my scenarios that rely on a clean database
|
11
|
+
Then I should see all green
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
| ORM |
|
15
|
+
| ActiveRecord |
|
16
|
+
| DataMapper |
|
17
|
+
| MongoMapper |
|
18
|
+
| Mongoid |
|
19
|
+
| CouchPotato |
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: multiple database cleaning
|
2
|
+
In order to ease example and feature writing
|
3
|
+
As a developer
|
4
|
+
I want to have my databases in a clean state
|
5
|
+
|
6
|
+
Scenario Outline: ruby app
|
7
|
+
Given I am using <ORM>
|
8
|
+
And the <Strategy> cleaning strategy
|
9
|
+
|
10
|
+
When I run my scenarios that rely on clean databases
|
11
|
+
Then I should see all green
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
| ORM | Strategy |
|
15
|
+
| ActiveRecord | truncation |
|
16
|
+
| ActiveRecord | deletion |
|
17
|
+
| DataMapper | truncation |
|
18
|
+
| MongoMapper | truncation |
|
19
|
+
| DataMapper | transaction |
|
20
|
+
# Not working...
|
21
|
+
#| ActiveRecord | transaction |
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Feature: database cleaning using multiple ORMs
|
2
|
+
In order to ease example and feature writing
|
3
|
+
As a developer
|
4
|
+
I want to have my database in a clean state
|
5
|
+
|
6
|
+
Scenario Outline: ruby app
|
7
|
+
Given I am using <ORM1> and <ORM2>
|
8
|
+
|
9
|
+
When I run my scenarios that rely on clean databases using multiple orms
|
10
|
+
Then I should see all green
|
11
|
+
|
12
|
+
Examples:
|
13
|
+
| ORM1 | ORM2 |
|
14
|
+
| ActiveRecord | DataMapper |
|
15
|
+
| ActiveRecord | MongoMapper |
|
16
|
+
| ActiveRecord | Mongoid |
|
17
|
+
| ActiveRecord | CouchPotato |
|
18
|
+
| DataMapper | ActiveRecord |
|
19
|
+
| DataMapper | MongoMapper |
|
20
|
+
| DataMapper | Mongoid |
|
21
|
+
| DataMapper | CouchPotato |
|
22
|
+
| MongoMapper | ActiveRecord |
|
23
|
+
| MongoMapper | DataMapper |
|
24
|
+
| MongoMapper | Mongoid |
|
25
|
+
| MongoMapper | CouchPotato |
|
26
|
+
| CouchPotato | ActiveRecord |
|
27
|
+
| CouchPotato | DataMapper |
|
28
|
+
| CouchPotato | MongoMapper |
|
29
|
+
| CouchPotato | Mongoid |
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
Given /^I am using (ActiveRecord|DataMapper|MongoMapper|Mongoid|CouchPotato)$/ do |orm|
|
3
|
+
@feature_runner = FeatureRunner.new
|
4
|
+
@feature_runner.orm = orm
|
5
|
+
end
|
6
|
+
|
7
|
+
Given /^I am using (ActiveRecord|DataMapper|MongoMapper|CouchPotato|Mongoid) and (ActiveRecord|DataMapper|MongoMapper|CouchPotato|Mongoid)$/ do |orm1,orm2|
|
8
|
+
@feature_runner = FeatureRunner.new
|
9
|
+
@feature_runner.orm = orm1
|
10
|
+
@feature_runner.another_orm = orm2
|
11
|
+
end
|
12
|
+
|
13
|
+
Given /^the (.+) cleaning strategy$/ do |strategy|
|
14
|
+
@feature_runner.strategy = strategy
|
15
|
+
end
|
16
|
+
|
17
|
+
When "I run my scenarios that rely on a clean database" do
|
18
|
+
@feature_runner.go 'example'
|
19
|
+
end
|
20
|
+
|
21
|
+
When "I run my scenarios that rely on clean databases" do
|
22
|
+
@feature_runner.multiple_databases = true
|
23
|
+
@feature_runner.go 'example_multiple_db'
|
24
|
+
end
|
25
|
+
|
26
|
+
When "I run my scenarios that rely on clean databases using multiple orms" do
|
27
|
+
@feature_runner.go 'example_multiple_orm'
|
28
|
+
end
|
29
|
+
|
30
|
+
Then "I should see all green" do
|
31
|
+
fail "Feature failed with :#{@feature_runner.output}" unless @feature_runner.exit_status == 0
|
32
|
+
end
|