database_cleaner 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +12 -12
- data/History.rdoc +17 -0
- data/README.markdown +4 -0
- data/Rakefile +1 -0
- data/VERSION.yml +2 -2
- data/examples/Gemfile.lock +12 -12
- data/lib/database_cleaner/active_record/base.rb +3 -3
- data/lib/database_cleaner/active_record/deletion.rb +19 -36
- data/lib/database_cleaner/active_record/truncation.rb +40 -67
- data/lib/database_cleaner/base.rb +3 -3
- data/lib/database_cleaner/configuration.rb +1 -1
- data/lib/database_cleaner/data_mapper/base.rb +1 -1
- data/lib/database_cleaner/data_mapper/truncation.rb +22 -2
- data/lib/database_cleaner/generic/truncation.rb +4 -3
- data/lib/database_cleaner/mongo_mapper/base.rb +1 -1
- data/lib/database_cleaner/moped/base.rb +2 -2
- data/lib/database_cleaner/redis/base.rb +1 -1
- data/spec/database_cleaner/active_record/base_spec.rb +10 -10
- data/spec/database_cleaner/active_record/transaction_spec.rb +1 -1
- data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +42 -0
- data/spec/database_cleaner/active_record/truncation_spec.rb +50 -29
- data/spec/database_cleaner/base_spec.rb +44 -48
- data/spec/database_cleaner/configuration_spec.rb +74 -74
- data/spec/database_cleaner/couch_potato/truncation_spec.rb +2 -2
- data/spec/database_cleaner/data_mapper/base_spec.rb +2 -2
- data/spec/database_cleaner/generic/base_spec.rb +1 -1
- data/spec/database_cleaner/generic/truncation_spec.rb +26 -16
- data/spec/database_cleaner/mongo_mapper/base_spec.rb +2 -2
- data/spec/database_cleaner/moped/truncation_spec.rb +1 -1
- data/spec/database_cleaner/ohm/truncation_spec.rb +8 -8
- data/spec/database_cleaner/redis/base_spec.rb +2 -2
- data/spec/database_cleaner/redis/truncation_spec.rb +8 -8
- data/spec/database_cleaner/sequel/base_spec.rb +2 -2
- data/spec/support/active_record/sqlite3_setup.rb +40 -0
- metadata +4 -2
data/Gemfile.lock
CHANGED
@@ -167,21 +167,21 @@ GEM
|
|
167
167
|
redis (3.0.4)
|
168
168
|
rest-client (1.6.7)
|
169
169
|
mime-types (>= 1.16)
|
170
|
-
rspec (2.
|
171
|
-
rspec-core (~> 2.
|
172
|
-
rspec-expectations (~> 2.
|
173
|
-
rspec-mocks (~> 2.
|
174
|
-
rspec-core (2.
|
175
|
-
rspec-expectations (2.
|
176
|
-
diff-lcs (
|
177
|
-
rspec-mocks (2.
|
178
|
-
rspec-rails (2.
|
170
|
+
rspec (2.14.1)
|
171
|
+
rspec-core (~> 2.14.0)
|
172
|
+
rspec-expectations (~> 2.14.0)
|
173
|
+
rspec-mocks (~> 2.14.0)
|
174
|
+
rspec-core (2.14.5)
|
175
|
+
rspec-expectations (2.14.2)
|
176
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
177
|
+
rspec-mocks (2.14.3)
|
178
|
+
rspec-rails (2.14.0)
|
179
179
|
actionpack (>= 3.0)
|
180
180
|
activesupport (>= 3.0)
|
181
181
|
railties (>= 3.0)
|
182
|
-
rspec-core (~> 2.
|
183
|
-
rspec-expectations (~> 2.
|
184
|
-
rspec-mocks (~> 2.
|
182
|
+
rspec-core (~> 2.14.0)
|
183
|
+
rspec-expectations (~> 2.14.0)
|
184
|
+
rspec-mocks (~> 2.14.0)
|
185
185
|
sequel (3.21.0)
|
186
186
|
slop (3.3.3)
|
187
187
|
sprockets (2.2.2)
|
data/History.rdoc
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
== 1.2.0 2013-10-09
|
2
|
+
|
3
|
+
A huge thanks goes to @tommeier for fixing the bug with class loading that was cuasing the wrong adapters
|
4
|
+
to be used in certain cases.
|
5
|
+
|
6
|
+
=== New Features/Changes
|
7
|
+
|
8
|
+
* Upgraded RSpec to remove deprecation warnings (John Rowe)
|
9
|
+
* Caching of tables to truncate is now optional (@marcoow)
|
10
|
+
|
11
|
+
=== Bug Fixes
|
12
|
+
|
13
|
+
* Use class_eval loading of superclasses to ensure right version of class is patched. (Tom Meier, Joel Nimety, Ernesto Tagwerker)
|
14
|
+
* Add truncate_tables method to SQLiteAdapter. (Chris Mo)
|
15
|
+
* Fixes missing #uses_sequence invokation in adapter classes for sqlite and sqlite3 (Lefteris Laskaridis)
|
16
|
+
|
17
|
+
|
1
18
|
== 1.1.1 2013-08-01
|
2
19
|
|
3
20
|
=== Bug Fixes
|
data/README.markdown
CHANGED
@@ -181,6 +181,10 @@ The following options are available for ActiveRecord's `:truncation` strategy _o
|
|
181
181
|
* `:pre_count` - When set to `true` this will check each table for existing rows before truncating it. This can speed up test suites when many of the tables to be truncated are never populated. Defaults to `:false`. (Also, see the section on [What strategy is fastest?](#what-strategy-is-fastest))
|
182
182
|
* `:reset_ids` - This only matters when `:pre_count` is used, and it will make sure that a tables auto-incrementing id is reset even if there are no rows in the table (e.g. records were created in the test but also removed before DatabaseCleaner gets to it). Defaults to `true`.
|
183
183
|
|
184
|
+
The following option is available for ActiveRecord's `:truncation` and `:deletion` strategy for any DB.
|
185
|
+
|
186
|
+
* `:cache_tables` - When set to `true` the list of tables to truncate or delete from will only be read from the DB once, otherwise it will be read before each cleanup run. Set this to `false` if you create and drop tables in your tests. Defaults to `true`.
|
187
|
+
|
184
188
|
|
185
189
|
### RSpec Example
|
186
190
|
|
data/Rakefile
CHANGED
@@ -14,6 +14,7 @@ begin
|
|
14
14
|
s.description = "Strategies for cleaning databases. Can be used to ensure a clean state for testing."
|
15
15
|
s.files = FileList["[A-Z]*.*", "{examples,lib,features,spec}/**/*", "Rakefile", "cucumber.yml"]
|
16
16
|
s.authors = ["Ben Mabey"]
|
17
|
+
s.licence = 'MIT'
|
17
18
|
end
|
18
19
|
rescue LoadError
|
19
20
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION.yml
CHANGED
data/examples/Gemfile.lock
CHANGED
@@ -167,21 +167,21 @@ GEM
|
|
167
167
|
redis (3.0.4)
|
168
168
|
rest-client (1.6.7)
|
169
169
|
mime-types (>= 1.16)
|
170
|
-
rspec (2.
|
171
|
-
rspec-core (~> 2.
|
172
|
-
rspec-expectations (~> 2.
|
173
|
-
rspec-mocks (~> 2.
|
174
|
-
rspec-core (2.
|
175
|
-
rspec-expectations (2.
|
176
|
-
diff-lcs (
|
177
|
-
rspec-mocks (2.
|
178
|
-
rspec-rails (2.
|
170
|
+
rspec (2.14.1)
|
171
|
+
rspec-core (~> 2.14.0)
|
172
|
+
rspec-expectations (~> 2.14.0)
|
173
|
+
rspec-mocks (~> 2.14.0)
|
174
|
+
rspec-core (2.14.5)
|
175
|
+
rspec-expectations (2.14.2)
|
176
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
177
|
+
rspec-mocks (2.14.3)
|
178
|
+
rspec-rails (2.14.0)
|
179
179
|
actionpack (>= 3.0)
|
180
180
|
activesupport (>= 3.0)
|
181
181
|
railties (>= 3.0)
|
182
|
-
rspec-core (~> 2.
|
183
|
-
rspec-expectations (~> 2.
|
184
|
-
rspec-mocks (~> 2.
|
182
|
+
rspec-core (~> 2.14.0)
|
183
|
+
rspec-expectations (~> 2.14.0)
|
184
|
+
rspec-mocks (~> 2.14.0)
|
185
185
|
sequel (3.21.0)
|
186
186
|
slop (3.3.3)
|
187
187
|
sprockets (2.2.2)
|
@@ -28,7 +28,7 @@ module DatabaseCleaner
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def db
|
31
|
-
@db
|
31
|
+
@db ||= super
|
32
32
|
end
|
33
33
|
|
34
34
|
def load_config
|
@@ -39,8 +39,8 @@ module DatabaseCleaner
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def connection_class
|
42
|
-
@connection_class ||= if
|
43
|
-
|
42
|
+
@connection_class ||= if db && !db.is_a?(Symbol)
|
43
|
+
db
|
44
44
|
elsif connection_hash
|
45
45
|
lookup_from_connection_pool || establish_connection
|
46
46
|
else
|
@@ -3,55 +3,41 @@ require 'active_record/connection_adapters/abstract_adapter'
|
|
3
3
|
require "database_cleaner/generic/truncation"
|
4
4
|
require 'database_cleaner/active_record/base'
|
5
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
6
|
|
9
|
-
module
|
7
|
+
module DatabaseCleaner
|
10
8
|
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 < MYSQL2_ADAPTER_PARENT
|
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 < POSTGRES_ADAPTER_PARENT
|
9
|
+
module AbstractDeleteAdapter
|
31
10
|
def delete_table(table_name)
|
32
|
-
|
11
|
+
raise NotImplementedError
|
33
12
|
end
|
34
13
|
end
|
35
14
|
|
36
|
-
|
15
|
+
module GenericDeleteAdapter
|
37
16
|
def delete_table(table_name)
|
38
17
|
execute("DELETE FROM #{quote_table_name(table_name)};")
|
39
18
|
end
|
40
19
|
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
20
|
end
|
49
21
|
end
|
50
22
|
|
23
|
+
module ActiveRecord
|
24
|
+
module ConnectionAdapters
|
25
|
+
AbstractAdapter.class_eval { include DatabaseCleaner::ConnectionAdapters::AbstractDeleteAdapter }
|
26
|
+
|
27
|
+
JdbcAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::GenericDeleteAdapter } if defined?(JdbcAdapter)
|
28
|
+
AbstractMysqlAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::GenericDeleteAdapter } if defined?(AbstractMysqlAdapter)
|
29
|
+
Mysql2Adapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::GenericDeleteAdapter } if defined?(Mysql2Adapter)
|
30
|
+
SQLiteAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::GenericDeleteAdapter } if defined?(SQLiteAdapter)
|
31
|
+
SQLite3Adapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::GenericDeleteAdapter } if defined?(SQLite3Adapter)
|
32
|
+
PostgreSQLAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::GenericDeleteAdapter } if defined?(PostgreSQLAdapter)
|
33
|
+
IBM_DBAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::GenericDeleteAdapter } if defined?(IBM_DBAdapter)
|
34
|
+
SQLServerAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::GenericDeleteAdapter } if defined?(SQLServerAdapter)
|
35
|
+
OracleEnhancedAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::GenericDeleteAdapter } if defined?(OracleEnhancedAdapter)
|
36
|
+
end
|
37
|
+
end
|
51
38
|
|
52
39
|
module DatabaseCleaner::ActiveRecord
|
53
40
|
class Deletion < Truncation
|
54
|
-
|
55
41
|
def clean
|
56
42
|
connection = connection_class.connection
|
57
43
|
connection.disable_referential_integrity do
|
@@ -60,8 +46,5 @@ module DatabaseCleaner::ActiveRecord
|
|
60
46
|
end
|
61
47
|
end
|
62
48
|
end
|
63
|
-
|
64
49
|
end
|
65
50
|
end
|
66
|
-
|
67
|
-
|
@@ -2,16 +2,19 @@ require 'active_record/base'
|
|
2
2
|
|
3
3
|
require 'active_record/connection_adapters/abstract_adapter'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
#Load available connection adapters
|
6
|
+
%w( abstract_mysql_adapter postgresql_adapter sqlite3_adapter ).each do |known_adapter|
|
7
|
+
begin
|
8
|
+
require "active_record/connection_adapters/#{known_adapter}"
|
9
|
+
rescue LoadError
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
10
13
|
require "database_cleaner/generic/truncation"
|
11
14
|
require 'database_cleaner/active_record/base'
|
12
15
|
|
13
16
|
module DatabaseCleaner
|
14
|
-
module
|
17
|
+
module ConnectionAdapters
|
15
18
|
|
16
19
|
module AbstractAdapter
|
17
20
|
# used to be called views but that can clash with gems like schema_plus
|
@@ -19,7 +22,6 @@ module DatabaseCleaner
|
|
19
22
|
def database_cleaner_view_cache
|
20
23
|
@views ||= select_values("select table_name from information_schema.views where table_schema = '#{current_database}'") rescue []
|
21
24
|
end
|
22
|
-
|
23
25
|
def database_cleaner_table_cache
|
24
26
|
# the adapters don't do caching (#130) but we make the assumption that the list stays the same in tests
|
25
27
|
@database_cleaner_tables ||= tables
|
@@ -36,8 +38,7 @@ module DatabaseCleaner
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
module
|
40
|
-
|
41
|
+
module AbstractMysqlAdapter
|
41
42
|
def truncate_table(table_name)
|
42
43
|
execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
|
43
44
|
end
|
@@ -53,7 +54,6 @@ module DatabaseCleaner
|
|
53
54
|
|
54
55
|
private
|
55
56
|
|
56
|
-
|
57
57
|
def row_count(table)
|
58
58
|
# Patch for MysqlAdapter with ActiveRecord 3.2.7 later
|
59
59
|
# select_value("SELECT 1") #=> "1"
|
@@ -65,15 +65,15 @@ module DatabaseCleaner
|
|
65
65
|
# but then the table is cleaned. In other words, this function tells us if the given table
|
66
66
|
# was ever inserted into.
|
67
67
|
def has_been_used?(table)
|
68
|
-
if
|
68
|
+
if has_rows?(table)
|
69
69
|
true
|
70
70
|
else
|
71
71
|
# Patch for MysqlAdapter with ActiveRecord 3.2.7 later
|
72
72
|
# select_value("SELECT 1") #=> "1"
|
73
73
|
select_value(<<-SQL).to_i > 1 # returns nil if not present
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
SELECT Auto_increment
|
75
|
+
FROM information_schema.tables
|
76
|
+
WHERE table_name='#{table}';
|
77
77
|
SQL
|
78
78
|
end
|
79
79
|
end
|
@@ -83,14 +83,12 @@ module DatabaseCleaner
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
|
87
86
|
module IBM_DBAdapter
|
88
87
|
def truncate_table(table_name)
|
89
88
|
execute("TRUNCATE #{quote_table_name(table_name)} IMMEDIATE")
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
|
-
|
94
92
|
module SQLiteAdapter
|
95
93
|
def delete_table(table_name)
|
96
94
|
execute("DELETE FROM #{quote_table_name(table_name)};")
|
@@ -100,6 +98,10 @@ module DatabaseCleaner
|
|
100
98
|
end
|
101
99
|
alias truncate_table delete_table
|
102
100
|
|
101
|
+
def truncate_tables(tables)
|
102
|
+
tables.each { |t| truncate_table(t) }
|
103
|
+
end
|
104
|
+
|
103
105
|
private
|
104
106
|
|
105
107
|
# Returns a boolean indicating if the SQLite database is using the sqlite_sequence table.
|
@@ -118,6 +120,12 @@ module DatabaseCleaner
|
|
118
120
|
end
|
119
121
|
end
|
120
122
|
|
123
|
+
module OracleEnhancedAdapter
|
124
|
+
def truncate_table(table_name)
|
125
|
+
execute("TRUNCATE TABLE #{quote_table_name(table_name)}")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
121
129
|
module PostgreSQLAdapter
|
122
130
|
def db_version
|
123
131
|
@db_version ||= postgresql_version
|
@@ -160,66 +168,26 @@ module DatabaseCleaner
|
|
160
168
|
select_value("SELECT true FROM #{table} LIMIT 1;")
|
161
169
|
end
|
162
170
|
end
|
163
|
-
|
164
|
-
module OracleEnhancedAdapter
|
165
|
-
def truncate_table(table_name)
|
166
|
-
execute("TRUNCATE TABLE #{quote_table_name(table_name)}")
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
171
|
end
|
171
172
|
end
|
172
173
|
|
173
|
-
#TODO: Remove monkeypatching and decorate the connection instead!
|
174
|
-
|
175
174
|
module ActiveRecord
|
176
175
|
module ConnectionAdapters
|
177
|
-
#
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
if
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
end
|
190
|
-
MYSQL2_ADAPTER_PARENT = MYSQL_ABSTRACT_ADAPTER
|
191
|
-
|
192
|
-
if defined?(SQLite3Adapter) && SQLite3Adapter.superclass == ActiveRecord::ConnectionAdapters::AbstractAdapter
|
193
|
-
SQLITE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
|
194
|
-
else
|
195
|
-
SQLITE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : SQLiteAdapter
|
196
|
-
end
|
197
|
-
POSTGRES_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
|
198
|
-
|
199
|
-
MYSQL_ADAPTER_PARENT.class_eval { include ::DatabaseCleaner::ActiveRecord::MysqlAdapter }
|
200
|
-
MYSQL2_ADAPTER_PARENT.class_eval { include ::DatabaseCleaner::ActiveRecord::MysqlAdapter }
|
201
|
-
SQLITE_ADAPTER_PARENT.class_eval { include ::DatabaseCleaner::ActiveRecord::SQLiteAdapter }
|
202
|
-
POSTGRES_ADAPTER_PARENT.class_eval { include ::DatabaseCleaner::ActiveRecord::PostgreSQLAdapter }
|
203
|
-
|
204
|
-
class IBM_DBAdapter < AbstractAdapter
|
205
|
-
include ::DatabaseCleaner::ActiveRecord::IBM_DBAdapter
|
206
|
-
end
|
207
|
-
|
208
|
-
class JdbcAdapter < AbstractAdapter
|
209
|
-
include ::DatabaseCleaner::ActiveRecord::TruncateOrDelete
|
210
|
-
end
|
211
|
-
|
212
|
-
class SQLServerAdapter < AbstractAdapter
|
213
|
-
include ::DatabaseCleaner::ActiveRecord::TruncateOrDelete
|
214
|
-
end
|
215
|
-
|
216
|
-
class OracleEnhancedAdapter < AbstractAdapter
|
217
|
-
include ::DatabaseCleaner::ActiveRecord::OracleEnhancedAdapter
|
218
|
-
end
|
176
|
+
#Apply adapter decoraters where applicable (adapter should be loaded)
|
177
|
+
AbstractAdapter.class_eval { include DatabaseCleaner::ConnectionAdapters::AbstractAdapter }
|
178
|
+
|
179
|
+
JdbcAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::TruncateOrDelete } if defined?(JdbcAdapter)
|
180
|
+
AbstractMysqlAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::AbstractMysqlAdapter } if defined?(AbstractMysqlAdapter)
|
181
|
+
Mysql2Adapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::AbstractMysqlAdapter } if defined?(Mysql2Adapter)
|
182
|
+
SQLiteAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::SQLiteAdapter } if defined?(SQLiteAdapter)
|
183
|
+
SQLite3Adapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::SQLiteAdapter } if defined?(SQLite3Adapter)
|
184
|
+
PostgreSQLAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::PostgreSQLAdapter } if defined?(PostgreSQLAdapter)
|
185
|
+
IBM_DBAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::IBM_DBAdapter } if defined?(IBM_DBAdapter)
|
186
|
+
SQLServerAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::TruncateOrDelete } if defined?(SQLServerAdapter)
|
187
|
+
OracleEnhancedAdapter.class_eval { include ::DatabaseCleaner::ConnectionAdapters::OracleEnhancedAdapter } if defined?(OracleEnhancedAdapter)
|
219
188
|
end
|
220
189
|
end
|
221
190
|
|
222
|
-
|
223
191
|
module DatabaseCleaner::ActiveRecord
|
224
192
|
class Truncation
|
225
193
|
include ::DatabaseCleaner::ActiveRecord::Base
|
@@ -239,7 +207,8 @@ module DatabaseCleaner::ActiveRecord
|
|
239
207
|
private
|
240
208
|
|
241
209
|
def tables_to_truncate(connection)
|
242
|
-
|
210
|
+
tables_in_db = cache_tables? ? connection.database_cleaner_table_cache : connection.tables
|
211
|
+
(@only || tables_in_db) - @tables_to_exclude - connection.database_cleaner_view_cache
|
243
212
|
end
|
244
213
|
|
245
214
|
# overwritten
|
@@ -247,6 +216,10 @@ module DatabaseCleaner::ActiveRecord
|
|
247
216
|
[::ActiveRecord::Migrator.schema_migrations_table_name]
|
248
217
|
end
|
249
218
|
|
219
|
+
def cache_tables?
|
220
|
+
!!@cache_tables
|
221
|
+
end
|
222
|
+
|
250
223
|
def pre_count?
|
251
224
|
@pre_count == true
|
252
225
|
end
|
@@ -25,7 +25,7 @@ module DatabaseCleaner
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def db
|
28
|
-
@db
|
28
|
+
@db ||= :default
|
29
29
|
end
|
30
30
|
|
31
31
|
def create_strategy(*args)
|
@@ -67,7 +67,7 @@ module DatabaseCleaner
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def strategy
|
70
|
-
@strategy
|
70
|
+
@strategy ||= NullStrategy
|
71
71
|
end
|
72
72
|
|
73
73
|
def orm=(desired_orm)
|
@@ -128,7 +128,7 @@ module DatabaseCleaner
|
|
128
128
|
def orm_strategy(strategy)
|
129
129
|
require "database_cleaner/#{orm.to_s}/#{strategy.to_s}"
|
130
130
|
orm_module.const_get(strategy.to_s.capitalize)
|
131
|
-
rescue LoadError
|
131
|
+
rescue LoadError
|
132
132
|
if orm_module.respond_to? :available_strategies
|
133
133
|
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}"
|
134
134
|
else
|