switchman 1.2.10 → 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/switchman/shard.rb +2 -2
  3. data/lib/switchman/active_record/connection_handler.rb +18 -9
  4. data/lib/switchman/active_record/connection_pool.rb +3 -0
  5. data/lib/switchman/active_record/query_cache.rb +6 -1
  6. data/lib/switchman/active_record/query_methods.rb +1 -1
  7. data/lib/switchman/connection_pool_proxy.rb +1 -1
  8. data/lib/switchman/r_spec_helper.rb +73 -61
  9. data/lib/switchman/test_helper.rb +8 -2
  10. data/lib/switchman/version.rb +1 -1
  11. data/lib/tasks/switchman.rake +5 -0
  12. data/spec/dummy/config/database.yml +2 -4
  13. data/spec/dummy/config/environments/development.rb +0 -4
  14. data/spec/dummy/config/environments/test.rb +1 -1
  15. data/spec/dummy/db/schema.rb +12 -12
  16. data/spec/dummy/db/shard_120.sqlite3 +0 -0
  17. data/spec/dummy/db/shard_156.sqlite3 +0 -0
  18. data/spec/dummy/db/shard_193.sqlite3 +0 -0
  19. data/spec/dummy/db/shard_23.sqlite3 +0 -0
  20. data/spec/dummy/db/shard_234.sqlite3 +0 -0
  21. data/spec/dummy/db/shard_257.sqlite3 +0 -0
  22. data/spec/dummy/db/shard_277.sqlite3 +0 -0
  23. data/spec/dummy/db/shard_311.sqlite3 +0 -0
  24. data/spec/dummy/db/shard_324.sqlite3 +0 -0
  25. data/spec/dummy/db/shard_342.sqlite3 +0 -0
  26. data/spec/dummy/db/shard_375.sqlite3 +0 -0
  27. data/spec/dummy/db/shard_389.sqlite3 +0 -0
  28. data/spec/dummy/db/shard_428.sqlite3 +0 -0
  29. data/spec/dummy/db/shard_452.sqlite3 +0 -0
  30. data/spec/dummy/db/shard_462.sqlite3 +0 -0
  31. data/spec/dummy/db/shard_483.sqlite3 +0 -0
  32. data/spec/dummy/db/shard_508.sqlite3 +0 -0
  33. data/spec/dummy/db/shard_531.sqlite3 +0 -0
  34. data/spec/dummy/db/shard_554.sqlite3 +0 -0
  35. data/spec/dummy/db/shard_577.sqlite3 +0 -0
  36. data/spec/dummy/db/shard_58.sqlite3 +0 -0
  37. data/spec/dummy/db/shard_600.sqlite3 +0 -0
  38. data/spec/dummy/db/shard_623.sqlite3 +0 -0
  39. data/spec/dummy/db/shard_646.sqlite3 +0 -0
  40. data/spec/dummy/db/shard_668.sqlite3 +0 -0
  41. data/spec/dummy/db/shard_680.sqlite3 +0 -0
  42. data/spec/dummy/db/shard_708.sqlite3 +0 -0
  43. data/spec/dummy/db/shard_735.sqlite3 +0 -0
  44. data/spec/dummy/db/shard_753.sqlite3 +0 -0
  45. data/spec/dummy/db/shard_76.sqlite3 +0 -0
  46. data/spec/dummy/db/shard_802.sqlite3 +0 -0
  47. data/spec/dummy/db/test.sqlite3 +0 -0
  48. data/spec/dummy/log/development.log +7 -0
  49. data/spec/dummy/log/test.log +106293 -0
  50. data/spec/dummy/tmp/cache/313/970/shard%2F30 +1 -0
  51. data/spec/dummy/tmp/cache/316/980/shard%2F15 +1 -0
  52. data/spec/dummy/tmp/cache/317/9D0/shard%2F52 +1 -0
  53. data/spec/dummy/tmp/cache/31C/A40/shard%2F75 +1 -0
  54. data/spec/dummy/tmp/cache/345/E00/shard%2F500 +1 -0
  55. data/spec/dummy/tmp/cache/346/DF0/shard%2F321 +1 -0
  56. data/spec/dummy/tmp/cache/349/DE0/shard%2F126 +1 -0
  57. data/spec/dummy/tmp/cache/349/E10/shard%2F153 +0 -0
  58. data/spec/dummy/tmp/cache/349/E20/shard%2F243 +1 -0
  59. data/spec/dummy/tmp/cache/34A/E20/shard%2F154 +0 -0
  60. data/spec/dummy/tmp/cache/34A/E40/shard%2F172 +1 -0
  61. data/spec/dummy/tmp/cache/34A/E70/shard%2F523 +1 -0
  62. data/spec/dummy/tmp/cache/34A/EB0/shard%2F721 +1 -0
  63. data/spec/dummy/tmp/cache/34A/EC0/shard%2F730 +1 -0
  64. data/spec/dummy/tmp/cache/34B/E40/shard%2F245 +0 -0
  65. data/spec/dummy/tmp/cache/34B/E60/shard%2F425 +1 -0
  66. data/spec/dummy/tmp/cache/34B/EC0/shard%2F722 +1 -0
  67. data/spec/dummy/tmp/cache/34C/E50/shard%2F246 +0 -0
  68. data/spec/dummy/tmp/cache/34C/E80/shard%2F273 +1 -0
  69. data/spec/dummy/tmp/cache/34C/E90/shard%2F363 +0 -0
  70. data/spec/dummy/tmp/cache/34C/E90/shard%2F444 +1 -0
  71. data/spec/dummy/tmp/cache/34C/EA0/shard%2F615 +1 -0
  72. data/spec/dummy/tmp/cache/34C/F00/shard%2F750 +1 -0
  73. data/spec/dummy/tmp/cache/34D/E80/shard%2F265 +1 -0
  74. data/spec/dummy/tmp/cache/34D/ED0/shard%2F391 +1 -0
  75. data/spec/dummy/tmp/cache/34D/EE0/shard%2F724 +1 -0
  76. data/spec/dummy/tmp/cache/34E/ED0/shard%2F383 +1 -0
  77. data/spec/dummy/tmp/cache/34E/EF0/shard%2F725 +1 -0
  78. data/spec/dummy/tmp/cache/34E/F00/shard%2F653 +1 -0
  79. data/spec/dummy/tmp/cache/34F/EE0/shard%2F546 +1 -0
  80. data/spec/dummy/tmp/cache/34F/F00/shard%2F807 +1 -0
  81. data/spec/dummy/tmp/cache/34F/F30/shard%2F672 +1 -0
  82. data/spec/dummy/tmp/cache/350/EA0/shard%2F178 +1 -0
  83. data/spec/dummy/tmp/cache/350/EB0/shard%2F349 +1 -0
  84. data/spec/dummy/tmp/cache/350/F00/shard%2F718 +0 -0
  85. data/spec/dummy/tmp/cache/350/F40/shard%2F592 +1 -0
  86. data/spec/dummy/tmp/cache/351/F00/shard%2F386 +0 -0
  87. data/spec/dummy/tmp/cache/351/F10/shard%2F638 +1 -0
  88. data/spec/dummy/tmp/cache/351/F10/shard%2F719 +0 -0
  89. data/spec/dummy/tmp/cache/352/F10/shard%2F387 +0 -0
  90. data/spec/dummy/tmp/cache/352/F10/shard%2F468 +1 -0
  91. data/spec/dummy/tmp/cache/352/F30/shard%2F729 +1 -0
  92. data/spec/dummy/tmp/cache/353/F10/shard%2F298 +1 -0
  93. data/spec/dummy/tmp/cache/353/F50/shard%2F739 +1 -0
  94. data/spec/dummy/tmp/cache/354/F50/shard%2F569 +1 -0
  95. data/spec/dummy/tmp/cache/354/F80/shard%2F677 +1 -0
  96. data/spec/dummy/tmp/cache/354/F90/shard%2F767 +1 -0
  97. data/spec/dummy/tmp/cache/358/FE0/shard%2F699 +1 -0
  98. data/spec/dummy/tmp/cache/3A5/EA0/shard%2F10004 +1 -0
  99. data/spec/dummy/tmp/cache/3A6/F40/shard%2F10410 +1 -0
  100. data/spec/dummy/tmp/cache/3A7/F30/shard%2F10231 +1 -0
  101. data/spec/dummy/tmp/cache/3A8/F90/shard%2F10520 +1 -0
  102. data/spec/dummy/tmp/cache/3A9/F40/shard%2F10062 +1 -0
  103. data/spec/dummy/tmp/cache/3A9/F80/shard%2F10341 +1 -0
  104. data/spec/dummy/tmp/cache/3AA/F10/shard%2F10027 +1 -0
  105. data/spec/dummy/tmp/cache/3AA/F10/shard%2F10108 +1 -0
  106. data/spec/dummy/tmp/cache/3AA/FB0/shard%2F10441 +1 -0
  107. data/spec/dummy/tmp/cache/3AA/FC0/shard%2F10612 +1 -0
  108. data/spec/dummy/tmp/cache/3AB/010/shard%2F10730 +1 -0
  109. data/spec/dummy/tmp/cache/3AB/F70/shard%2F10154 +1 -0
  110. data/spec/dummy/tmp/cache/3AC/020/shard%2F10650 +1 -0
  111. data/spec/dummy/tmp/cache/3AC/FC0/shard%2F10272 +1 -0
  112. data/spec/dummy/tmp/cache/3AD/000/shard%2F10543 +1 -0
  113. data/spec/dummy/tmp/cache/3AD/F50/shard%2F10039 +1 -0
  114. data/spec/dummy/tmp/cache/3AD/F90/shard%2F10318 +1 -0
  115. data/spec/dummy/tmp/cache/3AD/FA0/shard%2F10246 +1 -0
  116. data/spec/dummy/tmp/cache/3AE/060/shard%2F10751 +1 -0
  117. data/spec/dummy/tmp/cache/3AE/FF0/shard%2F10364 +1 -0
  118. data/spec/dummy/tmp/cache/3AF/030/shard%2F10635 +1 -0
  119. data/spec/dummy/tmp/cache/3B0/FE0/shard%2F10177 +1 -0
  120. data/spec/dummy/tmp/cache/3B1/030/shard%2F10295 +1 -0
  121. data/spec/dummy/tmp/cache/3B1/040/shard%2F10466 +1 -0
  122. data/spec/dummy/tmp/cache/3B1/090/shard%2F10673 +1 -0
  123. data/spec/dummy/tmp/cache/3B2/070/shard%2F10566 +1 -0
  124. data/spec/dummy/tmp/cache/3B3/060/shard%2F10387 +1 -0
  125. data/spec/dummy/tmp/cache/3B5/0B0/shard%2F10497 +1 -0
  126. data/spec/dummy/tmp/cache/3B6/100/shard%2F10696 +1 -0
  127. data/spec/dummy/tmp/cache/3B7/0E0/shard%2F10589 +1 -0
  128. data/spec/dummy/tmp/cache/3BA/160/shard%2F10799 +1 -0
  129. data/spec/lib/action_controller/caching_spec.rb +4 -4
  130. data/spec/lib/active_record/abstract_adapter_spec.rb +1 -1
  131. data/spec/lib/active_record/association_spec.rb +83 -67
  132. data/spec/lib/active_record/attribute_methods_spec.rb +29 -29
  133. data/spec/lib/active_record/base_spec.rb +20 -20
  134. data/spec/lib/active_record/calculations_spec.rb +79 -59
  135. data/spec/lib/active_record/connection_handler_spec.rb +14 -14
  136. data/spec/lib/active_record/connection_pool_spec.rb +7 -7
  137. data/spec/lib/active_record/finder_methods_spec.rb +8 -8
  138. data/spec/lib/active_record/query_cache_spec.rb +38 -38
  139. data/spec/lib/active_record/query_methods_spec.rb +45 -45
  140. data/spec/lib/active_record/relation_spec.rb +8 -8
  141. data/spec/lib/active_record/spawn_methods_spec.rb +11 -11
  142. data/spec/lib/connection_pool_proxy_spec.rb +2 -2
  143. data/spec/lib/database_server_spec.rb +37 -37
  144. data/spec/lib/default_shard_spec.rb +3 -3
  145. data/spec/lib/r_spec_helper_spec.rb +33 -7
  146. data/spec/lib/rails_spec.rb +5 -5
  147. data/spec/lib/shackles_spec.rb +35 -35
  148. data/spec/models/shard_spec.rb +104 -104
  149. data/spec/spec_helper.rb +1 -1
  150. metadata +254 -29
