con_air 0.0.5 → 0.0.6

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
- NWEyZDcxNTBlZTVhOTE3N2I0MzNlZTkwM2NlZWQ4MjljY2UxMGI1Zg==
4
+ MmUwZjFjMGVlYjI5NDA4MGE4OTI3Yjc2NDM1MTFlNzg1NzU4NGZmYQ==
5
5
  data.tar.gz: !binary |-
6
- ZGZjNmUxZjc1OTE5ZTk2ODkyOTE3MTQxYWU0OTY0YTkxMjRlYzM0OQ==
6
+ ZDY3MGQzZTY5ZDc5MzRkMDhhYjNiMGFlODgwNDI1MWQ0MjU3YTM5Ng==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YTc5MDYzMGVmNjJmYmRkYWZmMDY0MjU0ZTBjYjBhN2Q1YjhiY2FlMjQ0N2Qy
10
- MzU0MDM3NmFlNzljOWYxMjQyZDdkZDdhNzk1OTVkMDVmZTc3NmViMTkwYWY5
11
- MDQxM2Y1YWUzYjEzMmVjM2Y2MmY1NmUyMDFiMmY3ZGMzOTE2ZTY=
9
+ NTI0YmFlOGY0NzRjYWViZDhjZDJlYTU2ZjY4MWIwZDYxYTZkZDQxZGM2M2Vm
10
+ MzQ5YzMxOTI5Y2UyYzUyZTJlNzc3Zjk4ZDA4NDE3ODBhYmE2ZTMwMDllMjBl
11
+ MWM5YzVhYWUwOGNmZWVjNzMzZjYxNmE5ODU1MWIyMjUxMDg3NTQ=
12
12
  data.tar.gz: !binary |-
13
- ZTA2OWRlZjQ0ZDY0NmVjY2ZhYzBiNmRiNDJjMGIzMDJkOWIwYThkNzUyNDc3
14
- ODY2ZTUyNTEwZDJiMWZkZDM1MWJhNTdlOTA3Mjg2MDI3MTFhZTk1YjBiOGNk
15
- OWM4ZGY5NzE2OTBiYmE2NDQ0MzQ3N2FkYzAwNjZjYjk0ZGIxZWE=
13
+ NTBmZmFlZjZhOGU2ZmQzOGVlYTExZjBjN2ZlODFmMGQ2NjlmZmMxZmM0Mjk2
14
+ ZGNjNWE2ZTY3ZmU4OTUzM2M5YmU0MDZiN2IwYWY0NmNlNWQzODk0OTc2MzAz
15
+ MjRiNDJkZmJmNTUxZmZiYjBiNzBiMTk2NzJmNWVhMDJiZGRiNmU=
@@ -11,18 +11,9 @@ module ConAir
11
11
  @swap_class = swap_class
12
12
 
13
13
  # Init connections after switching handler
14
-
15
14
  ActiveRecord::Base.establish_connection
16
- establish_connection(hijacked_spec, swap_class)
17
- end
18
-
19
- def establish_connection(name, spec)
20
- if name == swap_class.name
21
- @connection_pools[@hijacked_spec] ||= ActiveRecord::ConnectionAdapters::ConnectionPool.new(@hijacked_spec)
22
- @class_to_pool[name] = @connection_pools[@hijacked_spec]
23
- else
24
- super
25
- end
15
+ @connection_pools[@hijacked_spec] ||= ActiveRecord::ConnectionAdapters::ConnectionPool.new(@hijacked_spec)
16
+ @class_to_pool[@swap_class.name] = @connection_pools[@hijacked_spec]
26
17
  end
27
18
 
28
19
  def exist?(config, klass)
@@ -1,3 +1,3 @@
1
1
  module ConAir
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -3,31 +3,31 @@ require "spec_helper"
3
3
  describe ConAir::ConnectionHandler do
4
4
  before do
5
5
  @swap_class = double(name: "Swap")
6
- @config = double
6
+ @config = double.as_null_object
7
7
  @spec = double(config: @config)
8
- @original_spec = double
9
- @handler = ConAir::ConnectionHandler.new(@swap_class, @spec)
10
8
  end
11
9
 
12
- context "#establish_connection" do
13
- context "when class matches the one we want to swap" do
14
- it "creates pool using passing in spec" do
15
- expect(ActiveRecord::ConnectionAdapters::ConnectionPool).to receive(:new).with(@spec)
10
+ 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]
16
14
 
17
- @handler.establish_connection(@swap_class.name, @original_spec)
18
- end
15
+ expect(pool).to be_instance_of(ActiveRecord::ConnectionAdapters::ConnectionPool)
16
+ expect(pool.spec).to eq(@spec)
19
17
  end
