database_cleaner 1.99.0.beta → 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/lib/database_cleaner.rb +1 -47
  3. metadata +11 -481
  4. data/CONTRIBUTE.markdown +0 -27
  5. data/Gemfile.lock +0 -324
  6. data/History.rdoc +0 -514
  7. data/LICENSE +0 -20
  8. data/README.markdown +0 -389
  9. data/Rakefile +0 -44
  10. data/TODO +0 -3
  11. data/adapters/database_cleaner-active_record/lib/database_cleaner-active_record.rb +0 -1
  12. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record.rb +0 -6
  13. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/base.rb +0 -101
  14. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/deletion.rb +0 -108
  15. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/transaction.rb +0 -59
  16. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/truncation.rb +0 -288
  17. data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/version.rb +0 -5
  18. data/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb +0 -1
  19. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb +0 -13
  20. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/base.rb +0 -7
  21. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/truncation.rb +0 -28
  22. data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb +0 -5
  23. data/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb +0 -1
  24. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb +0 -6
  25. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/base.rb +0 -25
  26. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/transaction.rb +0 -28
  27. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/truncation.rb +0 -173
  28. data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb +0 -5
  29. data/adapters/database_cleaner-mongo/lib/database_cleaner-mongo.rb +0 -1
  30. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb +0 -11
  31. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/base.rb +0 -16
  32. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/deletion.rb +0 -8
  33. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation.rb +0 -74
  34. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
  35. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +0 -5
  36. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner-mongo_mapper.rb +0 -1
  37. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +0 -5
  38. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/base.rb +0 -24
  39. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb +0 -35
  40. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +0 -5
  41. data/adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb +0 -1
  42. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +0 -11
  43. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/base.rb +0 -20
  44. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/deletion.rb +0 -10
  45. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb +0 -26
  46. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb +0 -38
  47. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb +0 -65
  48. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/truncation.rb +0 -49
  49. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +0 -5
  50. data/adapters/database_cleaner-moped/lib/database_cleaner-moped.rb +0 -1
  51. data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +0 -12
  52. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/base.rb +0 -39
  53. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/truncation.rb +0 -9
  54. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/truncation_base.rb +0 -44
  55. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +0 -5
  56. data/adapters/database_cleaner-neo4j/lib/database_cleaner-neo4j.rb +0 -1
  57. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +0 -7
  58. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/base.rb +0 -66
  59. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/deletion.rb +0 -16
  60. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/transaction.rb +0 -35
  61. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/truncation.rb +0 -9
  62. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +0 -5
  63. data/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb +0 -1
  64. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +0 -12
  65. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb +0 -24
  66. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +0 -5
  67. data/adapters/database_cleaner-redis/lib/database_cleaner-redis.rb +0 -1
  68. data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +0 -5
  69. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/base.rb +0 -45
  70. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/deletion.rb +0 -9
  71. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/truncation.rb +0 -26
  72. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +0 -5
  73. data/adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb +0 -1
  74. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel.rb +0 -6
  75. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/base.rb +0 -26
  76. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/deletion.rb +0 -47
  77. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb +0 -40
  78. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/truncation.rb +0 -79
  79. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +0 -5
  80. data/cucumber.yml +0 -1
  81. data/lib/database_cleaner/base.rb +0 -169
  82. data/lib/database_cleaner/configuration.rb +0 -136
  83. data/lib/database_cleaner/cucumber.rb +0 -3
  84. data/lib/database_cleaner/deprecation.rb +0 -26
  85. data/lib/database_cleaner/generic/base.rb +0 -29
  86. data/lib/database_cleaner/generic/transaction.rb +0 -11
  87. data/lib/database_cleaner/generic/truncation.rb +0 -40
  88. data/lib/database_cleaner/null_strategy.rb +0 -20
  89. data/lib/database_cleaner/orm_autodetector.rb +0 -41
  90. data/lib/database_cleaner/safeguard.rb +0 -107
  91. data/lib/database_cleaner/spec.rb +0 -2
  92. data/lib/database_cleaner/spec/database_helper.rb +0 -82
  93. data/lib/database_cleaner/spec/shared_examples.rb +0 -15
  94. data/lib/database_cleaner/version.rb +0 -3