@@ -6,39 +6,39 @@ module Switchman
6
6
  include RSpecHelper
7
7
 
8
8
  it "should use different proxies for different categories" do
9
- Shard.connection_pool.should_not == User.connection_pool
9
+ expect(Shard.connection_pool).not_to eq User.connection_pool
10
10
  end
11
11
 
12
12
  it "should share underlying pools for different categories on the same shard" do
13
- Shard.connection_pool.current_pool.should == User.connection_pool.current_pool
13
+ expect(Shard.connection_pool.current_pool).to eq User.connection_pool.current_pool
14
14
  end
15
15
 
16
16
  it "should insert sharding for connections established after initialization" do
17
- User.connection_pool.should == ::ActiveRecord::Base.connection_pool
17
+ expect(User.connection_pool).to eq ::ActiveRecord::Base.connection_pool
18
18
  begin
19
19
  config = { :adapter => 'sqlite3', :database => ':memory:', :something_unique_in_the_spec => true }
20
20
  User.establish_connection(config)
21
- User.connection_pool.should_not == ::ActiveRecord::Base.connection_pool
22
- User.connection_pool.spec.config.should == config
23
- User.connection_pool.should be_is_a(ConnectionPoolProxy)
21
+ expect(User.connection_pool).not_to eq ::ActiveRecord::Base.connection_pool
22
+ expect(User.connection_pool.spec.config).to eq config
23
+ expect(User.connection_pool).to be_is_a(ConnectionPoolProxy)
24
24
  @shard2.activate do
