database_cleaner 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +19 -16
- data/History.rdoc +37 -0
- data/README.markdown +77 -7
- data/VERSION.yml +1 -1
- data/examples/Gemfile.lock +19 -16
- data/examples/db/activerecord_one.db +0 -0
- data/examples/db/activerecord_two.db +0 -0
- data/examples/db/datamapper_default.db +0 -0
- data/examples/db/datamapper_one.db +0 -0
- data/examples/db/datamapper_two.db +0 -0
- data/examples/lib/redis_models.rb +3 -3
- data/lib/database_cleaner/active_record/deletion.rb +1 -0
- data/lib/database_cleaner/active_record/truncation.rb +1 -1
- data/lib/database_cleaner/base.rb +6 -5
- data/lib/database_cleaner/mongo/truncation_mixin.rb +6 -2
- data/lib/database_cleaner/mongo2/truncation_mixin.rb +6 -4
- data/lib/database_cleaner/mongoid/truncation.rb +1 -1
- data/lib/database_cleaner/redis/base.rb +9 -3
- data/spec/database_cleaner/active_record/truncation_spec.rb +2 -2
- data/spec/database_cleaner/base_spec.rb +34 -21
- data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +2 -2
- data/spec/database_cleaner/redis/base_spec.rb +15 -4
- data/spec/database_cleaner/redis/truncation_spec.rb +1 -1
- data/spec/support/active_record/postgresql_setup.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2205055282f9fccb03b24e5d41985778c6f257a2
|
4
|
+
data.tar.gz: 28d503c34fd8f35f9f9f46526e145dad8dc29534
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd0ce19c0e1cfb249aa59c816b2f482c6fd279c1f404043b1f1354488edd8e757650778241c3c5c0b81c92957fe10dd0e17a498323a5a0d2849508cebd846e2f
|
7
|
+
data.tar.gz: eec65c6f11a279fe2f1bdf1a94c00f5dd245b5cfadb13c299487e2efe8494b62be1a47134677f3ccea3f02f355bf87e81a6fd8a846ada085191c86b281836efa
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
database_cleaner (1.5.
|
4
|
+
database_cleaner (1.5.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -69,7 +69,7 @@ GEM
|
|
69
69
|
dm-transactions (~> 1.2.0)
|
70
70
|
dm-types (~> 1.2.0)
|
71
71
|
dm-validations (~> 1.2.0)
|
72
|
-
diff-lcs (1.
|
72
|
+
diff-lcs (1.2.5)
|
73
73
|
dm-aggregates (1.2.0)
|
74
74
|
dm-core (~> 1.2.0)
|
75
75
|
dm-constraints (1.2.0)
|
@@ -210,7 +210,7 @@ GEM
|
|
210
210
|
activesupport (= 3.0.0)
|
211
211
|
rake (>= 0.8.4)
|
212
212
|
thor (~> 0.14.0)
|
213
|
-
rake (
|
213
|
+
rake (11.1.2)
|
214
214
|
rb-fsevent (0.9.4)
|
215
215
|
rb-inotify (0.9.5)
|
216
216
|
ffi (>= 0.5.0)
|
@@ -222,19 +222,22 @@ GEM
|
|
222
222
|
rest-client (1.6.8)
|
223
223
|
mime-types (~> 1.16)
|
224
224
|
rdoc (>= 2.4.2)
|
225
|
-
rspec (2.
|
226
|
-
rspec-core (~> 2.
|
227
|
-
rspec-expectations (~> 2.
|
228
|
-
rspec-mocks (~> 2.
|
229
|
-
rspec-core (2.
|
230
|
-
rspec-expectations (2.
|
231
|
-
diff-lcs (
|
232
|
-
rspec-mocks (2.
|
233
|
-
rspec-rails (2.
|
225
|
+
rspec (2.14.1)
|
226
|
+
rspec-core (~> 2.14.0)
|
227
|
+
rspec-expectations (~> 2.14.0)
|
228
|
+
rspec-mocks (~> 2.14.0)
|
229
|
+
rspec-core (2.14.8)
|
230
|
+
rspec-expectations (2.14.5)
|
231
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
232
|
+
rspec-mocks (2.14.6)
|
233
|
+
rspec-rails (2.14.2)
|
234
234
|
actionpack (>= 3.0)
|
235
|
+
activemodel (>= 3.0)
|
235
236
|
activesupport (>= 3.0)
|
236
237
|
railties (>= 3.0)
|
237
|
-
rspec (~> 2.
|
238
|
+
rspec-core (~> 2.14.0)
|
239
|
+
rspec-expectations (~> 2.14.0)
|
240
|
+
rspec-mocks (~> 2.14.0)
|
238
241
|
sequel (3.21.0)
|
239
242
|
slop (3.6.0)
|
240
243
|
spoon (0.0.4)
|
@@ -242,7 +245,7 @@ GEM
|
|
242
245
|
sqlite3 (1.3.10)
|
243
246
|
stringex (1.5.1)
|
244
247
|
thor (0.14.6)
|
245
|
-
tzinfo (0.3.
|
248
|
+
tzinfo (0.3.48)
|
246
249
|
uuidtools (2.1.5)
|
247
250
|
zip (2.0.2)
|
248
251
|
|
@@ -274,10 +277,10 @@ DEPENDENCIES
|
|
274
277
|
ohm (~> 0.1.3)
|
275
278
|
pg
|
276
279
|
rake
|
277
|
-
rspec-rails (~> 2.
|
280
|
+
rspec-rails (~> 2.14.2)
|
278
281
|
sequel (~> 3.21.0)
|
279
282
|
sqlite3
|
280
283
|
tzinfo
|
281
284
|
|
282
285
|
BUNDLED WITH
|
283
|
-
1.
|
286
|
+
1.11.2
|
data/History.rdoc
CHANGED
@@ -1,5 +1,42 @@
|
|
1
1
|
== Development (master)
|
2
2
|
|
3
|
+
== 1.5.2 2016-04-17
|
4
|
+
|
5
|
+
=== New Features/Changes
|
6
|
+
* Use default_client with mongoid 5.0 (@stjhimy)
|
7
|
+
* Added comparable support for strategies (@st0012)
|
8
|
+
* Better README instructions that suggest `append_after` (@jrochkind)
|
9
|
+
* Removed deprecation warnings for Rails 5.0+ (@pschambacher)
|
10
|
+
* Upgrade to RSpec 2.14 (@skalee)
|
11
|
+
|
12
|
+
=== Bug Fixes
|
13
|
+
* @dmitrypol fixed issue #409
|
14
|
+
* @schmierkov fixed the Travis builds with PR #416
|
15
|
+
* @shosti fixed issue #345
|
16
|
+
* @kylev fixed issue #379
|
17
|
+
* @skalee fixed the Travis builds for Neo4j with PR #433
|
18
|
+
|
19
|
+
== 1.5.1 2015-09-05
|
20
|
+
|
21
|
+
== Bug Fix
|
22
|
+
* Added mongo2 missing files to the gemspec. (@geerzo)
|
23
|
+
|
24
|
+
== 1.5.0 2015-09-02
|
25
|
+
|
26
|
+
=== New Features/Changes
|
27
|
+
* Use ensure within the cleaning method. (@cema-sp)
|
28
|
+
* Restored mysql2 + jruby support. (@ahorek)
|
29
|
+
* Added required ruby version to gemspec. (@garethrees)
|
30
|
+
* Added support for Mongoid 5.0 and Mongo Ruby Driver 2.0. (@jprincipe)
|
31
|
+
* Added support for additional Neo4j::Session.open options. (@brienw)
|
32
|
+
* And a bunch of code style and README improvements
|
33
|
+
|
34
|
+
=== Bug Fixes
|
35
|
+
* Fixed truncation for MongoDB 3. (@andreale)
|
36
|
+
* Fixed YAML error when building gem. (@joshnesbitt)
|
37
|
+
* Fixed deletion strategy for JDBC MySQL. (@DanElbert)
|
38
|
+
* Fixed open transactions for multiple connections. (@claptimes5)
|
39
|
+
|
3
40
|
== 1.4.1 2015-03-09
|
4
41
|
* Support for deletion with Sequel. (@cyberdelia)
|
5
42
|
* Use ActiveRecord::Base configuration when different from config file. (@wendy0402)
|
data/README.markdown
CHANGED
@@ -1,13 +1,25 @@
|
|
1
1
|
# Database Cleaner
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner)
|
5
|
+
|
3
6
|
Database Cleaner is a set of strategies for cleaning your database in Ruby.
|
4
7
|
|
5
8
|
The original use case was to ensure a clean state during tests.
|
6
9
|
Each strategy is a small amount of code but is code that is usually needed in any ruby app that is testing with a database.
|
7
10
|
|
8
|
-
|
11
|
+
## Gem Setup
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
# Gemfile
|
15
|
+
group :test do
|
16
|
+
gem 'database_cleaner'
|
17
|
+
end
|
18
|
+
```
|
9
19
|
|
10
|
-
|
20
|
+
## Supported Databases, Libraries and Strategies
|
21
|
+
|
22
|
+
ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, CouchPotato, Ohm and Redis are supported.
|
11
23
|
|
12
24
|
Here is an overview of the strategies supported for each library:
|
13
25
|
|
@@ -76,7 +88,7 @@ Here is an overview of the strategies supported for each library:
|
|
76
88
|
</tbody>
|
77
89
|
</table>
|
78
90
|
|
79
|
-
|
91
|
+
\* Truncation and Deletion strategies for Neo4j will just delete all nodes and relationships from the database.
|
80
92
|
|
81
93
|
<table>
|
82
94
|
<tbody>
|
@@ -221,23 +233,81 @@ end
|
|
221
233
|
|
222
234
|
### RSpec with Capybara Example
|
223
235
|
|
224
|
-
|
236
|
+
You'll typically discover a feature spec is incorrectly using transaction
|
237
|
+
instead of truncation strategy when the data created in the spec is not
|
238
|
+
visible in the app-under-test.
|
239
|
+
|
240
|
+
A frequently occurring example of this is when, after creating a user in a
|
241
|
+
spec, the spec mysteriously fails to login with the user. This happens because
|
242
|
+
the user is created inside of an uncommitted transaction on one database
|
243
|
+
connection, while the login attempt is made using a separate database
|
244
|
+
connection. This separate database connection cannot access the
|
245
|
+
uncommitted user data created over the first database connection due to
|
246
|
+
transaction isolation.
|
247
|
+
|
248
|
+
For feature specs using a Capybara driver for an external
|
249
|
+
JavaScript-capable browser (in practice this is all drivers except
|
250
|
+
`:rack_test`), the Rack app under test and the specs do not share a
|
251
|
+
database connection.
|
252
|
+
|
253
|
+
When a spec and app-under-test do not share a database connection,
|
254
|
+
you'll likely need to use the truncation strategy instead of the
|
255
|
+
transaction strategy.
|
256
|
+
|
257
|
+
See the suggested config below to temporarily enable truncation strategy
|
258
|
+
for affected feature specs only. This config continues to use transaction
|
259
|
+
strategy for all other specs.
|
260
|
+
|
261
|
+
It's also recommended to use `append_after` to ensure `DatabaseCleaner.clean`
|
262
|
+
runs *after* the after-test cleanup `capybara/rspec` installs.
|
225
263
|
|
226
264
|
```ruby
|
265
|
+
require 'capybara/rspec'
|
266
|
+
|
267
|
+
#...
|
268
|
+
|
227
269
|
RSpec.configure do |config|
|
228
270
|
|
229
271
|
config.use_transactional_fixtures = false
|
230
272
|
|
231
273
|
config.before(:suite) do
|
274
|
+
if config.use_transactional_fixtures?
|
275
|
+
raise(<<-MSG)
|
276
|
+
Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
|
277
|
+
(or set it to false) to prevent uncommitted transactions being used in
|
278
|
+
JavaScript-dependent specs.
|
279
|
+
|
280
|
+
During testing, the app-under-test that the browser driver connects to
|
281
|
+
uses a different database connection to the database connection used by
|
282
|
+
the spec. The app's database connection would not be able to access
|
283
|
+
uncommitted transaction data setup over the spec's database connection.
|
284
|
+
MSG
|
285
|
+
end
|
232
286
|
DatabaseCleaner.clean_with(:truncation)
|
287
|
+
end
|
288
|
+
|
289
|
+
config.before(:each) do
|
290
|
+
DatabaseCleaner.strategy = :transaction
|
291
|
+
end
|
292
|
+
|
293
|
+
config.before(:each, type: :feature) do
|
294
|
+
# :rack_test driver's Rack app under test shares database connection
|
295
|
+
# with the specs, so continue to use transaction strategy for speed.
|
296
|
+
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
|
297
|
+
|
298
|
+
if !driver_shares_db_connection_with_specs
|
299
|
+
# Driver is probably for an external browser with an app
|
300
|
+
# under test that does *not* share a database connection with the
|
301
|
+
# specs, so use truncation strategy.
|
302
|
+
DatabaseCleaner.strategy = :truncation
|
303
|
+
end
|
233
304
|
end
|
234
305
|
|
235
|
-
config.before(:each) do
|
236
|
-
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
|
306
|
+
config.before(:each) do
|
237
307
|
DatabaseCleaner.start
|
238
308
|
end
|
239
309
|
|
240
|
-
config.
|
310
|
+
config.append_after(:each) do
|
241
311
|
DatabaseCleaner.clean
|
242
312
|
end
|
243
313
|
|
data/VERSION.yml
CHANGED
data/examples/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
database_cleaner (1.5.
|
4
|
+
database_cleaner (1.5.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -69,7 +69,7 @@ GEM
|
|
69
69
|
dm-transactions (~> 1.2.0)
|
70
70
|
dm-types (~> 1.2.0)
|
71
71
|
dm-validations (~> 1.2.0)
|
72
|
-
diff-lcs (1.
|
72
|
+
diff-lcs (1.2.5)
|
73
73
|
dm-aggregates (1.2.0)
|
74
74
|
dm-core (~> 1.2.0)
|
75
75
|
dm-constraints (1.2.0)
|
@@ -210,7 +210,7 @@ GEM
|
|
210
210
|
activesupport (= 3.0.0)
|
211
211
|
rake (>= 0.8.4)
|
212
212
|
thor (~> 0.14.0)
|
213
|
-
rake (
|
213
|
+
rake (11.1.2)
|
214
214
|
rb-fsevent (0.9.4)
|
215
215
|
rb-inotify (0.9.5)
|
216
216
|
ffi (>= 0.5.0)
|
@@ -222,19 +222,22 @@ GEM
|
|
222
222
|
rest-client (1.6.8)
|
223
223
|
mime-types (~> 1.16)
|
224
224
|
rdoc (>= 2.4.2)
|
225
|
-
rspec (2.
|
226
|
-
rspec-core (~> 2.
|
227
|
-
rspec-expectations (~> 2.
|
228
|
-
rspec-mocks (~> 2.
|
229
|
-
rspec-core (2.
|
230
|
-
rspec-expectations (2.
|
231
|
-
diff-lcs (
|
232
|
-
rspec-mocks (2.
|
233
|
-
rspec-rails (2.
|
225
|
+
rspec (2.14.1)
|
226
|
+
rspec-core (~> 2.14.0)
|
227
|
+
rspec-expectations (~> 2.14.0)
|
228
|
+
rspec-mocks (~> 2.14.0)
|
229
|
+
rspec-core (2.14.8)
|
230
|
+
rspec-expectations (2.14.5)
|
231
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
232
|
+
rspec-mocks (2.14.6)
|
233
|
+
rspec-rails (2.14.2)
|
234
234
|
actionpack (>= 3.0)
|
235
|
+
activemodel (>= 3.0)
|
235
236
|
activesupport (>= 3.0)
|
236
237
|
railties (>= 3.0)
|
237
|
-
rspec (~> 2.
|
238
|
+
rspec-core (~> 2.14.0)
|
239
|
+
rspec-expectations (~> 2.14.0)
|
240
|
+
rspec-mocks (~> 2.14.0)
|
238
241
|
sequel (3.21.0)
|
239
242
|
slop (3.6.0)
|
240
243
|
spoon (0.0.4)
|
@@ -242,7 +245,7 @@ GEM
|
|
242
245
|
sqlite3 (1.3.10)
|
243
246
|
stringex (1.5.1)
|
244
247
|
thor (0.14.6)
|
245
|
-
tzinfo (0.3.
|
248
|
+
tzinfo (0.3.48)
|
246
249
|
uuidtools (2.1.5)
|
247
250
|
zip (2.0.2)
|
248
251
|
|
@@ -274,10 +277,10 @@ DEPENDENCIES
|
|
274
277
|
ohm (~> 0.1.3)
|
275
278
|
pg
|
276
279
|
rake
|
277
|
-
rspec-rails (~> 2.
|
280
|
+
rspec-rails (~> 2.14.2)
|
278
281
|
sequel (~> 3.21.0)
|
279
282
|
sqlite3
|
280
283
|
tzinfo
|
281
284
|
|
282
285
|
BUNDLED WITH
|
283
|
-
1.
|
286
|
+
1.11.2
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -3,7 +3,7 @@ require 'redis'
|
|
3
3
|
class RedisWidget
|
4
4
|
|
5
5
|
def self.redis
|
6
|
-
threaded ||= Redis.
|
6
|
+
threaded ||= Redis.new
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.redis=(connection)
|
@@ -45,7 +45,7 @@ end
|
|
45
45
|
class RedisWidgetUsingDatabaseOne < RedisWidget
|
46
46
|
|
47
47
|
def self.redis
|
48
|
-
threaded[self.class.to_s] ||= Redis.
|
48
|
+
threaded[self.class.to_s] ||= Redis.new :url => ENV['REDIS_URL_ONE']
|
49
49
|
end
|
50
50
|
|
51
51
|
def self.create!
|
@@ -56,7 +56,7 @@ end
|
|
56
56
|
class RedisWidgetUsingDatabaseTwo < RedisWidget
|
57
57
|
|
58
58
|
def self.redis
|
59
|
-
threaded[self.class.to_s] ||= Redis.
|
59
|
+
threaded[self.class.to_s] ||= Redis.new :url => ENV['REDIS_URL_TWO']
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.create!
|
@@ -59,6 +59,7 @@ module DatabaseCleaner::ActiveRecord
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def information_schema_exists? connection
|
62
|
+
return false unless connection.is_a? ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
62
63
|
@information_schema_exists ||=
|
63
64
|
begin
|
64
65
|
connection.execute("SELECT 1 FROM information_schema.tables")
|
@@ -27,7 +27,7 @@ module DatabaseCleaner
|
|
27
27
|
|
28
28
|
def database_cleaner_table_cache
|
29
29
|
# the adapters don't do caching (#130) but we make the assumption that the list stays the same in tests
|
30
|
-
@database_cleaner_tables ||= tables
|
30
|
+
@database_cleaner_tables ||= ::ActiveRecord::VERSION::MAJOR >= 5 ? data_sources : tables
|
31
31
|
end
|
32
32
|
|
33
33
|
def truncate_table(table_name)
|
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'database_cleaner/null_strategy'
|
2
2
|
module DatabaseCleaner
|
3
3
|
class Base
|
4
|
+
include Comparable
|
5
|
+
|
6
|
+
def <=>(other)
|
7
|
+
(self.orm <=> other.orm) == 0 ? self.db <=> other.db : self.orm <=> other.orm
|
8
|
+
end
|
9
|
+
|
4
10
|
def initialize(desired_orm = nil,opts = {})
|
5
11
|
if [:autodetect, nil, "autodetect"].include?(desired_orm)
|
6
12
|
autodetect
|
@@ -96,11 +102,6 @@ module DatabaseCleaner
|
|
96
102
|
!!@autodetected
|
97
103
|
end
|
98
104
|
|
99
|
-
#TODO make strategies directly comparable
|
100
|
-
def ==(other)
|
101
|
-
self.orm == other.orm && self.db == other.db
|
102
|
-
end
|
103
|
-
|
104
105
|
def autodetect_orm
|
105
106
|
if defined? ::ActiveRecord
|
106
107
|
:active_record
|
@@ -4,9 +4,9 @@ module DatabaseCleaner
|
|
4
4
|
|
5
5
|
def clean
|
6
6
|
if @only
|
7
|
-
collections.each { |c| c.
|
7
|
+
collections.each { |c| c.send(truncate_method_name) if @only.include?(c.name) }
|
8
8
|
else
|
9
|
-
collections.each { |c| c.
|
9
|
+
collections.each { |c| c.send(truncate_method_name) unless @tables_to_exclude.include?(c.name) }
|
10
10
|
end
|
11
11
|
true
|
12
12
|
end
|
@@ -17,6 +17,10 @@ module DatabaseCleaner
|
|
17
17
|
database.collections.select { |c| c.name !~ /^system\./ }
|
18
18
|
end
|
19
19
|
|
20
|
+
def truncate_method_name
|
21
|
+
# This constant only exists in the 2.x series.
|
22
|
+
defined?(::Mongo::VERSION) ? :delete_many : :remove
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
@@ -26,10 +26,12 @@ module DatabaseCleaner
|
|
26
26
|
database.use(db)
|
27
27
|
end
|
28
28
|
|
29
|
-
database
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
database.collections.collect { |c| c.namespace.split('.',2)[1] }
|
30
|
+
|
31
|
+
# database['system.namespaces'].find(:name => { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
|
32
|
+
# _, name = collection['name'].split('.', 2)
|
33
|
+
# name
|
34
|
+
# end
|
33
35
|
end
|
34
36
|
|
35
37
|
end
|
@@ -22,10 +22,16 @@ module DatabaseCleaner
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def connection
|
25
|
-
@connection ||=
|
25
|
+
@connection ||= begin
|
26
|
+
if url == :default
|
27
|
+
::Redis.new
|
28
|
+
elsif db.class.is_a?(::Redis) # pass directly the connection
|
29
|
+
db
|
30
|
+
else
|
31
|
+
::Redis.new(:url => url)
|
32
|
+
end
|
33
|
+
end
|
26
34
|
end
|
27
|
-
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|
31
|
-
|
@@ -118,7 +118,7 @@ module DatabaseCleaner
|
|
118
118
|
connection.should_receive(:database_cleaner_table_cache).and_return([])
|
119
119
|
connection.should_not_receive(:tables)
|
120
120
|
|
121
|
-
connection.stub
|
121
|
+
connection.stub(:truncate_tables)
|
122
122
|
Truncation.new({ :cache_tables => true }).clean
|
123
123
|
end
|
124
124
|
end
|
@@ -128,7 +128,7 @@ module DatabaseCleaner
|
|
128
128
|
connection.should_not_receive(:database_cleaner_table_cache)
|
129
129
|
connection.should_receive(:tables).and_return([])
|
130
130
|
|
131
|
-
connection.stub
|
131
|
+
connection.stub(:truncate_tables)
|
132
132
|
Truncation.new({ :cache_tables => false }).clean
|
133
133
|
end
|
134
134
|
end
|
@@ -9,6 +9,12 @@ require 'database_cleaner/neo4j/transaction'
|
|
9
9
|
module DatabaseCleaner
|
10
10
|
describe Base do
|
11
11
|
|
12
|
+
let(:mock_strategy) {
|
13
|
+
double("strategy").tap{|strategy|
|
14
|
+
strategy.stub(:to_ary => [strategy])
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
12
18
|
describe "autodetect" do
|
13
19
|
|
14
20
|
#Cache all ORMs, we'll need them later but not now.
|
@@ -201,18 +207,38 @@ module DatabaseCleaner
|
|
201
207
|
|
202
208
|
describe "comparison" do
|
203
209
|
it "should be equal if orm, connection and strategy are the same" do
|
204
|
-
strategy = mock("strategy")
|
205
|
-
strategy.stub!(:to_ary => [strategy])
|
206
|
-
|
207
210
|
one = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
208
|
-
one.strategy =
|
211
|
+
one.strategy = mock_strategy
|
209
212
|
|
210
213
|
two = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
211
|
-
two.strategy =
|
214
|
+
two.strategy = mock_strategy
|
212
215
|
|
213
216
|
one.should eq two
|
214
217
|
two.should eq one
|
215
218
|
end
|
219
|
+
|
220
|
+
it "should not be equal if orm are not the same" do
|
221
|
+
one = DatabaseCleaner::Base.new(:mongo_id, :connection => :default)
|
222
|
+
one.strategy = mock_strategy
|
223
|
+
|
224
|
+
two = DatabaseCleaner::Base.new(:active_record, :connection => :default)
|
225
|
+
two.strategy = mock_strategy
|
226
|
+
|
227
|
+
one.should_not eq two
|
228
|
+
two.should_not eq one
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should not be equal if connection are not the same" do
|
232
|
+
|
233
|
+
one = DatabaseCleaner::Base.new(:active_record, :connection => :default)
|
234
|
+
one.strategy = :truncation
|
235
|
+
|
236
|
+
two = DatabaseCleaner::Base.new(:active_record, :connection => :other)
|
237
|
+
two.strategy = :truncation
|
238
|
+
|
239
|
+
one.should_not eq two
|
240
|
+
two.should_not eq one
|
241
|
+
end
|
216
242
|
end
|
217
243
|
|
218
244
|
describe "initialization" do
|
@@ -269,11 +295,7 @@ module DatabaseCleaner
|
|
269
295
|
end
|
270
296
|
|
271
297
|
describe "strategy_db=" do
|
272
|
-
let(:strategy) {
|
273
|
-
mock("strategy").tap{|strategy|
|
274
|
-
strategy.stub!(:to_ary => [strategy])
|
275
|
-
}
|
276
|
-
}
|
298
|
+
let(:strategy) { mock_strategy }
|
277
299
|
|
278
300
|
before(:each) do
|
279
301
|
subject.strategy = strategy
|
@@ -373,12 +395,6 @@ module DatabaseCleaner
|
|
373
395
|
end
|
374
396
|
|
375
397
|
describe "strategy=" do
|
376
|
-
let(:mock_strategy) {
|
377
|
-
mock("strategy").tap{|strategy|
|
378
|
-
strategy.stub!(:to_ary => [strategy])
|
379
|
-
}
|
380
|
-
}
|
381
|
-
|
382
398
|
it "should proxy symbolised strategies to create_strategy" do
|
383
399
|
subject.should_receive(:create_strategy).with(:symbol)
|
384
400
|
subject.strategy = :symbol
|
@@ -417,11 +433,8 @@ module DatabaseCleaner
|
|
417
433
|
end
|
418
434
|
|
419
435
|
it "returns the set strategy" do
|
420
|
-
|
421
|
-
|
422
|
-
}
|
423
|
-
subject.strategy = strategum
|
424
|
-
subject.strategy.should eq strategum
|
436
|
+
subject.strategy = mock_strategy
|
437
|
+
subject.strategy.should eq mock_strategy
|
425
438
|
end
|
426
439
|
end
|
427
440
|
|
@@ -27,8 +27,8 @@ module DatabaseCleaner
|
|
27
27
|
expected_counts.each do |model_class, expected_count|
|
28
28
|
model_class.count.should equal(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
|
29
29
|
end
|
30
|
-
rescue
|
31
|
-
raise !sanity_check ? e :
|
30
|
+
rescue RSpec::Expectations::ExpectationNotMetError => e
|
31
|
+
raise !sanity_check ? e : RSpec::ExpectationNotMetError::ExpectationNotMetError.new("SANITY CHECK FAILURE! This should never happen here: #{e.message}")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'redis'
|
2
3
|
require 'database_cleaner/redis/base'
|
3
4
|
require 'database_cleaner/shared_strategy'
|
4
5
|
|
@@ -18,10 +19,20 @@ module DatabaseCleaner
|
|
18
19
|
it { should respond_to(:db) }
|
19
20
|
it { should respond_to(:db=) }
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
context "when passing url" do
|
23
|
+
it "should store my describe db" do
|
24
|
+
url = 'redis://localhost:6379/2'
|
25
|
+
subject.db = 'redis://localhost:6379/2'
|
26
|
+
subject.db.should eq url
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when passing connection" do
|
31
|
+
it "should store my describe db" do
|
32
|
+
connection = ::Redis.new :url => 'redis://localhost:6379/2'
|
33
|
+
subject.db = connection
|
34
|
+
subject.db.should eq connection
|
35
|
+
end
|
25
36
|
end
|
26
37
|
|
27
38
|
it "should default to :default" do
|
@@ -9,7 +9,7 @@ module DatabaseCleaner
|
|
9
9
|
describe Truncation do
|
10
10
|
before(:all) do
|
11
11
|
config = YAML::load(File.open("#{File.dirname(__FILE__)}/../../../examples/config/redis.yml"))
|
12
|
-
@redis = ::Redis.
|
12
|
+
@redis = ::Redis.new :url => config['test']['url']
|
13
13
|
end
|
14
14
|
|
15
15
|
before(:each) do
|
@@ -14,6 +14,7 @@ module PostgreSQLHelper
|
|
14
14
|
@encoding = default_config['encoding'] || ENV['CHARSET'] || 'utf8'
|
15
15
|
begin
|
16
16
|
establish_connection(default_config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
17
|
+
ActiveRecord::Base.connection.drop_database(default_config['database']) rescue nil
|
17
18
|
ActiveRecord::Base.connection.create_database(default_config['database'], default_config.merge('encoding' => @encoding))
|
18
19
|
rescue Exception => e
|
19
20
|
$stderr.puts e, *(e.backtrace)
|
@@ -32,7 +33,6 @@ module PostgreSQLHelper
|
|
32
33
|
end
|
33
34
|
|
34
35
|
def active_record_pg_migrate
|
35
|
-
`dropdb #{default_config['database']}`
|
36
36
|
create_db
|
37
37
|
establish_connection
|
38
38
|
ActiveRecord::Migrator.migrate 'spec/support/active_record/migrations'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Mabey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -268,14 +268,14 @@ dependencies:
|
|
268
268
|
requirements:
|
269
269
|
- - "~>"
|
270
270
|
- !ruby/object:Gem::Version
|
271
|
-
version: 2.
|
271
|
+
version: 2.14.2
|
272
272
|
type: :development
|
273
273
|
prerelease: false
|
274
274
|
version_requirements: !ruby/object:Gem::Requirement
|
275
275
|
requirements:
|
276
276
|
- - "~>"
|
277
277
|
- !ruby/object:Gem::Version
|
278
|
-
version: 2.
|
278
|
+
version: 2.14.2
|
279
279
|
- !ruby/object:Gem::Dependency
|
280
280
|
name: cucumber
|
281
281
|
requirement: !ruby/object:Gem::Requirement
|
@@ -540,7 +540,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
540
540
|
version: '0'
|
541
541
|
requirements: []
|
542
542
|
rubyforge_project:
|
543
|
-
rubygems_version: 2.4.
|
543
|
+
rubygems_version: 2.4.5.1
|
544
544
|
signing_key:
|
545
545
|
specification_version: 4
|
546
546
|
summary: Strategies for cleaning databases. Can be used to ensure a clean state for
|