@@ -1,5 +0,0 @@
1
- module DatabaseCleaner
2
- module ActiveRecord
3
- VERSION = "1.99.0.beta"
4
- end
5
- end
@@ -1 +0,0 @@
1
- require "database_cleaner/couch_potato"
@@ -1,13 +0,0 @@
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
- DatabaseCleaner.deprecate "Due to lack of maintenance, the Couch Potato adapter for DatabaseCleaner is deprecated, and will be removed in v2.0 with no replacement. Contact us if you are interested in resurrecting this adapter!"
7
-
8
- module DatabaseCleaner::CouchPotato
9
- def self.default_strategy
10
- :truncation
11
- end
12
- end
13
-
@@ -1,7 +0,0 @@
1
- module DatabaseCleaner
2
- module CouchPotato
3
- def self.available_strategies
4
- %w[truncation]
5
- end
6
- end
7
- end
@@ -1,28 +0,0 @@
1
- require 'database_cleaner/generic/truncation'
2
-
3
- module DatabaseCleaner
4
- module CouchPotato
5
- class Truncation
6
- include ::DatabaseCleaner::Generic::Truncation
7
-
8
- def initialize(options = {})
9
- if options.has_key?(:only) || options.has_key?(:except)
10
- raise ArgumentError, "The :only and :except options are not available for use with CouchPotato/CouchDB."
11
- elsif !options.empty?
12
- raise ArgumentError, "Unsupported option. You specified #{options.keys.join(',')}."
13
- end
14
- super
15
- end
16
-
17
- def clean
18
- database.recreate!
19
- end
20
-
21
- private
22
-
23
- def database
24
- ::CouchPotato.couchrest_database
25
- end
26
- end
27
- end
28
- end
@@ -1,5 +0,0 @@
1
- module DatabaseCleaner
2
- module CouchPotato
3
- VERSION = "1.99.0.beta"
4
- end
5
- end
@@ -1 +0,0 @@
1
- require "database_cleaner/data_mapper"
@@ -1,6 +0,0 @@
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"
5
-
6
- DatabaseCleaner.deprecate "Due to lack of maintenance, the DataMapper adapter for DatabaseCleaner is deprecated, and will be removed in v2.0 with no replacement. Contact us if you are interested in resurrecting this adapter!"
@@ -1,25 +0,0 @@
1
- require 'database_cleaner/generic/base'
2
- module DatabaseCleaner
3
- module DataMapper
4
- def self.available_strategies
5
- %w[truncation transaction]
6
- end
7
-
8
- def self.default_strategy
9
- :transaction
10
- end
11
-
12
- module Base
13
- include ::DatabaseCleaner::Generic::Base
14
-
15
- def db=(desired_db)
16
- @db = desired_db
17
- end
18
-
19
- def db
20
- @db ||= :default
21
- end
22
-
23
- end
24
- end
25
- end
@@ -1,28 +0,0 @@
1
- require 'database_cleaner/data_mapper/base'
2
- require 'database_cleaner/generic/transaction'
3
-
4
- module DatabaseCleaner::DataMapper
5
- class Transaction
6
- include ::DatabaseCleaner::DataMapper::Base
7
- include ::DatabaseCleaner::Generic::Transaction
8
-
9
- def start(repository = self.db)
10
- ::DataMapper.repository(repository) do |r|
11
- transaction = DataMapper::Transaction.new(r)
12
- transaction.begin
13
- r.adapter.push_transaction(transaction)
14
- end
15
- end
16
-
17
- def clean(repository = self.db)
18
- ::DataMapper.repository(repository) do |r|
19
- adapter = r.adapter
20
- while adapter.current_transaction
21
- adapter.current_transaction.rollback
22
- adapter.pop_transaction
23
- end
24
- end
25
- end
26
-
27
- end
28
- end
@@ -1,173 +0,0 @@
1
- require "database_cleaner/generic/truncation"
2
- require 'database_cleaner/data_mapper/base'
3
- require 'data_mapper'
4
-
5
- module DataMapper
6
- module Adapters
7
-
8
- class DataObjectsAdapter
9
-
10
- def storage_names(repository = :default)
11
- raise NotImplementedError
12
- end
13
-
14
- def truncate_tables(table_names)
15
- table_names.each do |table_name|
16
- truncate_table table_name
17
- end
18
- end
19
-
20
- end
21
-
22
- class MysqlAdapter < DataObjectsAdapter
23
-
24
- # taken from https://github.com/godfat/dm-mapping/tree/master
25
- def storage_names(repository = :default)
26
- select 'SHOW TABLES'
27
- end
28
-
29
- def truncate_table(table_name)
30
- execute("TRUNCATE TABLE #{quote_name(table_name)};")
31
- end
32
-
33
- # copied from activerecord
34
- def disable_referential_integrity
35
- old = select("SELECT @@FOREIGN_KEY_CHECKS;")
36
- begin
37
- execute("SET FOREIGN_KEY_CHECKS = 0;")
38
- yield
39
- ensure
40
- execute("SET FOREIGN_KEY_CHECKS = ?", *old)
41
- end
42
- end
43
-
44
- end
45
-
46
- module SqliteAdapterMethods
47
-
48
- # taken from https://github.com/godfat/dm-mapping/tree/master
49
- def storage_names(repository = :default)
50
- # activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 177
51
- sql = <<-SQL
52
- SELECT name
53
- FROM sqlite_master
54
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
55
- SQL
56
- # activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 181
57
- select(sql)
58
- end
59
-
60
- def truncate_table(table_name)
61
- execute("DELETE FROM #{quote_name(table_name)};")
62
- if uses_sequence?
63
- execute("DELETE FROM sqlite_sequence where name = '#{table_name}';")
64
- end
65
- end
66
-
67
- # this is a no-op copied from activerecord
68
- # i didn't find out if/how this is possible
69
- # activerecord also doesn't do more here
70
- def disable_referential_integrity
71
- yield
72
- end
73
-
74
- private
75
-
76
- # Returns a boolean indicating if the SQLite database is using the sqlite_sequence table.
77
- def uses_sequence?
78
- sql = <<-SQL
79
- SELECT name FROM sqlite_master
80
- WHERE type='table' AND name='sqlite_sequence'
81
- SQL
82
- select(sql).first
83
- end
84
- end
85
-
86
- class SqliteAdapter; include SqliteAdapterMethods; end
87
- class Sqlite3Adapter; include SqliteAdapterMethods; end
88
-
89
- # FIXME
90
- # i don't know if this works
91
- # i basically just copied activerecord code to get a rough idea what they do.
92
- # i don't have postgres available, so i won't be the one to write this.
93
- # maybe codes below gets some postgres/datamapper user going, though.
94
- class PostgresAdapter < DataObjectsAdapter
95
-
96
- # taken from https://github.com/godfat/dm-mapping/tree/master
97
- def storage_names(repository = :default)
98
- sql = <<-SQL
99
- SELECT table_name FROM "information_schema"."tables"
100
- WHERE table_schema = current_schema() and table_type = 'BASE TABLE'
101
- SQL
102
- select(sql)
103
- end
104
-
105
- def truncate_table(table_name)
106
- execute("TRUNCATE TABLE #{quote_name(table_name)} RESTART IDENTITY CASCADE;")
107
- end
108
-
109
- # override to use a single statement
110
- def truncate_tables(table_names)
111
- quoted_names = table_names.collect { |n| quote_name(n) }.join(', ')
112
- execute("TRUNCATE TABLE #{quoted_names} RESTART IDENTITY;")
113
- end
114
-
115
- # FIXME
116
- # copied from activerecord
117
- def supports_disable_referential_integrity?
118
- version = select("SHOW server_version")[0][0].split('.')
119
- (version[0].to_i >= 8 && version[1].to_i >= 1) ? true : false
120
- rescue
121
- return false
122
- end
123
-
124
- # FIXME
125
- # copied unchanged from activerecord
126
- def disable_referential_integrity(repository = :default)
127
- if supports_disable_referential_integrity? then
128
- execute(storage_names(repository).collect do |name|
129
- "ALTER TABLE #{quote_name(name)} DISABLE TRIGGER ALL"
130
- end.join(";"))
131
- end
132
- yield
133
- ensure
134
- if supports_disable_referential_integrity? then
135
- execute(storage_names(repository).collect do |name|
136
- "ALTER TABLE #{quote_name(name)} ENABLE TRIGGER ALL"
137
- end.join(";"))
138
- end
139
- end
140
-
141
- end
142
-
143
- end
144
- end
145
-
146
-
147
- module DatabaseCleaner
148
- module DataMapper
149
- class Truncation
150
- include ::DatabaseCleaner::DataMapper::Base
151
- include ::DatabaseCleaner::Generic::Truncation
152
-
153
- def clean(repository = self.db)
154
- adapter = ::DataMapper.repository(repository).adapter
155
- adapter.disable_referential_integrity do
156
- adapter.truncate_tables(tables_to_truncate(repository))
157
- end
158
- end
159
-
160
- private
161
-
162
- def tables_to_truncate(repository = self.db)
163
- (@only || ::DataMapper.repository(repository).adapter.storage_names(repository)) - @tables_to_exclude
164
- end
165
-
166
- # overwritten
167
- def migration_storage_names
168
- %w[migration_info]
169
- end
170
-
171
- end
172
- end
173
- end
@@ -1,5 +0,0 @@
1
- module DatabaseCleaner
2
- module DataMapper
3
- VERSION = "1.99.0.beta"
4
- end
5
- end
@@ -1 +0,0 @@
1
- require "database_cleaner/mongo"
@@ -1,11 +0,0 @@
1
- require 'database_cleaner/mongo/version'
2
- require 'database_cleaner'
3
- require 'database_cleaner/mongo/truncation'
4
- require 'database_cleaner/mongo/deletion'
5
-
6
- module DatabaseCleaner::Mongo
7
- def self.default_strategy
8
- :truncation
9
- end
10
- end
11
-
@@ -1,16 +0,0 @@
1
- module DatabaseCleaner
2
- module Mongo
3
- def self.available_strategies
4
- %w[truncation deletion]
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,8 +0,0 @@
1
- require 'database_cleaner/mongo/truncation'
2
-
3
- module DatabaseCleaner
4
- module Mongo
5
- class Deletion < Truncation
6
- end
7
- end
8
- end
@@ -1,74 +0,0 @@
1
- require 'database_cleaner/mongo/base'
2
- require 'database_cleaner/generic/base'
3
- require 'database_cleaner/generic/truncation'
4
- require 'database_cleaner/mongo/truncation_mixin'
5
- require 'database_cleaner/deprecation'
6
-
7
- module DatabaseCleaner
8
- module Mongo
9
- class Truncation
10
- include ::DatabaseCleaner::Generic::Base
11
- include ::DatabaseCleaner::Generic::Truncation
12
- include TruncationMixin
13
- include Base
14
-
15
- def initialize(opts={})
16
- super
17
- if !opts.has_key?(:cache_tables) || opts[:cache_tables]
18
- DatabaseCleaner.deprecate "The mongo adapter caches collection names between cleanings. However, this behavior can introduce test-order-dependency issues, because the collections that exist after the first test has executed are saved and used for the remainder of the suite. This means that any collection created during the subsequent tests are not cleaned! This is fixed in database_cleaner-mongo 2.0 by removing this collection caching functionality altogether. To ease the transition into this new behavior, it can be opted into by specifying the `:cache_tables` option to false: `DatabaseCleaner[:mongo].strategy = :deletion, cache_tables: false`. For more information, see https://github.com/DatabaseCleaner/database_cleaner/pull/646"
19
- end
20
- end
21
-
22
- private
23
-
24
- def database
25
- db
26
- end
27
-
28
- def collections_cache
29
- @collections_cache ||= {}
30
- end
31
-
32
- def mongoid_collection_names
33
- @mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names|
34
- ObjectSpace.each_object(Class) do |klass|
35
- (names[klass.db.name] << klass.collection_name) if valid_collection_name?(klass)
36
- end
37
- end
38
- end
39
-
40
- def not_caching(db_name, list)
41
- @not_caching ||= {}
42
-
43
- unless @not_caching.has_key?(db_name)
44
- @not_caching[db_name] = true
45
-
46
- puts "Not caching collection names for db #{db_name}. Missing these from models: #{list}"
47
- end
48
- end
49
-
50
- def collections
51
- return collections_cache[database.name] if collections_cache.has_key?(database.name) && @cache_tables
52
- db_collections = database.collections.select { |c| c.name !~ /^system\./ }
53
-
54
- missing_collections = mongoid_collection_names[database.name] - db_collections.map(&:name)
55
-
56
- if missing_collections.empty?
57
- collections_cache[database.name] = db_collections
58
- else
59
- not_caching(database.name, missing_collections)
60
- end
61
-
62
- db_collections
63
- end
64
-
65
- private
66
-
67
- def valid_collection_name?(klass)
68
- klass.ancestors.map(&:to_s).include?('Mongoid::Document') &&
69
- !klass.embedded &&
70
- !klass.collection_name.empty?
71
- end
72
- end
73
- end
74
- 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