25
- User.connection_pool.spec.config.should == ::ActiveRecord::Base.connection_pool.spec.config
26
- User.connection_pool.spec.config.should_not == config
25
+ expect(User.connection_pool.spec.config).to eq ::ActiveRecord::Base.connection_pool.spec.config
26
+ expect(User.connection_pool.spec.config).not_to eq config
27
27
  end
28
28
  ensure
29
29
  User.remove_connection
30
- User.connection_pool.should == ::ActiveRecord::Base.connection_pool
31
- User.connection_pool.should be_is_a(ConnectionPoolProxy)
30
+ expect(User.connection_pool).to eq ::ActiveRecord::Base.connection_pool
31
+ expect(User.connection_pool).to be_is_a(ConnectionPoolProxy)
32
32
  end
33
33
  end
34
34
 
35
35
  it "should set up separate pools for different categories" do
36
- User.connection_pool.should_not == MirrorUser.connection_pool
36
+ expect(User.connection_pool).not_to eq MirrorUser.connection_pool
37
37
  mu = MirrorUser.create!
38
- MirrorUser.find(mu.local_id).should == mu
38
+ expect(MirrorUser.find(mu.local_id)).to eq mu
39
39
  # didn't activate the :mirror_universe category
40
- @shard1.activate { MirrorUser.find(mu.local_id).should == mu }
41
- @shard1.activate(:mirror_universe) { MirrorUser.find_by_id(mu.local_id).should == nil }
40
+ @shard1.activate { expect(MirrorUser.find(mu.local_id)).to eq mu }
41
+ @shard1.activate(:mirror_universe) { expect(MirrorUser.where(id: mu.local_id).first).to eq nil }
42
42
  end
43
43
  end
44
44
  end
@@ -4,24 +4,24 @@ module Switchman
4
4
  module ActiveRecord
5
5
  describe ConnectionPool do
6
6
  it "should be able to access another shard on a db server after the 'primary' shard is gone" do
7
- pending 'A "real" database"' unless Shard.default.database_server.shareable?
7
+ skip 'A "real" database"' unless Shard.default.database_server.shareable?
8
8
  # separate connections
