database_cleaner 1.7.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/lib/database_cleaner.rb +1 -12
  3. metadata +17 -417
  4. data/CONTRIBUTE.markdown +0 -28
  5. data/Gemfile.lock +0 -286
  6. data/History.rdoc +0 -453
  7. data/LICENSE +0 -20
  8. data/README.markdown +0 -541
  9. data/Rakefile +0 -40
  10. data/TODO +0 -3
  11. data/VERSION.yml +0 -4
  12. data/cucumber.yml +0 -1
  13. data/lib/database_cleaner/active_record/base.rb +0 -92
  14. data/lib/database_cleaner/active_record/deletion.rb +0 -108
  15. data/lib/database_cleaner/active_record/transaction.rb +0 -59
  16. data/lib/database_cleaner/active_record/truncation.rb +0 -275
  17. data/lib/database_cleaner/base.rb +0 -166
  18. data/lib/database_cleaner/configuration.rb +0 -131
  19. data/lib/database_cleaner/couch_potato/base.rb +0 -7
  20. data/lib/database_cleaner/couch_potato/truncation.rb +0 -28
  21. data/lib/database_cleaner/cucumber.rb +0 -3
  22. data/lib/database_cleaner/data_mapper/base.rb +0 -21
  23. data/lib/database_cleaner/data_mapper/transaction.rb +0 -28
  24. data/lib/database_cleaner/data_mapper/truncation.rb +0 -172
  25. data/lib/database_cleaner/generic/base.rb +0 -29
  26. data/lib/database_cleaner/generic/transaction.rb +0 -11
  27. data/lib/database_cleaner/generic/truncation.rb +0 -40
  28. data/lib/database_cleaner/mongo/base.rb +0 -16
  29. data/lib/database_cleaner/mongo/truncation.rb +0 -62
  30. data/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
  31. data/lib/database_cleaner/mongo2/base.rb +0 -16
  32. data/lib/database_cleaner/mongo2/truncation_mixin.rb +0 -39
  33. data/lib/database_cleaner/mongo_mapper/base.rb +0 -20
  34. data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
  35. data/lib/database_cleaner/mongoid/base.rb +0 -20
  36. data/lib/database_cleaner/mongoid/truncation.rb +0 -49
  37. data/lib/database_cleaner/moped/base.rb +0 -39
  38. data/lib/database_cleaner/moped/truncation.rb +0 -9
  39. data/lib/database_cleaner/moped/truncation_base.rb +0 -40
  40. data/lib/database_cleaner/neo4j/base.rb +0 -62
  41. data/lib/database_cleaner/neo4j/deletion.rb +0 -16
  42. data/lib/database_cleaner/neo4j/transaction.rb +0 -35
  43. data/lib/database_cleaner/neo4j/truncation.rb +0 -9
  44. data/lib/database_cleaner/null_strategy.rb +0 -20
  45. data/lib/database_cleaner/ohm/truncation.rb +0 -15
  46. data/lib/database_cleaner/redis/base.rb +0 -37
  47. data/lib/database_cleaner/redis/truncation.rb +0 -26
  48. data/lib/database_cleaner/safeguard.rb +0 -72
  49. data/lib/database_cleaner/sequel/base.rb +0 -22
  50. data/lib/database_cleaner/sequel/deletion.rb +0 -47
  51. data/lib/database_cleaner/sequel/transaction.rb +0 -40
  52. data/lib/database_cleaner/sequel/truncation.rb +0 -78
@@ -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,11 +0,0 @@
1
- module DatabaseCleaner
2
- module Generic
3
- module Transaction
4
- def initialize(opts = {})
5
- if !opts.empty?
6
- raise ArgumentError, "Options are not available for transaction strategies."
7
- end
8
- end
9
- end
10
- end
11
- 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,9 +0,0 @@
1
- require 'database_cleaner/moped/truncation_base'
2
-
3
- module DatabaseCleaner
4
- module Moped
5
- class Truncation
6
- include ::DatabaseCleaner::Moped::TruncationBase
7
- end
8
- end
9
- 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