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.
Files changed (170) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTE.markdown +1 -2
  3. data/Gemfile.lock +132 -93
  4. data/History.rdoc +67 -0
  5. data/README.markdown +88 -217
  6. data/Rakefile +12 -8
  7. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/base.rb +14 -5
  8. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/deletion.rb +19 -17
  9. data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/truncation.rb +25 -20
  10. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/version.rb +5 -0
  11. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record.rb +6 -0
  12. data/adapters/database_cleaner-active_record/lib/database_cleaner-active_record.rb +1 -0
  13. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb +5 -0
  14. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb +11 -0
  15. data/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb +1 -0
  16. data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/base.rb +4 -0
  17. data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/truncation.rb +4 -3
  18. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb +5 -0
  19. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb +4 -0
  20. data/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb +1 -0
  21. data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/truncation.rb +2 -0
  22. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +5 -0
  23. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb +10 -0
  24. data/adapters/database_cleaner-mongo/lib/database_cleaner-mongo.rb +1 -0
  25. data/{lib → adapters/database_cleaner-mongo_mapper/lib}/database_cleaner/mongo_mapper/base.rb +4 -0
  26. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb +35 -0
  27. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +5 -0
  28. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +4 -0
  29. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner-mongo_mapper.rb +1 -0
  30. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb +26 -0
  31. data/{lib/database_cleaner/mongo2/truncation_mixin.rb → adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb} +3 -4
  32. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb +65 -0
  33. data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongoid/truncation.rb +6 -6
  34. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +5 -0
  35. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +10 -0
  36. data/adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb +1 -0
  37. data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/base.rb +1 -1
  38. data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/truncation_base.rb +4 -0
  39. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +5 -0
  40. data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +10 -0
  41. data/adapters/database_cleaner-moped/lib/database_cleaner-moped.rb +1 -0
  42. data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/base.rb +4 -0
  43. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +5 -0
  44. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +6 -0
  45. data/adapters/database_cleaner-neo4j/lib/database_cleaner-neo4j.rb +1 -0
  46. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb +24 -0
  47. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +5 -0
  48. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +12 -0
  49. data/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb +1 -0
  50. data/{lib → adapters/database_cleaner-redis/lib}/database_cleaner/redis/base.rb +4 -0
  51. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +5 -0
  52. data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +4 -0
  53. data/adapters/database_cleaner-redis/lib/database_cleaner-redis.rb +1 -0
  54. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/base.rb +4 -0
  55. data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/truncation.rb +16 -15
  56. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +5 -0
  57. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel.rb +6 -0
  58. data/adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb +1 -0
  59. data/lib/database_cleaner/base.rb +94 -105
  60. data/lib/database_cleaner/configuration.rb +87 -83
  61. data/lib/database_cleaner/deprecation.rb +26 -0
  62. data/lib/database_cleaner/null_strategy.rb +6 -6
  63. data/lib/database_cleaner/orm_autodetector.rb +41 -0
  64. data/lib/database_cleaner/safeguard.rb +107 -0
  65. data/lib/database_cleaner/spec/database_helper.rb +82 -0
  66. data/lib/database_cleaner/spec/shared_examples.rb +15 -0
  67. data/lib/database_cleaner/spec.rb +2 -0
  68. data/lib/database_cleaner/version.rb +3 -0
  69. data/lib/database_cleaner.rb +41 -2
  70. metadata +113 -126
  71. data/VERSION.yml +0 -4
  72. data/examples/Gemfile +0 -1
  73. data/examples/Gemfile.lock +0 -1
  74. data/examples/config/database.yml.example +0 -8
  75. data/examples/config/redis.yml +0 -8
  76. data/examples/db/sqlite_databases_go_here +0 -0
  77. data/examples/features/example.feature +0 -11
  78. data/examples/features/example_multiple_db.feature +0 -23
  79. data/examples/features/example_multiple_orm.feature +0 -22
  80. data/examples/features/step_definitions/activerecord_steps.rb +0 -31
  81. data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
  82. data/examples/features/step_definitions/datamapper_steps.rb +0 -37
  83. data/examples/features/step_definitions/mongoid_steps.rb +0 -23
  84. data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
  85. data/examples/features/step_definitions/neo4j_steps.rb +0 -23
  86. data/examples/features/step_definitions/ohm_steps.rb +0 -31
  87. data/examples/features/step_definitions/redis_steps.rb +0 -31
  88. data/examples/features/step_definitions/translation_steps.rb +0 -55
  89. data/examples/features/support/env.rb +0 -61
  90. data/examples/lib/activerecord_models.rb +0 -41
  91. data/examples/lib/couchpotato_models.rb +0 -61
  92. data/examples/lib/datamapper_models.rb +0 -50
  93. data/examples/lib/mongoid_models.rb +0 -44
  94. data/examples/lib/mongomapper_models.rb +0 -51
  95. data/examples/lib/neo4j_models.rb +0 -17
  96. data/examples/lib/ohm_models.rb +0 -43
  97. data/examples/lib/redis_models.rb +0 -65
  98. data/examples/lib/sequel_models.rb +0 -9
  99. data/features/cleaning.feature +0 -30
  100. data/features/cleaning_default_strategy.feature +0 -23
  101. data/features/cleaning_multiple_dbs.feature +0 -22
  102. data/features/cleaning_multiple_orms.feature +0 -67
  103. data/features/step_definitions/database_cleaner_steps.rb +0 -33
  104. data/features/support/env.rb +0 -4
  105. data/features/support/feature_runner.rb +0 -39
  106. data/lib/database_cleaner/mongo2/base.rb +0 -16
  107. data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
  108. data/lib/database_cleaner/ohm/truncation.rb +0 -15
  109. data/spec/database_cleaner/active_record/base_spec.rb +0 -188
  110. data/spec/database_cleaner/active_record/transaction_spec.rb +0 -176
  111. data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +0 -38
  112. data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +0 -38
  113. data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +0 -75
  114. data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +0 -40
  115. data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +0 -40
  116. data/spec/database_cleaner/active_record/truncation_spec.rb +0 -180
  117. data/spec/database_cleaner/base_spec.rb +0 -617
  118. data/spec/database_cleaner/configuration_spec.rb +0 -345
  119. data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
  120. data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
  121. data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
  122. data/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +0 -41
  123. data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
  124. data/spec/database_cleaner/generic/base_spec.rb +0 -61
  125. data/spec/database_cleaner/generic/truncation_spec.rb +0 -118
  126. data/spec/database_cleaner/mongo/mongo_examples.rb +0 -26
  127. data/spec/database_cleaner/mongo/truncation_spec.rb +0 -72
  128. data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
  129. data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
  130. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
  131. data/spec/database_cleaner/moped/moped_examples.rb +0 -32
  132. data/spec/database_cleaner/moped/truncation_spec.rb +0 -80
  133. data/spec/database_cleaner/neo4j/base_spec.rb +0 -43
  134. data/spec/database_cleaner/neo4j/transaction_spec.rb +0 -25
  135. data/spec/database_cleaner/null_strategy_spec.rb +0 -28
  136. data/spec/database_cleaner/ohm/truncation_spec.rb +0 -70
  137. data/spec/database_cleaner/redis/base_spec.rb +0 -43
  138. data/spec/database_cleaner/redis/truncation_spec.rb +0 -63
  139. data/spec/database_cleaner/sequel/base_spec.rb +0 -32
  140. data/spec/database_cleaner/sequel/deletion_spec.rb +0 -58
  141. data/spec/database_cleaner/sequel/transaction_spec.rb +0 -21
  142. data/spec/database_cleaner/sequel/truncation/sqlite3_spec.rb +0 -0
  143. data/spec/database_cleaner/sequel/truncation_spec.rb +0 -182
  144. data/spec/database_cleaner/shared_strategy.rb +0 -15
  145. data/spec/rcov.opts +0 -1
  146. data/spec/spec_helper.rb +0 -21
  147. data/spec/support/active_record/database_setup.rb +0 -6
  148. data/spec/support/active_record/migrations/20150101010000_create_users.rb +0 -14
  149. data/spec/support/active_record/migrations/20150101020000_create_agents.rb +0 -14
  150. data/spec/support/active_record/mysql2_setup.rb +0 -39
  151. data/spec/support/active_record/mysql_setup.rb +0 -38
  152. data/spec/support/active_record/postgresql_setup.rb +0 -48
  153. data/spec/support/active_record/schema_setup.rb +0 -17
  154. data/spec/support/active_record/sqlite3_setup.rb +0 -40
  155. data/spec/support/data_mapper/schema_setup.rb +0 -15
  156. data/spec/support/data_mapper/sqlite3_setup.rb +0 -39
  157. /data/{lib → adapters/database_cleaner-active_record/lib}/database_cleaner/active_record/transaction.rb +0 -0
  158. /data/{lib → adapters/database_cleaner-couch_potato/lib}/database_cleaner/couch_potato/base.rb +0 -0
  159. /data/{lib → adapters/database_cleaner-couch_potato/lib}/database_cleaner/couch_potato/truncation.rb +0 -0
  160. /data/{lib → adapters/database_cleaner-data_mapper/lib}/database_cleaner/data_mapper/transaction.rb +0 -0
  161. /data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/base.rb +0 -0
  162. /data/{lib → adapters/database_cleaner-mongo/lib}/database_cleaner/mongo/truncation_mixin.rb +0 -0
  163. /data/{lib → adapters/database_cleaner-mongoid/lib}/database_cleaner/mongoid/base.rb +0 -0
  164. /data/{lib → adapters/database_cleaner-moped/lib}/database_cleaner/moped/truncation.rb +0 -0
  165. /data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/deletion.rb +0 -0
  166. /data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/transaction.rb +0 -0
  167. /data/{lib → adapters/database_cleaner-neo4j/lib}/database_cleaner/neo4j/truncation.rb +0 -0
  168. /data/{lib → adapters/database_cleaner-redis/lib}/database_cleaner/redis/truncation.rb +0 -0
  169. /data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/deletion.rb +0 -0
  170. /data/{lib → adapters/database_cleaner-sequel/lib}/database_cleaner/sequel/transaction.rb +0 -0
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module ActiveRecord
3
+ VERSION = "1.8.0"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'database_cleaner/active_record/version'
2
+ require 'database_cleaner'
3
+ require 'database_cleaner/active_record/deletion'
4
+ require 'database_cleaner/active_record/transaction'
5
+ require 'database_cleaner/active_record/truncation'
6
+
@@ -0,0 +1 @@
1
+ require "database_cleaner/active_record"
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module CouchPotato
3
+ VERSION = "1.8.0"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require "database_cleaner/couch_potato/version"
2
+ require "database_cleaner"
3
+ require "database_cleaner/couch_potato/base"
4
+ require "database_cleaner/couch_potato/truncation"
5
+
6
+ module DatabaseCleaner::CouchPotato
7
+ def self.default_strategy
8
+ :truncation
9
+ end
10
+ end
11
+
@@ -0,0 +1 @@
1
+ require "database_cleaner/couch_potato"
@@ -5,6 +5,10 @@ module DatabaseCleaner
5
5
  %w[truncation transaction]