9
9
  server = DatabaseServer.create(:config => Shard.default.database_server.config.dup)
10
10
  s1 = server.shards.create!(:name => 'non_existent_shard') # don't actually create any schema
11
11
  s2 = server.shards.create! # inherit's the default shard's config, which is functional
12
12
  s1.activate do
13
- lambda { User.count }.should raise_exception
13
+ expect { User.count }.to raise_exception
14
14
  end
15
15
  # the config for s1 should not be the permanent default for all new
16
16
  # connections now
17
17
  s2.activate do
18
- lambda { User.count }.should_not raise_exception
18
+ expect { User.count }.not_to raise_exception
19
19
  end
20
20
  end
21
21
 
22
22
  describe "clear_idle_connections!" do
23
23
  before do
24
- pending 'A "real" database"' unless Shard.default.database_server.shareable?
24
+ skip 'A "real" database"' unless Shard.default.database_server.shareable?
25
25
  @server = DatabaseServer.create(:config => Shard.default.database_server.config.dup)
26
26
  @shard = @server.shards.create!
27
27
  @conn, @pool = @shard.activate{ [User.connection, User.connection_pool.current_pool] }
@@ -36,7 +36,7 @@ module Switchman
36
36
  it "should remove idle connections" do
37
37
  @pool.checkin(@conn)
38
38
  @pool.clear_idle_connections!(@conn.last_query_at + 1)
39
- @pool.connections.should be_empty
39
+ expect(@pool.connections).to be_empty
40
40
  end
41
41
 
42
42
  it "should not affect idle but checked out connections" do
@@ -53,7 +53,7 @@ module Switchman
53
53
 
54
54
  describe "release_connection" do
55
55
  before do
56
- pending 'A "real" database"' unless Shard.default.database_server.shareable?
56
+ skip 'A "real" database"' unless Shard.default.database_server.shareable?
57
57
  @server = DatabaseServer.create(:config => Shard.default.database_server.config.dup)
58
58
  @shard = @server.shards.create!
59
59
  @pool = @shard.activate{ User.connection_pool.current_pool }
@@ -73,7 +73,7 @@ module Switchman
73
73
  it "should still work if idle timeout is not configured" do
74
74
  @pool.spec.config[:idle_timeout] = nil
75
75
  @pool.expects(:clear_idle_connections!).never
76
- lambda { @pool.release_connection }.should_not raise_exception
76
+ expect { @pool.release_connection }.not_to raise_exception
77
77
  end
78
78
  end
79
79
  end
@@ -11,17 +11,17 @@ module Switchman
11
11
 
12
12
  describe "#find_one" do
13
13
  it "should find with a global id" do
14
- User.find(@user.global_id).should == @user
14
+ expect(User.find(@user.global_id)).to eq @user
15
15
  end
16
16
  end
17
17
 
18
18
  describe "#find_by_attributes" do
19
19
  it "should find with a global id" do
20
- User.find_by_id(@user.global_id).should == @user
20
+ expect(User.find_by_id(@user.global_id)).to eq @user
21
21
  end
22
22
 
23
23
  it "should find with an array of global ids" do
24
- User.find_by_id([@user.global_id]).should == @user
24
+ expect(User.find_by_id([@user.global_id])).to eq @user
25
25
  end
26
26
  end
27
27
 
@@ -29,21 +29,21 @@ module Switchman
29
29
  it "should initialize with the shard from the scope" do
30
30
  @user.destroy
31
31
  u = User.shard(@shard1).where(id: @user).first_or_initialize
32
- u.should be_new_record
33
- u.shard.should == @shard1
32
+ expect(u).to be_new_record
33
+ expect(u.shard).to eq @shard1
34
34
  end
35
35
  end
36
36
 
37
37
  describe "#exists?" do
38
38
  it "should work for an out-of-shard scope" do
39
39
  scope = @shard1.activate { User.where(id: @user) }
40
- scope.shard_value.should == @shard1
41
- scope.exists?.should be_true
40
+ expect(scope.shard_value).to eq @shard1
41
+ expect(scope.exists?).to eq true
42
42
  end
43
43
 
44
44
  it "should work for a multi-shard scope" do
45
45
  user2 = @shard2.activate { User.create!(name: "multi-shard exists") }
46
- User.where(name: "multi-shard exists").shard(::Rails.version < '4' ? Shard.scoped : Shard.all).exists?.should be_true
46
+ expect(User.where(name: "multi-shard exists").shard(::Rails.version < '4' ? Shard.scoped : Shard.all).exists?).to eq true
47
47
  end
48
48
  end
49
49
  end
@@ -53,27 +53,27 @@ module Switchman
53
53
  @shard3.activate do
54
54
  User.create!
55
55
  end
56
- @shard1.activate { User.all.to_a }.should_not == @shard3.activate { User.all.to_a }
56
+ expect(@shard1.activate { User.all.to_a }).not_to eq @shard3.activate { User.all.to_a }
57
57
  end
58
58
 
59
59
  describe "query_cache_enabled" do
60
60
  it "should be shared across shards on the same server" do
61
61
  @shard1.activate{ User.connection.query_cache_enabled = true }
62
62
  @shard3.activate{ User.connection.query_cache_enabled = false }
63
- @shard1.activate{ User.connection.query_cache_enabled.should == false }
63
+ @shard1.activate{ expect(User.connection.query_cache_enabled).to eq false }
64
64
  end