20
18
 
21
- context "when class does not match the one we want to swap" do
22
- it "creates pool using original in spec" do
23
- expect(ActiveRecord::ConnectionAdapters::ConnectionPool).to receive(:new).with(@original_spec)
19
+ it "establishes activerecords connection" do
20
+ expect(ActiveRecord::Base).to receive(:establish_connection)
24
21
 
25
- @handler.establish_connection("SomeClass", @original_spec)
26
- end
22
+ ConAir::ConnectionHandler.new(@swap_class, @spec)
27
23
  end
28
24
  end
29
25
 
30
26
  context "#exist?" do
27
+ before do
28
+ @handler = ConAir::ConnectionHandler.new(@swap_class, @spec)
29
+ end
30
+
31
31
  context "when has same config and class to swap" do
32
32
  it "returns true" do
33
33
  expect(@handler.exist?(@config, @swap_class)).to be(true)
data/spec/con_air_spec.rb CHANGED
@@ -43,7 +43,7 @@ describe ConAir do
43
43
  end
44
44
 
45
45
  it "establish connection" do
46
- expect(ActiveRecord::Base).to receive(:establish_connection)
46
+ expect(klass).to receive(:establish_connection)
47
47
 
48
48
  ConAir.hijack(@config, klass) { }
49
49
  end
Binary file
@@ -5,3 +5,69 @@ Connecting to database specified by database.yml
5
5
   (17.4ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6
6
   (0.1ms) SELECT version FROM "schema_migrations"
7
7
   (17.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20131220144142')
8
+ Connecting to database specified by database.yml
9
+  (29.5ms) select sqlite_version(*)
10
+  (21.4ms) DROP TABLE "users"
11
+  (17.6ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
12
+  (0.1ms) SELECT version FROM "schema_migrations"
13
+  (17.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223111850')
14
+ Connecting to database specified by database.yml
15
+  (25.0ms) select sqlite_version(*)
16
+  (27.5ms) DROP TABLE "users"
17
+  (4.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
18
+  (0.1ms) SELECT version FROM "schema_migrations"
19
+  (5.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223112540')
20
+ Connecting to database specified by database.yml
21
+  (26.1ms) select sqlite_version(*)
22
+  (8.7ms) DROP TABLE "users"
23
+  (5.2ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
24
+  (0.2ms) SELECT version FROM "schema_migrations"
25
+  (8.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223112642')
26
+ Connecting to database specified by database.yml
27
+  (24.2ms) select sqlite_version(*)
28
+  (12.7ms) DROP TABLE "users"
29
+  (14.7ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
30
+  (0.1ms) SELECT version FROM "schema_migrations"
31
+  (17.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223112746')
32
+ Connecting to database specified by database.yml
33
+  (24.3ms) select sqlite_version(*)
34
+  (25.0ms) DROP TABLE "users"
35
+  (17.3ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
36
+  (0.1ms) SELECT version FROM "schema_migrations"
37
+  (10.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223112802')
38
+ Connecting to database specified by database.yml
39
+  (24.2ms) select sqlite_version(*)
40
+  (26.8ms) DROP TABLE "users"
41
+  (17.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
42
+  (0.1ms) SELECT version FROM "schema_migrations"
43
+  (17.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223113032')
44
+ Connecting to database specified by database.yml
45
+  (26.9ms) select sqlite_version(*)
46
+  (24.9ms) DROP TABLE "users"
47
+  (17.5ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
48
+  (0.1ms) SELECT version FROM "schema_migrations"
49
+  (6.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223113046')
50
+ Connecting to database specified by database.yml
51
+  (26.4ms) select sqlite_version(*)
52
+  (13.2ms) DROP TABLE "users"
53
+  (5.3ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
54
+  (0.1ms) SELECT version FROM "schema_migrations"
55
+  (4.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223113114')
56
+ Connecting to database specified by database.yml
57
+  (25.7ms) select sqlite_version(*)
58
+  (21.5ms) DROP TABLE "users"
59
+  (17.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
60
+  (0.1ms) SELECT version FROM "schema_migrations"
61
+  (17.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223113405')
62
+ Connecting to database specified by database.yml
63
+  (26.7ms) select sqlite_version(*)
64
+  (9.4ms) DROP TABLE "users"
65
+  (17.5ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
66
+  (0.1ms) SELECT version FROM "schema_migrations"
67
+  (17.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223113450')
68
+ Connecting to database specified by database.yml
69
+  (19.0ms) select sqlite_version(*)
70
+  (21.2ms) DROP TABLE "users"
71
+  (14.0ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
72
+  (0.1ms) SELECT version FROM "schema_migrations"
73
+  (5.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20131223113501')
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham