database_cleaner 1.8.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/lib/database_cleaner.rb +1 -47
  3. metadata +11 -478
  4. data/CONTRIBUTE.markdown +0 -27
  5. data/Gemfile.lock +0 -325
  6. data/History.rdoc +0 -497
  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 -280
  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 -11
  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 -4
  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 -10
  31. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/base.rb +0 -16
  32. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation.rb +0 -64
  33. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
  34. data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +0 -5
  35. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner-mongo_mapper.rb +0 -1
  36. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +0 -4
  37. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/base.rb +0 -24
  38. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb +0 -35
  39. data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +0 -5
  40. data/adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb +0 -1
  41. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +0 -10
  42. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/base.rb +0 -20
  43. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb +0 -26
  44. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb +0 -38
  45. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb +0 -65
  46. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/truncation.rb +0 -49
  47. data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +0 -5
  48. data/adapters/database_cleaner-moped/lib/database_cleaner-moped.rb +0 -1
  49. data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +0 -10
  50. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/base.rb +0 -39
  51. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/truncation.rb +0 -9
  52. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/truncation_base.rb +0 -44
  53. data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +0 -5
  54. data/adapters/database_cleaner-neo4j/lib/database_cleaner-neo4j.rb +0 -1
  55. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +0 -6
  56. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/base.rb +0 -66
  57. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/deletion.rb +0 -16
  58. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/transaction.rb +0 -35
  59. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/truncation.rb +0 -9
  60. data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +0 -5
  61. data/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb +0 -1
  62. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +0 -12
  63. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb +0 -24
  64. data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +0 -5
  65. data/adapters/database_cleaner-redis/lib/database_cleaner-redis.rb +0 -1
  66. data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +0 -4
  67. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/base.rb +0 -41
  68. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/truncation.rb +0 -26
  69. data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +0 -5
  70. data/adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb +0 -1
  71. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel.rb +0 -6
  72. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/base.rb +0 -26
  73. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/deletion.rb +0 -47
  74. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb +0 -40
  75. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/truncation.rb +0 -79
  76. data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +0 -5
  77. data/cucumber.yml +0 -1
  78. data/lib/database_cleaner/base.rb +0 -153
  79. data/lib/database_cleaner/configuration.rb +0 -135
  80. data/lib/database_cleaner/cucumber.rb +0 -3
  81. data/lib/database_cleaner/deprecation.rb +0 -26
  82. data/lib/database_cleaner/generic/base.rb +0 -29
  83. data/lib/database_cleaner/generic/transaction.rb +0 -11
  84. data/lib/database_cleaner/generic/truncation.rb +0 -40
  85. data/lib/database_cleaner/null_strategy.rb +0 -20
  86. data/lib/database_cleaner/orm_autodetector.rb +0 -41
  87. data/lib/database_cleaner/safeguard.rb +0 -107
  88. data/lib/database_cleaner/spec.rb +0 -2
  89. data/lib/database_cleaner/spec/database_helper.rb +0 -82
  90. data/lib/database_cleaner/spec/shared_examples.rb +0 -15
  91. data/lib/database_cleaner/version.rb +0 -3
@@ -1,5 +0,0 @@
1
- module DatabaseCleaner
2
- module ActiveRecord
3
- VERSION = "1.8.0"
4
- end
5
- end
@@ -1 +0,0 @@
1
- require "database_cleaner/couch_potato"
@@ -1,11 +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
- module DatabaseCleaner::CouchPotato
7
- def self.default_strategy
8
- :truncation
9
- end
10
- end
11
-
@@ -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.8.0"
4
- end
5
- end
@@ -1 +0,0 @@
1
- require "database_cleaner/data_mapper"
@@ -1,4 +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"
@@ -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.8.0"
4
- end
5
- end
@@ -1 +0,0 @@
1
- require "database_cleaner/mongo"
@@ -1,10 +0,0 @@
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
-
@@ -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,64 +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
- module DatabaseCleaner
6
- module Mongo
7
- class Truncation
8
- include ::DatabaseCleaner::Generic::Base
9
- include ::DatabaseCleaner::Generic::Truncation
10
- include TruncationMixin
11
- include Base
12
- private
13
-
14
- def database
15
- db
16
- end
17
-
18
- def collections_cache
19
- @@collections_cache ||= {}
20
- end
21
-
22
- def mongoid_collection_names
23
- @@mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names|
24
- ObjectSpace.each_object(Class) do |klass|
25
- (names[klass.db.name] << klass.collection_name) if valid_collection_name?(klass)
26
- end
27
- end
28
- end
29
-
30
- def not_caching(db_name, list)
31
- @@not_caching ||= {}
32
-
33
- unless @@not_caching.has_key?(db_name)
34
- @@not_caching[db_name] = true
35
-
36
- puts "Not caching collection names for db #{db_name}. Missing these from models: #{list}"
37
- end
38
- end
39
-
40
- def collections
41
- return collections_cache[database.name] if collections_cache.has_key?(database.name)
42
- db_collections = database.collections.select { |c| c.name !~ /^system\./ }
43
-
44
- missing_collections = mongoid_collection_names[database.name] - db_collections.map(&:name)
45
-
46
- if missing_collections.empty?
47
- collections_cache[database.name] = db_collections
48
- else
49
- not_caching(database.name, missing_collections)
50
- end
51
-
52
- db_collections
53
- end
54
-
55
- private
56
-
57
- def valid_collection_name?(klass)
58
- klass.ancestors.map(&:to_s).include?('Mongoid::Document') &&
59
- !klass.embedded &&
60
- !klass.collection_name.empty?
61
- end
62
- end
63
- end
64
- 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,5 +0,0 @@
1
- module DatabaseCleaner
2
- module Mongo
3
- VERSION = "1.8.0"
4
- end
5
- end
@@ -1 +0,0 @@
1
- require "database_cleaner/mongo_mapper"