65
65
 
66
66
  it "should be shared across servers" do
67
67
  @shard1.activate{ User.connection.query_cache_enabled = true }
68
68
  @shard2.activate{ User.connection.query_cache_enabled = false }
69
- @shard1.activate{ User.connection.query_cache_enabled.should == false }
69
+ @shard1.activate{ expect(User.connection.query_cache_enabled).to eq false }
70
70
  end
71
71
 
72
72
  it "should be distinct across threads" do
73
73
  User.connection.query_cache_enabled = true
74
74
  threaded(
75
75
  lambda{ |cc| User.connection.query_cache_enabled = false; cc.call },
76
- lambda{ User.connection.query_cache_enabled.should == true })
76
+ lambda{ expect(User.connection.query_cache_enabled).to eq true })
77
77
  end
78
78
  end
79
79
 
@@ -84,10 +84,10 @@ module Switchman
84
84
  lambda{ |cc|
85
85
  User.connection.query_cache_enabled = false
86
86
  User.connection.enable_query_cache!
87
- User.connection.query_cache_enabled.should == true
87
+ expect(User.connection.query_cache_enabled).to eq true
88
88
  cc.call
89
89
  },
90
- lambda{ User.connection.query_cache_enabled.should == false })
90
+ lambda{ expect(User.connection.query_cache_enabled).to eq false })
91
91
  end
92
92
  end
93
93
 
@@ -98,10 +98,10 @@ module Switchman
98
98
  lambda{ |cc|
99
99
  User.connection.query_cache_enabled = true
100
100
  User.connection.disable_query_cache!
101
- User.connection.query_cache_enabled.should == false
101
+ expect(User.connection.query_cache_enabled).to eq false
102
102
  cc.call
103
103
  },
104
- lambda{ User.connection.query_cache_enabled.should == true })
104
+ lambda{ expect(User.connection.query_cache_enabled).to eq true })
105
105
  end
106
106
  end
107
107
 
@@ -112,15 +112,15 @@ module Switchman
112
112
  User.connection.disable_query_cache!
113
113
  threaded(
114
114
  lambda{ |cc| User.connection.cache{ cc.call } },
115
- lambda{ User.connection.query_cache_enabled.should == false })
115
+ lambda{ expect(User.connection.query_cache_enabled).to eq false })
116
116
  end
117
117
 
118
118
  it "should only enable for the duration of the block" do
119
119
  User.connection.disable_query_cache!
120
120
  User.connection.cache do
121
- User.connection.query_cache_enabled.should == true
121
+ expect(User.connection.query_cache_enabled).to eq true
122
122
  end
123
- User.connection.query_cache_enabled.should == false
123
+ expect(User.connection.query_cache_enabled).to eq false
124
124
  end
125
125
 
126
126
  it "should clear query cache if disabling query cache after block" do
@@ -128,7 +128,7 @@ module Switchman
128
128
  User.connection.cache do
129
129
  User.connection.query_cache[:key][:binds] = :value
130
130
  end
131
- User.connection.query_cache[:key][:binds].should be_nil
131
+ expect(User.connection.query_cache[:key][:binds]).to be_nil
132
132
  end
133
133
 
134
134
  it "should not clear query cache if the cache was already enabled" do
@@ -136,7 +136,7 @@ module Switchman
136
136
  User.connection.cache do
137
137
  User.connection.query_cache[:key][:binds] = :value
138
138
  end
139
- User.connection.query_cache[:key][:binds].should == :value
139
+ expect(User.connection.query_cache[:key][:binds]).to eq :value
140
140
  end
141
141
  end
142
142
 
@@ -147,21 +147,21 @@ module Switchman
147
147
  User.connection.enable_query_cache!
148
148
  threaded(
149
149
  lambda{ |cc| User.connection.uncached{ cc.call } },
150
- lambda{ User.connection.query_cache_enabled.should == true })
150
+ lambda{ expect(User.connection.query_cache_enabled).to eq true })
151
151
  end
152
152
 
153
153
  it "should only disable for the duration of the block" do
154
154
  User.connection.enable_query_cache!
155
155
  User.connection.uncached do
156
- User.connection.query_cache_enabled.should == false
156
+ expect(User.connection.query_cache_enabled).to eq false
157
157
  end
158
- User.connection.query_cache_enabled.should == true
158
+ expect(User.connection.query_cache_enabled).to eq true
159
159
  end
160
160
 
161
161
  it "should not clear query cache" do
162
162
  User.connection.query_cache[:key][:binds] = :value
163
163
  User.connection.uncached{}
164
- User.connection.query_cache[:key][:binds].should == :value
164
+ expect(User.connection.query_cache[:key][:binds]).to eq :value
165
165
  end
166
166
  end
167
167
 
@@ -169,26 +169,26 @@ module Switchman
169
169
  it "should cache when query cache enabled" do
170
170
  User.connection.enable_query_cache!
171
171
  User.all.to_a
172
- User.connection.query_cache.should_not be_empty
172
+ expect(User.connection.query_cache).not_to be_empty
173
173
  end
174
174
 
175
175
  it "should not cache when query cache disabled" do
176
176
  User.connection.disable_query_cache!
177
177
  User.all.to_a
178
- User.connection.query_cache.should be_empty
178
+ expect(User.connection.query_cache).to be_empty
179
179
  end
180
180
 
181
181
  it "should not cache when query cache disabled but other thread's enabled" do
182
182
  User.connection.disable_query_cache!
183
183
  threaded(
184
184
  lambda{ |cc| User.connection.cache{ cc.call } },
185
- lambda{ User.all.to_a; User.connection.query_cache.should be_empty })
185
+ lambda{ User.all.to_a; expect(User.connection.query_cache).to be_empty })
186
186
  end
187
187
 
188
188
  it "should not cache when query is locked" do
189
189
  User.connection.enable_query_cache!
190
190
  User.lock.to_a
191
- User.connection.query_cache.should be_empty
191
+ expect(User.connection.query_cache).to be_empty
192
192
  end
193
193
  end
194
194
 
@@ -197,7 +197,7 @@ module Switchman
197
197
  User.connection.enable_query_cache!
198
198
  User.all.to_a
199
199
  User.create!
200
- User.connection.query_cache.should be_empty
200
+ expect(User.connection.query_cache).to be_empty
201
201
  end
202
202
 
203
203
  it "should not clear thread's query cache if disabled" do
@@ -205,7 +205,7 @@ module Switchman
205
205
  User.all.to_a
206
206
  User.connection.disable_query_cache!
207
207
  User.create!
208
- User.connection.query_cache.should_not be_empty
208
+ expect(User.connection.query_cache).not_to be_empty
209
209
  end
210
210
 
211
211
  it "should not clear thread's query cache if disabled but other thread's enabled" do
@@ -214,7 +214,7 @@ module Switchman
214
214
  User.connection.disable_query_cache!
215
215
  threaded(
216
216
  lambda{ |cc| User.create!; cc.call },
217
- lambda{ User.connection.query_cache.should_not be_empty })
217
+ lambda{ expect(User.connection.query_cache).not_to be_empty })
218
218
  end
219
219
 
220
220
  it "should not clear other thread's query cache" do
@@ -223,7 +223,7 @@ module Switchman
223
223
  User.connection.disable_query_cache!
224
224
  threaded(
225
225
  lambda{ |cc| User.create!; cc.call },
226
- lambda{ User.connection.query_cache.should_not be_empty })
226
+ lambda{ expect(User.connection.query_cache).not_to be_empty })
227
227
  end
228
228
  end
229
229
 
@@ -236,7 +236,7 @@ module Switchman
236
236
  User.connection.enable_query_cache!
237
237
  User.all.to_a
238
238
  User.update_all(updated_at: Time.now)
239
- User.connection.query_cache.should be_empty
239
+ expect(User.connection.query_cache).to be_empty
240
240
  end
241
241
 
242
242
  it "should not clear thread's query cache if disabled" do
@@ -244,7 +244,7 @@ module Switchman
244
244
  User.all.to_a
245
245
  User.connection.disable_query_cache!
246
246
  User.update_all(updated_at: Time.now)
247
- User.connection.query_cache.should_not be_empty
247
+ expect(User.connection.query_cache).not_to be_empty
248
248
  end
249
249
 
250
250
  context "non-transactional" do
@@ -262,7 +262,7 @@ module Switchman
262
262
  User.connection.disable_query_cache!
263
263
  threaded(
264
264
  lambda{ |cc| User.update_all(updated_at: Time.now); cc.call },
265
- lambda{ User.connection.query_cache.should_not be_empty })
265
+ lambda{ expect(User.connection.query_cache).not_to be_empty })
266
266
  end
267
267
 
268
268
  it "should not clear other thread's query cache" do
@@ -271,7 +271,7 @@ module Switchman
271
271
  User.connection.disable_query_cache!
272
272
  threaded(
273
273
  lambda{ |cc| User.update_all(updated_at: Time.now); cc.call },
274
- lambda{ User.connection.query_cache.should_not be_empty })
274
+ lambda{ expect(User.connection.query_cache).not_to be_empty })
275
275
  end
276
276
  end
277
277
  end
@@ -285,7 +285,7 @@ module Switchman
285
285
  User.connection.enable_query_cache!
286
286
  User.all.to_a
287
287
  User.delete_all
288
- User.connection.query_cache.should be_empty
288
+ expect(User.connection.query_cache).to be_empty
289
289
  end
290
290
 
291
291
  it "should not clear thread's query cache if disabled" do
@@ -293,7 +293,7 @@ module Switchman
293
293
  User.all.to_a
294
294
  User.connection.disable_query_cache!
295
295
  User.delete_all
296
- User.connection.query_cache.should_not be_empty
296
+ expect(User.connection.query_cache).not_to be_empty
297
297
  end
298
298
 
299
299
  context "non-transactional" do
@@ -311,7 +311,7 @@ module Switchman
311
311
  User.connection.disable_query_cache!
312
312
  threaded(
313
313
  lambda{ |cc| User.delete_all; cc.call },
314
- lambda{ User.connection.query_cache.should_not be_empty })
314
+ lambda{ expect(User.connection.query_cache).not_to be_empty })
315
315
  end
316
316
 
317
317
  it "should not clear other thread's query cache" do
@@ -320,22 +320,22 @@ module Switchman
320
320
  User.connection.disable_query_cache!
321
321
  threaded(
322
322
  lambda{ |cc| User.delete_all; cc.call },
323
- lambda{ User.connection.query_cache.should_not be_empty })
323
+ lambda{ expect(User.connection.query_cache).not_to be_empty })
324
324
  end
325
325
 
326
326
  it "should clear cache for all connections" do
327
327
  u = User.create!(name: 'a')
328
328
  User.connection.cache do
329
- u.reload.name.should == 'a'
329
+ expect(u.reload.name).to eq 'a'
330
330
  ::Shackles.activate(:slave) do
331
- u.reload.name.should == 'a'
331
+ expect(u.reload.name).to eq 'a'
332
332
  end
333
- u.reload.name.should == 'a'
333
+ expect(u.reload.name).to eq 'a'
334
334
  u.name = 'b'
335
335
  u.save!
336
- u.reload.name.should == 'b'
336
+ expect(u.reload.name).to eq 'b'
337
337
  ::Shackles.activate(:slave) do
338
- u.reload.name.should == 'b'
338
+ expect(u.reload.name).to eq 'b'
339
339
  end
340
340
  end
341
341
  end
@@ -16,88 +16,88 @@ module Switchman
16
16
 
17
17
  describe "#primary_shard" do
18
18
  it "should be the shard if it's a shard" do
19
- User.shard(Shard.default).primary_shard.should == Shard.default
20
- User.shard(@shard1).primary_shard.should == @shard1
19
+ expect(User.shard(Shard.default).primary_shard).to eq Shard.default
20
+ expect(User.shard(@shard1).primary_shard).to eq @shard1
21
21
  end
22
22
 
23
23
  it "should be the first shard of an array of shards" do
24
- User.shard([Shard.default, @shard1]).primary_shard.should == Shard.default
25
- User.shard([@shard1, Shard.default]).primary_shard.should == @shard1
24
+ expect(User.shard([Shard.default, @shard1]).primary_shard).to eq Shard.default
25
+ expect(User.shard([@shard1, Shard.default]).primary_shard).to eq @shard1
26
26
  end
27
27
 
28
28
  it "should be the object's shard if it's a model" do
29
- User.shard(@user1).primary_shard.should == Shard.default
30
- User.shard(@user2).primary_shard.should == @shard1
29
+ expect(User.shard(@user1).primary_shard).to eq Shard.default
30
+ expect(User.shard(@user2).primary_shard).to eq @shard1
31
31
  end
32
32
 
33
33
  it "should be the default shard if it's a scope of Shard" do
34
- User.shard(::Rails.version < '4' ? Shard.scoped : Shard.all).primary_shard.should == Shard.default
34
+ expect(User.shard(::Rails.version < '4' ? Shard.scoped : Shard.all).primary_shard).to eq Shard.default
35
35
  @shard1.activate do
36
- User.shard(::Rails.version < '4' ? Shard.scoped : Shard.all).primary_shard.should == Shard.default
36
+ expect(User.shard(::Rails.version < '4' ? Shard.scoped : Shard.all).primary_shard).to eq Shard.default
37
37
  end
38
38
  end
39
39
  end
40
40
 
41
41
  it "should default to the current shard" do
42
42
  relation = ::Rails.version < '4' ? User.scoped : User.all
43
- relation.shard_value.should == Shard.default
44
- relation.shard_source_value.should == :implicit
43
+ expect(relation.shard_value).to eq Shard.default
44
+ expect(relation.shard_source_value).to eq :implicit
45
45
 
46
46
  @shard1.activate do
47
- relation.shard_value.should == Shard.default
47
+ expect(relation.shard_value).to eq Shard.default
48
48
 
49
49
  relation = ::Rails.version < '4' ? User.scoped : User.all
50
- relation.shard_value.should == @shard1
51
- relation.shard_source_value.should == :implicit
50
+ expect(relation.shard_value).to eq @shard1
51
+ expect(relation.shard_source_value).to eq :implicit
52
52
  end
53
- relation.shard_value.should == @shard1
53
+ expect(relation.shard_value).to eq @shard1
54
54
  end
55
55
 
56
56
  describe "with primary key conditions" do
57
57
  it "should be changeable, and change conditions when it is changed" do
58
58
  relation = User.where(:id => @user1).shard(@shard1)
59
- relation.shard_value.should == @shard1
60
- relation.shard_source_value.should == :explicit
61
- relation.where_values.first.right.should == @user1.global_id
59
+ expect(relation.shard_value).to eq @shard1
60
+ expect(relation.shard_source_value).to eq :explicit
61
+ expect(relation.where_values.first.right).to eq @user1.global_id
62
62
  end
63
63
 
64
64
  it "should infer the shard from a single argument" do
65
65
  relation = User.where(:id => @user2)
66
66
  # execute on @shard1, with id local to that shard
67
- relation.shard_value.should == @shard1
68
- relation.where_values.first.right.should == @user2.local_id
67
+ expect(relation.shard_value).to eq @shard1
68
+ expect(relation.where_values.first.right).to eq @user2.local_id
69
69
  end
70
70
 
71
71
  it "should infer the shard from multiple arguments" do
72
72
  relation = User.where(:id => [@user2, @user2])
73
73
  # execute on @shard1, with id local to that shard
74
- relation.shard_value.should == @shard1
75
- relation.where_values.first.right.should == [@user2.local_id, @user2.local_id]
74
+ expect(relation.shard_value).to eq @shard1
75
+ expect(relation.where_values.first.right).to eq [@user2.local_id, @user2.local_id]
76
76
  end
77
77
 
78
78
  it "should infer the correct shard from an array of 1" do
79
79
  relation = User.where(:id => [@user2])
80
80
  # execute on @shard1, with id local to that shard
81
- relation.shard_value.should == @shard1
82
- relation.where_values.first.right.should == [@user2.local_id]
81
+ expect(relation.shard_value).to eq @shard1
82
+ expect(relation.where_values.first.right).to eq [@user2.local_id]
83
83
  end
84
84
 
85
85
  it "should do nothing when it's an array of 0" do
86
86
  relation = User.where(:id => [])
87
87
  # execute on @shard1, with id local to that shard
88
- relation.shard_value.should == Shard.default
89
- relation.where_values.first.right.should == []
88
+ expect(relation.shard_value).to eq Shard.default
89
+ expect(relation.where_values.first.right).to eq []
90
90
  end
91
91
 
92
92
  it "should order the shards preferring the shard it already had as primary" do
93
93
  relation = User.where(:id => [@user1, @user2])
94
- relation.shard_value.should == [Shard.default, @shard1]
95
- relation.where_values.first.right.should == [@user1.local_id, @user2.global_id]
94
+ expect(relation.shard_value).to eq [Shard.default, @shard1]
95
+ expect(relation.where_values.first.right).to eq [@user1.local_id, @user2.global_id]
96
96
 
97
97
  @shard1.activate do
98
98
  relation = User.where(:id => [@user1, @user2])
99
- relation.shard_value.should == [@shard1, Shard.default]
100
- relation.where_values.first.right.should == [@user1.global_id, @user2.local_id]
99
+ expect(relation.shard_value).to eq [@shard1, Shard.default]
100
+ expect(relation.where_values.first.right).to eq [@user1.global_id, @user2.local_id]
101
101
  end
102
102
  end
103
103
  end
@@ -105,36 +105,36 @@ module Switchman
105
105
  describe "with foreign key conditions" do
106
106
  it "should be changeable, and change conditions when it is changed" do
107
107
  relation = Appendage.where(:user_id => @user1)
108
- relation.shard_value.should == Shard.default
109
- relation.shard_source_value.should == :implicit
110
- relation.where_values.first.right.should == @user1.local_id
108
+ expect(relation.shard_value).to eq Shard.default
109
+ expect(relation.shard_source_value).to eq :implicit
110
+ expect(relation.where_values.first.right).to eq @user1.local_id
111
111
 
112
112
  relation = relation.shard(@shard1)
113
- relation.shard_value.should == @shard1
114
- relation.shard_source_value.should == :explicit
115
- relation.where_values.first.right.should == @user1.global_id
113
+ expect(relation.shard_value).to eq @shard1
114
+ expect(relation.shard_source_value).to eq :explicit
115
+ expect(relation.where_values.first.right).to eq @user1.global_id
116
116
  end
117
117
 
118
118
  it "should translate ids based on current shard" do
119
119
  relation = Appendage.where(:user_id => [@user1, @user2])
120
- relation.where_values.first.right.should == [@user1.local_id, @user2.global_id]
120
+ expect(relation.where_values.first.right).to eq [@user1.local_id, @user2.global_id]
121
121
 
122
122
  @shard1.activate do
123
123
  relation = Appendage.where(:user_id => [@user1, @user2])
124
- relation.where_values.first.right.should == [@user1.global_id, @user2.local_id]
124
+ expect(relation.where_values.first.right).to eq [@user1.global_id, @user2.local_id]
125
125
  end
126
126
  end
127
127
 
128
128
  it "should translate ids in joins" do
129
129
  relation = User.joins(:appendage).where(appendages: { user_id: [@user1, @user2]})
130
- relation.where_values.first.right.should == [@user1.local_id, @user2.global_id]
130
+ expect(relation.where_values.first.right).to eq [@user1.local_id, @user2.global_id]
131
131
  end
132
132
 
133
133
  it "should translate ids according to the current shard of the foreign type" do
134
134
  @shard1.activate(:mirror_universe) do
135
135
  mirror_user = MirrorUser.create!
136
136
  relation = User.where(mirror_user_id: mirror_user)
137
- relation.where_values.first.right.should == mirror_user.global_id
137
+ expect(relation.where_values.first.right).to eq mirror_user.global_id
138
138
  end
139
139
  end
140
140
  end
@@ -143,20 +143,20 @@ module Switchman
143
143
  it "should properly construct the query" do
144
144
  child = @user1.children.create!
145
145
  grandchild = child.children.create!
146
- child.reload.parent.should == @user1
146
+ expect(child.reload.parent).to eq @user1
147
147
 
148
148
  relation = @user1.association(:grandchildren)
149
149
  relation = ::Rails.version < '4' ? relation.scoped : relation.scope
150
150
 
151
151
  attribute = relation.where_values.first.left
152
- attribute.name.to_s.should == 'parent_id'
153
- attribute.relation.class.should == Arel::Nodes::TableAlias
152
+ expect(attribute.name.to_s).to eq 'parent_id'
153
+ expect(attribute.relation.class).to eq Arel::Nodes::TableAlias
154
154
 
155
155
  rel, column = relation.send(:relation_and_column, attribute)
156
- relation.send(:sharded_primary_key?, rel, column).should == false
157
- relation.send(:sharded_foreign_key?, rel, column).should == true
156
+ expect(relation.send(:sharded_primary_key?, rel, column)).to eq false
157
+ expect(relation.send(:sharded_foreign_key?, rel, column)).to eq true
158
158
 
159
- @user1.grandchildren.should == [grandchild]
159
+ expect(@user1.grandchildren).to eq [grandchild]
160
160
  end
161
161
  end
162
162
  end