database_flusher 0.3.1 → 0.3.2

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: f228160138e843a8bed353ad7cc4582b1390846d
4
- data.tar.gz: fea5700dd7a8e3d27d36bf32205472982de6de21
3
+ metadata.gz: 90cac9582ff73ebe0151abb8ea901bdae8280dc4
4
+ data.tar.gz: 99ebfe15fbf6de3c1ac4d479f7bda06ec6c89995
5
5
  SHA512:
6
- metadata.gz: '0846ed665fa63a8c664352f89c7160351c344578bc6efb800f13b2314f9c92fb2e24507c5fb797354f3dd875cde218836f110306272ffc61b659bb2bd5e84188'
7
- data.tar.gz: 98e3cb45b170ad48bec6b220de6007b276b58500a17c07d147e7d3345561e356f0d41928767b2e7079341a936748ff1feef62485864aad0b52d6c5a31fbf1022
6
+ metadata.gz: 1b30f3618eff2f27ecb506c79ee2d80df941ac008ddbbed8c505f82b6df9bd31344ef6cecaa9534987450b49c7e80f2390b815dbb910ba56f2b256f7e9c9d56c
7
+ data.tar.gz: a5b2ce6762f219a3172c4db6eb229a2a1a0ee5344b9956690ebbc6bda4e41fa9152c9adc4a76bdd1ec28dc1e01b26ff4572a5106c811a430e5c5b9ef0ecc5635
data/README.md CHANGED
@@ -7,7 +7,7 @@ database_flusher is a tiny and fast database cleaner inspired by [database_clean
7
7
 
8
8
  ## Features
9
9
 
10
- * No monkey patching - uses `ActiveSupport::Notifications` and `Mongo::Monitoring::Global` to catch `INSERT` statements
10
+ * No monkey patching - uses `ActiveSupport::Notifications` and `Mongo::Monitoring` to catch `INSERT` statements
11
11
  * Fast `:deletion` strategy that cleans only tables/collections where `INSERT` statements were performed
12
12
  * Faster `disable_referential_integrity` for PostgreSQL
13
13
  * Executes multiple `DELETE` statements as one query with ActiveRecord
@@ -105,17 +105,14 @@ end
105
105
  DatabaseFlusher[:active_record].strategy = :transaction
106
106
  DatabaseFlusher[:mongoid].strategy = :deletion
107
107
 
108
- Before do
108
+ # Use Around hook to make sure it runs after capybara session reset.
109
+ Around do |scenario, block|
109
110
  if Capybara.current_driver == :rack_test
110
111
  DatabaseFlusher[:active_record].strategy = :transaction
111
112
  else
112
113
  DatabaseFlusher[:active_record].strategy = :deletion
113
114
  end
114
- DatabaseFlusher.start
115
- end
116
-
117
- After do
118
- DatabaseFlusher.clean
115
+ DatabaseFlusher.cleaning(&block)
119
116
  end
120
117
  ```
121
118
 
@@ -31,4 +31,11 @@ module DatabaseFlusher
31
31
  def clean
32
32
  cleaners.values.each(&:clean)
33
33
  end
34
+
35
+ def cleaning
36
+ start
37
+ yield
38
+ ensure
39
+ clean
40
+ end
34
41
  end
@@ -5,18 +5,10 @@ module DatabaseFlusher
5
5
  private
6
6
 
7
7
  def disable_referential_integrity(*tables)
8
- begin
9
- execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
10
- rescue
11
- execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER USER" }.join(";"))
12
- end
8
+ execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
13
9
  yield
14
10
  ensure
15
- begin
16
- execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
17
- rescue
18
- execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER USER" }.join(";"))
19
- end
11
+ execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
20
12
  end
21
13
  end
22
14
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DatabaseFlusher
3
- VERSION = '0.3.1'.freeze
3
+ VERSION = '0.3.2'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_flusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgars Beigarts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-13 00:00:00.000000000 Z
11
+ date: 2017-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler