database_cleaner 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35bb176b3479b670a9d789e0b6115590fe84aeee
4
- data.tar.gz: 30b5dbd03d0b8ac5249712fbe2b1e9ec44809f99
3
+ metadata.gz: ee5d65788bad454f27cf157e4015b137c7f1df81
4
+ data.tar.gz: 824981f5faf89ee047760c5059f5ffc0315fd953
5
5
  SHA512:
6
- metadata.gz: 9e70863bb6c44d9fea1364be4d5308a7221c1b2babd6bc4d4fbbc5515eaee929d54b5bf655d8816ad7f1085f34136dcf7d471437c6c2ed535985e3fe421c3f63
7
- data.tar.gz: b93b8e8de63d8d5c7602b6e7ab219ebb4bfa9cfc9013e30f723879538aa1d0ef1943ca1652892836de8cd633a689af083ab639b24dc8370036e360ced9608cfb
6
+ metadata.gz: 89fe47e944fa6151f788c80607472c72316db36b516ade7780c11e9830bb7d55e977601453d865775fdedaddcae6109d8c163288e6aeebd974efcdfc61c95dff
7
+ data.tar.gz: 93c1ebe47ddbe32f66524711cba00adb70e13c9a501d6cd8caaf785f17771a9e7625e65d73afecb2847dbeb8b367003c0aa99ab4362f2c161c89557251b38257
@@ -1,3 +1,8 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ database_cleaner (1.5.0)
5
+
1
6
  GEM
2
7
  remote: https://rubygems.org/
3
8
  specs:
@@ -25,7 +30,6 @@ GEM
25
30
  mysql2
26
31
  activesupport (3.0.0)
27
32
  addressable (2.3.6)
28
- archive-tar-minitar (0.5.2)
29
33
  arel (1.0.1)
30
34
  activesupport (~> 3.0.0)
31
35
  bcrypt (3.1.7)
@@ -40,7 +44,6 @@ GEM
40
44
  bson (~> 1.11.1)
41
45
  builder (2.1.2)
42
46
  coderay (1.1.0)
43
- columnize (0.8.9)
44
47
  couch_potato (1.3.0)
45
48
  activemodel
46
49
  couchrest (~> 1.2.0)
@@ -101,8 +104,14 @@ GEM
101
104
  uuidtools (~> 2.1)
102
105
  dm-validations (1.2.0)
103
106
  dm-core (~> 1.2.0)
107
+ do_jdbc (0.10.14-java)
108
+ data_objects (= 0.10.14)
104
109
  do_sqlite3 (0.10.14)
105
110
  data_objects (= 0.10.14)
111
+ do_sqlite3 (0.10.14-java)
112
+ data_objects (= 0.10.14)
113
+ do_jdbc (= 0.10.14)
114
+ jdbc-sqlite3 (>= 3.5.8)
106
115
  erubis (2.6.6)
107
116
  abstract (>= 1.0.0)
108
117
  faraday (0.9.0)
@@ -131,13 +140,10 @@ GEM
131
140
  multi_xml (>= 0.5.2)
132
141
  httpclient (2.5.3.3)
133
142
  i18n (0.4.2)
143
+ jdbc-sqlite3 (3.8.10.1)
134
144
  json (1.8.1)
135
145
  json (1.8.1-java)
136
146
  json_pure (1.8.1)
137
- linecache (0.46)
138
- rbx-require-relative (> 0.0.4)
139
- linecache19 (0.5.12)
140
- ruby_core_source (>= 0.1.4)
141
147
  listen (1.3.1)
142
148
  rb-fsevent (>= 0.9.3)
143
149
  rb-inotify (>= 0.9)
@@ -163,7 +169,7 @@ GEM
163
169
  multi_xml (0.5.5)
164
170
  multipart-post (2.0.0)
165
171
  mysql (2.9.1)
166
- mysql2 (0.3.16)
172
+ mysql2 (0.3.18)
167
173
  neo4j-community (2.1.5)
168
174
  neo4j-core (3.0.8)
169
175
  activesupport
@@ -182,7 +188,7 @@ GEM
182
188
  ohm (0.1.5)
183
189
  nest (~> 1.0)
184
190
  os (0.9.6)
185
- pg (0.17.1)
191
+ pg (0.18.2)
186
192
  plucky (0.5.2)
187
193
  mongo (~> 1.5)
188
194
  pry (0.10.1)
@@ -210,7 +216,6 @@ GEM
210
216
  ffi (>= 0.5.0)
211
217
  rb-kqueue (0.2.3)
212
218
  ffi (>= 0.5.0)
213
- rbx-require-relative (0.0.9)
214
219
  rdoc (4.1.2)
215
220
  json (~> 1.4)
216
221
  redis (3.1.0)
