database_cleaner 0.6.7 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/lib/database_cleaner.rb +1 -3
  3. metadata +48 -154
  4. data/Gemfile.lock +0 -161
  5. data/History.txt +0 -173
  6. data/LICENSE +0 -20
  7. data/README.textile +0 -165
  8. data/Rakefile +0 -65
  9. data/TODO +0 -3
  10. data/VERSION.yml +0 -5
  11. data/cucumber.yml +0 -1
  12. data/examples/Gemfile +0 -48
  13. data/examples/Gemfile.lock +0 -161
  14. data/examples/config/database.yml.example +0 -8
  15. data/examples/db/sqlite_databases_go_here +0 -0
  16. data/examples/features/example.feature +0 -11
  17. data/examples/features/example_multiple_db.feature +0 -23
  18. data/examples/features/example_multiple_orm.feature +0 -22
  19. data/examples/features/step_definitions/activerecord_steps.rb +0 -31
  20. data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
  21. data/examples/features/step_definitions/datamapper_steps.rb +0 -37
  22. data/examples/features/step_definitions/mongoid_steps.rb +0 -23
  23. data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
  24. data/examples/features/step_definitions/translation_steps.rb +0 -55
  25. data/examples/features/support/env.rb +0 -62
  26. data/examples/lib/activerecord_models.rb +0 -41
  27. data/examples/lib/couchpotato_models.rb +0 -61
  28. data/examples/lib/datamapper_models.rb +0 -50
  29. data/examples/lib/mongoid_models.rb +0 -49
  30. data/examples/lib/mongomapper_models.rb +0 -51
  31. data/features/cleaning.feature +0 -22
  32. data/features/cleaning_default_strategy.feature +0 -19
  33. data/features/cleaning_multiple_dbs.feature +0 -21
  34. data/features/cleaning_multiple_orms.feature +0 -29
  35. data/features/step_definitions/database_cleaner_steps.rb +0 -32
  36. data/features/support/env.rb +0 -7
  37. data/features/support/feature_runner.rb +0 -39
  38. data/lib/database_cleaner/active_record/#transaction.rb# +0 -34
  39. data/lib/database_cleaner/active_record/base.rb +0 -53
  40. data/lib/database_cleaner/active_record/deletion.rb +0 -64
  41. data/lib/database_cleaner/active_record/transaction.rb +0 -26
  42. data/lib/database_cleaner/active_record/truncation.rb +0 -134
  43. data/lib/database_cleaner/base.rb +0 -136
  44. data/lib/database_cleaner/configuration.rb +0 -92
  45. data/lib/database_cleaner/couch_potato/base.rb +0 -7
  46. data/lib/database_cleaner/couch_potato/truncation.rb +0 -28
  47. data/lib/database_cleaner/cucumber.rb +0 -11
  48. data/lib/database_cleaner/data_mapper/base.rb +0 -21
  49. data/lib/database_cleaner/data_mapper/transaction.rb +0 -28
  50. data/lib/database_cleaner/data_mapper/truncation.rb +0 -175
  51. data/lib/database_cleaner/generic/base.rb +0 -23
  52. data/lib/database_cleaner/generic/truncation.rb +0 -43
  53. data/lib/database_cleaner/mongo/truncation.rb +0 -22
  54. data/lib/database_cleaner/mongo_mapper/base.rb +0 -20
  55. data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
  56. data/lib/database_cleaner/mongoid/base.rb +0 -20
  57. data/lib/database_cleaner/mongoid/truncation.rb +0 -20
  58. data/lib/database_cleaner/null_strategy.rb +0 -15
  59. data/spec/database_cleaner/active_record/base_spec.rb +0 -141
  60. data/spec/database_cleaner/active_record/transaction_spec.rb +0 -65
  61. data/spec/database_cleaner/active_record/truncation_spec.rb +0 -82
  62. data/spec/database_cleaner/base_spec.rb +0 -478
  63. data/spec/database_cleaner/configuration_spec.rb +0 -294
  64. data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
  65. data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
  66. data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
  67. data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
  68. data/spec/database_cleaner/generic/base_spec.rb +0 -22
  69. data/spec/database_cleaner/generic/truncation_spec.rb +0 -78
  70. data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
  71. data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
  72. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
  73. data/spec/database_cleaner/shared_strategy_spec.rb +0 -13
  74. data/spec/rcov.opts +0 -1
  75. data/spec/spec.opts +0 -7
  76. data/spec/spec_helper.rb +0 -19
@@ -1,55 +0,0 @@
1
- When /^I create a widget$/ do
2
- When "I create a widget using #{ENV['ORM'].downcase}"
3
- end
4
-
5
- Then /^I should see 1 widget$/ do
6
- Then "I should see 1 widget using #{ENV['ORM'].downcase}"
7
- end
8
-
9
- When /^I create a widget in one orm$/ do
10
- When "I create a widget using #{ENV['ORM'].downcase}"
11
- end
12
-
13
- When /^I create a widget in another orm$/ do
14
- When "I create a widget using #{ENV['ANOTHER_ORM'].downcase}"
15
- end
16
-
17
- Then /^I should see 1 widget in one orm$/ do
18
- When "I should see 1 widget using #{ENV['ORM'].downcase}"
19
- end
20
-
21
- Then /^I should see 1 widget in another orm$/ do
22
- When "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
- When "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
- When "I should see 0 widget using #{ENV['ORM'].downcase}"
31
- end
32
-
33
- When /^I create a widget in one db$/ do
34
- When "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
- When "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
- When "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
- When "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
- When "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
- When "I should see 0 widget in one db using #{ENV['ORM'].downcase}"
55
- end
@@ -1,62 +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 'spec/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
-
19
- if orm && strategy
20
- $:.unshift(File.dirname(__FILE__) + '/../../../lib')
21
- require 'database_cleaner'
22
- require 'database_cleaner/cucumber'
23
-
24
- begin
25
- require "#{File.dirname(__FILE__)}/../../lib/#{orm.downcase}_models"
26
- rescue LoadError => e
27
- raise "You don't have the #{orm} ORM installed"
28
- end
29
-
30
- if another_orm
31
- begin
32
- require "#{File.dirname(__FILE__)}/../../lib/#{another_orm.downcase}_models"
33
- rescue LoadError => e
34
- raise "You don't have the #{another_orm} ORM installed"
35
- end
36
- end
37
-
38
-
39
-
40
-
41
- if multiple_db
42
- DatabaseCleaner.app_root = "#{File.dirname(__FILE__)}/../.."
43
- orm_sym = orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym
44
-
45
- if orm_sym == :mongo_mapper
46
- DatabaseCleaner[ orm_sym, {:connection => 'database_cleaner_test_one'} ].strategy = strategy.to_sym
47
- DatabaseCleaner[ orm_sym, {:connection => 'database_cleaner_test_two'} ].strategy = strategy.to_sym
48
- else
49
- DatabaseCleaner[ orm_sym, {:connection => :one} ].strategy = strategy.to_sym
50
- DatabaseCleaner[ orm_sym, {:connection => :two} ].strategy = strategy.to_sym
51
- end
52
-
53
- elsif another_orm
54
- DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym ].strategy = strategy.to_sym
55
- DatabaseCleaner[ another_orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym ].strategy = strategy.to_sym
56
- else
57
- DatabaseCleaner.strategy = strategy.to_sym unless strategy == "default"
58
- end
59
-
60
- else
61
- raise "Run 'ORM=ActiveRecord|DataMapper|MongoMapper|CouchPotato [ANOTHER_ORM=...] [MULTIPLE_DBS=true] STRATEGY=transaction|truncation|default cucumber examples/features'"
62
- 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,49 +0,0 @@
1
- require 'mongoid'
2
-
3
- Mongoid.configure do |config|
4
- name = 'database_cleaner_test'
5
- config.master = Mongo::Connection.new.db(name)
6
- end
7
-
8
-
9
- #::MongoMapper.connection = Mongo::Connection.new('127.0.0.1')
10
- #::MongoMapper.database = 'database_cleaner_test'
11
-
12
- class MongoidWidget
13
- include Mongoid::Document
14
- field :id, :type => Integer
15
- field :name
16
-
17
- class << self
18
- #mongoid doesn't seem to provide this...
19
- def create!(*args)
20
- new(*args).save!
21
- end
22
- end
23
- end
24
-
25
- class MongoidWidgetUsingDatabaseOne
26
- include Mongoid::Document
27
- field :id, :type => Integer
28
- field :name
29
-
30
- class << self
31
- #mongoid doesn't seem to provide this...
32
- def create!(*args)
33
- new(*args).save!
34
- end
35
- end
36
- end
37
-
38
- class MongoidWidgetUsingDatabaseTwo
39
- include Mongoid::Document
40
- field :id, :type => Integer
41
- field :name
42
-
43
- class << self
44
- #mongoid doesn't seem to provide this...
45
- def create!(*args)
46
- new(*args).save!
47
- end
48
- end
49
- 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,22 +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
- | MongoMapper | truncation |
21
- | Mongoid | truncation |
22
- | CouchPotato | truncation |
@@ -1,19 +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
- | MongoMapper |
18
- | Mongoid |
19
- | CouchPotato |
@@ -1,21 +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
- | MongoMapper | truncation |
19
- | DataMapper | transaction |
20
- # Not working...
21
- #| ActiveRecord | transaction |
@@ -1,29 +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 | MongoMapper |
16
- | ActiveRecord | Mongoid |
17
- | ActiveRecord | CouchPotato |
18
- | DataMapper | ActiveRecord |
19
- | DataMapper | MongoMapper |
20
- | DataMapper | Mongoid |
21
- | DataMapper | CouchPotato |
22
- | MongoMapper | ActiveRecord |
23
- | MongoMapper | DataMapper |
24
- | MongoMapper | Mongoid |
25
- | MongoMapper | CouchPotato |
26
- | CouchPotato | ActiveRecord |
27
- | CouchPotato | DataMapper |
28
- | CouchPotato | MongoMapper |
29
- | CouchPotato | Mongoid |
@@ -1,32 +0,0 @@
1
-
2
- Given /^I am using (ActiveRecord|DataMapper|MongoMapper|Mongoid|CouchPotato)$/ do |orm|
3
- @feature_runner = FeatureRunner.new
4
- @feature_runner.orm = orm
5
- end
6
-
7
- Given /^I am using (ActiveRecord|DataMapper|MongoMapper|CouchPotato|Mongoid) and (ActiveRecord|DataMapper|MongoMapper|CouchPotato|Mongoid)$/ do |orm1,orm2|
8
- @feature_runner = FeatureRunner.new
9
- @feature_runner.orm = orm1
10
- @feature_runner.another_orm = orm2
11
- end
12
-
13
- Given /^the (.+) cleaning strategy$/ do |strategy|
14
- @feature_runner.strategy = strategy
15
- end
16
-
17
- When "I run my scenarios that rely on a clean database" do
18
- @feature_runner.go 'example'
19
- end
20
-
21
- When "I run my scenarios that rely on clean databases" do
22
- @feature_runner.multiple_databases = true
23
- @feature_runner.go 'example_multiple_db'
24
- end
25
-
26
- When "I run my scenarios that rely on clean databases using multiple orms" do
27
- @feature_runner.go 'example_multiple_orm'
28
- end
29
-
30
- Then "I should see all green" do
31
- fail "Feature failed with :#{@feature_runner.output}" unless @feature_runner.exit_status == 0
32
- end
@@ -1,7 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
- require 'database_cleaner'
3
-
4
- require 'spec/expectations'
5
-
6
- require 'test/unit/assertions'
7
-
@@ -1,39 +0,0 @@
1
- class FeatureRunner
2
- attr_accessor :orm
3
- attr_accessor :another_orm
4
- attr_accessor :multiple_databases
5
- attr_accessor :strategy
6
- attr_accessor :exit_status
7
- attr_accessor :output
8
-
9
- def strategy
10
- @strategy || 'truncation'
11
- end
12
-
13
- def go(feature)
14
- full_dir ||= File.expand_path(File.dirname(__FILE__) + "/../../examples/")
15
- Dir.chdir(full_dir) do
16
-
17
-
18
- ENV['ORM'] = orm
19
- ENV['STRATEGY'] = strategy
20
-
21
- if another_orm
22
- ENV['ANOTHER_ORM'] = another_orm
23
- else
24
- ENV['ANOTHER_ORM'] = nil
25
- end
26
-
27
- if multiple_databases
28
- ENV['MULTIPLE_DBS'] = "true"
29
- else
30
- ENV['MULTIPLE_DBS'] = nil
31
- end
32
-
33
- self.output = `#{"jruby -S " if defined?(JRUBY_VERSION)}cucumber features/#{feature}.feature`
34
-
35
- self.exit_status = $?.exitstatus
36
- end
37
- end
38
-
39
- end
@@ -1,34 +0,0 @@
1
- require 'database_cleaner/active_record/base'
2
- class Foo
3
- def bar
4
- "fdfd"
5
- end
6
- def zaz(x,y)
7
- end
8
- end
9
- module DatabaseCleaner::ActiveRecord
10
- class Transaction
11
- include ::DatabaseCleaner::ActiveRecord::Base
12
-
13
- def start
14
- connection_klass.Foo
15
- if connection_klass.connection.respond_to?(:increment_open_transactions)
16
- connection_klass.connection.increment_open_transactions
17
- else
18
- connection_klass.__send__(:increment_open_transactions)
19
- end
20
- connection_klass.connection.begin_db_transaction
21
- end
22
-
23
-
24
- def clean
25
- connection_klass.connection.rollback_db_transaction
26
-
27
- if connection_klass.connection.respond_to?(:decrement_open_transactions)
28
- connection_klass.connection.decrement_open_transactions
29
- else
30
- connection_klass.__send__(:decrement_open_transactions)
31
- end
32
- end
33
- end
34
- end
@@ -1,53 +0,0 @@
1
- require 'database_cleaner/generic/base'
2
- require 'active_record'
3
- require 'erb'
4
-
5
- module DatabaseCleaner
6
- module ActiveRecord
7
-
8
- def self.available_strategies
9
- %w[truncation transaction deletion]
10
- end
11
-
12
- def self.config_file_location=(path)
13
- @config_file_location = path
14
- end
15
-
16
- def self.config_file_location
17
- @config_file_location ||= "#{DatabaseCleaner.app_root}/config/database.yml"
18
- end
19
-
20
- module Base
21
- include ::DatabaseCleaner::Generic::Base
22
-
23
- attr_accessor :connection_hash
24
-
25
- def db=(desired_db)
26
- @db = desired_db
27
- load_config
28
- end
29
-
30
- def db
31
- @db || super
32
- end
33
-
34
- def load_config
35
- if File.file?(ActiveRecord.config_file_location)
36
- connection_details = YAML::load(ERB.new(IO.read(ActiveRecord.config_file_location)).result)
37
- self.connection_hash = connection_details[self.db.to_s]
38
- end
39
- end
40
-
41
- def create_connection_klass
42
- Class.new(::ActiveRecord::Base)
43
- end
44
-
45
- def connection_klass
46
- return ::ActiveRecord::Base if connection_hash.nil?
47
- klass = create_connection_klass
48
- klass.send :establish_connection, connection_hash
49
- klass
50
- end
51
- end
52
- end
53
- end