6
6
  end
7
7
 
8
+ def self.default_strategy
9
+ :transaction
10
+ end
11
+
8
12
  module Base
9
13
  include ::DatabaseCleaner::Generic::Base
10
14
 
@@ -1,5 +1,6 @@
1
1
  require "database_cleaner/generic/truncation"
2
2
  require 'database_cleaner/data_mapper/base'
3
+ require 'data_mapper'
3
4
 
4
5
  module DataMapper
5
6
  module Adapters
@@ -20,7 +21,7 @@ module DataMapper
20
21
 
21
22
  class MysqlAdapter < DataObjectsAdapter
22
23
 
23
- # taken from http://github.com/godfat/dm-mapping/tree/master
24
+ # taken from https://github.com/godfat/dm-mapping/tree/master
24
25
  def storage_names(repository = :default)
25
26
  select 'SHOW TABLES'
26
27
  end
@@ -44,7 +45,7 @@ module DataMapper
44
45
 
45
46
  module SqliteAdapterMethods
46
47
 
47
- # taken from http://github.com/godfat/dm-mapping/tree/master
48
+ # taken from https://github.com/godfat/dm-mapping/tree/master
48
49
  def storage_names(repository = :default)
49
50
  # activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 177
50
51
  sql = <<-SQL
@@ -92,7 +93,7 @@ module DataMapper
92
93
  # maybe codes below gets some postgres/datamapper user going, though.
93
94
  class PostgresAdapter < DataObjectsAdapter
94
95
 
95
- # taken from http://github.com/godfat/dm-mapping/tree/master
96
+ # taken from https://github.com/godfat/dm-mapping/tree/master
96
97
  def storage_names(repository = :default)
97
98
  sql = <<-SQL
98
99
  SELECT table_name FROM "information_schema"."tables"
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module DataMapper
3
+ VERSION = "1.8.0"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "database_cleaner/data_mapper/version"
2
+ require "database_cleaner"
3
+ require "database_cleaner/data_mapper/transaction"
4
+ require "database_cleaner/data_mapper/truncation"
@@ -0,0 +1 @@
1
+ require "database_cleaner/data_mapper"
@@ -1,9 +1,11 @@
1
1
  require 'database_cleaner/mongo/base'
2
+ require 'database_cleaner/generic/base'
2
3
  require 'database_cleaner/generic/truncation'
3
4
  require 'database_cleaner/mongo/truncation_mixin'
4
5
  module DatabaseCleaner
5
6
  module Mongo
6
7
  class Truncation
8
+ include ::DatabaseCleaner::Generic::Base
7
9
  include ::DatabaseCleaner::Generic::Truncation
8
10
  include TruncationMixin
9
11
  include Base
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module Mongo
3
+ VERSION = "1.8.0"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'database_cleaner/mongo/version'
2
+ require 'database_cleaner'
3
+ require 'database_cleaner/mongo/truncation'
4
+
5
+ module DatabaseCleaner::Mongo
6
+ def self.default_strategy
7
+ :truncation
8
+ end
9
+ end
10
+
@@ -0,0 +1 @@
1
+ require "database_cleaner/mongo"
@@ -5,6 +5,10 @@ module DatabaseCleaner
5
5
  %w[truncation]
