database_cleaner 1.6.2 → 2.0.0
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.
- checksums.yaml +5 -5
- data/lib/database_cleaner.rb +1 -8
- metadata +18 -498
- data/CONTRIBUTE.markdown +0 -28
- data/Gemfile.lock +0 -286
- data/History.rdoc +0 -430
- data/LICENSE +0 -20
- data/README.markdown +0 -518
- data/Rakefile +0 -40
- data/TODO +0 -3
- data/VERSION.yml +0 -4
- data/cucumber.yml +0 -1
- 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/active_record/base.rb +0 -92
- data/lib/database_cleaner/active_record/deletion.rb +0 -106
- data/lib/database_cleaner/active_record/transaction.rb +0 -59
- data/lib/database_cleaner/active_record/truncation.rb +0 -275
- data/lib/database_cleaner/base.rb +0 -164
- data/lib/database_cleaner/configuration.rb +0 -131
- data/lib/database_cleaner/couch_potato/base.rb +0 -7
- data/lib/database_cleaner/couch_potato/truncation.rb +0 -28
- data/lib/database_cleaner/cucumber.rb +0 -3
- data/lib/database_cleaner/data_mapper/base.rb +0 -21
- data/lib/database_cleaner/data_mapper/transaction.rb +0 -28
- data/lib/database_cleaner/data_mapper/truncation.rb +0 -172
- data/lib/database_cleaner/generic/base.rb +0 -29
- data/lib/database_cleaner/generic/transaction.rb +0 -11
- data/lib/database_cleaner/generic/truncation.rb +0 -40
- data/lib/database_cleaner/mongo/base.rb +0 -16
- data/lib/database_cleaner/mongo/truncation.rb +0 -62
- data/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
- data/lib/database_cleaner/mongo2/base.rb +0 -16
- data/lib/database_cleaner/mongo2/truncation_mixin.rb +0 -39
- data/lib/database_cleaner/mongo_mapper/base.rb +0 -20
- data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
- data/lib/database_cleaner/mongoid/base.rb +0 -20
- data/lib/database_cleaner/mongoid/truncation.rb +0 -49
- data/lib/database_cleaner/moped/base.rb +0 -39
- data/lib/database_cleaner/moped/truncation.rb +0 -9
- data/lib/database_cleaner/moped/truncation_base.rb +0 -40
- data/lib/database_cleaner/neo4j/base.rb +0 -62
- data/lib/database_cleaner/neo4j/deletion.rb +0 -16
- data/lib/database_cleaner/neo4j/transaction.rb +0 -35
- data/lib/database_cleaner/neo4j/truncation.rb +0 -9
- data/lib/database_cleaner/null_strategy.rb +0 -20
- data/lib/database_cleaner/ohm/truncation.rb +0 -15
- data/lib/database_cleaner/redis/base.rb +0 -37
- data/lib/database_cleaner/redis/truncation.rb +0 -26
- data/lib/database_cleaner/sequel/base.rb +0 -22
- data/lib/database_cleaner/sequel/deletion.rb +0 -47
- data/lib/database_cleaner/sequel/transaction.rb +0 -40
- data/lib/database_cleaner/sequel/truncation.rb +0 -78
- 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
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
require "database_cleaner/generic/truncation"
|
|
2
|
-
require 'database_cleaner/data_mapper/base'
|
|
3
|
-
|
|
4
|
-
module DataMapper
|
|
5
|
-
module Adapters
|
|
6
|
-
|
|
7
|
-
class DataObjectsAdapter
|
|
8
|
-
|
|
9
|
-
def storage_names(repository = :default)
|
|
10
|
-
raise NotImplementedError
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def truncate_tables(table_names)
|
|
14
|
-
table_names.each do |table_name|
|
|
15
|
-
truncate_table table_name
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class MysqlAdapter < DataObjectsAdapter
|
|
22
|
-
|
|
23
|
-
# taken from http://github.com/godfat/dm-mapping/tree/master
|
|
24
|
-
def storage_names(repository = :default)
|
|
25
|
-
select 'SHOW TABLES'
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def truncate_table(table_name)
|
|
29
|
-
execute("TRUNCATE TABLE #{quote_name(table_name)};")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# copied from activerecord
|
|
33
|
-
def disable_referential_integrity
|
|
34
|
-
old = select("SELECT @@FOREIGN_KEY_CHECKS;")
|
|
35
|
-
begin
|
|
36
|
-
execute("SET FOREIGN_KEY_CHECKS = 0;")
|
|
37
|
-
yield
|
|
38
|
-
ensure
|
|
39
|
-
execute("SET FOREIGN_KEY_CHECKS = ?", *old)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
module SqliteAdapterMethods
|
|
46
|
-
|
|
47
|
-
# taken from http://github.com/godfat/dm-mapping/tree/master
|
|
48
|
-
def storage_names(repository = :default)
|
|
49
|
-
# activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 177
|
|
50
|
-
sql = <<-SQL
|
|
51
|
-
SELECT name
|
|
52
|
-
FROM sqlite_master
|
|
53
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
|
54
|
-
SQL
|
|
55
|
-
# activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 181
|
|
56
|
-
select(sql)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def truncate_table(table_name)
|
|
60
|
-
execute("DELETE FROM #{quote_name(table_name)};")
|
|
61
|
-
if uses_sequence?
|
|
62
|
-
execute("DELETE FROM sqlite_sequence where name = '#{table_name}';")
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# this is a no-op copied from activerecord
|
|
67
|
-
# i didn't find out if/how this is possible
|
|
68
|
-
# activerecord also doesn't do more here
|
|
69
|
-
def disable_referential_integrity
|
|
70
|
-
yield
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
private
|
|
74
|
-
|
|
75
|
-
# Returns a boolean indicating if the SQLite database is using the sqlite_sequence table.
|
|
76
|
-
def uses_sequence?
|
|
77
|
-
sql = <<-SQL
|
|
78
|
-
SELECT name FROM sqlite_master
|
|
79
|
-
WHERE type='table' AND name='sqlite_sequence'
|
|
80
|
-
SQL
|
|
81
|
-
select(sql).first
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
class SqliteAdapter; include SqliteAdapterMethods; end
|
|
86
|
-
class Sqlite3Adapter; include SqliteAdapterMethods; end
|
|
87
|
-
|
|
88
|
-
# FIXME
|
|
89
|
-
# i don't know if this works
|
|
90
|
-
# i basically just copied activerecord code to get a rough idea what they do.
|
|
91
|
-
# i don't have postgres available, so i won't be the one to write this.
|
|
92
|
-
# maybe codes below gets some postgres/datamapper user going, though.
|
|
93
|
-
class PostgresAdapter < DataObjectsAdapter
|
|
94
|
-
|
|
95
|
-
# taken from http://github.com/godfat/dm-mapping/tree/master
|
|
96
|
-
def storage_names(repository = :default)
|
|
97
|
-
sql = <<-SQL
|
|
98
|
-
SELECT table_name FROM "information_schema"."tables"
|
|
99
|
-
WHERE table_schema = current_schema() and table_type = 'BASE TABLE'
|
|
100
|
-
SQL
|
|
101
|
-
select(sql)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def truncate_table(table_name)
|
|
105
|
-
execute("TRUNCATE TABLE #{quote_name(table_name)} RESTART IDENTITY CASCADE;")
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# override to use a single statement
|
|
109
|
-
def truncate_tables(table_names)
|
|
110
|
-
quoted_names = table_names.collect { |n| quote_name(n) }.join(', ')
|
|
111
|
-
execute("TRUNCATE TABLE #{quoted_names} RESTART IDENTITY;")
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
# FIXME
|
|
115
|
-
# copied from activerecord
|
|
116
|
-
def supports_disable_referential_integrity?
|
|
117
|
-
version = select("SHOW server_version")[0][0].split('.')
|
|
118
|
-
(version[0].to_i >= 8 && version[1].to_i >= 1) ? true : false
|
|
119
|
-
rescue
|
|
120
|
-
return false
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# FIXME
|
|
124
|
-
# copied unchanged from activerecord
|
|
125
|
-
def disable_referential_integrity(repository = :default)
|
|
126
|
-
if supports_disable_referential_integrity? then
|
|
127
|
-
execute(storage_names(repository).collect do |name|
|
|
128
|
-
"ALTER TABLE #{quote_name(name)} DISABLE TRIGGER ALL"
|
|
129
|
-
end.join(";"))
|
|
130
|
-
end
|
|
131
|
-
yield
|
|
132
|
-
ensure
|
|
133
|
-
if supports_disable_referential_integrity? then
|
|
134
|
-
execute(storage_names(repository).collect do |name|
|
|
135
|
-
"ALTER TABLE #{quote_name(name)} ENABLE TRIGGER ALL"
|
|
136
|
-
end.join(";"))
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
module DatabaseCleaner
|
|
147
|
-
module DataMapper
|
|
148
|
-
class Truncation
|
|
149
|
-
include ::DatabaseCleaner::DataMapper::Base
|
|
150
|
-
include ::DatabaseCleaner::Generic::Truncation
|
|
151
|
-
|
|
152
|
-
def clean(repository = self.db)
|
|
153
|
-
adapter = ::DataMapper.repository(repository).adapter
|
|
154
|
-
adapter.disable_referential_integrity do
|
|
155
|
-
adapter.truncate_tables(tables_to_truncate(repository))
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
private
|
|
160
|
-
|
|
161
|
-
def tables_to_truncate(repository = self.db)
|
|
162
|
-
(@only || ::DataMapper.repository(repository).adapter.storage_names(repository)) - @tables_to_exclude
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
# overwritten
|
|
166
|
-
def migration_storage_names
|
|
167
|
-
%w[migration_info]
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module ::DatabaseCleaner
|
|
2
|
-
module Generic
|
|
3
|
-
module Base
|
|
4
|
-
|
|
5
|
-
def self.included(base)
|
|
6
|
-
base.extend(ClassMethods)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def db
|
|
10
|
-
:default
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def cleaning(&block)
|
|
14
|
-
begin
|
|
15
|
-
start
|
|
16
|
-
yield
|
|
17
|
-
ensure
|
|
18
|
-
clean
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
module ClassMethods
|
|
23
|
-
def available_strategies
|
|
24
|
-
%W[]
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
module DatabaseCleaner
|
|
2
|
-
module Generic
|
|
3
|
-
module Truncation
|
|
4
|
-
def initialize(opts={})
|
|
5
|
-
if !opts.empty? && !(opts.keys - [:only, :except, :pre_count, :reset_ids, :cache_tables]).empty?
|
|
6
|
-
raise ArgumentError, "The only valid options are :only, :except, :pre_count, :reset_ids or :cache_tables. You specified #{opts.keys.join(',')}."
|
|
7
|
-
end
|
|
8
|
-
if opts.has_key?(:only) && opts.has_key?(:except)
|
|
9
|
-
raise ArgumentError, "You may only specify either :only or :except. Doing both doesn't really make sense does it?"
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
@only = opts[:only]
|
|
13
|
-
@tables_to_exclude = Array( (opts[:except] || []).dup ).flatten
|
|
14
|
-
@tables_to_exclude += migration_storage_names
|
|
15
|
-
@pre_count = opts[:pre_count]
|
|
16
|
-
@reset_ids = opts[:reset_ids]
|
|
17
|
-
@cache_tables = opts.has_key?(:cache_tables) ? !!opts[:cache_tables] : true
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def start
|
|
21
|
-
#included for compatability reasons, do nothing if you don't need to
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def clean
|
|
25
|
-
raise NotImplementedError
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
def tables_to_truncate
|
|
30
|
-
raise NotImplementedError
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# overwrite in subclasses
|
|
34
|
-
# default implementation given because migration storage need not be present
|
|
35
|
-
def migration_storage_names
|
|
36
|
-
%w[]
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module DatabaseCleaner
|
|
2
|
-
module Mongo
|
|
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 Mongo::Database)")
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
require 'database_cleaner/mongo/base'
|
|
2
|
-
require 'database_cleaner/generic/truncation'
|
|
3
|
-
require 'database_cleaner/mongo/truncation_mixin'
|
|
4
|
-
module DatabaseCleaner
|
|
5
|
-
module Mongo
|
|
6
|
-
class Truncation
|
|
7
|
-
include ::DatabaseCleaner::Generic::Truncation
|
|
8
|
-
include TruncationMixin
|
|
9
|
-
include Base
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
def database
|
|
13
|
-
db
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def collections_cache
|
|
17
|
-
@@collections_cache ||= {}
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def mongoid_collection_names
|
|
21
|
-
@@mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names|
|
|
22
|
-
ObjectSpace.each_object(Class) do |klass|
|
|
23
|
-
(names[klass.db.name] << klass.collection_name) if valid_collection_name?(klass)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def not_caching(db_name, list)
|
|
29
|
-
@@not_caching ||= {}
|
|
30
|
-
|
|
31
|
-
unless @@not_caching.has_key?(db_name)
|
|
32
|
-
@@not_caching[db_name] = true
|
|
33
|
-
|
|
34
|
-
puts "Not caching collection names for db #{db_name}. Missing these from models: #{list}"
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def collections
|
|
39
|
-
return collections_cache[database.name] if collections_cache.has_key?(database.name)
|
|
40
|
-
db_collections = database.collections.select { |c| c.name !~ /^system\./ }
|
|
41
|
-
|
|
42
|
-
missing_collections = mongoid_collection_names[database.name] - db_collections.map(&:name)
|
|
43
|
-
|
|
44
|
-
if missing_collections.empty?
|
|
45
|
-
collections_cache[database.name] = db_collections
|
|
46
|
-
else
|
|
47
|
-
not_caching(database.name, missing_collections)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
db_collections
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
private
|
|
54
|
-
|
|
55
|
-
def valid_collection_name?(klass)
|
|
56
|
-
klass.ancestors.map(&:to_s).include?('Mongoid::Document') &&
|
|
57
|
-
!klass.embedded &&
|
|
58
|
-
!klass.collection_name.empty?
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
module DatabaseCleaner
|
|
2
|
-
module Mongo
|
|
3
|
-
module TruncationMixin
|
|
4
|
-
|
|
5
|
-
def clean
|
|
6
|
-
if @only
|
|
7
|
-
collections.each { |c| c.send(truncate_method_name) if @only.include?(c.name) }
|
|
8
|
-
else
|
|
9
|
-
collections.each { |c| c.send(truncate_method_name) unless @tables_to_exclude.include?(c.name) }
|
|
10
|
-
end
|
|
11
|
-
true
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
def collections
|
|
17
|
-
database.collections.select { |c| c.name !~ /^system\./ }
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def truncate_method_name
|
|
21
|
-
# This constant only exists in the 2.x series.
|
|
22
|
-
defined?(::Mongo::VERSION) ? :delete_many : :remove
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
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,39 +0,0 @@
|
|
|
1
|
-
module DatabaseCleaner
|
|
2
|
-
module Mongo2
|
|
3
|
-
module TruncationMixin
|
|
4
|
-
|
|
5
|
-
def clean
|
|
6
|
-
if @only
|
|
7
|
-
collections.each { |c| database[c].find.delete_many if @only.include?(c) }
|
|
8
|
-
else
|
|
9
|
-
collections.each { |c| database[c].find.delete_many unless @tables_to_exclude.include?(c) }
|
|
10
|
-
end
|
|
11
|
-
true
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
def database
|
|
17
|
-
if @db.nil? || @db == :default
|
|
18
|
-
::Mongoid::Clients.default
|
|
19
|
-
else
|
|
20
|
-
::Mongoid::Clients.with_name(@db)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def collections
|
|
25
|
-
if db != :default
|
|
26
|
-
database.use(db)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
database.collections.collect { |c| c.namespace.split('.',2)[1] }
|
|
30
|
-
|
|
31
|
-
# database['system.namespaces'].find(:name => { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
|
|
32
|
-
# _, name = collection['name'].split('.', 2)
|
|
33
|
-
# name
|
|
34
|
-
# end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
require 'database_cleaner/generic/base'
|
|
2
|
-
module DatabaseCleaner
|
|
3
|
-
module MongoMapper
|
|
4
|
-
def self.available_strategies
|
|
5
|
-
%w[truncation]
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
module Base
|
|
9
|
-
include ::DatabaseCleaner::Generic::Base
|
|
10
|
-
|
|
11
|
-
def db=(desired_db)
|
|
12
|
-
@db = desired_db
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def db
|
|
16
|
-
@db ||= :default
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
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,20 +0,0 @@
|
|
|
1
|
-
require 'database_cleaner/generic/base'
|
|
2
|
-
module DatabaseCleaner
|
|
3
|
-
module Mongoid
|
|
4
|
-
def self.available_strategies
|
|
5
|
-
%w[truncation]
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
module Base
|
|
9
|
-
include ::DatabaseCleaner::Generic::Base
|
|
10
|
-
|
|
11
|
-
def db=(desired_db)
|
|
12
|
-
@db = desired_db
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def db
|
|
16
|
-
@db || :default
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
require 'database_cleaner/mongoid/base'
|
|
2
|
-
require 'database_cleaner/generic/truncation'
|
|
3
|
-
require 'database_cleaner/mongo/truncation_mixin'
|
|
4
|
-
require 'database_cleaner/mongo2/truncation_mixin'
|
|
5
|
-
require 'database_cleaner/moped/truncation_base'
|
|
6
|
-
require 'mongoid/version'
|
|
7
|
-
|
|
8
|
-
module DatabaseCleaner
|
|
9
|
-
module Mongoid
|
|
10
|
-
class Truncation
|
|
11
|
-
include ::DatabaseCleaner::Mongoid::Base
|
|
12
|
-
include ::DatabaseCleaner::Generic::Truncation
|
|
13
|
-
|
|
14
|
-
if ::Mongoid::VERSION < '3'
|
|
15
|
-
|
|
16
|
-
include ::DatabaseCleaner::Mongo::TruncationMixin
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
def database
|
|
21
|
-
::Mongoid.database
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
elsif ::Mongoid::VERSION < '5'
|
|
25
|
-
|
|
26
|
-
include ::DatabaseCleaner::Moped::TruncationBase
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
def session
|
|
31
|
-
::Mongoid::VERSION > "5.0.0" ? ::Mongoid.default_client : ::Mongoid.default_session
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def database
|
|
35
|
-
if not(@db.nil? or @db == :default)
|
|
36
|
-
::Mongoid.databases[@db]
|
|
37
|
-
else
|
|
38
|
-
::Mongoid.database
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
else
|
|
43
|
-
|
|
44
|
-
include ::DatabaseCleaner::Mongo2::TruncationMixin
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
require 'database_cleaner/generic/base'
|
|
2
|
-
|
|
3
|
-
module DatabaseCleaner
|
|
4
|
-
module Moped
|
|
5
|
-
def self.available_strategies
|
|
6
|
-
%w[truncation]
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
module Base
|
|
10
|
-
include ::DatabaseCleaner::Generic::Base
|
|
11
|
-
|
|
12
|
-
def db=(desired_db)
|
|
13
|
-
@db = desired_db
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def db
|
|
17
|
-
@db ||= :default
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def host_port=(desired_host)
|
|
21
|
-
@host = desired_host
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def host
|
|
25
|
-
@host ||= '127.0.0.1:27017'
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def db_version
|
|
29
|
-
@db_version ||= session.command('buildinfo' => 1)['version']
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
def session
|
|
35
|
-
::Moped::Session.new([host], database: db)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require 'database_cleaner/moped/base'
|
|
2
|
-
require 'database_cleaner/generic/truncation'
|
|
3
|
-
|
|
4
|
-
module DatabaseCleaner
|
|
5
|
-
module Moped
|
|
6
|
-
module TruncationBase
|
|
7
|
-
include ::DatabaseCleaner::Moped::Base
|
|
8
|
-
include ::DatabaseCleaner::Generic::Truncation
|
|
9
|
-
|
|
10
|
-
def clean
|
|
11
|
-
if @only
|
|
12
|
-
collections.each { |c| session[c].find.remove_all if @only.include?(c) }
|
|
13
|
-
else
|
|
14
|
-
collections.each { |c| session[c].find.remove_all unless @tables_to_exclude.include?(c) }
|
|
15
|
-
end
|
|
16
|
-
true
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def collections
|
|
22
|
-
if db != :default
|
|
23
|
-
session.use(db)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
if db_version.split('.').first.to_i >= 3
|
|
27
|
-
session.command(listCollections: 1, filter: { 'name' => { '$not' => /.?system\.|\$/ } })['cursor']['firstBatch'].map do |collection|
|
|
28
|
-
collection['name']
|
|
29
|
-
end
|
|
30
|
-
else
|
|
31
|
-
session['system.namespaces'].find(name: { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
|
|
32
|
-
_, name = collection['name'].split('.', 2)
|
|
33
|
-
name
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
require 'database_cleaner/generic/base'
|
|
2
|
-
module DatabaseCleaner
|
|
3
|
-
module Neo4j
|
|
4
|
-
def self.available_strategies
|
|
5
|
-
%w[transaction truncation deletion]
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
module Base
|
|
9
|
-
include ::DatabaseCleaner::Generic::Base
|
|
10
|
-
|
|
11
|
-
def db=(desired_db)
|
|
12
|
-
@db = desired_db == :default ? nil : desired_db
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def db
|
|
16
|
-
@db ||= nil
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def start
|
|
20
|
-
if db_type == :embedded_db and not session.running?
|
|
21
|
-
session.start
|
|
22
|
-
else
|
|
23
|
-
session
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def database
|
|
28
|
-
db && default_db.merge(db) || default_db
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
def default_db
|
|
34
|
-
{:type => default_db_type, :path => default_db_path}
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def default_db_type
|
|
38
|
-
:server_db
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def default_db_path(type = default_db_type)
|
|
42
|
-
type == :server_db ? 'http://localhost:7475/' : './db/test'
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def db_type
|
|
46
|
-
database[:type]
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def db_path
|
|
50
|
-
database[:path]
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def db_params
|
|
54
|
-
database.reject!{|key, value| [:type, :path].include? key }
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def session
|
|
58
|
-
@session ||= ::Neo4j::Session.open(db_type, db_path, db_params)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|