database_cleaner 1.6.2 → 1.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CONTRIBUTE.markdown +1 -2
- data/Gemfile.lock +132 -93
- data/History.rdoc +67 -0
- data/README.markdown +88 -217
- data/Rakefile +12 -8
- data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/base.rb +14 -5
- data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/deletion.rb +19 -17
- data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/truncation.rb +25 -20
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/version.rb +5 -0
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record.rb +6 -0
- data/adapters/database_cleaner-active_record/lib/database_cleaner-active_record.rb +1 -0
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb +5 -0
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb +11 -0
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb +1 -0
- data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/base.rb +4 -0
- data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/truncation.rb +4 -3
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb +5 -0
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb +4 -0
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb +1 -0
- data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/truncation.rb +2 -0
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +5 -0
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb +10 -0
- data/adapters/database_cleaner-mongo/lib/database_cleaner-mongo.rb +1 -0
- data/{lib → adapters/database_cleaner-mongo_mapper/lib}/database_cleaner/mongo_mapper/base.rb +4 -0
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb +35 -0
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +5 -0
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +4 -0
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner-mongo_mapper.rb +1 -0
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb +26 -0
- data/{lib/database_cleaner/mongo2/truncation_mixin.rb → adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb} +3 -4
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb +65 -0
- data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongoid/truncation.rb +6 -6
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +5 -0
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +10 -0
- data/adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb +1 -0
- data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/base.rb +1 -1
- data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/truncation_base.rb +4 -0
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +5 -0
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +10 -0
- data/adapters/database_cleaner-moped/lib/database_cleaner-moped.rb +1 -0
- data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/base.rb +4 -0
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +5 -0
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +6 -0
- data/adapters/database_cleaner-neo4j/lib/database_cleaner-neo4j.rb +1 -0
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb +24 -0
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +5 -0
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +12 -0
- data/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb +1 -0
- data/{lib → adapters/database_cleaner-redis/lib}/database_cleaner/redis/base.rb +4 -0
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +5 -0
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +4 -0
- data/adapters/database_cleaner-redis/lib/database_cleaner-redis.rb +1 -0
- data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/base.rb +4 -0
- data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/truncation.rb +16 -15
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +5 -0
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel.rb +6 -0
- data/adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb +1 -0
- data/lib/database_cleaner/base.rb +94 -105
- data/lib/database_cleaner/configuration.rb +87 -83
- data/lib/database_cleaner/deprecation.rb +26 -0
- data/lib/database_cleaner/null_strategy.rb +6 -6
- data/lib/database_cleaner/orm_autodetector.rb +41 -0
- data/lib/database_cleaner/safeguard.rb +107 -0
- data/lib/database_cleaner/spec/database_helper.rb +82 -0
- data/lib/database_cleaner/spec/shared_examples.rb +15 -0
- data/lib/database_cleaner/spec.rb +2 -0
- data/lib/database_cleaner/version.rb +3 -0
- data/lib/database_cleaner.rb +41 -2
- metadata +113 -126
- data/VERSION.yml +0 -4
- data/examples/Gemfile +0 -1
- data/examples/Gemfile.lock +0 -1
- data/examples/config/database.yml.example +0 -8
- data/examples/config/redis.yml +0 -8
- data/examples/db/sqlite_databases_go_here +0 -0
- data/examples/features/example.feature +0 -11
- data/examples/features/example_multiple_db.feature +0 -23
- data/examples/features/example_multiple_orm.feature +0 -22
- data/examples/features/step_definitions/activerecord_steps.rb +0 -31
- data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
- data/examples/features/step_definitions/datamapper_steps.rb +0 -37
- data/examples/features/step_definitions/mongoid_steps.rb +0 -23
- data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
- data/examples/features/step_definitions/neo4j_steps.rb +0 -23
- data/examples/features/step_definitions/ohm_steps.rb +0 -31
- data/examples/features/step_definitions/redis_steps.rb +0 -31
- data/examples/features/step_definitions/translation_steps.rb +0 -55
- data/examples/features/support/env.rb +0 -61
- data/examples/lib/activerecord_models.rb +0 -41
- data/examples/lib/couchpotato_models.rb +0 -61
- data/examples/lib/datamapper_models.rb +0 -50
- data/examples/lib/mongoid_models.rb +0 -44
- data/examples/lib/mongomapper_models.rb +0 -51
- data/examples/lib/neo4j_models.rb +0 -17
- data/examples/lib/ohm_models.rb +0 -43
- data/examples/lib/redis_models.rb +0 -65
- data/examples/lib/sequel_models.rb +0 -9
- data/features/cleaning.feature +0 -30
- data/features/cleaning_default_strategy.feature +0 -23
- data/features/cleaning_multiple_dbs.feature +0 -22
- data/features/cleaning_multiple_orms.feature +0 -67
- data/features/step_definitions/database_cleaner_steps.rb +0 -33
- data/features/support/env.rb +0 -4
- data/features/support/feature_runner.rb +0 -39
- data/lib/database_cleaner/mongo2/base.rb +0 -16
- data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
- data/lib/database_cleaner/ohm/truncation.rb +0 -15
- data/spec/database_cleaner/active_record/base_spec.rb +0 -188
- data/spec/database_cleaner/active_record/transaction_spec.rb +0 -176
- data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +0 -38
- data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +0 -38
- data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +0 -75
- data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +0 -40
- data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +0 -40
- data/spec/database_cleaner/active_record/truncation_spec.rb +0 -180
- data/spec/database_cleaner/base_spec.rb +0 -617
- data/spec/database_cleaner/configuration_spec.rb +0 -345
- data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
- data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
- data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
- data/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +0 -41
- data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
- data/spec/database_cleaner/generic/base_spec.rb +0 -61
- data/spec/database_cleaner/generic/truncation_spec.rb +0 -118
- data/spec/database_cleaner/mongo/mongo_examples.rb +0 -26
- data/spec/database_cleaner/mongo/truncation_spec.rb +0 -72
- data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
- data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
- data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
- data/spec/database_cleaner/moped/moped_examples.rb +0 -32
- data/spec/database_cleaner/moped/truncation_spec.rb +0 -80
- data/spec/database_cleaner/neo4j/base_spec.rb +0 -43
- data/spec/database_cleaner/neo4j/transaction_spec.rb +0 -25
- data/spec/database_cleaner/null_strategy_spec.rb +0 -28
- data/spec/database_cleaner/ohm/truncation_spec.rb +0 -70
- data/spec/database_cleaner/redis/base_spec.rb +0 -43
- data/spec/database_cleaner/redis/truncation_spec.rb +0 -63
- data/spec/database_cleaner/sequel/base_spec.rb +0 -32
- data/spec/database_cleaner/sequel/deletion_spec.rb +0 -58
- data/spec/database_cleaner/sequel/transaction_spec.rb +0 -21
- data/spec/database_cleaner/sequel/truncation/sqlite3_spec.rb +0 -0
- data/spec/database_cleaner/sequel/truncation_spec.rb +0 -182
- data/spec/database_cleaner/shared_strategy.rb +0 -15
- data/spec/rcov.opts +0 -1
- data/spec/spec_helper.rb +0 -21
- data/spec/support/active_record/database_setup.rb +0 -6
- data/spec/support/active_record/migrations/20150101010000_create_users.rb +0 -14
- data/spec/support/active_record/migrations/20150101020000_create_agents.rb +0 -14
- data/spec/support/active_record/mysql2_setup.rb +0 -39
- data/spec/support/active_record/mysql_setup.rb +0 -38
- data/spec/support/active_record/postgresql_setup.rb +0 -48
- data/spec/support/active_record/schema_setup.rb +0 -17
- data/spec/support/active_record/sqlite3_setup.rb +0 -40
- data/spec/support/data_mapper/schema_setup.rb +0 -15
- data/spec/support/data_mapper/sqlite3_setup.rb +0 -39
- /data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/transaction.rb +0 -0
- /data/{lib → adapters/database_cleaner-couch_potato/lib}/database_cleaner/couch_potato/base.rb +0 -0
- /data/{lib → adapters/database_cleaner-couch_potato/lib}/database_cleaner/couch_potato/truncation.rb +0 -0
- /data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/transaction.rb +0 -0
- /data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/base.rb +0 -0
- /data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/truncation_mixin.rb +0 -0
- /data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongoid/base.rb +0 -0
- /data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/truncation.rb +0 -0
- /data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/deletion.rb +0 -0
- /data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/transaction.rb +0 -0
- /data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/truncation.rb +0 -0
- /data/{lib → adapters/database_cleaner-redis/lib}/database_cleaner/redis/truncation.rb +0 -0
- /data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/deletion.rb +0 -0
- /data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/transaction.rb +0 -0
@@ -1,23 +0,0 @@
|
|
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
|
-
| Sequel |
|
18
|
-
| MongoMapper |
|
19
|
-
| Mongoid |
|
20
|
-
| CouchPotato |
|
21
|
-
| Redis |
|
22
|
-
| Ohm |
|
23
|
-
| Neo4j |
|
@@ -1,22 +0,0 @@
|
|
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
|
-
| Sequel | truncation |
|
19
|
-
| MongoMapper | truncation |
|
20
|
-
| DataMapper | transaction |
|
21
|
-
| ActiveRecord | transaction |
|
22
|
-
| Sequel | transaction |
|
@@ -1,67 +0,0 @@
|
|
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 | Sequel |
|
16
|
-
| ActiveRecord | MongoMapper |
|
17
|
-
| ActiveRecord | Mongoid |
|
18
|
-
| ActiveRecord | CouchPotato |
|
19
|
-
| ActiveRecord | Ohm |
|
20
|
-
| ActiveRecord | Redis |
|
21
|
-
| DataMapper | ActiveRecord |
|
22
|
-
| DataMapper | Sequel |
|
23
|
-
| DataMapper | MongoMapper |
|
24
|
-
| DataMapper | Mongoid |
|
25
|
-
| DataMapper | CouchPotato |
|
26
|
-
| DataMapper | Ohm |
|
27
|
-
| DataMapper | Redis |
|
28
|
-
| Sequel | ActiveRecord |
|
29
|
-
| Sequel | DataMapper |
|
30
|
-
| Sequel | MongoMapper |
|
31
|
-
| Sequel | Mongoid |
|
32
|
-
| Sequel | CouchPotato |
|
33
|
-
| Sequel | Ohm |
|
34
|
-
| Sequel | Redis |
|
35
|
-
| MongoMapper | ActiveRecord |
|
36
|
-
| MongoMapper | DataMapper |
|
37
|
-
| MongoMapper | Sequel |
|
38
|
-
| MongoMapper | Mongoid |
|
39
|
-
| MongoMapper | CouchPotato |
|
40
|
-
| MongoMapper | Ohm |
|
41
|
-
| MongoMapper | Redis |
|
42
|
-
| CouchPotato | ActiveRecord |
|
43
|
-
| CouchPotato | DataMapper |
|
44
|
-
| CouchPotato | Sequel |
|
45
|
-
| CouchPotato | MongoMapper |
|
46
|
-
| CouchPotato | Mongoid |
|
47
|
-
| CouchPotato | Ohm |
|
48
|
-
| CouchPotato | Redis |
|
49
|
-
| Ohm | ActiveRecord |
|
50
|
-
| Ohm | DataMapper |
|
51
|
-
| Ohm | Sequel |
|
52
|
-
| Ohm | MongoMapper |
|
53
|
-
| Ohm | Mongoid |
|
54
|
-
| Ohm | CouchPotato |
|
55
|
-
| Redis | ActiveRecord |
|
56
|
-
| Redis | DataMapper |
|
57
|
-
| Redis | Sequel |
|
58
|
-
| Redis | MongoMapper |
|
59
|
-
| Redis | Mongoid |
|
60
|
-
| Redis | CouchPotato |
|
61
|
-
| Redis | Ohm |
|
62
|
-
| Neo4j | ActiveRecord |
|
63
|
-
| Neo4j | DataMapper |
|
64
|
-
| Neo4j | Sequel |
|
65
|
-
| Neo4j | Redis |
|
66
|
-
| Neo4j | Ohm |
|
67
|
-
| Neo4j | MongoMapper |
|
@@ -1,33 +0,0 @@
|
|
1
|
-
orms_pattern = /(ActiveRecord|DataMapper|Sequel|MongoMapper|Mongoid|CouchPotato|Redis|Ohm|Neo4j)/
|
2
|
-
|
3
|
-
Given /^I am using #{orms_pattern}$/ do |orm|
|
4
|
-
@feature_runner = FeatureRunner.new
|
5
|
-
@feature_runner.orm = orm
|
6
|
-
end
|
7
|
-
|
8
|
-
Given /^I am using #{orms_pattern} and #{orms_pattern}$/ do |orm1,orm2|
|
9
|
-
@feature_runner = FeatureRunner.new
|
10
|
-
@feature_runner.orm = orm1
|
11
|
-
@feature_runner.another_orm = orm2
|
12
|
-
end
|
13
|
-
|
14
|
-
Given /^the (.+) cleaning strategy$/ do |strategy|
|
15
|
-
@feature_runner.strategy = strategy
|
16
|
-
end
|
17
|
-
|
18
|
-
When "I run my scenarios that rely on a clean database" do
|
19
|
-
@feature_runner.go 'example'
|
20
|
-
end
|
21
|
-
|
22
|
-
When "I run my scenarios that rely on clean databases" do
|
23
|
-
@feature_runner.multiple_databases = true
|
24
|
-
@feature_runner.go 'example_multiple_db'
|
25
|
-
end
|
26
|
-
|
27
|
-
When "I run my scenarios that rely on clean databases using multiple orms" do
|
28
|
-
@feature_runner.go 'example_multiple_orm'
|
29
|
-
end
|
30
|
-
|
31
|
-
Then "I should see all green" do
|
32
|
-
fail "Feature failed with :#{@feature_runner.output}" unless @feature_runner.exit_status == 0
|
33
|
-
end
|
data/features/support/env.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
class FeatureRunner
|
2
|
-
attr_accessor :orm
|
3
|
-
attr_accessor :another_orm
|
4
|
-
attr_accessor :multiple_databases
|
5
|
-
attr_accessor :strategy
|
6
|
-
attr_accessor :exit_status
|
7
|
-
attr_accessor :output
|
8
|
-
|
9
|
-
def strategy
|
10
|
-
@strategy || 'truncation'
|
11
|
-
end
|
12
|
-
|
13
|
-
def go(feature)
|
14
|
-
full_dir ||= File.expand_path(File.dirname(__FILE__) + "/../../examples/")
|
15
|
-
Dir.chdir(full_dir) do
|
16
|
-
|
17
|
-
|
18
|
-
ENV['ORM'] = orm
|
19
|
-
ENV['STRATEGY'] = strategy
|
20
|
-
|
21
|
-
if another_orm
|
22
|
-
ENV['ANOTHER_ORM'] = another_orm
|
23
|
-
else
|
24
|
-
ENV['ANOTHER_ORM'] = nil
|
25
|
-
end
|
26
|
-
|
27
|
-
if multiple_databases
|
28
|
-
ENV['MULTIPLE_DBS'] = "true"
|
29
|
-
else
|
30
|
-
ENV['MULTIPLE_DBS'] = nil
|
31
|
-
end
|
32
|
-
|
33
|
-
self.output = `#{"jruby -S " if defined?(JRUBY_VERSION)}cucumber features/#{feature}.feature`
|
34
|
-
|
35
|
-
self.exit_status = $?.exitstatus
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module DatabaseCleaner
|
2
|
-
module Mongo2
|
3
|
-
def self.available_strategies
|
4
|
-
%w[truncation]
|
5
|
-
end
|
6
|
-
module Base
|
7
|
-
def db=(desired_db)
|
8
|
-
@db = desired_db
|
9
|
-
end
|
10
|
-
|
11
|
-
def db
|
12
|
-
@db || raise("You have not specified a database. (see Mongo2::Database)")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'database_cleaner/mongo_mapper/base'
|
2
|
-
require 'database_cleaner/generic/truncation'
|
3
|
-
require 'database_cleaner/mongo/truncation_mixin'
|
4
|
-
|
5
|
-
module DatabaseCleaner
|
6
|
-
module MongoMapper
|
7
|
-
class Truncation
|
8
|
-
include ::DatabaseCleaner::MongoMapper::Base
|
9
|
-
include ::DatabaseCleaner::Generic::Truncation
|
10
|
-
include ::DatabaseCleaner::Mongo::TruncationMixin
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def database
|
15
|
-
::MongoMapper.database
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,188 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'active_record'
|
3
|
-
require 'database_cleaner/active_record/base'
|
4
|
-
require 'database_cleaner/shared_strategy'
|
5
|
-
|
6
|
-
class FakeModel
|
7
|
-
def self.connection
|
8
|
-
:fake_connection
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
module DatabaseCleaner
|
13
|
-
describe ActiveRecord do
|
14
|
-
it { should respond_to(:available_strategies) }
|
15
|
-
|
16
|
-
describe "config_file_location" do
|
17
|
-
subject { ActiveRecord.config_file_location }
|
18
|
-
|
19
|
-
it "should default to DatabaseCleaner.root / config / database.yml" do
|
20
|
-
ActiveRecord.config_file_location=nil
|
21
|
-
DatabaseCleaner.should_receive(:app_root).and_return("/path/to")
|
22
|
-
subject.should eq '/path/to/config/database.yml'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
module ActiveRecord
|
29
|
-
class ExampleStrategy
|
30
|
-
include ::DatabaseCleaner::ActiveRecord::Base
|
31
|
-
end
|
32
|
-
|
33
|
-
describe ExampleStrategy do
|
34
|
-
let :config_location do
|
35
|
-
'/path/to/config/database.yml'
|
36
|
-
end
|
37
|
-
|
38
|
-
before { ::DatabaseCleaner::ActiveRecord.stub(:config_file_location).and_return(config_location) }
|
39
|
-
|
40
|
-
it_should_behave_like "a generic strategy"
|
41
|
-
|
42
|
-
describe "db" do
|
43
|
-
|
44
|
-
it "should store my desired db" do
|
45
|
-
subject.stub(:load_config)
|
46
|
-
|
47
|
-
subject.db = :my_db
|
48
|
-
subject.db.should eq :my_db
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should default to :default" do
|
52
|
-
subject.db.should eq :default
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should load_config when I set db" do
|
56
|
-
subject.should_receive(:load_config)
|
57
|
-
subject.db = :my_db
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "load_config" do
|
62
|
-
|
63
|
-
before do
|
64
|
-
subject.db = :my_db
|
65
|
-
yaml = <<-Y
|
66
|
-
my_db:
|
67
|
-
database: <%= "ONE".downcase %>
|
68
|
-
Y
|
69
|
-
File.stub(:file?).with(config_location).and_return(true)
|
70
|
-
IO.stub(:read).with(config_location).and_return(yaml)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should parse the config" do
|
74
|
-
YAML.should_receive(:load).and_return({ :nil => nil })
|
75
|
-
subject.load_config
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should process erb in the config" do
|
79
|
-
transformed = <<-Y
|
80
|
-
my_db:
|
81
|
-
database: one
|
82
|
-
Y
|
83
|
-
YAML.should_receive(:load).with(transformed).and_return({ "my_db" => { "database" => "one" } })
|
84
|
-
subject.load_config
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'use ActiveRecord::Base.configuration' do
|
88
|
-
it 'when config file different with it' do
|
89
|
-
::ActiveRecord::Base.stub(:configurations).and_return({ "my_db" =>{ "database" => "two"} })
|
90
|
-
subject.load_config
|
91
|
-
subject.connection_hash.should eq({ "database" => "two"})
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'use config file' do
|
96
|
-
it 'when config file same with it' do
|
97
|
-
::ActiveRecord::Base.stub(:configurations).and_return({ "my_db" =>{ "database" => "one"} })
|
98
|
-
subject.load_config
|
99
|
-
subject.connection_hash.should eq({ "database" => "one"})
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'when ::ActiveRecord::Base.configurations nil' do
|
103
|
-
::ActiveRecord::Base.stub(:configurations).and_return(nil)
|
104
|
-
subject.load_config
|
105
|
-
subject.connection_hash.should eq({ "database" => "one"})
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'when ::ActiveRecord::Base.configurations empty' do
|
109
|
-
::ActiveRecord::Base.stub(:configurations).and_return({})
|
110
|
-
subject.load_config
|
111
|
-
subject.connection_hash.should eq({ "database" => "one"})
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should store the relevant config in connection_hash" do
|
116
|
-
subject.load_config
|
117
|
-
subject.connection_hash.should eq( "database" => "one" )
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should skip config if config file is not available" do
|
121
|
-
File.should_receive(:file?).with(config_location).and_return(false)
|
122
|
-
subject.load_config
|
123
|
-
subject.connection_hash.should_not be
|
124
|
-
end
|
125
|
-
|
126
|
-
it "skips the file when the model is set" do
|
127
|
-
subject.db = FakeModel
|
128
|
-
YAML.should_not_receive(:load)
|
129
|
-
subject.load_config
|
130
|
-
subject.connection_hash.should_not be
|
131
|
-
end
|
132
|
-
|
133
|
-
it "skips the file when the db is set to :default" do
|
134
|
-
# to avoid https://github.com/bmabey/database_cleaner/issues/72
|
135
|
-
subject.db = :default
|
136
|
-
YAML.should_not_receive(:load)
|
137
|
-
subject.load_config
|
138
|
-
subject.connection_hash.should_not be
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "connection_hash" do
|
144
|
-
it "should store connection_hash" do
|
145
|
-
subject.connection_hash = { :key => "value" }
|
146
|
-
subject.connection_hash.should eq( :key => "value" )
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "connection_class" do
|
151
|
-
it { expect { subject.connection_class }.to_not raise_error }
|
152
|
-
it "should default to ActiveRecord::Base" do
|
153
|
-
subject.connection_class.should eq ::ActiveRecord::Base
|
154
|
-
end
|
155
|
-
|
156
|
-
context "with database models" do
|
157
|
-
context "connection_hash is set" do
|
158
|
-
it "allows for database models to be passed in" do
|
159
|
-
subject.db = FakeModel
|
160
|
-
subject.connection_hash = { }
|
161
|
-
subject.load_config
|
162
|
-
subject.connection_class.should eq FakeModel
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context "connection_hash is not set" do
|
167
|
-
it "allows for database models to be passed in" do
|
168
|
-
subject.db = FakeModel
|
169
|
-
subject.connection_class.should eq FakeModel
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
context "when connection_hash is set" do
|
175
|
-
let(:hash) { double("hash") }
|
176
|
-
before { ::ActiveRecord::Base.stub(:respond_to?).and_return(false) }
|
177
|
-
before { subject.stub(:connection_hash).and_return(hash) }
|
178
|
-
|
179
|
-
it "establish a connection using ActiveRecord::Base" do
|
180
|
-
::ActiveRecord::Base.should_receive(:establish_connection).with(hash)
|
181
|
-
|
182
|
-
subject.connection_class
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
@@ -1,176 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
require 'database_cleaner/active_record/transaction'
|
3
|
-
require 'active_record'
|
4
|
-
|
5
|
-
module DatabaseCleaner
|
6
|
-
module ActiveRecord
|
7
|
-
|
8
|
-
describe Transaction do
|
9
|
-
let (:connection) { double("connection") }
|
10
|
-
let (:connection_2) { double("connection") }
|
11
|
-
let (:connection_pool) { double("connection_pool")}
|
12
|
-
before(:each) do
|
13
|
-
::ActiveRecord::Base.stub(:connection_pool).and_return(connection_pool)
|
14
|
-
connection_pool.stub(:connections).and_return([connection])
|
15
|
-
::ActiveRecord::Base.stub(:connection).and_return(connection)
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#start" do
|
19
|
-
[:begin_transaction, :begin_db_transaction].each do |begin_transaction_method|
|
20
|
-
context "using #{begin_transaction_method}" do
|
21
|
-
before do
|
22
|
-
connection.stub(:transaction)
|
23
|
-
connection.stub(begin_transaction_method)
|
24
|
-
connection.stub(:respond_to?).with(:begin_transaction).and_return(:begin_transaction == begin_transaction_method)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should increment open transactions if possible" do
|
28
|
-
connection.stub(:respond_to?).with(:increment_open_transactions).and_return(true)
|
29
|
-
connection.should_receive(:increment_open_transactions)
|
30
|
-
Transaction.new.start
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should tell ActiveRecord to increment connection if its not possible to increment current connection" do
|
34
|
-
connection.stub(:respond_to?).with(:increment_open_transactions).and_return(false)
|
35
|
-
::ActiveRecord::Base.should_receive(:increment_open_transactions)
|
36
|
-
Transaction.new.start
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should start a transaction" do
|
40
|
-
connection.stub(:respond_to?).with(:increment_open_transactions).and_return(true)
|
41
|
-
connection.stub(:increment_open_transactions)
|
42
|
-
connection.should_receive(begin_transaction_method)
|
43
|
-
connection.should_receive(:transaction)
|
44
|
-
Transaction.new.start
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "#clean" do
|
51
|
-
context "manual accounting of transaction count" do
|
52
|
-
it "should start a transaction" do
|
53
|
-
connection.should_receive(:open_transactions).and_return(1)
|
54
|
-
|
55
|
-
connection.stub(:decrement_open_transactions)
|
56
|
-
|
57
|
-
connection.should_receive(:rollback_db_transaction)
|
58
|
-
Transaction.new.clean
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should decrement open transactions if possible" do
|
62
|
-
connection.should_receive(:open_transactions).and_return(1)
|
63
|
-
|
64
|
-
connection.stub(:respond_to?).with(:decrement_open_transactions).and_return(true)
|
65
|
-
connection.stub(:respond_to?).with(:rollback_transaction_records, true).and_return(false)
|
66
|
-
connection.stub(:respond_to?).with(:rollback_transaction).and_return(false)
|
67
|
-
connection.stub(:rollback_db_transaction)
|
68
|
-
|
69
|
-
connection.should_receive(:decrement_open_transactions)
|
70
|
-
Transaction.new.clean
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should not try to decrement or rollback if open_transactions is 0 for whatever reason" do
|
74
|
-
connection.should_receive(:open_transactions).and_return(0)
|
75
|
-
|
76
|
-
Transaction.new.clean
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should decrement connection via ActiveRecord::Base if connection won't" do
|
80
|
-
connection.should_receive(:open_transactions).and_return(1)
|
81
|
-
connection.stub(:respond_to?).with(:decrement_open_transactions).and_return(false)
|
82
|
-
connection.stub(:respond_to?).with(:rollback_transaction_records, true).and_return(false)
|
83
|
-
connection.stub(:respond_to?).with(:rollback_transaction).and_return(false)
|
84
|
-
connection.stub(:rollback_db_transaction)
|
85
|
-
|
86
|
-
::ActiveRecord::Base.should_receive(:decrement_open_transactions)
|
87
|
-
Transaction.new.clean
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should rollback open transactions in all connections" do
|
91
|
-
connection_pool.stub(:connections).and_return([connection, connection_2])
|
92
|
-
|
93
|
-
connection.should_receive(:open_transactions).and_return(1)
|
94
|
-
connection.stub(:respond_to?).with(:decrement_open_transactions).and_return(false)
|
95
|
-
connection.stub(:respond_to?).with(:rollback_transaction_records, true).and_return(false)
|
96
|
-
connection.stub(:respond_to?).with(:rollback_transaction).and_return(false)
|
97
|
-
connection.stub(:rollback_db_transaction)
|
98
|
-
|
99
|
-
connection_2.should_receive(:open_transactions).and_return(1)
|
100
|
-
connection_2.stub(:respond_to?).with(:decrement_open_transactions).and_return(false)
|
101
|
-
connection_2.stub(:respond_to?).with(:rollback_transaction_records, true).and_return(false)
|
102
|
-
connection_2.stub(:respond_to?).with(:rollback_transaction).and_return(false)
|
103
|
-
connection_2.stub(:rollback_db_transaction)
|
104
|
-
|
105
|
-
::ActiveRecord::Base.should_receive(:decrement_open_transactions).twice
|
106
|
-
Transaction.new.clean
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should rollback open transactions in all connections with an open transaction" do
|
110
|
-
connection_pool.stub(:connections).and_return([connection, connection_2])
|
111
|
-
|
112
|
-
connection.should_receive(:open_transactions).and_return(1)
|
113
|
-
connection.stub(:respond_to?).with(:decrement_open_transactions).and_return(false)
|
114
|
-
connection.stub(:respond_to?).with(:rollback_transaction_records, true).and_return(false)
|
115
|
-
connection.stub(:respond_to?).with(:rollback_transaction).and_return(false)
|
116
|
-
connection.stub(:rollback_db_transaction)
|
117
|
-
|
118
|
-
connection_2.should_receive(:open_transactions).and_return(0)
|
119
|
-
|
120
|
-
::ActiveRecord::Base.should_receive(:decrement_open_transactions).exactly(1).times
|
121
|
-
Transaction.new.clean
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "automatic accounting of transaction count (AR 4)" do
|
126
|
-
before {stub_const("ActiveRecord::VERSION::MAJOR", 4) }
|
127
|
-
|
128
|
-
it "should start a transaction" do
|
129
|
-
connection.stub(:rollback_db_transaction)
|
130
|
-
connection.should_receive(:open_transactions).and_return(1)
|
131
|
-
|
132
|
-
connection.should_not_receive(:decrement_open_transactions)
|
133
|
-
connection.should_receive(:rollback_transaction)
|
134
|
-
Transaction.new.clean
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should decrement open transactions if possible" do
|
138
|
-
connection.stub(:rollback_transaction)
|
139
|
-
connection.should_receive(:open_transactions).and_return(1)
|
140
|
-
|
141
|
-
connection.should_not_receive(:decrement_open_transactions)
|
142
|
-
Transaction.new.clean
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should not try to decrement or rollback if open_transactions is 0 for whatever reason" do
|
146
|
-
connection.should_receive(:open_transactions).and_return(0)
|
147
|
-
|
148
|
-
Transaction.new.clean
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should decrement connection via ActiveRecord::Base if connection won't" do
|
152
|
-
connection.should_receive(:open_transactions).and_return(1)
|
153
|
-
connection.stub(:respond_to?).with(:rollback_transaction_records, true).and_return(false)
|
154
|
-
connection.stub(:respond_to?).with(:rollback_transaction).and_return(true)
|
155
|
-
connection.stub(:rollback_transaction)
|
156
|
-
|
157
|
-
::ActiveRecord::Base.should_not_receive(:decrement_open_transactions)
|
158
|
-
Transaction.new.clean
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe "#connection_maintains_transaction_count?" do
|
164
|
-
it "should return true if the major active record version is < 4" do
|
165
|
-
stub_const("ActiveRecord::VERSION::MAJOR", 3)
|
166
|
-
Transaction.new.connection_maintains_transaction_count?.should be_true
|
167
|
-
end
|
168
|
-
it "should return false if the major active record version is > 3" do
|
169
|
-
stub_const("ActiveRecord::VERSION::MAJOR", 4)
|
170
|
-
Transaction.new.connection_maintains_transaction_count?.should be_false
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'active_record'
|
3
|
-
require 'support/active_record/mysql2_setup'
|
4
|
-
require 'database_cleaner/active_record/truncation'
|
5
|
-
require 'database_cleaner/active_record/truncation/shared_fast_truncation'
|
6
|
-
|
7
|
-
module ActiveRecord
|
8
|
-
module ConnectionAdapters
|
9
|
-
describe do
|
10
|
-
before(:all) { active_record_mysql2_setup }
|
11
|
-
|
12
|
-
let(:connection) { active_record_mysql2_connection }
|
13
|
-
|
14
|
-
describe "#truncate_table" do
|
15
|
-
it "should truncate the table" do
|
16
|
-
2.times { User.create }
|
17
|
-
|
18
|
-
connection.truncate_table('users')
|
19
|
-
User.count.should eq 0
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should reset AUTO_INCREMENT index of table" do
|
23
|
-
2.times { User.create }
|
24
|
-
User.delete_all
|
25
|
-
|
26
|
-
connection.truncate_table('users')
|
27
|
-
|
28
|
-
User.create.id.should eq 1
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it_behaves_like "an adapter with pre-count truncation" do
|
33
|
-
let(:connection) { active_record_mysql2_connection }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'active_record'
|
3
|
-
require 'support/active_record/mysql_setup'
|
4
|
-
require 'database_cleaner/active_record/truncation'
|
5
|
-
require 'database_cleaner/active_record/truncation/shared_fast_truncation'
|
6
|
-
|
7
|
-
module ActiveRecord
|
8
|
-
module ConnectionAdapters
|
9
|
-
describe do
|
10
|
-
before(:all) { active_record_mysql_setup }
|
11
|
-
|
12
|
-
let(:connection) { active_record_mysql_connection }
|
13
|
-
|
14
|
-
describe "#truncate_table" do
|
15
|
-
it "should truncate the table" do
|
16
|
-
2.times { User.create }
|
17
|
-
|
18
|
-
connection.truncate_table('users')
|
19
|
-
User.count.should eq 0
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should reset AUTO_INCREMENT index of table" do
|
23
|
-
2.times { User.create }
|
24
|
-
User.delete_all
|
25
|
-
|
26
|
-
connection.truncate_table('users')
|
27
|
-
|
28
|
-
User.create.id.should eq 1
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it_behaves_like "an adapter with pre-count truncation" do
|
33
|
-
let(:connection) { active_record_mysql_connection }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|