6
6
  end
7
7
 
8
+ def self.default_strategy
9
+ :truncation
10
+ end
11
+
8
12
  module Base
9
13
  include ::DatabaseCleaner::Generic::Base
10
14
 
@@ -0,0 +1,35 @@
1
+ require 'database_cleaner/mongo_mapper/base'
2
+ require 'database_cleaner/generic/truncation'
3
+
4
+ module DatabaseCleaner
5
+ module MongoMapper
6
+ class Truncation
7
+ include ::DatabaseCleaner::MongoMapper::Base
8
+ include ::DatabaseCleaner::Generic::Truncation
9
+
10
+ def clean
11
+ if @only
12
+ collections.each { |c| c.send(truncate_method_name) if @only.include?(c.name) }
13
+ else
14
+ collections.each { |c| c.send(truncate_method_name) unless @tables_to_exclude.include?(c.name) }
15
+ end
16
+ true
17
+ end
18
+
19
+ private
20
+
21
+ def collections
22
+ database.collections.select { |c| c.name !~ /^system\./ }
23
+ end
24
+
25
+ def truncate_method_name
26
+ # This constant only exists in the 2.x series.
27
+ defined?(::Mongo::VERSION) ? :delete_many : :remove
28
+ end
29
+
30
+ def database
31
+ ::MongoMapper.database
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module MongoMapper
3
+ VERSION = "1.8.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "database_cleaner/mongo_mapper/version"
2
+ require "database_cleaner"
3
+ require "database_cleaner/mongo_mapper/truncation"
4
+
@@ -0,0 +1 @@
1
+ require "database_cleaner/mongo_mapper"
@@ -0,0 +1,26 @@
1
+ module DatabaseCleaner
2
+ module Mongoid
3
+ module Mongo1TruncationMixin
4
+ def clean
5
+ if @only
6
+ collections.each { |c| c.send(truncate_method_name) if @only.include?(c.name) }
7
+ else
8
+ collections.each { |c| c.send(truncate_method_name) unless @tables_to_exclude.include?(c.name) }
9
+ end
10
+ true
11
+ end
12
+
13
+ private
14
+
15
+ def collections
16
+ database.collections.select { |c| c.name !~ /^system\./ }
17
+ end
18
+
19
+ def truncate_method_name
20
+ # This constant only exists in the 2.x series.
21
+ defined?(::Mongo::VERSION) ? :delete_many : :remove
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -1,7 +1,6 @@
1
1
  module DatabaseCleaner
