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,22 +0,0 @@
1
- Feature: example
2
- In order to test DataBase Cleaner
3
- Here are some scenarios that rely on the DB being clean!
4
-
5
- # Background:
6
- # Given I have setup DatabaseCleaner to clean multiple orms
7
-
8
- Scenario: dirty the db
9
- When I create a widget in one orm
10
- And I create a widget in another orm
11
- Then I should see 1 widget in one orm
12
- And I should see 1 widget in another orm
13
-
14
- Scenario: assume a clean db
15
- When I create a widget in one orm
16
- Then I should see 1 widget in one orm
17
- And I should see 0 widget in another orm
18
-
19
- Scenario: assume a clean db
20
- When I create a widget in another orm
21
- Then I should see 0 widget in one orm
22
- And I should see 1 widget in another orm
@@ -1,31 +0,0 @@
1
- Given /^I have setup database cleaner to clean multiple databases using activerecord$/ 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 activerecord$/ do
10
- ActiveRecordWidget.create!
11
- end
12
-
13
- Then /^I should see ([\d]+) widget using activerecord$/ do |widget_count|
14
- ActiveRecordWidget.count.should == widget_count.to_i
15
- end
16
-
17
- When /^I create a widget in one db using activerecord$/ do
18
- ActiveRecordWidgetUsingDatabaseOne.create!
19
- end
20
-
21
- When /^I create a widget in another db using activerecord$/ do
22
- ActiveRecordWidgetUsingDatabaseTwo.create!
23
- end
24
-
25
- Then /^I should see ([\d]+) widget in one db using activerecord$/ do |widget_count|
26
- ActiveRecordWidgetUsingDatabaseOne.count.should == widget_count.to_i
27
- end
28
-
29
- Then /^I should see ([\d]+) widget in another db using activerecord$/ do |widget_count|
30
- ActiveRecordWidgetUsingDatabaseTwo.count.should == widget_count.to_i
31
- end
@@ -1,31 +0,0 @@
1
- Given /^I have setup database cleaner to clean multiple databases using couchpotato$/ do
2
- #DatabaseCleaner
3
- # require "#{File.dirname(__FILE__)}/../../../lib/couchpotato_models"
4
- #
5
- # DatabaseCleaner[:couchpotato, {:connection => :one} ].strategy = :truncation
6
- # DatabaseCleaner[:couchpotato, {:connection => :two} ].strategy = :truncation
7
- end
8
-
9
- When /^I create a widget using couchpotato$/ do
10
- CouchPotatoWidget.create!
11
- end
12
-
13
- Then /^I should see ([\d]+) widget using couchpotato$/ do |widget_count|
14
- CouchPotatoWidget.count.should == widget_count.to_i
15
- end
16
-
17
- When /^I create a widget in one db using couchpotato$/ do
18
- CouchPotatoWidgetUsingDatabaseOne.create!
19
- end
20
-
21
- When /^I create a widget in another db using couchpotato$/ do
22
- CouchPotatoWidgetUsingDatabaseTwo.create!
23
- end
24
-
25
- Then /^I should see ([\d]+) widget in one db using couchpotato$/ do |widget_count|
26
- CouchPotatoWidgetUsingDatabaseOne.count.should == widget_count.to_i
27
- end
28
-
29
- Then /^I should see ([\d]+) widget in another db using couchpotato$/ do |widget_count|
30
- CouchPotatoWidgetUsingDatabaseTwo.count.should == widget_count.to_i
31
- end
@@ -1,37 +0,0 @@
1
- Given /^I have setup database cleaner to clean multiple databases using datamapper$/ 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 datamapper$/ do
10
- DataMapperWidget.create!
11
- end
12
-
13
- Then /^I should see ([\d]+) widget using datamapper$/ do |widget_count|
14
- DataMapperWidget.count.should == widget_count.to_i
15
- end
16
-
17
- When /^I create a widget in one db using datamapper$/ do
18
- begin
19
- DataMapperWidgetUsingDatabaseOne.create!
20
- rescue StandardError => e
21
- BREAK = e.backtrace
22
- debugger
23
- DataMapperWidgetUsingDatabaseOne.create!
24
- end
25
- end
26
-
27
- When /^I create a widget in another db using datamapper$/ do
28
- DataMapperWidgetUsingDatabaseTwo.create!
29
- end
30
-
31
- Then /^I should see ([\d]+) widget in one db using datamapper$/ do |widget_count|
32
- DataMapperWidgetUsingDatabaseOne.count.should == widget_count.to_i
33
- end
34
-
35
- Then /^I should see ([\d]+) widget in another db using datamapper$/ do |widget_count|
36
- DataMapperWidgetUsingDatabaseTwo.count.should == widget_count.to_i
37
- end
@@ -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