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
@@ -1,23 +0,0 @@
1
- When /^I create a widget using mongoid$/ do
2
- MongoidWidget.create!( :id => rand(1000)+1000)
3
- end
4
-
5
- Then /^I should see ([\d]+) widget using mongoid$/ do |widget_count|
6
- MongoidWidget.count.should == widget_count.to_i
7
- end
8
-
9
- When /^I create a widget in one db using mongoid$/ do
10
- MongoidWidgetUsingDatabaseOne.create!
11
- end
12
-
13
- When /^I create a widget in another db using mongoid$/ do
14
- MongoidWidgetUsingDatabaseTwo.create!
15
- end
16
-
17
- Then /^I should see ([\d]+) widget in one db using mongoid$/ do |widget_count|
18
- MongoidWidgetUsingDatabaseOne.count.should == widget_count.to_i
19
- end
20
-
21
- Then /^I should see ([\d]+) widget in another db using mongoid$/ do |widget_count|
22
- MongoidWidgetUsingDatabaseTwo.count.should == widget_count.to_i
23
- end
@@ -1,31 +0,0 @@
1
- Given /^I have setup database cleaner to clean multiple databases using mongomapper$/ do
2
- #DatabaseCleaner
3
- # require "#{File.dirname(__FILE__)}/../../../lib/datamapper_models"
4
- #
5
- # DatabaseCleaner[:datamapper, {:connection => :one} ].strategy = :truncation
6
- # DatabaseCleaner[:datamapper, {:connection => :two} ].strategy = :truncation
7
- end
8
-
9
- When /^I create a widget using mongomapper$/ do
10
- MongoMapperWidget.create!
11
- end
12
-
13
- Then /^I should see ([\d]+) widget using mongomapper$/ do |widget_count|
14
- MongoMapperWidget.count.should == widget_count.to_i
15
- end
16
-
17
- When /^I create a widget in one db using mongomapper$/ do
18
- MongoMapperWidgetUsingDatabaseOne.create!
19
- end
20
-
21
- When /^I create a widget in another db using mongomapper$/ do
22
- MongoMapperWidgetUsingDatabaseTwo.create!
23
- end
24
-
25
- Then /^I should see ([\d]+) widget in one db using mongomapper$/ do |widget_count|
26
- MongoMapperWidgetUsingDatabaseOne.count.should == widget_count.to_i
27
- end
28
-
29
- Then /^I should see ([\d]+) widget in another db using mongomapper$/ do |widget_count|
30
- MongoMapperWidgetUsingDatabaseTwo.count.should == widget_count.to_i
31
- end
@@ -1,23 +0,0 @@
1
- When /^I create a widget using neo4j$/ do
2
- Neo4jWidget.create!
3
- end
4
-
5
- Then /^I should see ([\d]+) widget using neo4j$/ do |widget_count|
6
- Neo4jWidget.count.should == widget_count.to_i
7
- end
8
-
9
- When /^I create a widget in one db using neo4j$/ do
10
- Neo4jWidgetUsingDatabaseOne.create!
11
- end
12
-
13
- When /^I create a widget in another db using neo4j$/ do
14
- Neo4jWidgetUsingDatabaseTwo.create!
15
- end
16
-
17
- Then /^I should see ([\d]+) widget in one db using neo4j$/ do |widget_count|
18
- Neo4jWidgetUsingDatabaseOne.count.should == widget_count.to_i
19
- end
20
-
21
- Then /^I should see ([\d]+) widget in another db using neo4j$/ do |widget_count|
22
- Neo4jWidgetUsingDatabaseTwo.count.should == widget_count.to_i
23
- end
@@ -1,31 +0,0 @@
1
- Given /^I have setup database cleaner to clean multiple databases using ohm$/ do
2
- #DatabaseCleaner
3
- # require "#{File.dirname(__FILE__)}/../../../lib/ohm_models"
4
- #
5
- # DatabaseCleaner[:ohm, {:connection => ENV['REDIS_URL_ONE']} ].strategy = :truncation
6
- # DatabaseCleaner[:ohm, {:connection => ENV['REDIS_URL_TWO']} ].strategy = :truncation
7
- end
8
-
9
- When /^I create a widget using ohm$/ do
10
- OhmWidget.create!
11
- end
12
-
13
- Then /^I should see ([\d]+) widget using ohm$/ do |widget_count|
14
- OhmWidget.count.should == widget_count.to_i
15
- end
16
-
17
- When /^I create a widget in one db using ohm$/ do
18
- OhmWidgetUsingDatabaseOne.create!
19
- end
20
-
21
- When /^I create a widget in another db using ohm$/ do
22
- OhmWidgetUsingDatabaseTwo.create!
23
- end
24
-
25
- Then /^I should see ([\d]+) widget in one db using ohm$/ do |widget_count|
26
- OhmWidgetUsingDatabaseOne.count.should == widget_count.to_i
27
- end
28
-
29
- Then /^I should see ([\d]+) widget in another db using ohm$/ do |widget_count|
30
- OhmWidgetUsingDatabaseTwo.count.should == widget_count.to_i
31
- end
@@ -1,31 +0,0 @@
1
- Given /^I have setup database cleaner to clean multiple databases using redis$/ do
2
- #DatabaseCleaner
3
- # require "#{File.dirname(__FILE__)}/../../../lib/redis_models"
4
- #
5
- # DatabaseCleaner[:redis, {:connection => ENV['REDIS_URL_ONE']} ].strategy = :truncation
6
- # DatabaseCleaner[:redis, {:connection => ENV['REDIS_URL_TWO']} ].strategy = :truncation
7
- end
8
-
9
- When /^I create a widget using redis$/ do
10
- RedisWidget.create!
11
- end
12
-
13
- Then /^I should see ([\d]+) widget using redis$/ do |widget_count|
14
- RedisWidget.count.should == widget_count.to_i
15
- end
16
-
17
- When /^I create a widget in one db using redis$/ do
18
- RedisWidgetUsingDatabaseOne.create!
19
- end
20
-
21
- When /^I create a widget in another db using redis$/ do
22
- RedisWidgetUsingDatabaseTwo.create!
23
- end
24
-
25
- Then /^I should see ([\d]+) widget in one db using redis$/ do |widget_count|
26
- RedisWidgetUsingDatabaseOne.count.should == widget_count.to_i
27
- end
28
-
29
- Then /^I should see ([\d]+) widget in another db using redis$/ do |widget_count|
30
- RedisWidgetUsingDatabaseTwo.count.should == widget_count.to_i
31
- end
@@ -1,55 +0,0 @@
1
- When /^I create a widget$/ do
2
- step "I create a widget using #{ENV['ORM'].downcase}"
3
- end
4
-
5
- Then /^I should see 1 widget$/ do
6
- step "I should see 1 widget using #{ENV['ORM'].downcase}"
7
- end
8
-
9
- When /^I create a widget in one orm$/ do
10
- step "I create a widget using #{ENV['ORM'].downcase}"
11
- end
12
-
13
- When /^I create a widget in another orm$/ do
14
- step "I create a widget using #{ENV['ANOTHER_ORM'].downcase}"
15
- end
16
-
17
- Then /^I should see 1 widget in one orm$/ do
18
- step "I should see 1 widget using #{ENV['ORM'].downcase}"
19
- end
20
-
21
- Then /^I should see 1 widget in another orm$/ do
22
- step "I should see 1 widget using #{ENV['ANOTHER_ORM'].downcase}"
23
- end
24
-
25
- Then /^I should see 0 widget in another orm$/ do
26
- step "I should see 0 widget using #{ENV['ANOTHER_ORM'].downcase}"
27
- end
28
-
29
- Then /^I should see 0 widget in one orm$/ do
30
- step "I should see 0 widget using #{ENV['ORM'].downcase}"
31
- end
32
-
33
- When /^I create a widget in one db$/ do
34
- step "I create a widget in one db using #{ENV['ORM'].downcase}"
35
- end
36
-
37
- When /^I create a widget in another db$/ do
38
- step "I create a widget in another db using #{ENV['ORM'].downcase}"
39
- end
40
-
41
- Then /^I should see 1 widget in one db$/ do
42
- step "I should see 1 widget in one db using #{ENV['ORM'].downcase}"
43
- end
44
-
45
- Then /^I should see 1 widget in another db$/ do
46
- step "I should see 1 widget in another db using #{ENV['ORM'].downcase}"
47
- end
48
-
49
- Then /^I should see 0 widget in another db$/ do
50
- step "I should see 0 widget in another db using #{ENV['ORM'].downcase}"
51
- end
52
-
53
- Then /^I should see 0 widget in one db$/ do
54
- step "I should see 0 widget in one db using #{ENV['ORM'].downcase}"
55
- end
@@ -1,61 +0,0 @@
1
- #Hilarious as it seems, this is necessary so bundle exec cucumber works for mongoid cukeage (I'm assuming mongomapper is automatically present because its a git repo)
2
- Object.send(:remove_const, 'MongoMapper') if defined?(::MongoMapper)
3
-
4
- require 'rubygems'
5
- require 'bundler'
6
-
7
- Bundler.setup
8
- require 'rspec/expectations'
9
- #require 'ruby-debug'
10
-
11
- DB_DIR = "#{File.dirname(__FILE__)}/../../db"
12
-
13
- orm = ENV['ORM']
14
- another_orm = ENV['ANOTHER_ORM']
15
- strategy = ENV['STRATEGY']
16
- multiple_db = ENV['MULTIPLE_DBS']
17
-
18
- config = YAML::load(File.open("#{File.dirname(__FILE__)}/../../config/redis.yml"))
19
- ENV['REDIS_URL'] = config['test']['url']
20
- ENV['REDIS_URL_ONE'] = config['one']['url']
21
- ENV['REDIS_URL_TWO'] = config['two']['url']
22
-
23
- if orm && strategy
24
- $:.unshift(File.dirname(__FILE__) + '/../../../lib')
25
- require 'database_cleaner'
26
- require 'database_cleaner/cucumber'
27
- require "#{File.dirname(__FILE__)}/../../lib/#{orm.downcase}_models"
28
-
29
- if another_orm
30
- require "#{File.dirname(__FILE__)}/../../lib/#{another_orm.downcase}_models"
31
- end
32
-
33
- if multiple_db
34
- DatabaseCleaner.app_root = "#{File.dirname(__FILE__)}/../.."
35
- orm_sym = orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym
36
-
37
- case orm_sym
38
- when :mongo_mapper
39
- DatabaseCleaner[ orm_sym, {:connection => 'database_cleaner_test_one'} ].strategy = strategy.to_sym
40
- DatabaseCleaner[ orm_sym, {:connection => 'database_cleaner_test_two'} ].strategy = strategy.to_sym
41
- when :redis, :ohm
42
- DatabaseCleaner[ orm_sym, {:connection => ENV['REDIS_URL_ONE']} ].strategy = strategy.to_sym
43
- DatabaseCleaner[ orm_sym, {:connection => ENV['REDIS_URL_TWO']} ].strategy = strategy.to_sym
44
- when :active_record
45
- DatabaseCleaner[:active_record, {:model => ActiveRecordWidgetUsingDatabaseOne} ].strategy = strategy.to_sym
46
- DatabaseCleaner[:active_record, {:model => ActiveRecordWidgetUsingDatabaseTwo} ].strategy = strategy.to_sym
47
- else
48
- DatabaseCleaner[ orm_sym, {:connection => :one} ].strategy = strategy.to_sym
49
- DatabaseCleaner[ orm_sym, {:connection => :two} ].strategy = strategy.to_sym
50
- end
51
-
52
- elsif another_orm
53
- DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym ].strategy = strategy.to_sym
54
- DatabaseCleaner[ another_orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym ].strategy = strategy.to_sym
55
- else
56
- DatabaseCleaner.strategy = strategy.to_sym unless strategy == "default"
57
- end
58
-
59
- else
60
- raise "Run 'ORM=ActiveRecord|DataMapper|MongoMapper|CouchPotato|Ohm|Redis [ANOTHER_ORM=...] [MULTIPLE_DBS=true] STRATEGY=transaction|truncation|default cucumber examples/features'"
61
- end
@@ -1,41 +0,0 @@
1
- require 'active_record'
2
- databases_config = {
3
- "one" => {"adapter" => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", "database" => "#{DB_DIR}/activerecord_one.db"},
4
- "two" => {"adapter" => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", "database" => "#{DB_DIR}/activerecord_two.db"}
5
- }
6
-
7
- File.open("#{File.dirname(__FILE__)}/../config/database.yml", 'w') do |file|
8
- file.write(YAML.dump(databases_config))
9
- end
10
-
11
- ["two","one"].each do |db|
12
- ActiveRecord::Base.establish_connection(databases_config[db])
13
- ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widgets"')
14
- ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widget_using_database_ones"')
15
- ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widget_using_database_twos"')
16
-
17
- ActiveRecord::Schema.define(:version => 1) do
18
- create_table :active_record_widgets do |t|
19
- t.string :name
20
- end
21
-
22
- create_table :active_record_widget_using_database_ones do |t|
23
- t.string :name
24
- end
25
-
26
- create_table :active_record_widget_using_database_twos do |t|
27
- t.string :name
28
- end
29
- end
30
- end
31
-
32
- class ActiveRecordWidget < ActiveRecord::Base
33
- end
34
-
35
- class ActiveRecordWidgetUsingDatabaseOne < ActiveRecord::Base
36
- establish_connection(:adapter => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", :database => "#{DB_DIR}/activerecord_one.db")
37
- end
38
-
39
- class ActiveRecordWidgetUsingDatabaseTwo < ActiveRecord::Base
40
- establish_connection(:adapter => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", :database => "#{DB_DIR}/activerecord_two.db")
41
- end
@@ -1,61 +0,0 @@
1
- require 'couch_potato'
2
- require 'json/pure' unless defined? ::JSON
3
- ::CouchPotato::Config.database_name = 'couch_potato_test'
4
-
5
- class CouchPotatoWidget
6
- include CouchPotato::Persistence
7
-
8
- property :name
9
- view :by_name, :key => :name
10
-
11
-
12
- # mimic the AR interface used in example_steps
13
-
14
- def self.create!(attrs = {})
15
- CouchPotato.database.save(self.new)
16
- end
17
-
18
- def self.count
19
- CouchPotato.database.view(self.by_name).size
20
- end
21
- end
22
-
23
- class CouchPotatoWidgetUsingDatabaseOne
24
- include CouchPotato::Persistence
25
-
26
- database_name = 'couch_potato_test_one'
27
-
28
- property :name
29
- view :by_name, :key => :name
30
-
31
-
32
- # mimic the AR interface used in example_steps
33
-
34
- def self.create!(attrs = {})
35
- CouchPotato.database.save(self.new)
36
- end
37
-
38
- def self.count
39
- CouchPotato.database.view(self.by_name).size
40
- end
41
- end
42
-
43
- class CouchPotatoWidgetUsingDatabaseTwo
44
- include CouchPotato::Persistence
45
-
46
- database_name = 'couch_potato_test_two'
47
-
48
- property :name
49
- view :by_name, :key => :name
50
-
51
-
52
- # mimic the AR interface used in example_steps
53
-
54
- def self.create!(attrs = {})
55
- CouchPotato.database.save(self.new)
56
- end
57
-
58
- def self.count
59
- CouchPotato.database.view(self.by_name).size
60
- end
61
- end
@@ -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 |