octoshark 0.0.7 → 0.0.8
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 +4 -4
- data/README.md +7 -10
- data/lib/octoshark.rb +8 -4
- data/lib/octoshark/connection_switcher.rb +4 -0
- data/lib/octoshark/version.rb +1 -1
- data/spec/octoshark/connection_switcher_spec.rb +15 -0
- data/spec/octoshark_spec.rb +8 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a80290fe7affe4b399c3a48d9676c9f910618fdc
|
4
|
+
data.tar.gz: 65278830e411768633d4ec5f65e227caea97f52e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3759cd06b0ac6f5f6426287a191dc6c1a6e427b0cc93ef8ddebc998cd413f83cd6147dc9d47f58faaaf580d7e4de63038cec0b78a6ee96aa6bc88709021dc2e8
|
7
|
+
data.tar.gz: 62b469072a953bf8cd6d62d7e9fd6c9e4517371bfb16fc23b6d7edeab6f0533ee923306f0c118ce3de6e1158e3f5888889ba9ef5f400cdb3f68b544e9d3dfc4a
|
data/README.md
CHANGED
@@ -131,27 +131,24 @@ Here's an example how to clean default and shard databases using both default co
|
|
131
131
|
|
132
132
|
```ruby
|
133
133
|
config.before(:suite) do
|
134
|
-
|
134
|
+
setup_database_cleaner
|
135
|
+
DatabaseCleaner.clean_with(:truncation)
|
135
136
|
end
|
136
137
|
|
137
138
|
config.before(:each) do
|
139
|
+
setup_database_cleaner
|
138
140
|
DatabaseCleaner.start
|
139
141
|
end
|
140
142
|
|
141
143
|
config.after(:each) do
|
142
|
-
|
144
|
+
setup_database_cleaner
|
145
|
+
DatabaseCleaner.clean_with(:transaction)
|
143
146
|
end
|
144
147
|
|
145
|
-
def
|
146
|
-
|
147
|
-
DatabaseCleaner[:active_record, {connection: ActiveRecord::Base.connection_pool}]
|
148
|
-
|
149
|
-
# Octoshark connection pool for the connection
|
150
|
-
Octoshark.connection_pools.each_pair do |name, connection_pool|
|
148
|
+
def setup_database_cleaner
|
149
|
+
Octoshark.connection_pools.each_pair do |connection_name, connection_pool|
|
151
150
|
DatabaseCleaner[:active_record, {connection: connection_pool}]
|
152
151
|
end
|
153
|
-
|
154
|
-
DatabaseCleaner.clean_with(strategy)
|
155
152
|
end
|
156
153
|
```
|
157
154
|
|
data/lib/octoshark.rb
CHANGED
@@ -12,10 +12,14 @@ module Octoshark
|
|
12
12
|
OCTOSHARK = :octoshark
|
13
13
|
|
14
14
|
class << self
|
15
|
-
delegate :
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
15
|
+
delegate :connection_pools,
|
16
|
+
:current_or_default_connection,
|
17
|
+
:disconnect!,
|
18
|
+
:find_connection_pool,
|
19
|
+
:with_connection,
|
20
|
+
:current_connection,
|
21
|
+
:current_connection?,
|
22
|
+
to: :switcher
|
19
23
|
|
20
24
|
def configure(configs)
|
21
25
|
@configs = configs
|
@@ -18,6 +18,10 @@ module Octoshark
|
|
18
18
|
Thread.current[OCTOSHARK] || raise(NoCurrentConnectionError, "No current connection, use Octoshark.with_connection")
|
19
19
|
end
|
20
20
|
|
21
|
+
def current_connection?
|
22
|
+
!Thread.current[OCTOSHARK].nil?
|
23
|
+
end
|
24
|
+
|
21
25
|
def current_or_default_connection
|
22
26
|
Thread.current[OCTOSHARK] || @default_pool.connection
|
23
27
|
end
|
data/lib/octoshark/version.rb
CHANGED
@@ -41,6 +41,21 @@ describe Octoshark::ConnectionSwitcher do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
describe "#current_connection?" do
|
45
|
+
it "returns true if current one" do
|
46
|
+
switcher = Octoshark::ConnectionSwitcher.new(configs)
|
47
|
+
switcher.with_connection(:db1) do |connection|
|
48
|
+
expect(switcher.current_connection?).to be_truthy
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns false if no current one" do
|
53
|
+
switcher = Octoshark::ConnectionSwitcher.new
|
54
|
+
|
55
|
+
expect(switcher.current_connection?).to be_falsey
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
44
59
|
describe "#current_or_default_connection" do
|
45
60
|
it "returns current connection" do
|
46
61
|
switcher = Octoshark::ConnectionSwitcher.new(configs)
|
data/spec/octoshark_spec.rb
CHANGED
@@ -71,14 +71,18 @@ describe Octoshark do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
[
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:
|
77
|
-
:
|
74
|
+
:connection_pools,
|
75
|
+
:current_connection,
|
76
|
+
:current_connection?,
|
77
|
+
:current_or_default_connection,
|
78
|
+
:disconnect!,
|
79
|
+
:find_connection_pool,
|
80
|
+
:with_connection,
|
78
81
|
].each do |method_name|
|
79
82
|
describe ".#{method_name}" do
|
80
83
|
it "delegates #{method_name} to connection switcher" do
|
81
84
|
Octoshark.configure({})
|
85
|
+
expect(Octoshark.switcher).to respond_to(method_name)
|
82
86
|
expect(Octoshark.switcher).to receive(method_name)
|
83
87
|
|
84
88
|
Octoshark.send(method_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octoshark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dalibor Nasevic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.2.
|
147
|
+
rubygems_version: 2.2.2
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: Octoshark is an ActiveRecord connection switcher
|