@@ -230,28 +235,11 @@ GEM
230
235
  activesupport (>= 3.0)
231
236
  railties (>= 3.0)
232
237
  rspec (~> 2.11.0)
233
- ruby-debug (0.10.4)
234
- columnize (>= 0.1)
235
- ruby-debug-base (~> 0.10.4.0)
236
- ruby-debug-base (0.10.4)
237
- linecache (>= 0.3)
238
- ruby-debug-base19 (0.11.25)
239
- columnize (>= 0.3.1)
240
- linecache19 (>= 0.5.11)
241
- ruby_core_source (>= 0.1.4)
242
- ruby-debug19 (0.11.6)
243
- columnize (>= 0.3.1)
244
- linecache19 (>= 0.5.11)
245
- ruby-debug-base19 (>= 0.11.19)
246
- ruby_core_source (0.1.5)
247
- archive-tar-minitar (>= 0.5.2)
248
238
  sequel (3.21.0)
249
239
  slop (3.6.0)
250
240
  spoon (0.0.4)
251
241
  ffi
252
- sqlite3 (1.3.9)
253
- sqlite3-ruby (1.3.3)
254
- sqlite3 (>= 1.3.3)
242
+ sqlite3 (1.3.10)
255
243
  stringex (1.5.1)
256
244
  thor (0.14.6)
257
245
  tzinfo (0.3.41)
@@ -269,6 +257,7 @@ DEPENDENCIES
269
257
  bundler
270
258
  couch_potato
271
259
  cucumber
260
+ database_cleaner!
272
261
  datamapper
273
262
  dm-migrations
274
263
  dm-sqlite-adapter
@@ -285,10 +274,10 @@ DEPENDENCIES
285
274
  ohm (~> 0.1.3)
286
275
  pg
287
276
  rake
288
- rspec-rails
289
- ruby-debug
290
- ruby-debug19
277
+ rspec-rails (~> 2.11.0)
291
278
  sequel (~> 3.21.0)
292
279
  sqlite3
293
- sqlite3-ruby
294
280
  tzinfo
281
+
282
+ BUNDLED WITH
283
+ 1.10.5
@@ -7,7 +7,7 @@ Each strategy is a small amount of code but is code that is usually needed in an
7
7
 
8
8
  ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, CouchPotato, Ohm and Redis are supported.
9
9
 
10
- [![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner)
10
+ [![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner) [![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner)
11
11
 
12
12
  Here is an overview of the strategies supported for each library:
13
13
 
@@ -197,7 +197,7 @@ The following options are available for ActiveRecord's `:truncation` strategy _o
197
197
 
198
198
  The following option is available for ActiveRecord's `:truncation` and `:deletion` strategy for any DB.
199
199
 
200
- * `: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`.
200
+ * `: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 (1) you create and drop tables in your tests, or (2) you change Postgres schemas (`ActiveRecord::Base.connection.schema_search_path`) in your tests (for example, in a multitenancy setup with each tenant in a different Postgres schema). Defaults to `true`.
201
201
 
202
202
 
203
203
  ### RSpec Example
@@ -219,12 +219,38 @@ RSpec.configure do |config|
219
219
  end
220
220
  ```
221
221
 
222
+ ### RSpec with Capybara Example
223
+
224
+ If you're using Capybara with RSpec and using an external browser (not using RackTest) you'll almost certainly need to use truncation rather than transactions for tests tagged `:js`.
225
+
226
+ ```ruby
227
+ RSpec.configure do |config|
228
+
229
+ config.use_transactional_fixtures = false
230
+
231
+ config.before(:suite) do
232
+ DatabaseCleaner.clean_with(:truncation)
233
+ end
234
+
235
+ config.before(:each) do |example|
236
+ DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
237
+ DatabaseCleaner.start
238
+ end
239
+
240
+ config.after(:each) do
241
+ DatabaseCleaner.clean
242
+ end
243
+
244
+ end
245
+ ```
246
+
247
+
222
248
  ### Minitest Example
223
249
 
224
250
  ```ruby
225
251
  DatabaseCleaner.strategy = :transaction
226
252
 
227
- class MiniTest::Spec
253
+ class Minitest::Spec
228
254
  before :each do
229
255
  DatabaseCleaner.start
230
256
  end
@@ -279,10 +305,10 @@ DatabaseCleaner[:active_record].strategy = :transaction
279
305
  DatabaseCleaner[:mongo_mapper].strategy = :truncation
280
306
 
281
307
  #How to specify particular connections
282
- DatabaseCleaner[:active_record,{:connection => :two}]
308
+ DatabaseCleaner[:active_record, { :connection => :two }]
283
309
 
284
310
  # You may also pass in the model directly:
285
- DatabaseCleaner[:active_record,{:model => ModelWithDifferentConnection}]
311
+ DatabaseCleaner[:active_record, { :model => ModelWithDifferentConnection }]
286
312
  ```
287
313
 
288
314
  Usage beyond that remains the same with `DatabaseCleaner.start` calling any setup on the different configured connections, and `DatabaseCleaner.clean` executing afterwards.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 4
4
- :patch: 1
3
+ :minor: 5
4
+ :patch: 0
@@ -1,56 +1 @@
1
- source "https://rubygems.org"
2
- # TODO: move these to the gemspec...
3
-
4
- group :development, :test do
5
- gem "rake"
6
- gem "ruby-debug", :platform => :ruby_18
7
- gem "ruby-debug19", :platform => :ruby_19
8
- gem "bundler"
9
-
10
- gem "json_pure"
11
-
12
- gem "activerecord-mysql2-adapter"
13
- #ORM's
14
- gem "activerecord"
15
- gem "datamapper"
16
- gem "dm-migrations"
17
- gem "dm-sqlite-adapter"
18
- gem "mongoid"
19
- gem "tzinfo"
20
- gem "mongo_ext"
21
- gem "bson_ext"
22
- gem "mongoid-tree"
23
-
24
- gem "mongo_mapper"
25
- gem "moped"
26
- gem "neo4j-core"
27
- gem "couch_potato"
28
-
29
- gem "sequel", "~> 3.21.0"
30
- #gem "ibm_db" # I don't want to add this dependency, even as a dev one since it requires DB2 to be installed
31
- gem 'mysql', '~> 2.9.1'
32
- gem 'mysql2'
33
- gem 'pg'
34
- gem 'ohm', '~> 0.1.3'
35
-
36
- gem 'guard-rspec'
37
- end
38
-
39
- group :test do
40
- gem "rspec-rails"
41
- gem "sqlite3"
42
- end
43
-
44
- group :cucumber do
45
- gem "cucumber"
46
- end
47
-
48
- platforms :mri_18 do
49
- gem 'sqlite3-ruby', :group => :cucumber
50
- #gem 'mysql', :group => :development
51
- end
52
-
53
- platforms :mri_19 do
54
- gem 'sqlite3', :group => :cucumber
55
- #gem 'mysql2', :group => :development
56
- end
1
+ gemspec
@@ -1,3 +1,8 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ database_cleaner (1.5.0)
5
+
1
6
  GEM
2
7
  remote: https://rubygems.org/
3
8
  specs:
@@ -25,7 +30,6 @@ GEM
25
30
  mysql2
26
31
  activesupport (3.0.0)
27
32
  addressable (2.3.6)
28
- archive-tar-minitar (0.5.2)
29
33
  arel (1.0.1)
30
34
  activesupport (~> 3.0.0)
31
35
  bcrypt (3.1.7)
@@ -40,7 +44,6 @@ GEM
40
44
  bson (~> 1.11.1)
41
45
  builder (2.1.2)
42
46
  coderay (1.1.0)
43
- columnize (0.8.9)
44
47
  couch_potato (1.3.0)
45
48
  activemodel
46
49
  couchrest (~> 1.2.0)
@@ -101,8 +104,14 @@ GEM
101
104
  uuidtools (~> 2.1)
102
105
  dm-validations (1.2.0)
103
106
  dm-core (~> 1.2.0)
107
+ do_jdbc (0.10.14-java)
108
+ data_objects (= 0.10.14)
104
109
  do_sqlite3 (0.10.14)
105
110
  data_objects (= 0.10.14)
111
+ do_sqlite3 (0.10.14-java)
112
+ data_objects (= 0.10.14)
113
+ do_jdbc (= 0.10.14)
114
+ jdbc-sqlite3 (>= 3.5.8)
106
115
  erubis (2.6.6)
107
116
  abstract (>= 1.0.0)
108
117
  faraday (0.9.0)
@@ -131,13 +140,10 @@ GEM
131
140
  multi_xml (>= 0.5.2)
132
141
  httpclient (2.5.3.3)
133
142
  i18n (0.4.2)
143
+ jdbc-sqlite3 (3.8.10.1)
134
144
  json (1.8.1)
135
145
  json (1.8.1-java)
136
146
  json_pure (1.8.1)
137
- linecache (0.46)
138
- rbx-require-relative (> 0.0.4)
139
- linecache19 (0.5.12)
140
- ruby_core_source (>= 0.1.4)
141
147
  listen (1.3.1)
142
148
  rb-fsevent (>= 0.9.3)
143
149
  rb-inotify (>= 0.9)
@@ -163,7 +169,7 @@ GEM
163
169
  multi_xml (0.5.5)
164
170
  multipart-post (2.0.0)
165
171
  mysql (2.9.1)
166
- mysql2 (0.3.16)
172
+ mysql2 (0.3.18)
167
173
  neo4j-community (2.1.5)
168
174
  neo4j-core (3.0.8)
169
175
  activesupport
@@ -182,7 +188,7 @@ GEM
182
188
  ohm (0.1.5)
183
189
  nest (~> 1.0)
184
190
  os (0.9.6)
185
- pg (0.17.1)
191
+ pg (0.18.2)
186
192
  plucky (0.5.2)
187
193
  mongo (~> 1.5)
188
194
  pry (0.10.1)
@@ -210,7 +216,6 @@ GEM
210
216
  ffi (>= 0.5.0)
211
217
  rb-kqueue (0.2.3)
212
218
  ffi (>= 0.5.0)
213
- rbx-require-relative (0.0.9)
214
219
  rdoc (4.1.2)
215
220
  json (~> 1.4)
216
221
  redis (3.1.0)
@@ -230,28 +235,11 @@ GEM
230
235
  activesupport (>= 3.0)
231
236
  railties (>= 3.0)
232
237
  rspec (~> 2.11.0)
233
- ruby-debug (0.10.4)
234
- columnize (>= 0.1)
235
- ruby-debug-base (~> 0.10.4.0)
236
- ruby-debug-base (0.10.4)
237
- linecache (>= 0.3)
238
- ruby-debug-base19 (0.11.25)
239
- columnize (>= 0.3.1)
240
- linecache19 (>= 0.5.11)
241
- ruby_core_source (>= 0.1.4)
242
- ruby-debug19 (0.11.6)
243
- columnize (>= 0.3.1)
244
- linecache19 (>= 0.5.11)
245
- ruby-debug-base19 (>= 0.11.19)
246
- ruby_core_source (0.1.5)
247
- archive-tar-minitar (>= 0.5.2)
248
238
  sequel (3.21.0)
249
239
  slop (3.6.0)
250
240
  spoon (0.0.4)
251
241
  ffi
252
- sqlite3 (1.3.9)
253
- sqlite3-ruby (1.3.3)
254
- sqlite3 (>= 1.3.3)
242
+ sqlite3 (1.3.10)
255
243
  stringex (1.5.1)
256
244
  thor (0.14.6)
257
245
  tzinfo (0.3.41)
@@ -269,6 +257,7 @@ DEPENDENCIES
269
257
  bundler
270
258
  couch_potato
271
259
  cucumber
260
+ database_cleaner!
272
261
  datamapper
273
262
  dm-migrations
274
263
  dm-sqlite-adapter
@@ -285,10 +274,10 @@ DEPENDENCIES
285
274
  ohm (~> 0.1.3)
286
275
  pg
287
276
  rake
288
- rspec-rails
289
- ruby-debug
290
- ruby-debug19
277
+ rspec-rails (~> 2.11.0)
291
278
  sequel (~> 3.21.0)
292
279
  sqlite3
293
- sqlite3-ruby
294
280
  tzinfo
281
+
282
+ BUNDLED WITH
283
+ 1.10.5
@@ -54,14 +54,14 @@ module DatabaseCleaner::ActiveRecord
54
54
 
55
55
  def tables_with_new_rows(connection)
56
56
  @db_name ||= connection.instance_variable_get('@config')[:database]
57
- result = connection.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = '#{@db_name}' AND table_rows > 0")
58
- result.map{ |row| row[0] } - ['schema_migrations']
57
+ result = connection.exec_query("SELECT table_name FROM information_schema.tables WHERE table_schema = '#{@db_name}' AND table_rows > 0")
58
+ result.map{ |row| row['table_name'] } - ['schema_migrations']
59
59
  end
60
60
 
61
61
  def information_schema_exists? connection
62
62
  @information_schema_exists ||=
63
63
  begin
64
- connection.execute("SELECT * FROM information_schema.tables")
64
+ connection.execute("SELECT 1 FROM information_schema.tables")
65
65
  true
66
66
  rescue
67
67
  false
@@ -27,24 +27,26 @@ module DatabaseCleaner::ActiveRecord
27
27
 
28
28
 
29
29
  def clean
30
- return unless connection_class.connection.open_transactions > 0
30
+ connection_class.connection_pool.connections.each do |connection|
31
+ next unless connection.open_transactions > 0
31
32
 
32
- if connection_class.connection.respond_to?(:rollback_transaction)
33
- connection_class.connection.rollback_transaction
34
- else
35
- connection_class.connection.rollback_db_transaction
36
- end
33
+ if connection.respond_to?(:rollback_transaction)
34
+ connection.rollback_transaction
35
+ else
36
+ connection.rollback_db_transaction
37
+ end
37
38
 
38
- # The below is for handling after_commit hooks.. see https://github.com/bmabey/database_cleaner/issues/99
39
- if connection_class.connection.respond_to?(:rollback_transaction_records, true)
40
- connection_class.connection.send(:rollback_transaction_records, true)
41
- end
39
+ # The below is for handling after_commit hooks.. see https://github.com/bmabey/database_cleaner/issues/99
40
+ if connection.respond_to?(:rollback_transaction_records, true)
41
+ connection.send(:rollback_transaction_records, true)
42
+ end
42
43
 
43
- if connection_maintains_transaction_count?
44
- if connection_class.connection.respond_to?(:decrement_open_transactions)
45
- connection_class.connection.decrement_open_transactions
46
- else
47
- connection_class.__send__(:decrement_open_transactions)
44
+ if connection_maintains_transaction_count?
45
+ if connection.respond_to?(:decrement_open_transactions)
46
+ connection.decrement_open_transactions
47
+ else
48
+ connection_class.__send__(:decrement_open_transactions)
49
+ end
48
50
  end
49
51
  end
50
52
  end
@@ -190,9 +190,9 @@ module DatabaseCleaner
190
190
  rows = select_rows <<-_SQL
191
191
  SELECT schemaname || '.' || tablename
192
192
  FROM pg_tables
193
- WHERE
194
- tablename !~ '_prt_' AND
195
- tablename <> '#{::ActiveRecord::Migrator.schema_migrations_table_name}' AND
193
+ WHERE
194
+ tablename !~ '_prt_' AND
195
+ tablename <> '#{::ActiveRecord::Migrator.schema_migrations_table_name}' AND
196
196
  schemaname = ANY (current_schemas(false))
197
197
  _SQL
198
198
  rows.collect { |result| result.first }
@@ -247,12 +247,12 @@ module DatabaseCleaner::ActiveRecord
247
247
  tables_in_db = cache_tables? ? connection.database_cleaner_table_cache : connection.tables
248
248
  to_reject = (@tables_to_exclude + connection.database_cleaner_view_cache)
249
249
  (@only || tables_in_db).reject do |table|
250
- if ( m = table.match(/([^.]+)$/) )
251
- to_reject.include?(m[1])
252
- else
253
- false
254
- end
250
+ if ( m = table.match(/([^.]+)$/) )
251
+ to_reject.include?(m[1])
252
+ else
253
+ false
255
254
  end
255
+ end
256
256
  end
257
257
 
258
258
  # overwritten
@@ -42,7 +42,7 @@ module DatabaseCleaner
42
42
 
43
43
  def connections
44
44
  # double yuck.. can't wait to deprecate this whole class...
45
- unless @cleaners
45
+ unless defined?(@cleaners) && @cleaners
46
46
  autodetected = ::DatabaseCleaner::Base.new
47
47
  add_cleaner(autodetected.orm)
48
48
  end
@@ -1,26 +1,29 @@
1
1
  module ::DatabaseCleaner
2
- module Generic
3
- module Base
2
+ module Generic
3
+ module Base
4
4
 
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- end
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
8
 
9
- def db
10
- :default
11
- end
9
+ def db
10
+ :default
11
+ end
12
12
 
13
- def cleaning(&block)
14
- start
15
- yield
16
- clean
17
- end
13
+ def cleaning(&block)
14
+ begin
15
+ start
16
+ yield
17
+ ensure
18
+ clean
19
+ end
20
+ end
18
21
 
19
- module ClassMethods
20
- def available_strategies
21
- %W[]
22
- end
23
- end
24
- end
25
- end
22
+ module ClassMethods
23
+ def available_strategies
24
+ %W[]
25
+ end
26
+ end
27
+ end
28
+ end
26
29
  end
@@ -20,10 +20,7 @@ module DatabaseCleaner
20
20
  def mongoid_collection_names
21
21
  @@mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names|
22
22
  ObjectSpace.each_object(Class) do |klass|
23
- next unless klass.ancestors.map(&:to_s).include?('Mongoid::Document')
24
- next if klass.embedded
25
- next if klass.collection_name.empty?
26
- names[klass.db.name] << klass.collection_name
23
+ (names[klass.db.name] << klass.collection_name) if valid_collection_name?(klass)
27
24
  end
28
25
  end
29
26
  end
@@ -52,6 +49,14 @@ module DatabaseCleaner
52
49
 
53
50
  db_collections
54
51
  end
52
+
53
+ private
54
+
55
+ def valid_collection_name?(klass)
56
+ klass.ancestors.map(&:to_s).include?('Mongoid::Document') &&
57
+ !klass.embedded &&
58
+ !klass.collection_name.empty?
59
+ end
55
60
  end
56
61
  end
57
62
  end
@@ -1,6 +1,7 @@
1
1
  require 'database_cleaner/mongoid/base'
2
2
  require 'database_cleaner/generic/truncation'
3
3
  require 'database_cleaner/mongo/truncation_mixin'
4
+ require 'database_cleaner/mongo2/truncation_mixin'
4
5
  require 'database_cleaner/moped/truncation_base'
5
6
  require 'mongoid/version'
6
7
 
@@ -20,7 +21,7 @@ module DatabaseCleaner
20
21
  ::Mongoid.database
21
22
  end
22
23
 
23
- else
24
+ elsif ::Mongoid::VERSION < '5'
24
25
 
25
26
  include ::DatabaseCleaner::Moped::TruncationBase
26
27
 
@@ -37,6 +38,11 @@ module DatabaseCleaner
37
38
  ::Mongoid.database
38
39
  end
39
40
  end
41
+
42
+ else
43
+
44
+ include ::DatabaseCleaner::Mongo2::TruncationMixin
45
+
40
46
  end
41
47
  end
42
48
  end
@@ -25,6 +25,10 @@ module DatabaseCleaner
25
25
  @host ||= '127.0.0.1:27017'
26
26
  end
27
27
 
28
+ def db_version
29
+ @db_version ||= session.command('buildinfo' => 1)['version']
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def session
@@ -23,9 +23,15 @@ module DatabaseCleaner
23
23
  session.use(db)
24
24
  end
25
25
 
26
- session['system.namespaces'].find(:name => { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
27
- _, name = collection['name'].split('.', 2)
28
- name
26
+ if db_version.split('.').first.to_i >= 3
27
+ session.command(listCollections: 1, filter: { 'name' => { '$not' => /.?system\.|\$/ } })['cursor']['firstBatch'].map do |collection|
28
+ collection['name']
29
+ end
30
+ else
31
+ session['system.namespaces'].find(name: { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
32
+ _, name = collection['name'].split('.', 2)
33
+ name
34
+ end
29
35
  end
30
36
  end
31
37
 
@@ -50,8 +50,12 @@ module DatabaseCleaner
50
50
  database[:path]
51
51
  end
52
52
 
53
+ def db_params
54
+ database.reject!{|key, value| [:type, :path].include? key }
55
+ end
56
+
53
57
  def session
54
- @session ||= ::Neo4j::Session.open(db_type, db_path)
58
+ @session ||= ::Neo4j::Session.open(db_type, db_path, db_params)
55
59
  end
56
60
  end
57
61
  end
File without changes
@@ -7,7 +7,11 @@ module DatabaseCleaner
7
7
 
8
8
  describe Transaction do
9
9
  let (:connection) { double("connection") }
10
+ let (:connection_2) { double("connection") }
11
+ let (:connection_pool) { double("connection_pool")}
10
12
  before(:each) do
13
+ ::ActiveRecord::Base.stub(:connection_pool).and_return(connection_pool)
14
+ connection_pool.stub(:connections).and_return([connection])
11
15
  ::ActiveRecord::Base.stub(:connection).and_return(connection)
12
16
  end
13
17
 
@@ -82,6 +86,40 @@ module DatabaseCleaner
82
86
  ::ActiveRecord::Base.should_receive(:decrement_open_transactions)
83
87
  Transaction.new.clean
84
88
  end
89
+
90
+ it "should rollback open transactions in all connections" do
91
+ connection_pool.stub(:connections).and_return([connection, connection_2])
92
+
93
+ connection.should_receive(:open_transactions).and_return(1)
94
+ connection.stub(:respond_to?).with(:decrement_open_transactions).and_return(false)
95
+ connection.stub(:respond_to?).with(:rollback_transaction_records, true).and_return(false)
96
+ connection.stub(:respond_to?).with(:rollback_transaction).and_return(false)
97
+ connection.stub(:rollback_db_transaction)
98
+
99
+ connection_2.should_receive(:open_transactions).and_return(1)
100
+ connection_2.stub(:respond_to?).with(:decrement_open_transactions).and_return(false)
101
+ connection_2.stub(:respond_to?).with(:rollback_transaction_records, true).and_return(false)
102
+ connection_2.stub(:respond_to?).with(:rollback_transaction).and_return(false)
103
+ connection_2.stub(:rollback_db_transaction)
104
+
105
+ ::ActiveRecord::Base.should_receive(:decrement_open_transactions).twice
106
+ Transaction.new.clean
107
+ end
108
+
109
+ it "should rollback open transactions in all connections with an open transaction" do
110
+ connection_pool.stub(:connections).and_return([connection, connection_2])
111
+
112
+ connection.should_receive(:open_transactions).and_return(1)
113
+ connection.stub(:respond_to?).with(:decrement_open_transactions).and_return(false)
114
+ connection.stub(:respond_to?).with(:rollback_transaction_records, true).and_return(false)
115
+ connection.stub(:respond_to?).with(:rollback_transaction).and_return(false)
116
+ connection.stub(:rollback_db_transaction)
117
+
118
+ connection_2.should_receive(:open_transactions).and_return(0)
119
+
120
+ ::ActiveRecord::Base.should_receive(:decrement_open_transactions).exactly(1).times
121
+ Transaction.new.clean
122
+ end
85
123
  end
86
124
 
87
125
  context "automatic accounting of transaction count (AR 4)" do
@@ -1,22 +1,61 @@
1
1
  require 'spec_helper'
2
2
  require 'database_cleaner/shared_strategy'
3
3
  require 'database_cleaner/generic/base'
4
+ require 'active_record'
4
5
 
5
6
  module ::DatabaseCleaner
6
7
  module Generic
7
8
  class ExampleStrategy
8
9
  include ::DatabaseCleaner::Generic::Base
10
+
11
+ def start; end
9
12
  end
10
13
 
11
14
  describe ExampleStrategy do
12
15
  context "class methods" do
13
16
  subject { ExampleStrategy }
14
- its(:available_strategies) { should be_empty }
17
+
18
+ describe "#available_strategies" do
19
+ it "should have available strategies" do
20
+ expect(subject.available_strategies).to be_empty
21
+ end
22
+ end
15
23
  end
16
24
 
17
25
  it_should_behave_like "a generic strategy"
18
26
 
19
- its(:db) { should eq :default }
27
+ describe "#db" do
28
+ it "should be :default" do
29
+ expect(subject.db).to eql(:default)
30
+ end
31
+ end
32
+
33
+ describe "#cleaning" do
34
+ let (:connection) { double("connection") }
35
+ let (:strategy) { ExampleStrategy.new }
36
+ before do
37
+ # DatabaseCleaner.strategy = :truncation
38
+ connection.stub(:disable_referential_integrity).and_yield
39
+ connection.stub(:database_cleaner_view_cache).and_return([])
40
+ connection.stub(:database_cleaner_table_cache).and_return([])
41
+ ::ActiveRecord::Base.stub(:connection).and_return(connection)
42
+ end
43
+
44
+ it "calls #clean even if there is an exception" do
45
+ strategy.should_receive :clean
46
+ expect do
47
+ strategy.cleaning do
48
+ raise NoMethodError
49
+ end
50
+ end.to raise_exception(NoMethodError)
51
+ end
52
+
53
+ it "calls #clean after processing the block" do
54
+ strategy.should_receive :clean
55
+ strategy.cleaning do
56
+ end
57
+ end
58
+ end
20
59
  end
21
60
  end
22
61
  end
@@ -24,6 +24,13 @@ module DatabaseCleaner
24
24
  subject.db.should eq db_conf
25
25
  end
26
26
 
27
+ it "should respect additional connection parameters" do
28
+ db_conf = {:type => :server_db, :path => 'http://localhost:7474', basic_auth: {username: 'user', password: 'pass'}}
29
+ subject.db = db_conf
30
+ stub_const("Neo4j::Session", double()).should_receive(:open).with(:server_db, 'http://localhost:7474', {basic_auth: {username: 'user', password: 'pass'}}) { true }
31
+ subject.start
32
+ end
33
+
27
34
  it "should default to nil" do
28
35
  subject.db.should be_nil
29
36
  end
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.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Mabey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-02 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: ruby-debug
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: ruby-debug19
42
+ name: json_pure
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: bundler
56
+ name: activerecord-mysql2-adapter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: json_pure
70
+ name: activerecord
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: activerecord-mysql2-adapter
84
+ name: datamapper
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: activerecord
98
+ name: dm-migrations
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: datamapper
112
+ name: dm-sqlite-adapter
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: dm-migrations
126
+ name: mongoid
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: dm-sqlite-adapter
140
+ name: tzinfo
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: mongoid
154
+ name: mongoid-tree
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -165,7 +165,7 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
- name: tzinfo
168
+ name: mongo_mapper
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="
@@ -179,7 +179,7 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: mongo_ext
182
+ name: moped
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
@@ -193,7 +193,7 @@ dependencies:
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
- name: bson_ext
196
+ name: neo4j-core
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - ">="
@@ -207,7 +207,7 @@ dependencies:
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  - !ruby/object:Gem::Dependency
210
- name: mongoid-tree
210
+ name: couch_potato
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - ">="
@@ -221,21 +221,35 @@ dependencies:
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
223
  - !ruby/object:Gem::Dependency
224
- name: mongo_mapper
224
+ name: sequel
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
- - - ">="
227
+ - - "~>"
228
228
  - !ruby/object:Gem::Version
229
- version: '0'
229
+ version: 3.21.0
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
- - - ">="
234
+ - - "~>"
235
235
  - !ruby/object:Gem::Version
236
- version: '0'
236
+ version: 3.21.0
237
237
  - !ruby/object:Gem::Dependency
238
- name: moped
238
+ name: ohm
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: 0.1.3
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: 0.1.3
251
+ - !ruby/object:Gem::Dependency
252
+ name: guard-rspec
239
253
  requirement: !ruby/object:Gem::Requirement
240
254
  requirements:
241
255
  - - ">="
@@ -249,7 +263,21 @@ dependencies:
249
263
  - !ruby/object:Gem::Version
250
264
  version: '0'
251
265
  - !ruby/object:Gem::Dependency
252
- name: neo4j-core
266
+ name: rspec-rails
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - "~>"
270
+ - !ruby/object:Gem::Version
271
+ version: 2.11.0
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - "~>"
277
+ - !ruby/object:Gem::Version
278
+ version: 2.11.0
279
+ - !ruby/object:Gem::Dependency
280
+ name: cucumber
253
281
  requirement: !ruby/object:Gem::Requirement
254
282
  requirements:
255
283
  - - ">="
@@ -263,7 +291,7 @@ dependencies:
263
291
  - !ruby/object:Gem::Version
264
292
  version: '0'
265
293
  - !ruby/object:Gem::Dependency
266
- name: couch_potato
294
+ name: mongo_ext
267
295
  requirement: !ruby/object:Gem::Requirement
268
296
  requirements:
269
297
  - - ">="
@@ -277,33 +305,33 @@ dependencies:
277
305
  - !ruby/object:Gem::Version
278
306
  version: '0'
279
307
  - !ruby/object:Gem::Dependency
280
- name: sequel
308
+ name: bson_ext
281
309
  requirement: !ruby/object:Gem::Requirement
282
310
  requirements:
283
- - - "~>"
311
+ - - ">="
284
312
  - !ruby/object:Gem::Version
285
- version: 3.21.0
313
+ version: '0'
286
314
  type: :development
287
315
  prerelease: false
288
316
  version_requirements: !ruby/object:Gem::Requirement
289
317
  requirements:
290
- - - "~>"
318
+ - - ">="
291
319
  - !ruby/object:Gem::Version
292
- version: 3.21.0
320
+ version: '0'
293
321
  - !ruby/object:Gem::Dependency
294
322
  name: mysql
295
323
  requirement: !ruby/object:Gem::Requirement
296
324
  requirements:
297
325
  - - "~>"
298
326
  - !ruby/object:Gem::Version
299
- version: 2.8.1
327
+ version: 2.9.1
300
328
  type: :development
301
329
  prerelease: false
302
330
  version_requirements: !ruby/object:Gem::Requirement
303
331
  requirements:
304
332
  - - "~>"
305
333
  - !ruby/object:Gem::Version
306
- version: 2.8.1
334
+ version: 2.9.1
307
335
  - !ruby/object:Gem::Dependency
308
336
  name: mysql2
309
337
  requirement: !ruby/object:Gem::Requirement
@@ -333,21 +361,7 @@ dependencies:
333
361
  - !ruby/object:Gem::Version
334
362
  version: '0'
335
363
  - !ruby/object:Gem::Dependency
336
- name: ohm
337
- requirement: !ruby/object:Gem::Requirement
338
- requirements:
339
- - - "~>"
340
- - !ruby/object:Gem::Version
341
- version: 0.1.3
342
- type: :development
343
- prerelease: false
344
- version_requirements: !ruby/object:Gem::Requirement
345
- requirements:
346
- - - "~>"
347
- - !ruby/object:Gem::Version
348
- version: 0.1.3
349
- - !ruby/object:Gem::Dependency
350
- name: guard-rspec
364
+ name: sqlite3
351
365
  requirement: !ruby/object:Gem::Requirement
352
366
  requirements:
353
367
  - - ">="
@@ -508,7 +522,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
508
522
  requirements:
509
523
  - - ">="
510
524
  - !ruby/object:Gem::Version
511
- version: '0'
525
+ version: 1.9.3
512
526
  required_rubygems_version: !ruby/object:Gem::Requirement
513
527
  requirements:
514
528
  - - ">="
@@ -516,10 +530,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
516
530
  version: '0'
517
531
  requirements: []
518
532
  rubyforge_project:
519
- rubygems_version: 2.4.5
533
+ rubygems_version: 2.4.6
520
534
  signing_key:
521
535
  specification_version: 4
522
536
  summary: Strategies for cleaning databases. Can be used to ensure a clean state for
523
537
  testing.
524
538
  test_files: []
525
- has_rdoc: