database_cleaner 1.6.2 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile.lock +3 -3
  3. data/History.rdoc +23 -0
  4. data/README.markdown +24 -1
  5. data/VERSION.yml +2 -2
  6. data/lib/database_cleaner.rb +6 -2
  7. data/lib/database_cleaner/active_record/base.rb +1 -1
  8. data/lib/database_cleaner/active_record/deletion.rb +9 -7
  9. data/lib/database_cleaner/base.rb +2 -0
  10. data/lib/database_cleaner/safeguard.rb +72 -0
  11. metadata +6 -86
  12. data/examples/Gemfile +0 -1
  13. data/examples/Gemfile.lock +0 -1
  14. data/examples/config/database.yml.example +0 -8
  15. data/examples/config/redis.yml +0 -8
  16. data/examples/db/sqlite_databases_go_here +0 -0
  17. data/examples/features/example.feature +0 -11
  18. data/examples/features/example_multiple_db.feature +0 -23
  19. data/examples/features/example_multiple_orm.feature +0 -22
  20. data/examples/features/step_definitions/activerecord_steps.rb +0 -31
  21. data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
  22. data/examples/features/step_definitions/datamapper_steps.rb +0 -37
  23. data/examples/features/step_definitions/mongoid_steps.rb +0 -23
  24. data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
  25. data/examples/features/step_definitions/neo4j_steps.rb +0 -23
  26. data/examples/features/step_definitions/ohm_steps.rb +0 -31
  27. data/examples/features/step_definitions/redis_steps.rb +0 -31
  28. data/examples/features/step_definitions/translation_steps.rb +0 -55
  29. data/examples/features/support/env.rb +0 -61
  30. data/examples/lib/activerecord_models.rb +0 -41
  31. data/examples/lib/couchpotato_models.rb +0 -61
  32. data/examples/lib/datamapper_models.rb +0 -50
  33. data/examples/lib/mongoid_models.rb +0 -44
  34. data/examples/lib/mongomapper_models.rb +0 -51
  35. data/examples/lib/neo4j_models.rb +0 -17
  36. data/examples/lib/ohm_models.rb +0 -43
  37. data/examples/lib/redis_models.rb +0 -65
  38. data/examples/lib/sequel_models.rb +0 -9
  39. data/features/cleaning.feature +0 -30
  40. data/features/cleaning_default_strategy.feature +0 -23
  41. data/features/cleaning_multiple_dbs.feature +0 -22
  42. data/features/cleaning_multiple_orms.feature +0 -67
  43. data/features/step_definitions/database_cleaner_steps.rb +0 -33
  44. data/features/support/env.rb +0 -4
  45. data/features/support/feature_runner.rb +0 -39
  46. data/spec/database_cleaner/active_record/base_spec.rb +0 -188
  47. data/spec/database_cleaner/active_record/transaction_spec.rb +0 -176
  48. data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +0 -38
  49. data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +0 -38
  50. data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +0 -75
  51. data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +0 -40
  52. data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +0 -40
  53. data/spec/database_cleaner/active_record/truncation_spec.rb +0 -180
  54. data/spec/database_cleaner/base_spec.rb +0 -617
  55. data/spec/database_cleaner/configuration_spec.rb +0 -345
  56. data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
  57. data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
  58. data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
  59. data/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +0 -41
  60. data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
  61. data/spec/database_cleaner/generic/base_spec.rb +0 -61
  62. data/spec/database_cleaner/generic/truncation_spec.rb +0 -118
  63. data/spec/database_cleaner/mongo/mongo_examples.rb +0 -26
  64. data/spec/database_cleaner/mongo/truncation_spec.rb +0 -72
  65. data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
  66. data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
  67. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
  68. data/spec/database_cleaner/moped/moped_examples.rb +0 -32
  69. data/spec/database_cleaner/moped/truncation_spec.rb +0 -80
  70. data/spec/database_cleaner/neo4j/base_spec.rb +0 -43
  71. data/spec/database_cleaner/neo4j/transaction_spec.rb +0 -25
  72. data/spec/database_cleaner/null_strategy_spec.rb +0 -28
  73. data/spec/database_cleaner/ohm/truncation_spec.rb +0 -70
  74. data/spec/database_cleaner/redis/base_spec.rb +0 -43
  75. data/spec/database_cleaner/redis/truncation_spec.rb +0 -63
  76. data/spec/database_cleaner/sequel/base_spec.rb +0 -32
  77. data/spec/database_cleaner/sequel/deletion_spec.rb +0 -58
  78. data/spec/database_cleaner/sequel/transaction_spec.rb +0 -21
  79. data/spec/database_cleaner/sequel/truncation/sqlite3_spec.rb +0 -0
  80. data/spec/database_cleaner/sequel/truncation_spec.rb +0 -182
  81. data/spec/database_cleaner/shared_strategy.rb +0 -15
  82. data/spec/rcov.opts +0 -1
  83. data/spec/spec_helper.rb +0 -21
  84. data/spec/support/active_record/database_setup.rb +0 -6
  85. data/spec/support/active_record/migrations/20150101010000_create_users.rb +0 -14
  86. data/spec/support/active_record/migrations/20150101020000_create_agents.rb +0 -14
  87. data/spec/support/active_record/mysql2_setup.rb +0 -39
  88. data/spec/support/active_record/mysql_setup.rb +0 -38
  89. data/spec/support/active_record/postgresql_setup.rb +0 -48
  90. data/spec/support/active_record/schema_setup.rb +0 -17
  91. data/spec/support/active_record/sqlite3_setup.rb +0 -40
  92. data/spec/support/data_mapper/schema_setup.rb +0 -15
  93. data/spec/support/data_mapper/sqlite3_setup.rb +0 -39
