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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmUwZjFjMGVlYjI5NDA4MGE4OTI3Yjc2NDM1MTFlNzg1NzU4NGZmYQ==
4
+ Y2VmYmRmY2ZjOGQwMjdiZjRkMDI5ZmVlYzE3ZjlmYzEwMzMzNTMyOQ==
5
5
  data.tar.gz: !binary |-
6
- ZDY3MGQzZTY5ZDc5MzRkMDhhYjNiMGFlODgwNDI1MWQ0MjU3YTM5Ng==
6
+ ZGIzOThjOTQ2MmIyNWI2MDQ1MTA5OTUzODhkMDFlMTg0NTI2Nzg0OA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NTI0YmFlOGY0NzRjYWViZDhjZDJlYTU2ZjY4MWIwZDYxYTZkZDQxZGM2M2Vm
10
- MzQ5YzMxOTI5Y2UyYzUyZTJlNzc3Zjk4ZDA4NDE3ODBhYmE2ZTMwMDllMjBl
11
- MWM5YzVhYWUwOGNmZWVjNzMzZjYxNmE5ODU1MWIyMjUxMDg3NTQ=
9
+ OGYyYjdkZTA1OWI2NTI4ZmY5MmY1NDEwYTQzZWVjODJlNzA3OTNiOTRiZDMy
10
+ MDRiMDgxYzVhYjZmM2VhOTc2ZjRhODZkYWM5MTY0OGEzNmFjMmY0YzNjMmMz
11
+ ODY5YmU0Yzc3YTc4Y2QyMmQwZTMyNDM4NTIyMjFlZThhNDE0Yzc=
12
12
  data.tar.gz: !binary |-
13
- NTBmZmFlZjZhOGU2ZmQzOGVlYTExZjBjN2ZlODFmMGQ2NjlmZmMxZmM0Mjk2
14
- ZGNjNWE2ZTY3ZmU4OTUzM2M5YmU0MDZiN2IwYWY0NmNlNWQzODk0OTc2MzAz
15
- MjRiNDJkZmJmNTUxZmZiYjBiNzBiMTk2NzJmNWVhMDJiZGRiNmU=
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
- @connection_pools[@hijacked_spec] ||= ActiveRecord::ConnectionAdapters::ConnectionPool.new(@hijacked_spec)
16
- @class_to_pool[@swap_class.name] = @connection_pools[@hijacked_spec]
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)
@@ -1,3 +1,3 @@
1
1
  module ConAir
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -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 "#exist?" do
27
- before do
28
- @handler = ConAir::ConnectionHandler.new(@swap_class, @spec)
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)
Binary file
@@ -71,3 +71,39 @@ Connecting to database specified by database.yml
71
71
   (14.0ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
72
72
   (0.1ms) SELECT version FROM "schema_migrations"
73
73
   (5.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223113501')
74
+ Connecting to database specified by database.yml
75
+  (2.2ms) select sqlite_version(*)
76
+  (13.9ms) DROP TABLE "users"
77
+  (4.5ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
78
+  (0.1ms) SELECT version FROM "schema_migrations"
79
+  (10.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223122635')
80
+ Connecting to database specified by database.yml
81
+  (23.8ms) select sqlite_version(*)
82
+  (9.4ms) DROP TABLE "users"
83
+  (4.6ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
84
+  (0.1ms) SELECT version FROM "schema_migrations"
85
+  (7.9ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223122730')
86
+ Connecting to database specified by database.yml
87
+  (24.8ms) select sqlite_version(*)
88
+  (11.9ms) DROP TABLE "users"
89
+  (4.5ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
90
+  (0.1ms) SELECT version FROM "schema_migrations"
91
+  (5.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223122744')
92
+ Connecting to database specified by database.yml
93
+  (28.3ms) select sqlite_version(*)
94
+  (8.6ms) DROP TABLE "users"
95
+  (5.1ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
96
+  (0.1ms) SELECT version FROM "schema_migrations"
97
+  (5.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223122824')
98
+ Connecting to database specified by database.yml
99
+  (19.4ms) select sqlite_version(*)
100
+  (21.3ms) DROP TABLE "users"
101
+  (17.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
102
+  (0.1ms) SELECT version FROM "schema_migrations"
103
+  (6.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223122957')
104
+ Connecting to database specified by database.yml
105
+  (26.4ms) select sqlite_version(*)
106
+  (15.6ms) DROP TABLE "users"
107
+  (4.3ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
108
+  (0.1ms) SELECT version FROM "schema_migrations"
109
+  (5.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223123037')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: con_air
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham