con_air 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/con_air/connection_handler.rb +10 -2
- data/lib/con_air/version.rb +1 -1
- data/spec/con_air/connection_handler_spec.rb +23 -11
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +36 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2VmYmRmY2ZjOGQwMjdiZjRkMDI5ZmVlYzE3ZjlmYzEwMzMzNTMyOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGIzOThjOTQ2MmIyNWI2MDQ1MTA5OTUzODhkMDFlMTg0NTI2Nzg0OA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGYyYjdkZTA1OWI2NTI4ZmY5MmY1NDEwYTQzZWVjODJlNzA3OTNiOTRiZDMy
|
10
|
+
MDRiMDgxYzVhYjZmM2VhOTc2ZjRhODZkYWM5MTY0OGEzNmFjMmY0YzNjMmMz
|
11
|
+
ODY5YmU0Yzc3YTc4Y2QyMmQwZTMyNDM4NTIyMjFlZThhNDE0Yzc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODNhNjU5NDMxZjEyMjhmMzgwZTY0NWJjOGU0OTZiNmRjNjM2MTcwNmE2YzYz
|
14
|
+
Mzc3OGMzZjg1MzJlMzZkOGM4ODNjM2Y5NWZkYjEwN2VlNzNmOGIxNGU2ZWYz
|
15
|
+
ZDQwMDZkY2I2NGQ5NjVjMjc5NDFiODQxOWZkYjAxZWMzODFiZjE=
|
@@ -9,11 +9,19 @@ module ConAir
|
|
9
9
|
|
10
10
|
@hijacked_spec = hijacked_spec
|
11
11
|
@swap_class = swap_class
|
12
|
+
@active = true
|
12
13
|
|
13
14
|
# Init connections after switching handler
|
14
15
|
ActiveRecord::Base.establish_connection
|
15
|
-
|
16
|
-
|
16
|
+
end
|
17
|
+
|
18
|
+
def establish_connection(name, spec)
|
19
|
+
if name == swap_class.name
|
20
|
+
@connection_pools[@hijacked_spec] ||= ActiveRecord::ConnectionAdapters::ConnectionPool.new(@hijacked_spec)
|
21
|
+
@class_to_pool[name] = @connection_pools[@hijacked_spec]
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
def exist?(config, klass)
|
data/lib/con_air/version.rb
CHANGED
@@ -5,29 +5,41 @@ describe ConAir::ConnectionHandler do
|
|
5
5
|
@swap_class = double(name: "Swap")
|
6
6
|
@config = double.as_null_object
|
7
7
|
@spec = double(config: @config)
|
8
|
+
allow(ActiveRecord::Base).to receive(:establish_connection)
|
9
|
+
@handler = ConAir::ConnectionHandler.new(@swap_class, @spec)
|
8
10
|
end
|
9
11
|
|
10
12
|
context "#new" do
|
11
|
-
it "creates pool using passed-in spec" do
|
12
|
-
handler = ConAir::ConnectionHandler.new(@swap_class, @spec)
|
13
|
-
pool = handler.connection_pools[@spec]
|
14
|
-
|
15
|
-
expect(pool).to be_instance_of(ActiveRecord::ConnectionAdapters::ConnectionPool)
|
16
|
-
expect(pool.spec).to eq(@spec)
|
17
|
-
end
|
18
|
-
|
19
13
|
it "establishes activerecords connection" do
|
20
14
|
expect(ActiveRecord::Base).to receive(:establish_connection)
|
21
15
|
|
22
16
|
ConAir::ConnectionHandler.new(@swap_class, @spec)
|
23
17
|
end
|
18
|
+
|
19
|
+
it "is active" do
|
20
|
+
expect(@handler.active).to be(true)
|
21
|
+
end
|
24
22
|
end
|
25
23
|
|
26
|
-
context "#
|
27
|
-
|
28
|
-
|
24
|
+
context "#establish_connection" do
|
25
|
+
context "when class matches the one we want to swap" do
|
26
|
+
it "creates pool using passing in spec" do
|
27
|
+
expect(ActiveRecord::ConnectionAdapters::ConnectionPool).to receive(:new).with(@spec)
|
28
|
+
|
29
|
+
@handler.establish_connection(@swap_class.name, @original_spec)
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
33
|
+
context "when class does not match the one we want to swap" do
|
34
|
+
it "creates pool using original in spec" do
|
35
|
+
expect(ActiveRecord::ConnectionAdapters::ConnectionPool).to receive(:new).with(@original_spec)
|
36
|
+
|
37
|
+
@handler.establish_connection("SomeClass", @original_spec)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "#exist?" do
|
31
43
|
context "when has same config and class to swap" do
|
32
44
|
it "returns true" do
|
33
45
|
expect(@handler.exist?(@config, @swap_class)).to be(true)
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/spec/dummy/log/test.log
CHANGED
@@ -71,3 +71,39 @@ Connecting to database specified by database.yml
|
|
71
71
|
[1m[36m (14.0ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) [0m
|
72
72
|
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
73
73
|
[1m[36m (5.0ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20131223113501')[0m
|
74
|
+
Connecting to database specified by database.yml
|
75
|
+
[1m[36m (2.2ms)[0m [1mselect sqlite_version(*)[0m
|
76
|
+
[1m[35m (13.9ms)[0m DROP TABLE "users"
|
77
|
+
[1m[36m (4.5ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) [0m
|
78
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
79
|
+
[1m[36m (10.2ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20131223122635')[0m
|
80
|
+
Connecting to database specified by database.yml
|
81
|
+
[1m[36m (23.8ms)[0m [1mselect sqlite_version(*)[0m
|
82
|
+
[1m[35m (9.4ms)[0m DROP TABLE "users"
|
83
|
+
[1m[36m (4.6ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) [0m
|
84
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
85
|
+
[1m[36m (7.9ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20131223122730')[0m
|
86
|
+
Connecting to database specified by database.yml
|
87
|
+
[1m[36m (24.8ms)[0m [1mselect sqlite_version(*)[0m
|
88
|
+
[1m[35m (11.9ms)[0m DROP TABLE "users"
|
89
|
+
[1m[36m (4.5ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) [0m
|
90
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
91
|
+
[1m[36m (5.2ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20131223122744')[0m
|
92
|
+
Connecting to database specified by database.yml
|
93
|
+
[1m[36m (28.3ms)[0m [1mselect sqlite_version(*)[0m
|
94
|
+
[1m[35m (8.6ms)[0m DROP TABLE "users"
|
95
|
+
[1m[36m (5.1ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) [0m
|
96
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
97
|
+
[1m[36m (5.0ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20131223122824')[0m
|
98
|
+
Connecting to database specified by database.yml
|
99
|
+
[1m[36m (19.4ms)[0m [1mselect sqlite_version(*)[0m
|
100
|
+
[1m[35m (21.3ms)[0m DROP TABLE "users"
|
101
|
+
[1m[36m (17.4ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) [0m
|
102
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
103
|
+
[1m[36m (6.7ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20131223122957')[0m
|
104
|
+
Connecting to database specified by database.yml
|
105
|
+
[1m[36m (26.4ms)[0m [1mselect sqlite_version(*)[0m
|
106
|
+
[1m[35m (15.6ms)[0m DROP TABLE "users"
|
107
|
+
[1m[36m (4.3ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) [0m
|
108
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
109
|
+
[1m[36m (5.0ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20131223123037')[0m
|