@@ -1,50 +0,0 @@
1
- require "dm-core"
2
- require "dm-transactions"
3
-
4
- #Datamapper 1.0 requires you to require dm-migrations to automigrate
5
- require "dm-migrations"
6
-
7
- # only to please activerecord API used in database_cleaner/examples/features/step_definitions
8
- # yes, i know that's lazy ...
9
-
10
- require "dm-validations"
11
- require "dm-aggregates"
12
-
13
- DataMapper.setup(:default, "sqlite3:#{DB_DIR}/datamapper_default.db")
14
- DataMapper.setup(:one, "sqlite3:#{DB_DIR}/datamapper_one.db")
15
- DataMapper.setup(:two, "sqlite3:#{DB_DIR}/datamapper_two.db")
16
-
17
- class DataMapperWidget
18
- include DataMapper::Resource
19
-
20
- property :id, Serial
21
- property :name, String
22
- end
23
-
24
- class DataMapperWidgetUsingDatabaseOne
25
- include DataMapper::Resource
26
-
27
- def self.default_repository_name
28
- :one
29
- end
30
-
31
- property :id, Serial
32
- property :name, String
33
-
34
- end
35
-
36
- class DataMapperWidgetUsingDatabaseTwo
37
- include DataMapper::Resource
38
-
39
- def self.default_repository_name
40
- :two
41
- end
42
-
43
- property :id, Serial
44
- property :name, String
45
-
46
- end
47
-
48
- DataMapperWidget.auto_migrate!
49
- DataMapperWidgetUsingDatabaseOne.auto_migrate!
50
- DataMapperWidgetUsingDatabaseTwo.auto_migrate!
@@ -1,44 +0,0 @@
1
- require 'mongoid'
2
-
3
- Mongoid.configure do |config|
4
- config.master = Mongo::Connection.new.db('database_cleaner_test')
5
- end
6
-
7
- class MongoidWidget
8
- include Mongoid::Document
9
- field :id, :type => Integer
10
- field :name
11
-
12
- class << self
13
- #mongoid doesn't seem to provide this...
14
- def create!(*args)
15
- new(*args).save!
16
- end
17
- end
18
- end
19
-
20
- class MongoidWidgetUsingDatabaseOne
21
- include Mongoid::Document
22
- field :id, :type => Integer
23
- field :name
24
-
25
- class << self
26
- #mongoid doesn't seem to provide this...
27
- def create!(*args)
28
- new(*args).save!
29
- end
30
- end
31
- end
32
-
33
- class MongoidWidgetUsingDatabaseTwo
34
- include Mongoid::Document
35
- field :id, :type => Integer
36
- field :name
37
-
38
- class << self
39
- #mongoid doesn't seem to provide this...
40
- def create!(*args)
41
- new(*args).save!
42
- end
43
- end
44
- end
@@ -1,51 +0,0 @@
1
- require 'mongo_mapper'
2
-
3
- ::MongoMapper.connection = Mongo::Connection.new('127.0.0.1')
4
- ::MongoMapper.database = 'database_cleaner_test'
5
-
6
- class MongoMapperWidget
7
- include MongoMapper::Document
8
- key :id, Integer
9
- key :name, String
10
-
11
- class << self
12
- #mongomapper doesn't seem to provide this...
13
- def create!(*args)
14
- new(*args).save!
15
- end
16
- end
17
- end
18
-
19
- class MongoMapperWidgetUsingDatabaseOne
20
- include MongoMapper::Document
21
-
22
- connection = Mongo::Connection.new('127.0.0.1')
23
- set_database_name = 'database_cleaner_test_one'
24
-
25
- key :id, Integer
26
- key :name, String
27
-
28
- class << self
29
- #mongomapper doesn't seem to provide this...
30
- def create!(*args)
31
- new(*args).save!
32
- end
33
- end
34
- end
35
-
36
- class MongoMapperWidgetUsingDatabaseTwo
37
- include MongoMapper::Document
38
-
39
- connection = Mongo::Connection.new('127.0.0.1')
40
- set_database_name = 'database_cleaner_test_two'
41
-
42
- key :id, Integer
43
- key :name, String
44
-
45
- class << self
46
- #mongomapper doesn't seem to provide this...
47
- def create!(*args)
48
- new(*args).save!
49
- end
50
- end
51
- end
@@ -1,17 +0,0 @@
1
- require 'neo4j-core'
2
-
3
- class Neo4jWidget < Neo4j::Node
4
- def self.create!(*args)
5
- create(*args)
6
- end
7
-
8
- def self.count
9
- Neo4j::Session.query.match('n').pluck('COUNT(n)').first
10
- end
11
- end
12
-
13
- class Neo4jWidgetUsingDatabaseOne < Neo4jWidget
14
- end
15
-
16
- class Neo4jWidgetUsingDatabaseTwo < Neo4jWidget
17
- end
@@ -1,43 +0,0 @@
1
- require 'ohm'
2
-
3
- Ohm.connect :url => ENV['REDIS_URL']
4
-
5
- class OhmWidget < Ohm::Model
6
- attribute :name
7
-
8
- def self.create!(attrs = {})
9
- new({:name => 'some widget'}.merge(attrs)).save
10
- end
11
-
12
- def self.count
13
- all.count
14
- end
15
-
16
- end
17
-
18
- class OhmWidgetUsingDatabaseOne < Ohm::Model
19
- connect :url => ENV['REDIS_URL_ONE']
20
- attribute :name
21
-
22
- def self.create!(attrs = {})
23
- new({:name => 'a widget using database one'}.merge(attrs)).save
24
- end
25
-
26
- def self.count
27
- all.count
28
- end
29
-
30
- end
31
-
32
- class OhmWidgetUsingDatabaseTwo < Ohm::Model
33
- connect :url => ENV['REDIS_URL_TWO']
34
- attribute :name
35
-
36
- def self.create!(attrs = {})
37
- new({:name => 'a widget using database two'}.merge(attrs)).save
38
- end
39
-
40
- def self.count
41
- all.count
42
- end
43
- end
@@ -1,65 +0,0 @@
1
- require 'redis'
2
-
3
- class RedisWidget
4
-
5
- def self.redis
6
- threaded ||= Redis.new
7
- end
8
-
9
- def self.redis=(connection)
10
- threaded = connection
11
- end
12
-
13
- def self.threaded
14
- Thread.current[self.class.to_s] ||= {}
15
- end
16
-
17
- def initialize(options = {})
18
- options = options.dup
19
- @name = options[:name]
20
- end
21
-
22
- def connection
23
- self.class.redis
24
- end
25
-
26
- def save
27
- unless connection.get(self.class.to_s + ':id')
28
- @id = 0
29
- connection.set(self.class.to_s + ':id', @id)
30
- end
31
- @id = connection.incr(self.class.to_s + ':id')
32
- connection.set(self.class.to_s + ':%d:name' % @id, @name)
33
- end
34
-
35
- def self.count
36
- self.redis.keys(self.to_s + '*name').size
37
- end
38
-
39
- def self.create!
40
- new(:name => 'some widget').save
41
-
42
- end
43
- end
44
-
45
- class RedisWidgetUsingDatabaseOne < RedisWidget
46
-
47
- def self.redis
48
- threaded[self.class.to_s] ||= Redis.new :url => ENV['REDIS_URL_ONE']
49
- end
50
-
51
- def self.create!
52
- new(:name => 'a widget using database one').save
53
- end
54
- end
55
-
56
- class RedisWidgetUsingDatabaseTwo < RedisWidget
57
-
58
- def self.redis
59
- threaded[self.class.to_s] ||= Redis.new :url => ENV['REDIS_URL_TWO']
60
- end
61
-
62
- def self.create!
63
- new(:name => 'a widget using database two').save
64
- end
65
- end
@@ -1,9 +0,0 @@
1
- require 'sequel'
2
-
3
- db = Sequel.sqlite # memory database
4
-
5
- db.run 'DROP TABLE IF EXISTS "sequel_widgets"'
6
-
7
- db.create_table :sequel_widgets do
8
- String :name
9
- end
@@ -1,30 +0,0 @@
1
- Feature: database cleaning
2
- In order to ease example and feature writing
3
- As a developer
4
- I want to have my database in a clean state
5
-
6
- Scenario Outline: ruby app
7
- Given I am using <ORM>
8
- And the <Strategy> cleaning strategy
9
-
10
- When I run my scenarios that rely on a clean database
11
- Then I should see all green
12
-
13
- Examples:
14
- | ORM | Strategy |
15
- | ActiveRecord | transaction |
16
- | ActiveRecord | truncation |
17
- | ActiveRecord | deletion |
18
- | DataMapper | transaction |
19
- | DataMapper | truncation |
20
- | Sequel | transaction |
21
- | Sequel | truncation |
22
- | Sequel | deletion |
23
- | MongoMapper | truncation |
24
- | Mongoid | truncation |
25
- | CouchPotato | truncation |
26
- | Redis | truncation |
27
- | Ohm | truncation |
28
- | Neo4j | deletion |
29
- | Neo4j | truncation |
30
- | Neo4j | transaction |
@@ -1,23 +0,0 @@
1
- Feature: database cleaning
2
- In order to ease example and feature writing
3
- As a developer
4
- I want to have my database in a clean state with default strategy
5
-
6
- Scenario Outline: ruby app
7
- Given I am using <ORM>
8
- And the default cleaning strategy
9
-
10
- When I run my scenarios that rely on a clean database
11
- Then I should see all green
12
-
13
- Examples:
14
- | ORM |
15
- | ActiveRecord |
16
- | DataMapper |
17
- | Sequel |
18
- | MongoMapper |
19
- | Mongoid |
20
- | CouchPotato |
21
- | Redis |
22
- | Ohm |
23
- | Neo4j |
@@ -1,22 +0,0 @@
1
- Feature: multiple database cleaning
2
- In order to ease example and feature writing
3
- As a developer
4
- I want to have my databases in a clean state
5
-
6
- Scenario Outline: ruby app
7
- Given I am using <ORM>
8
- And the <Strategy> cleaning strategy
9
-
10
- When I run my scenarios that rely on clean databases
11
- Then I should see all green
12
-
13
- Examples:
14
- | ORM | Strategy |
15
- | ActiveRecord | truncation |
16
- | ActiveRecord | deletion |
17
- | DataMapper | truncation |
18
- | Sequel | truncation |
19
- | MongoMapper | truncation |
20
- | DataMapper | transaction |
21
- | ActiveRecord | transaction |
22
- | Sequel | transaction |
@@ -1,67 +0,0 @@
1
- Feature: database cleaning using multiple ORMs
2
- In order to ease example and feature writing
3
- As a developer
4
- I want to have my database in a clean state
5
-
6
- Scenario Outline: ruby app
7
- Given I am using <ORM1> and <ORM2>
8
-
9
- When I run my scenarios that rely on clean databases using multiple orms
10
- Then I should see all green
11
-
12
- Examples:
13
- | ORM1 | ORM2 |
14
- | ActiveRecord | DataMapper |
15
- | ActiveRecord | Sequel |
16
- | ActiveRecord | MongoMapper |
17
- | ActiveRecord | Mongoid |
18
- | ActiveRecord | CouchPotato |
19
- | ActiveRecord | Ohm |
20
- | ActiveRecord | Redis |
21
- | DataMapper | ActiveRecord |
22
- | DataMapper | Sequel |
23
- | DataMapper | MongoMapper |
24
- | DataMapper | Mongoid |
25
- | DataMapper | CouchPotato |
26
- | DataMapper | Ohm |
27
- | DataMapper | Redis |
28
- | Sequel | ActiveRecord |
29
- | Sequel | DataMapper |
30
- | Sequel | MongoMapper |
31
- | Sequel | Mongoid |
32
- | Sequel | CouchPotato |
33
- | Sequel | Ohm |
34
- | Sequel | Redis |
35
- | MongoMapper | ActiveRecord |
36
- | MongoMapper | DataMapper |
37
- | MongoMapper | Sequel |
38
- | MongoMapper | Mongoid |
39
- | MongoMapper | CouchPotato |
40
- | MongoMapper | Ohm |
41
- | MongoMapper | Redis |
42
- | CouchPotato | ActiveRecord |
43
- | CouchPotato | DataMapper |
44
- | CouchPotato | Sequel |
45
- | CouchPotato | MongoMapper |
46
- | CouchPotato | Mongoid |
47
- | CouchPotato | Ohm |
48
- | CouchPotato | Redis |
49
- | Ohm | ActiveRecord |
50
- | Ohm | DataMapper |
51
- | Ohm | Sequel |
52
- | Ohm | MongoMapper |
53
- | Ohm | Mongoid |
54
- | Ohm | CouchPotato |
55
- | Redis | ActiveRecord |
56
- | Redis | DataMapper |
57
- | Redis | Sequel |
58
- | Redis | MongoMapper |
59
- | Redis | Mongoid |
60
- | Redis | CouchPotato |
61
- | Redis | Ohm |
62
- | Neo4j | ActiveRecord |
63
- | Neo4j | DataMapper |
64
- | Neo4j | Sequel |
65
- | Neo4j | Redis |
66
- | Neo4j | Ohm |
67
- | Neo4j | MongoMapper |
@@ -1,33 +0,0 @@
1
- orms_pattern = /(ActiveRecord|DataMapper|Sequel|MongoMapper|Mongoid|CouchPotato|Redis|Ohm|Neo4j)/
2
-
3
- Given /^I am using #{orms_pattern}$/ do |orm|
4
- @feature_runner = FeatureRunner.new
5
- @feature_runner.orm = orm
6
- end
7
-
8
- Given /^I am using #{orms_pattern} and #{orms_pattern}$/ do |orm1,orm2|
9
- @feature_runner = FeatureRunner.new
10
- @feature_runner.orm = orm1
11
- @feature_runner.another_orm = orm2
12
- end
13
-
14
- Given /^the (.+) cleaning strategy$/ do |strategy|
15
- @feature_runner.strategy = strategy
16
- end
17
-
18
- When "I run my scenarios that rely on a clean database" do
19
- @feature_runner.go 'example'
20
- end
21
-
22
- When "I run my scenarios that rely on clean databases" do
23
- @feature_runner.multiple_databases = true
24
- @feature_runner.go 'example_multiple_db'
25
- end
26
-
27
- When "I run my scenarios that rely on clean databases using multiple orms" do
28
- @feature_runner.go 'example_multiple_orm'
29
- end
30
-
31
- Then "I should see all green" do
32
- fail "Feature failed with :#{@feature_runner.output}" unless @feature_runner.exit_status == 0
33
- end