database_cleaner 0.6.7 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/database_cleaner.rb +1 -3
- metadata +48 -154
- data/Gemfile.lock +0 -161
- data/History.txt +0 -173
- data/LICENSE +0 -20
- data/README.textile +0 -165
- data/Rakefile +0 -65
- data/TODO +0 -3
- data/VERSION.yml +0 -5
- data/cucumber.yml +0 -1
- data/examples/Gemfile +0 -48
- data/examples/Gemfile.lock +0 -161
- data/examples/config/database.yml.example +0 -8
- data/examples/db/sqlite_databases_go_here +0 -0
- data/examples/features/example.feature +0 -11
- data/examples/features/example_multiple_db.feature +0 -23
- data/examples/features/example_multiple_orm.feature +0 -22
- data/examples/features/step_definitions/activerecord_steps.rb +0 -31
- data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
- data/examples/features/step_definitions/datamapper_steps.rb +0 -37
- data/examples/features/step_definitions/mongoid_steps.rb +0 -23
- data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
- data/examples/features/step_definitions/translation_steps.rb +0 -55
- data/examples/features/support/env.rb +0 -62
- data/examples/lib/activerecord_models.rb +0 -41
- data/examples/lib/couchpotato_models.rb +0 -61
- data/examples/lib/datamapper_models.rb +0 -50
- data/examples/lib/mongoid_models.rb +0 -49
- data/examples/lib/mongomapper_models.rb +0 -51
- data/features/cleaning.feature +0 -22
- data/features/cleaning_default_strategy.feature +0 -19
- data/features/cleaning_multiple_dbs.feature +0 -21
- data/features/cleaning_multiple_orms.feature +0 -29
- data/features/step_definitions/database_cleaner_steps.rb +0 -32
- data/features/support/env.rb +0 -7
- data/features/support/feature_runner.rb +0 -39
- data/lib/database_cleaner/active_record/#transaction.rb# +0 -34
- data/lib/database_cleaner/active_record/base.rb +0 -53
- data/lib/database_cleaner/active_record/deletion.rb +0 -64
- data/lib/database_cleaner/active_record/transaction.rb +0 -26
- data/lib/database_cleaner/active_record/truncation.rb +0 -134
- data/lib/database_cleaner/base.rb +0 -136
- data/lib/database_cleaner/configuration.rb +0 -92
- data/lib/database_cleaner/couch_potato/base.rb +0 -7
- data/lib/database_cleaner/couch_potato/truncation.rb +0 -28
- data/lib/database_cleaner/cucumber.rb +0 -11
- data/lib/database_cleaner/data_mapper/base.rb +0 -21
- data/lib/database_cleaner/data_mapper/transaction.rb +0 -28
- data/lib/database_cleaner/data_mapper/truncation.rb +0 -175
- data/lib/database_cleaner/generic/base.rb +0 -23
- data/lib/database_cleaner/generic/truncation.rb +0 -43
- data/lib/database_cleaner/mongo/truncation.rb +0 -22
- data/lib/database_cleaner/mongo_mapper/base.rb +0 -20
- data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
- data/lib/database_cleaner/mongoid/base.rb +0 -20
- data/lib/database_cleaner/mongoid/truncation.rb +0 -20
- data/lib/database_cleaner/null_strategy.rb +0 -15
- data/spec/database_cleaner/active_record/base_spec.rb +0 -141
- data/spec/database_cleaner/active_record/transaction_spec.rb +0 -65
- data/spec/database_cleaner/active_record/truncation_spec.rb +0 -82
- data/spec/database_cleaner/base_spec.rb +0 -478
- data/spec/database_cleaner/configuration_spec.rb +0 -294
- data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
- data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
- data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
- data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
- data/spec/database_cleaner/generic/base_spec.rb +0 -22
- data/spec/database_cleaner/generic/truncation_spec.rb +0 -78
- data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
- data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
- data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
- data/spec/database_cleaner/shared_strategy_spec.rb +0 -13
- data/spec/rcov.opts +0 -1
- data/spec/spec.opts +0 -7
- data/spec/spec_helper.rb +0 -19
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'active_record/base'
|
2
|
-
require 'active_record/connection_adapters/abstract_adapter'
|
3
|
-
require "database_cleaner/generic/truncation"
|
4
|
-
require 'database_cleaner/active_record/base'
|
5
|
-
require 'database_cleaner/active_record/truncation'
|
6
|
-
# This file may seem to have duplication with that of truncation, but by keeping them separate
|
7
|
-
# we avoiding loading this code when it is not being used (which is the common case).
|
8
|
-
|
9
|
-
module ActiveRecord
|
10
|
-
module ConnectionAdapters
|
11
|
-
|
12
|
-
class MysqlAdapter < MYSQL_ADAPTER_PARENT
|
13
|
-
def delete_table(table_name)
|
14
|
-
execute("DELETE FROM #{quote_table_name(table_name)};")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Mysql2Adapter < AbstractAdapter
|
19
|
-
def delete_table(table_name)
|
20
|
-
execute("DELETE FROM #{quote_table_name(table_name)};")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class JdbcAdapter < AbstractAdapter
|
25
|
-
def delete_table(table_name)
|
26
|
-
execute("DELETE FROM #{quote_table_name(table_name)};")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class PostgreSQLAdapter < AbstractAdapter
|
31
|
-
def delete_table(table_name)
|
32
|
-
execute("DELETE FROM #{quote_table_name(table_name)};")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class SQLServerAdapter < AbstractAdapter
|
37
|
-
def delete_table(table_name)
|
38
|
-
execute("DELETE FROM #{quote_table_name(table_name)};")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class OracleEnhancedAdapter < AbstractAdapter
|
43
|
-
def delete_table(table_name)
|
44
|
-
execute("DELETE FROM #{quote_table_name(table_name)}")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
module DatabaseCleaner::ActiveRecord
|
53
|
-
class Deletion < Truncation
|
54
|
-
|
55
|
-
def clean
|
56
|
-
each_table do |connection, table_name|
|
57
|
-
connection.delete_table table_name
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'database_cleaner/active_record/base'
|
2
|
-
module DatabaseCleaner::ActiveRecord
|
3
|
-
class Transaction
|
4
|
-
include ::DatabaseCleaner::ActiveRecord::Base
|
5
|
-
|
6
|
-
def start
|
7
|
-
if connection_klass.connection.respond_to?(:increment_open_transactions)
|
8
|
-
connection_klass.connection.increment_open_transactions
|
9
|
-
else
|
10
|
-
connection_klass.__send__(:increment_open_transactions)
|
11
|
-
end
|
12
|
-
connection_klass.connection.begin_db_transaction
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
def clean
|
17
|
-
connection_klass.connection.rollback_db_transaction
|
18
|
-
|
19
|
-
if connection_klass.connection.respond_to?(:decrement_open_transactions)
|
20
|
-
connection_klass.connection.decrement_open_transactions
|
21
|
-
else
|
22
|
-
connection_klass.__send__(:decrement_open_transactions)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
require 'active_record/base'
|
2
|
-
require 'active_record/connection_adapters/abstract_adapter'
|
3
|
-
require "database_cleaner/generic/truncation"
|
4
|
-
require 'database_cleaner/active_record/base'
|
5
|
-
|
6
|
-
module ActiveRecord
|
7
|
-
module ConnectionAdapters
|
8
|
-
# Activerecord-jdbc-adapter defines class dependencies a bit differently - if it is present, confirm to ArJdbc hierarchy to avoid 'superclass mismatch' errors.
|
9
|
-
USE_ARJDBC_WORKAROUND = defined?(ArJdbc)
|
10
|
-
|
11
|
-
class AbstractAdapter
|
12
|
-
def views
|
13
|
-
@views ||= select_values("select table_name from information_schema.views where table_schema = '#{current_database}'") rescue []
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
unless USE_ARJDBC_WORKAROUND
|
18
|
-
class SQLiteAdapter < AbstractAdapter
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
MYSQL_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
|
23
|
-
SQLITE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : SQLiteAdapter
|
24
|
-
|
25
|
-
class MysqlAdapter < MYSQL_ADAPTER_PARENT
|
26
|
-
def truncate_table(table_name)
|
27
|
-
execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class Mysql2Adapter < AbstractAdapter
|
32
|
-
def truncate_table(table_name)
|
33
|
-
execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class IBM_DBAdapter < AbstractAdapter
|
38
|
-
def truncate_table(table_name)
|
39
|
-
execute("TRUNCATE #{quote_table_name(table_name)} IMMEDIATE")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class SQLite3Adapter < SQLITE_ADAPTER_PARENT
|
44
|
-
def delete_table(table_name)
|
45
|
-
execute("DELETE FROM #{quote_table_name(table_name)};")
|
46
|
-
end
|
47
|
-
alias truncate_table delete_table
|
48
|
-
end
|
49
|
-
|
50
|
-
class JdbcAdapter < AbstractAdapter
|
51
|
-
def truncate_table(table_name)
|
52
|
-
begin
|
53
|
-
execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
|
54
|
-
rescue ActiveRecord::StatementInvalid
|
55
|
-
execute("DELETE FROM #{quote_table_name(table_name)};")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
class PostgreSQLAdapter < AbstractAdapter
|
61
|
-
|
62
|
-
def db_version
|
63
|
-
@db_version ||= postgresql_version
|
64
|
-
end
|
65
|
-
|
66
|
-
def cascade
|
67
|
-
@cascade ||= db_version >= 80200 ? 'CASCADE' : ''
|
68
|
-
end
|
69
|
-
|
70
|
-
def restart_identity
|
71
|
-
@restart_identity ||= db_version >= 80400 ? 'RESTART IDENTITY' : ''
|
72
|
-
end
|
73
|
-
|
74
|
-
def truncate_table(table_name)
|
75
|
-
execute("TRUNCATE TABLE #{quote_table_name(table_name)} #{restart_identity} #{cascade};")
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
class SQLServerAdapter < AbstractAdapter
|
81
|
-
def truncate_table(table_name)
|
82
|
-
begin
|
83
|
-
execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
|
84
|
-
rescue ActiveRecord::StatementInvalid
|
85
|
-
execute("DELETE FROM #{quote_table_name(table_name)};")
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
class OracleEnhancedAdapter < AbstractAdapter
|
91
|
-
def truncate_table(table_name)
|
92
|
-
execute("TRUNCATE TABLE #{quote_table_name(table_name)}")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
module DatabaseCleaner::ActiveRecord
|
101
|
-
class Truncation
|
102
|
-
include ::DatabaseCleaner::ActiveRecord::Base
|
103
|
-
include ::DatabaseCleaner::Generic::Truncation
|
104
|
-
|
105
|
-
def clean
|
106
|
-
each_table do |connection, table_name|
|
107
|
-
connection.truncate_table table_name
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def each_table
|
112
|
-
connection = connection_klass.connection
|
113
|
-
connection.disable_referential_integrity do
|
114
|
-
tables_to_truncate(connection).each do |table_name|
|
115
|
-
yield connection, table_name
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
private
|
121
|
-
|
122
|
-
def tables_to_truncate(connection)
|
123
|
-
(@only || connection.tables) - @tables_to_exclude - connection.views
|
124
|
-
end
|
125
|
-
|
126
|
-
# overwritten
|
127
|
-
def migration_storage_name
|
128
|
-
'schema_migrations'
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
|
@@ -1,136 +0,0 @@
|
|
1
|
-
require 'database_cleaner/null_strategy'
|
2
|
-
module DatabaseCleaner
|
3
|
-
class Base
|
4
|
-
|
5
|
-
def initialize(desired_orm = nil,opts = {})
|
6
|
-
if [:autodetect, nil, "autodetect"].include?(desired_orm)
|
7
|
-
autodetect
|
8
|
-
else
|
9
|
-
self.orm = desired_orm
|
10
|
-
end
|
11
|
-
self.db = opts[:connection] if opts.has_key? :connection
|
12
|
-
set_default_orm_strategy
|
13
|
-
end
|
14
|
-
|
15
|
-
def db=(desired_db)
|
16
|
-
self.strategy_db = desired_db
|
17
|
-
@db = desired_db
|
18
|
-
end
|
19
|
-
|
20
|
-
def strategy_db=(desired_db)
|
21
|
-
if strategy.respond_to? :db=
|
22
|
-
strategy.db = desired_db
|
23
|
-
elsif desired_db!= :default
|
24
|
-
raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def db
|
29
|
-
@db || :default
|
30
|
-
end
|
31
|
-
|
32
|
-
def create_strategy(*args)
|
33
|
-
strategy, *strategy_args = args
|
34
|
-
orm_strategy(strategy).new(*strategy_args)
|
35
|
-
end
|
36
|
-
|
37
|
-
def clean_with(*args)
|
38
|
-
strategy = create_strategy(*args)
|
39
|
-
strategy.clean
|
40
|
-
strategy
|
41
|
-
end
|
42
|
-
|
43
|
-
alias clean_with! clean_with
|
44
|
-
|
45
|
-
def strategy=(args)
|
46
|
-
strategy, *strategy_args = args
|
47
|
-
if strategy.is_a?(Symbol)
|
48
|
-
@strategy = create_strategy(*args)
|
49
|
-
elsif strategy_args.empty?
|
50
|
-
@strategy = strategy
|
51
|
-
else
|
52
|
-
raise ArgumentError, "You must provide a strategy object, or a symbol for a known strategy along with initialization params."
|
53
|
-
end
|
54
|
-
|
55
|
-
self.strategy_db = self.db
|
56
|
-
|
57
|
-
@strategy
|
58
|
-
end
|
59
|
-
|
60
|
-
def strategy
|
61
|
-
@strategy || NullStrategy
|
62
|
-
end
|
63
|
-
|
64
|
-
def orm=(desired_orm)
|
65
|
-
@orm = desired_orm.to_sym
|
66
|
-
end
|
67
|
-
|
68
|
-
def orm
|
69
|
-
@orm || autodetect
|
70
|
-
end
|
71
|
-
|
72
|
-
def start
|
73
|
-
strategy.start
|
74
|
-
end
|
75
|
-
|
76
|
-
def clean
|
77
|
-
strategy.clean
|
78
|
-
end
|
79
|
-
|
80
|
-
alias clean! clean
|
81
|
-
|
82
|
-
def auto_detected?
|
83
|
-
return true unless @autodetected.nil?
|
84
|
-
end
|
85
|
-
|
86
|
-
#TODO make strategies directly comparable
|
87
|
-
def ==(other)
|
88
|
-
self.orm == other.orm && self.db == other.db && self.strategy.class == other.strategy.class
|
89
|
-
end
|
90
|
-
|
91
|
-
private
|
92
|
-
|
93
|
-
def orm_module
|
94
|
-
::DatabaseCleaner.orm_module(orm)
|
95
|
-
end
|
96
|
-
|
97
|
-
def orm_strategy(strategy)
|
98
|
-
require "database_cleaner/#{orm.to_s}/#{strategy.to_s}"
|
99
|
-
orm_module.const_get(strategy.to_s.capitalize)
|
100
|
-
rescue LoadError => e
|
101
|
-
if orm_module.respond_to? :available_strategies
|
102
|
-
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}"
|
103
|
-
else
|
104
|
-
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM!"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def autodetect
|
109
|
-
@orm ||= begin
|
110
|
-
@autodetected = true
|
111
|
-
if defined? ::ActiveRecord
|
112
|
-
:active_record
|
113
|
-
elsif defined? ::DataMapper
|
114
|
-
:data_mapper
|
115
|
-
elsif defined? ::MongoMapper
|
116
|
-
:mongo_mapper
|
117
|
-
elsif defined? ::Mongoid
|
118
|
-
:mongoid
|
119
|
-
elsif defined? ::CouchPotato
|
120
|
-
:couch_potato
|
121
|
-
else
|
122
|
-
raise NoORMDetected, "No known ORM was detected! Is ActiveRecord, DataMapper, MongoMapper, Mongoid, or CouchPotato loaded?"
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def set_default_orm_strategy
|
128
|
-
case orm
|
129
|
-
when :active_record, :data_mapper
|
130
|
-
self.strategy = :transaction
|
131
|
-
when :mongo_mapper, :mongoid, :couch_potato
|
132
|
-
self.strategy = :truncation
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'database_cleaner/base'
|
2
|
-
|
3
|
-
module DatabaseCleaner
|
4
|
-
|
5
|
-
class NoORMDetected < StandardError; end
|
6
|
-
class UnknownStrategySpecified < ArgumentError; end
|
7
|
-
|
8
|
-
class << self
|
9
|
-
def [](orm,opts = {})
|
10
|
-
raise NoORMDetected if orm.nil?
|
11
|
-
@connections ||= []
|
12
|
-
cleaner = DatabaseCleaner::Base.new(orm,opts)
|
13
|
-
connections.push cleaner
|
14
|
-
cleaner
|
15
|
-
end
|
16
|
-
|
17
|
-
def app_root=(desired_root)
|
18
|
-
@app_root = desired_root
|
19
|
-
end
|
20
|
-
|
21
|
-
def app_root
|
22
|
-
@app_root || Dir.pwd
|
23
|
-
end
|
24
|
-
|
25
|
-
def connections
|
26
|
-
@connections ||= [::DatabaseCleaner::Base.new]
|
27
|
-
end
|
28
|
-
|
29
|
-
def logger=(log_source)
|
30
|
-
@logger = log_source
|
31
|
-
end
|
32
|
-
|
33
|
-
def logger
|
34
|
-
return @logger if @logger
|
35
|
-
|
36
|
-
@logger = Logger.new(STDOUT)
|
37
|
-
@logger.level = Logger::ERROR
|
38
|
-
@logger
|
39
|
-
end
|
40
|
-
|
41
|
-
def strategy=(stratagem)
|
42
|
-
self.connections.each { |connect| connect.strategy = stratagem }
|
43
|
-
remove_duplicates
|
44
|
-
end
|
45
|
-
|
46
|
-
def orm=(orm)
|
47
|
-
self.connections.each { |connect| connect.orm = orm }
|
48
|
-
remove_duplicates
|
49
|
-
end
|
50
|
-
|
51
|
-
def start
|
52
|
-
self.connections.each { |connection| connection.start }
|
53
|
-
end
|
54
|
-
|
55
|
-
def clean
|
56
|
-
self.connections.each { |connection| connection.clean }
|
57
|
-
end
|
58
|
-
|
59
|
-
alias clean! clean
|
60
|
-
|
61
|
-
def clean_with(*args)
|
62
|
-
self.connections.each { |connection| connection.clean_with(*args) }
|
63
|
-
end
|
64
|
-
|
65
|
-
alias clean_with! clean_with
|
66
|
-
|
67
|
-
def remove_duplicates
|
68
|
-
temp = []
|
69
|
-
self.connections.each do |connect|
|
70
|
-
temp.push connect unless temp.include? connect
|
71
|
-
end
|
72
|
-
@connections = temp
|
73
|
-
end
|
74
|
-
|
75
|
-
def orm_module(symbol)
|
76
|
-
case symbol
|
77
|
-
when :active_record
|
78
|
-
DatabaseCleaner::ActiveRecord
|
79
|
-
when :data_mapper
|
80
|
-
DatabaseCleaner::DataMapper
|
81
|
-
when :mongo
|
82
|
-
DatabaseCleaner::Mongo
|
83
|
-
when :mongoid
|
84
|
-
DatabaseCleaner::Mongoid
|
85
|
-
when :mongo_mapper
|
86
|
-
DatabaseCleaner::MongoMapper
|
87
|
-
when :couch_potato
|
88
|
-
DatabaseCleaner::CouchPotato
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'database_cleaner/generic/truncation'
|
2
|
-
|
3
|
-
module DatabaseCleaner
|
4
|
-
module CouchPotato
|
5
|
-
class Truncation
|
6
|
-
include ::DatabaseCleaner::Generic::Truncation
|
7
|
-
|
8
|
-
def initialize(options = {})
|
9
|
-
if options.has_key?(:only) || options.has_key?(:except)
|
10
|
-
raise ArgumentError, "The :only and :except options are not available for use with CouchPotato/CouchDB."
|
11
|
-
elsif !options.empty?
|
12
|
-
raise ArgumentError, "Unsupported option. You specified #{options.keys.join(',')}."
|
13
|
-
end
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
def clean
|
18
|
-
database.recreate!
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def database
|
24
|
-
::CouchPotato.couchrest_database
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'database_cleaner/generic/base'
|
2
|
-
module DatabaseCleaner
|
3
|
-
module DataMapper
|
4
|
-
def self.available_strategies
|
5
|
-
%w[truncation transaction]
|
6
|
-
end
|
7
|
-
|
8
|
-
module Base
|
9
|
-
include ::DatabaseCleaner::Generic::Base
|
10
|
-
|
11
|
-
def db=(desired_db)
|
12
|
-
@db = desired_db
|
13
|
-
end
|
14
|
-
|
15
|
-
def db
|
16
|
-
@db || :default
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'database_cleaner/data_mapper/base'
|
2
|
-
|
3
|
-
module DatabaseCleaner::DataMapper
|
4
|
-
class Transaction
|
5
|
-
include ::DatabaseCleaner::DataMapper::Base
|
6
|
-
#TODO Figure out repositories, may have to refactor connection_klass to something more sensible
|
7
|
-
def start(repository = nil)
|
8
|
-
repository = self.db if repository.nil?
|
9
|
-
::DataMapper.repository(repository) do |r|
|
10
|
-
transaction = DataMapper::Transaction.new(r)
|
11
|
-
transaction.begin
|
12
|
-
r.adapter.push_transaction(transaction)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def clean(repository = nil)
|
17
|
-
repository = self.db if repository.nil?
|
18
|
-
::DataMapper.repository(repository) do |r|
|
19
|
-
adapter = r.adapter
|
20
|
-
while adapter.current_transaction
|
21
|
-
adapter.current_transaction.rollback
|
22
|
-
adapter.pop_transaction
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|