2
- module Mongo2
3
- module TruncationMixin
4
-
2
+ module Mongoid
3
+ module Mongo2TruncationMixin
5
4
  def clean
6
5
  if @only
7
6
  collections.each { |c| database[c].find.delete_many if @only.include?(c) }
@@ -33,7 +32,7 @@ module DatabaseCleaner
33
32
  # name
34
33
  # end
35
34
  end
36
-
37
35
  end
38
36
  end
39
37
  end
38
+
@@ -0,0 +1,65 @@
1
+ require 'database_cleaner/generic/base'
2
+ require 'database_cleaner/generic/truncation'
3
+
4
+ module DatabaseCleaner
5
+ module Mongoid
6
+ module MongoidTruncationMixin
7
+ include ::DatabaseCleaner::Generic::Base
8
+ include ::DatabaseCleaner::Generic::Truncation
9
+
10
+ def db=(desired_db)
11
+ @db = desired_db
12
+ end
13
+
14
+ def db
15
+ @db ||= :default
16
+ end
17
+
18
+ def host_port=(desired_host)
19
+ @host = desired_host
20
+ end
21
+
22
+ def host
23
+ @host ||= '127.0.0.1:27017'
24
+ end
25
+
26
+ def db_version
27
+ @db_version ||= session.command('buildinfo' => 1)['version']
28
+ end
29
+
30
+ def clean
31
+ if @only
32
+ collections.each { |c| session[c].find.remove_all if @only.include?(c) }
33
+ else
34
+ collections.each { |c| session[c].find.remove_all unless @tables_to_exclude.include?(c) }
35
+ end
36
+ wait_for_removals_to_finish
37
+ true
38
+ end
39
+
40
+ private
41
+
42
+ def collections
43
+ if db != :default
44
+ session.use(db)
45
+ end
46
+
47
+ if db_version.split('.').first.to_i >= 3
48
+ session.command(listCollections: 1, filter: { 'name' => { '$not' => /.?system\.|\$/ } })['cursor']['firstBatch'].map do |collection|
49
+ collection['name']
50
+ end
51
+ else
52
+ session['system.namespaces'].find(name: { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
53
+ _, name = collection['name'].split('.', 2)
54
+ name
55
+ end
56
+ end
57
+ end
58
+
59
+ def wait_for_removals_to_finish
60
+ session.command(getlasterror: 1)
61
+ end
62
+ end
63
+ end
64
+ end
65
+
@@ -1,8 +1,8 @@
1
1
  require 'database_cleaner/mongoid/base'
2
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'
3
+ require 'database_cleaner/mongoid/mongo1_truncation_mixin'
4
+ require 'database_cleaner/mongoid/mongo2_truncation_mixin'
5
+ require 'database_cleaner/mongoid/mongoid_truncation_mixin'
6
6
  require 'mongoid/version'
7
7
 
8
8
  module DatabaseCleaner
@@ -13,7 +13,7 @@ module DatabaseCleaner
13
13
 
14
14
  if ::Mongoid::VERSION < '3'
15
15
 
16
- include ::DatabaseCleaner::Mongo::TruncationMixin
16
+ include ::DatabaseCleaner::Mongoid::Mongo1TruncationMixin
17
17
 
18
18
  private
19
19
 
@@ -23,7 +23,7 @@ module DatabaseCleaner
23
23
 
24
24
  elsif ::Mongoid::VERSION < '5'
25
25
 
26
- include ::DatabaseCleaner::Moped::TruncationBase
26
+ include ::DatabaseCleaner::Mongoid::MongoidTruncationMixin
27
27
 
28
28
  private
29
29
 
@@ -41,7 +41,7 @@ module DatabaseCleaner
41
41
 
42
42
  else
43
43
 
44
- include ::DatabaseCleaner::Mongo2::TruncationMixin
44
+ include ::DatabaseCleaner::Mongoid::Mongo2TruncationMixin
45
45
 
46
46
  end
47
47
  end
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module Mongoid
3
+ VERSION = "1.8.1"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "database_cleaner/mongoid/version"
2
+ require "database_cleaner"
3
+ require "database_cleaner/mongoid/truncation"
4
+
5
+ module DatabaseCleaner::Mongoid
6
+ def self.default_strategy
7
+ :truncation
8
+ end
9
+ end
10
+
@@ -0,0 +1 @@
1
+ require "database_cleaner/mongoid"
@@ -32,7 +32,7 @@ module DatabaseCleaner
32
32
  private
33
33
 
34
34
  def session
35
- ::Moped::Session.new([host], database: db)
35
+ @session ||= ::Moped::Session.new([host], database: db)
36
36
  end
37
37
  end
38
38
  end
@@ -13,6 +13,7 @@ module DatabaseCleaner
13
13
  else
14
14
  collections.each { |c| session[c].find.remove_all unless @tables_to_exclude.include?(c) }
15
15
  end
16
+ wait_for_removals_to_finish
16
17
  true
17
18
  end
18
19
 
@@ -35,6 +36,9 @@ module DatabaseCleaner
35
36
  end
36
37
  end
37
38
 
39
+ def wait_for_removals_to_finish
40
+ session.command(getlasterror: 1)
41
+ end
38
42
  end
39
43
  end
40
44
  end
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module Moped
3
+ VERSION = "1.8.0"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "database_cleaner/moped/version"
2
+ require "database_cleaner"
3
+ require "database_cleaner/moped/truncation"
4
+
5
+ module DatabaseCleaner::Moped
6
+ def self.default_strategy
7
+ :truncation
8
+ end
9
+ end
10
+
@@ -0,0 +1 @@
1
+ require "database_cleaner/moped"
@@ -5,6 +5,10 @@ module DatabaseCleaner
5
5
  %w[transaction truncation deletion]
6
6
  end
7
7
 
8
+ def self.default_strategy
9
+ :transaction
10
+ end
11
+
8
12
  module Base
9
13
  include ::DatabaseCleaner::Generic::Base
10
14
 
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module Neo4j
3
+ VERSION = "1.8.0"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require "database_cleaner/neo4j/version"
2
+ require "database_cleaner"
3
+ require "database_cleaner/neo4j/transaction"
4
+ require "database_cleaner/neo4j/truncation"
5
+ require "database_cleaner/neo4j/deletion"
6
+
@@ -0,0 +1 @@
1
+ require "database_cleaner/neo4j"
@@ -0,0 +1,24 @@
1
+ begin # when database_cleaner-ohm is loaded as a gem
2
+ require 'database_cleaner/redis/truncation'
3
+ rescue LoadError # when database_cleaner is loaded as a gem
4
+ $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../../../../adapters/database_cleaner-redis/lib")
5
+ require 'database_cleaner/redis/truncation'
6
+ end
7
+
8
+ module DatabaseCleaner
9
+ module Ohm
10
+ def self.available_strategies
11
+ %w(truncation)
12
+ end
13
+
14
+ class Truncation < ::DatabaseCleaner::Redis::Truncation
15
+
16
+ private
17
+
18
+ def default_redis
19
+ ::Ohm.redis
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module Ohm
3
+ VERSION = "1.8.1"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require "database_cleaner/ohm/version"
2
+ require "database_cleaner"
3
+ require "database_cleaner/ohm/truncation"
4
+
5
+ DatabaseCleaner.deprecate "The Ohm adapter for DatabaseCleaner is deprecated, and will be removed in v2.0. Please use the Redis adapter instead."
6
+
7
+ module DatabaseCleaner::Ohm
8
+ def self.default_strategy
9
+ :truncation
10
+ end
11
+ end
12
+
@@ -0,0 +1 @@
1
+ require "database_cleaner/ohm"
@@ -6,6 +6,10 @@ module DatabaseCleaner
6
6
  %w{truncation}
7
7
  end
8
8
 
9
+ def self.default_strategy
10
+ :truncation
11
+ end
12
+
9
13
  module Base
10
14
  include ::DatabaseCleaner::Generic::Base
11
15
 
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module Redis
3
+ VERSION = "1.8.0"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "database_cleaner/redis/version"
2
+ require "database_cleaner"
3
+ require "database_cleaner/redis/truncation"
4
+
@@ -0,0 +1 @@
1
+ require "database_cleaner/redis"
@@ -5,6 +5,10 @@ module DatabaseCleaner
5
5
  %w(truncation transaction deletion)
6
6
  end
7
7
 
8
+ def self.default_strategy
9
+ :transaction
10
+ end
11
+
8
12
  module Base
9
13
  include ::DatabaseCleaner::Generic::Base
10
14
 
@@ -14,39 +14,40 @@ module DatabaseCleaner
14
14
  def clean
15
15
  return unless dirty?
16
16
 
17
+ tables = tables_to_truncate(db)
18
+
19
+ # Count rows before truncating
20
+ if pre_count?
21
+ tables = pre_count_tables(tables)
22
+ end
23
+
17
24
  case db.database_type
18
25
  when :postgres
19
26
  # PostgreSQL requires all tables with FKs to be truncates in the same command, or have the CASCADE keyword
20
27
  # appended. Bulk truncation without CASCADE is:
21
28
  # * Safer. Tables outside of tables_to_truncate won't be affected.
22
29
  # * Faster. Less roundtrips to the db.
23
- unless (tables = tables_to_truncate(db)).empty?
24
- all_tables = tables.map { |t| %("#{t}") }.join(',')
25
- db.run "TRUNCATE TABLE #{all_tables};"
30
+ unless tables.empty?
31
+ tables_sql = tables.map { |t| %("#{t}") }.join(',')
32
+ db.run "TRUNCATE TABLE #{tables_sql} RESTART IDENTITY;"
26
33
  end
27
34
  else
28
- tables = tables_to_truncate(db)
29
-
30
- if pre_count?
31
- # Count rows before truncating
32
- pre_count_truncate_tables(db, tables)
33
- else
34
- # Truncate each table normally
35
- truncate_tables(db, tables)
36
- end
35
+ truncate_tables(db, tables)
37
36
  end
38
37
  end
39
38
 
40
39
  private
41
40
 
42
- def pre_count_truncate_tables(db, tables)
43
- tables = tables.reject { |table| db[table.to_sym].count == 0 }
44
- truncate_tables(db, tables)
41
+ def pre_count_tables tables
42
+ tables.reject { |table| db[table.to_sym].count == 0 }
45
43
  end
46
44
 
47
45
  def truncate_tables(db, tables)
48
46
  tables.each do |table|
49
47
  db[table.to_sym].truncate
48
+ if db.database_type == :sqlite && db.table_exists?(:sqlite_sequence)
49
+ db[:sqlite_sequence].where(name: table).delete
50
+ end
50
51
  end
51
52
  end
52
53
 
@@ -0,0 +1,5 @@
1
+ module DatabaseCleaner
2
+ module Sequel
3
+ VERSION = "1.8.0"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require "database_cleaner/sequel/version"
2
+ require "database_cleaner"
3
+ require "database_cleaner/sequel/truncation"
4
+ require "database_cleaner/sequel/transaction"
5
+ require "database_cleaner/sequel/deletion"
6
+
@@ -0,0 +1 @@
1
+ require "database_cleaner/sequel"