database_rewinder 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f405cde3df1e298d2f65d7e7c4e73d35b5b38c6
4
- data.tar.gz: 0d69a9621b14d19a13b3ad3dcd87c04312898786
3
+ metadata.gz: 417842274697cd6d5616271d7c532fe3cf5a2801
4
+ data.tar.gz: 6f7bdafdf2c10fc2ad460be38d967ace506828ec
5
5
  SHA512:
6
- metadata.gz: a0ad597a5cb1c25948341f39234db1c5333b8dfeaed9a756fd2885cbcbd9ab5ba4747485ab9f41be8565932afb7e2c1bded047ea02d95d8ee93adabe9fcfcdde
7
- data.tar.gz: 64a54f2576a1b8d7d2a94add2828fb3525e8e663561d0907f568daaa113c64bdc2b406ab715dec34446ed2f3a988c75285e5122be267656a343034d32759ed8a
6
+ metadata.gz: 13e3e31d2eb7794f48c4036a8edfdab939564d4adce4750dd30f1188a13e519e1bb9f735b24f35d3efb03dc484ef1fe4d8a2834b980258ca784c4a00b43d6853
7
+ data.tar.gz: 10106fb52e312a5e2254e2773f4f4415bcbf2729d144e4a4f8709ec1e2682053d26b16750e7a29f4f975e424123c4501404e16488fa4afa4b246c9b4788d916d
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "database_rewinder"
7
- spec.version = '0.1.0'
7
+ spec.version = '0.2.0'
8
8
  spec.authors = ["Akira Matsuda"]
9
9
  spec.email = ["ronnie@dio.jp"]
10
10
  spec.description = "A minimalist's tiny and ultra-fast database cleaner"
@@ -10,7 +10,13 @@ module DatabaseRewinder
10
10
  def clean
11
11
  return if !pool || inserted_tables.empty?
12
12
 
13
- delete_all (ar_conn = pool.connection), DatabaseRewinder.all_table_names(ar_conn) & inserted_tables
13
+ # When the application uses multiple database connections, a connection
14
+ # pool used in test could be already removed (i.e., pool.connected? = false).
15
+ # In this case, we have to reconnect to the database to clean inserted
16
+ # tables.
17
+ with_automatic_reconnect(pool) do
18
+ delete_all (ar_conn = pool.connection), DatabaseRewinder.all_table_names(ar_conn) & inserted_tables
19
+ end
14
20
  reset
15
21
  end
16
22
 
@@ -50,5 +56,13 @@ module DatabaseRewinder
50
56
  def reset
51
57
  @inserted_tables = []
52
58
  end
59
+
60
+ def with_automatic_reconnect(pool, &block)
61
+ reconnect = pool.automatic_reconnect
62
+ pool.automatic_reconnect = true
63
+ block.call
64
+ ensure
65
+ pool.automatic_reconnect = reconnect
66
+ end
53
67
  end
54
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_rewinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-07 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler