octoshark 0.1.2 → 0.3.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 +5 -5
- data/.github/workflows/ci-legacy.yml +66 -0
- data/.github/workflows/ci.yml +64 -0
- data/.ruby-version +1 -1
- data/Appraisals +20 -10
- data/CHANGELOG.md +19 -0
- data/Gemfile +1 -0
- data/README.md +187 -72
- data/Rakefile +4 -4
- data/gemfiles/rails3.0.gemfile +9 -0
- data/gemfiles/rails3.1.gemfile +3 -1
- data/gemfiles/rails3.2.gemfile +3 -1
- data/gemfiles/{rails4.gemfile → rails4.0.gemfile} +3 -1
- data/gemfiles/rails4.1.gemfile +3 -1
- data/gemfiles/rails4.2.gemfile +3 -1
- data/gemfiles/rails5.0.gemfile +9 -0
- data/gemfiles/rails5.1.gemfile +9 -0
- data/gemfiles/rails5.2.gemfile +9 -0
- data/gemfiles/rails6.0.gemfile +9 -0
- data/gemfiles/rails6.1.gemfile +9 -0
- data/lib/octoshark.rb +4 -19
- data/lib/octoshark/active_record_extensions.rb +18 -34
- data/lib/octoshark/connection_manager.rb +8 -106
- data/lib/octoshark/connection_pools_manager.rb +97 -0
- data/lib/octoshark/current_connection.rb +37 -0
- data/lib/octoshark/version.rb +1 -1
- data/octoshark.gemspec +3 -4
- data/spec/octoshark/active_record_extensions_spec.rb +4 -4
- data/spec/octoshark/connection_manager_spec.rb +22 -219
- data/spec/octoshark/connection_pools_manager_spec.rb +180 -0
- data/spec/octoshark/current_connection_spec.rb +74 -0
- data/spec/support/{config.yml.travis → config.yml.github} +6 -6
- metadata +30 -33
- data/.travis.yml +0 -18
- data/spec/octoshark_spec.rb +0 -40
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "connection manager" do
|
4
|
+
let(:config) { configs[:db1] }
|
5
|
+
|
6
|
+
describe "#identifier" do
|
7
|
+
it "has unique identifiers" do
|
8
|
+
manager1 = Octoshark::ConnectionManager.new
|
9
|
+
manager2 = Octoshark::ConnectionManager.new
|
10
|
+
expect(manager1.identifier).to_not eq(manager2.identifier)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#current_connection" do
|
15
|
+
it "returns last used connection as current one" do
|
16
|
+
manager = Octoshark::ConnectionManager.new
|
17
|
+
manager.with_connection(config) do |connection|
|
18
|
+
expect(manager.current_connection).to eq(connection)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises error when no current connection" do
|
23
|
+
manager = Octoshark::ConnectionManager.new
|
24
|
+
|
25
|
+
expect { manager.current_connection }.to raise_error(Octoshark::Error::NoCurrentConnection)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#current_connection?" do
|
30
|
+
it "returns true if current one" do
|
31
|
+
manager = Octoshark::ConnectionManager.new
|
32
|
+
manager.with_connection(config) do
|
33
|
+
expect(manager.current_connection?).to be_truthy
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns false if no current one" do
|
38
|
+
manager = Octoshark::ConnectionManager.new
|
39
|
+
|
40
|
+
expect(manager.current_connection?).to be_falsey
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#current_or_default_connection" do
|
45
|
+
it "returns current connection" do
|
46
|
+
manager = Octoshark::ConnectionManager.new
|
47
|
+
manager.with_connection(config) do |connection|
|
48
|
+
expect(manager.current_or_default_connection).to eq(connection)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns default connection when no current connection" do
|
53
|
+
manager = Octoshark::ConnectionManager.new
|
54
|
+
|
55
|
+
expect(manager.current_or_default_connection).to eq(ActiveRecord::Base.connection_pool.connection)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#without_connection' do
|
60
|
+
it "can reset current connection temporarily inside nested connection block" do
|
61
|
+
manager = Octoshark::ConnectionManager.new
|
62
|
+
|
63
|
+
manager.with_connection(config) do
|
64
|
+
expect(db(manager.current_connection)).to eq("db1")
|
65
|
+
|
66
|
+
manager.without_connection do
|
67
|
+
expect { manager.current_connection }.to raise_error(Octoshark::Error::NoCurrentConnection)
|
68
|
+
end
|
69
|
+
|
70
|
+
expect(db(manager.current_connection)).to eq("db1")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -4,9 +4,9 @@ db1:
|
|
4
4
|
reconnect: false
|
5
5
|
database: octoshark_db1
|
6
6
|
pool: 5
|
7
|
-
username:
|
8
|
-
password:
|
9
|
-
host:
|
7
|
+
username: root
|
8
|
+
password: pass
|
9
|
+
host: 127.0.0.1
|
10
10
|
port: 3306
|
11
11
|
|
12
12
|
db2:
|
@@ -15,7 +15,7 @@ db2:
|
|
15
15
|
reconnect: false
|
16
16
|
database: octoshark_db2
|
17
17
|
pool: 5
|
18
|
-
username:
|
19
|
-
password:
|
20
|
-
host:
|
18
|
+
username: root
|
19
|
+
password: pass
|
20
|
+
host: 127.0.0.1
|
21
21
|
port: 3306
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dalibor Nasevic
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.5'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.5'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,42 +44,42 @@ dependencies:
|
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
47
|
+
version: 3.7.0
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
54
|
+
version: 3.7.0
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: sqlite3
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.
|
61
|
+
version: 1.4.1
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.
|
68
|
+
version: 1.4.1
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: mysql2
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
75
|
+
version: 0.5.2
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
82
|
+
version: 0.5.2
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: appraisal
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,38 +101,49 @@ executables: []
|
|
115
101
|
extensions: []
|
116
102
|
extra_rdoc_files: []
|
117
103
|
files:
|
104
|
+
- ".github/workflows/ci-legacy.yml"
|
105
|
+
- ".github/workflows/ci.yml"
|
118
106
|
- ".gitignore"
|
119
107
|
- ".rspec"
|
120
108
|
- ".ruby-version"
|
121
|
-
- ".travis.yml"
|
122
109
|
- Appraisals
|
110
|
+
- CHANGELOG.md
|
123
111
|
- Gemfile
|
124
112
|
- LICENSE.txt
|
125
113
|
- README.md
|
126
114
|
- Rakefile
|
115
|
+
- gemfiles/rails3.0.gemfile
|
127
116
|
- gemfiles/rails3.1.gemfile
|
128
117
|
- gemfiles/rails3.2.gemfile
|
118
|
+
- gemfiles/rails4.0.gemfile
|
129
119
|
- gemfiles/rails4.1.gemfile
|
130
120
|
- gemfiles/rails4.2.gemfile
|
131
|
-
- gemfiles/
|
121
|
+
- gemfiles/rails5.0.gemfile
|
122
|
+
- gemfiles/rails5.1.gemfile
|
123
|
+
- gemfiles/rails5.2.gemfile
|
124
|
+
- gemfiles/rails6.0.gemfile
|
125
|
+
- gemfiles/rails6.1.gemfile
|
132
126
|
- lib/octoshark.rb
|
133
127
|
- lib/octoshark/active_record_extensions.rb
|
134
128
|
- lib/octoshark/connection_manager.rb
|
129
|
+
- lib/octoshark/connection_pools_manager.rb
|
130
|
+
- lib/octoshark/current_connection.rb
|
135
131
|
- lib/octoshark/error.rb
|
136
132
|
- lib/octoshark/version.rb
|
137
133
|
- octoshark.gemspec
|
138
134
|
- spec/octoshark/active_record_extensions_spec.rb
|
139
135
|
- spec/octoshark/connection_manager_spec.rb
|
140
|
-
- spec/
|
136
|
+
- spec/octoshark/connection_pools_manager_spec.rb
|
137
|
+
- spec/octoshark/current_connection_spec.rb
|
141
138
|
- spec/spec_helper.rb
|
139
|
+
- spec/support/config.yml.github
|
142
140
|
- spec/support/config.yml.template
|
143
|
-
- spec/support/config.yml.travis
|
144
141
|
- spec/support/helpers.rb
|
145
142
|
homepage: https://github.com/dalibor/octoshark
|
146
143
|
licenses:
|
147
144
|
- MIT
|
148
145
|
metadata: {}
|
149
|
-
post_install_message:
|
146
|
+
post_install_message:
|
150
147
|
rdoc_options: []
|
151
148
|
require_paths:
|
152
149
|
- lib
|
@@ -161,16 +158,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
158
|
- !ruby/object:Gem::Version
|
162
159
|
version: '0'
|
163
160
|
requirements: []
|
164
|
-
|
165
|
-
|
166
|
-
signing_key:
|
161
|
+
rubygems_version: 3.1.6
|
162
|
+
signing_key:
|
167
163
|
specification_version: 4
|
168
164
|
summary: Octoshark is an ActiveRecord connection switcher
|
169
165
|
test_files:
|
170
166
|
- spec/octoshark/active_record_extensions_spec.rb
|
171
167
|
- spec/octoshark/connection_manager_spec.rb
|
172
|
-
- spec/
|
168
|
+
- spec/octoshark/connection_pools_manager_spec.rb
|
169
|
+
- spec/octoshark/current_connection_spec.rb
|
173
170
|
- spec/spec_helper.rb
|
171
|
+
- spec/support/config.yml.github
|
174
172
|
- spec/support/config.yml.template
|
175
|
-
- spec/support/config.yml.travis
|
176
173
|
- spec/support/helpers.rb
|
data/.travis.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
rvm:
|
2
|
-
- 2.1.0
|
3
|
-
cache:
|
4
|
-
- bundler
|
5
|
-
notifications:
|
6
|
-
email:
|
7
|
-
- dalibor.nasevic@gmail.com
|
8
|
-
gemfile:
|
9
|
-
- gemfiles/rails3.1.gemfile
|
10
|
-
- gemfiles/rails3.2.gemfile
|
11
|
-
- gemfiles/rails4.gemfile
|
12
|
-
- gemfiles/rails4.1.gemfile
|
13
|
-
- gemfiles/rails4.2.gemfile
|
14
|
-
before_script:
|
15
|
-
- cp spec/support/config.yml.travis spec/support/config.yml
|
16
|
-
- bundle exec rake db:create
|
17
|
-
script:
|
18
|
-
- bundle exec rspec spec
|
data/spec/octoshark_spec.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Octoshark do
|
4
|
-
|
5
|
-
describe ".reset_connection_managers!" do
|
6
|
-
it "resets connection managers" do
|
7
|
-
manager = Octoshark::ConnectionManager.new(configs)
|
8
|
-
old_pools = manager.connection_pools.map(&:object_id)
|
9
|
-
|
10
|
-
Octoshark.reset_connection_managers!
|
11
|
-
|
12
|
-
new_pools = manager.connection_pools.map(&:object_id)
|
13
|
-
expect(new_pools).to_not eq(old_pools)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe ".disconnect!" do
|
18
|
-
it "disconnects connection managers" do
|
19
|
-
manager = Octoshark::ConnectionManager.new(configs)
|
20
|
-
|
21
|
-
Octoshark.disconnect!
|
22
|
-
|
23
|
-
expect(Octoshark.connection_managers).to be_blank
|
24
|
-
end
|
25
|
-
|
26
|
-
it "cleans old connections" do
|
27
|
-
manager = Octoshark::ConnectionManager.new(configs)
|
28
|
-
|
29
|
-
manager.with_connection(:db1) { |connection| connection.execute("SELECT 1") }
|
30
|
-
manager.with_connection(:db2) { |connection| connection.execute("SELECT 1") }
|
31
|
-
expect(manager.connection_pools[:db1].connections.count).to eq(1)
|
32
|
-
expect(manager.connection_pools[:db2].connections.count).to eq(1)
|
33
|
-
|
34
|
-
Octoshark.disconnect!
|
35
|
-
|
36
|
-
expect(manager.connection_pools[:db1].connections.count).to eq(0)
|
37
|
-
expect(manager.connection_pools[:db2].connections.count).to eq(0)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|