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
@@ -8,14 +8,14 @@ module Switchman
8
8
  describe "ids" do
9
9
  it "should return id relative to the current shard" do
10
10
  user = User.create!
11
- user.id.should < Shard::IDS_PER_SHARD
12
- user.local_id.should < Shard::IDS_PER_SHARD
13
- user.global_id.should > Shard::IDS_PER_SHARD
11
+ expect(user.id).to be < Shard::IDS_PER_SHARD
12
+ expect(user.local_id).to be < Shard::IDS_PER_SHARD
13
+ expect(user.global_id).to be > Shard::IDS_PER_SHARD
14
14
 
15
15
  @shard1.activate do
16
- user.id.should > Shard::IDS_PER_SHARD
17
- user.local_id.should < Shard::IDS_PER_SHARD
18
- user.global_id.should > Shard::IDS_PER_SHARD
16
+ expect(user.id).to be > Shard::IDS_PER_SHARD
17
+ expect(user.local_id).to be < Shard::IDS_PER_SHARD
18
+ expect(user.global_id).to be > Shard::IDS_PER_SHARD
19
19
  end
20
20
  end
21
21
 
@@ -26,80 +26,80 @@ module Switchman
26
26
 
27
27
  # local id, should stay local
28
28
  appendage.original_user_id = 6
29
- appendage.user_id.should == 6
29
+ expect(appendage.user_id).to eq 6
30
30
 
31
31
  # (incorrect) self referencing global id; should come out as local
32
32
  appendage.original_user_id = Shard.current.global_id_for(6)
33
- appendage.user_id.should == 6
33
+ expect(appendage.user_id).to eq 6
34
34
 
35
35
  # global id referencing another shard; should come out unscathed
36
36
  appendage.original_user_id = @shard1.global_id_for(6)
37
- appendage.user_id.should == @shard1.global_id_for(6)
37
+ expect(appendage.user_id).to eq @shard1.global_id_for(6)
38
38
 
39
39
  @shard1.activate do
40
40
  # local id in another shard, should be global in this shard
41
41
  appendage.original_user_id = 6
42
- appendage.user_id.should == Shard.default.global_id_for(6)
42
+ expect(appendage.user_id).to eq Shard.default.global_id_for(6)
43
43
 
44
44
  # (incorrect) self referencing global id; should come out as global in this shard
45
45
  appendage.original_user_id = Shard.default.global_id_for(6)
46
- appendage.user_id.should == Shard.default.global_id_for(6)
46
+ expect(appendage.user_id).to eq Shard.default.global_id_for(6)
47
47
 
48
48
  # global id referencing this shard; should come out as a local id in this shard
49
49
  appendage.original_user_id = @shard1.global_id_for(6)
50
- appendage.user_id.should == 6
50
+ expect(appendage.user_id).to eq 6
51
51
 
52
52
  # global id from an unrelated shard; should stay global
53
53
  appendage.original_user_id = @shard2.global_id_for(6)
54
- appendage.user_id.should == @shard2.global_id_for(6)
54
+ expect(appendage.user_id).to eq @shard2.global_id_for(6)
55
55
  end
56
56
 
57
57
  # now that we trust the getters, try the setters
58
58
 
59
59
  # local stays local
60
60
  appendage.user_id = 6
61
- appendage.original_user_id.should == 6
61
+ expect(appendage.original_user_id).to eq 6
62
62
  appendage.user_id = '6'
63
- appendage.original_user_id.should == 6
63
+ expect(appendage.original_user_id).to eq 6
64
64
 
65
65
  # (incorrect) global id to this shard, should become local
66
66
  appendage.user_id = Shard.current.global_id_for(6)
67
- appendage.original_user_id.should == 6
67
+ expect(appendage.original_user_id).to eq 6
68
68
  appendage.user_id = Shard.current.global_id_for(6).to_s
69
- appendage.original_user_id.should == 6
69
+ expect(appendage.original_user_id).to eq 6
70
70
 
71
71
  # global id from another shard, should stay global
72
72
  appendage.user_id = @shard1.global_id_for(6)
73
- appendage.original_user_id.should == @shard1.global_id_for(6)
74
- appendage.local_user_id.should == 6
73
+ expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
74
+ expect(appendage.local_user_id).to eq 6
75
75
  appendage.user_id = @shard1.global_id_for(6).to_s
76
- appendage.original_user_id.should == @shard1.global_id_for(6)
77
- appendage.local_user_id.should == 6
76
+ expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
77
+ expect(appendage.local_user_id).to eq 6
78
78
 
79
79
  @shard1.activate do
80
80
  # local to this shard becomes global
81
81
  appendage.user_id = 6
82
- appendage.original_user_id.should == @shard1.global_id_for(6)
82
+ expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
83
83
  appendage.user_id = '6'
84
- appendage.original_user_id.should == @shard1.global_id_for(6)
84
+ expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
85
85
 
86
86
  # global id from original shard, should become local
87
87
  appendage.user_id = Shard.default.global_id_for(6)
88
- appendage.original_user_id.should == 6
88
+ expect(appendage.original_user_id).to eq 6
89
89
  appendage.user_id = Shard.default.global_id_for(6).to_s
90
- appendage.original_user_id.should == 6
90
+ expect(appendage.original_user_id).to eq 6
91
91
 
92
92
  # global id from this shard, should stay global
93
93
  appendage.user_id = Shard.current.global_id_for(6)
94
- appendage.original_user_id.should == @shard1.global_id_for(6)
94
+ expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
95
95
  appendage.user_id = Shard.current.global_id_for(6).to_s
96
- appendage.original_user_id.should == @shard1.global_id_for(6)
96
+ expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
97
97
 
98
98
  # global id from unrelated shard, should stay global
99
99
  appendage.user_id = @shard2.global_id_for(6)
100
- appendage.original_user_id.should == @shard2.global_id_for(6)
100
+ expect(appendage.original_user_id).to eq @shard2.global_id_for(6)
101
101
  appendage.user_id = @shard2.global_id_for(6).to_s
102
- appendage.original_user_id.should == @shard2.global_id_for(6)
102
+ expect(appendage.original_user_id).to eq @shard2.global_id_for(6)
103
103
  end
104
104
  end
105
105
 
@@ -8,21 +8,21 @@ module Switchman
8
8
  describe "to_param" do
9
9
  it "should return nil if no id" do
10
10
  user = User.new
11
- user.to_param.should be_nil
11
+ expect(user.to_param).to be_nil
12
12
  end
13
13
 
14
14
  it "should return the id even if not persisted" do
15
15
  user = User.new
16
16
  user.id = 1
17
- user.to_param.should == '1'
17
+ expect(user.to_param).to eq '1'
18
18
  end
19
19
 
20
20
  it "should return local id if in the current shard" do
21
21
  user = User.create!
22
- user.to_param.should == user.local_id.to_s
22
+ expect(user.to_param).to eq user.local_id.to_s
23
23
  @shard1.activate do
24
24
  user2 = User.create!
25
- user2.to_param.should == user2.local_id.to_s
25
+ expect(user2.to_param).to eq user2.local_id.to_s
26
26
  end
27
27
  end
28
28
 
@@ -32,7 +32,7 @@ module Switchman
32
32
  user = User.create!
33
33
  end
34
34
  @shard2.activate do
35
- user.to_param.should == "#{@shard1.id}~#{user.local_id}"
35
+ expect(user.to_param).to eq "#{@shard1.id}~#{user.local_id}"
36
36
  end
37
37
  end
38
38
 
@@ -45,25 +45,25 @@ module Switchman
45
45
  user = User.create!
46
46
  appendage = Appendage.create!
47
47
 
48
- helpers.user_path(user).should == "/users/#{user.local_id}"
49
- helpers.user_appendages_path(user).should == "/users/#{user.local_id}/appendages"
50
- helpers.user_appendage_path(user, appendage).should == "/users/#{user.local_id}/appendages/#{appendage.local_id}"
51
- helpers.user_test1_path(user).should == "/users/#{user.local_id}"
52
- helpers.user_test2_path(user).should == "/users/#{user.local_id}/test2"
48
+ expect(helpers.user_path(user)).to eq "/users/#{user.local_id}"
49
+ expect(helpers.user_appendages_path(user)).to eq "/users/#{user.local_id}/appendages"
50
+ expect(helpers.user_appendage_path(user, appendage)).to eq "/users/#{user.local_id}/appendages/#{appendage.local_id}"
51
+ expect(helpers.user_test1_path(user)).to eq "/users/#{user.local_id}"
52
+ expect(helpers.user_test2_path(user)).to eq "/users/#{user.local_id}/test2"
53
53
  end
54
54
 
55
55
  @shard2.activate do
56
56
  user_short_id = "#{@shard1.id}~#{user.local_id}"
57
57
  appendage_short_id = "#{@shard1.id}~#{appendage.local_id}"
58
58
 
59
- helpers.user_path(user).should == "/users/#{user_short_id}"
60
- helpers.user_appendages_path(user).should == "/users/#{user_short_id}/appendages"
61
- helpers.user_appendage_path(user, appendage).should == "/users/#{user_short_id}/appendages/#{appendage_short_id}"
62
- helpers.user_test1_path(user).should == "/users/#{user_short_id}"
63
- helpers.user_test2_path(user).should == "/users/#{user_short_id}/test2"
59
+ expect(helpers.user_path(user)).to eq "/users/#{user_short_id}"
60
+ expect(helpers.user_appendages_path(user)).to eq "/users/#{user_short_id}/appendages"
61
+ expect(helpers.user_appendage_path(user, appendage)).to eq "/users/#{user_short_id}/appendages/#{appendage_short_id}"
62
+ expect(helpers.user_test1_path(user)).to eq "/users/#{user_short_id}"
63
+ expect(helpers.user_test2_path(user)).to eq "/users/#{user_short_id}/test2"
64
64
 
65
65
  appendage2 = Appendage.create!
66
- helpers.user_appendage_path(user, appendage2).should == "/users/#{user_short_id}/appendages/#{appendage2.local_id}"
66
+ expect(helpers.user_appendage_path(user, appendage2)).to eq "/users/#{user_short_id}/appendages/#{appendage2.local_id}"
67
67
  end
68
68
  end
69
69
  end
@@ -74,21 +74,21 @@ module Switchman
74
74
  appendage = Appendage.new
75
75
  appendage.user_id = user.id
76
76
  appendage.shard = @shard1
77
- appendage.attributes["user_id"].should == user.global_id
77
+ expect(appendage.attributes["user_id"]).to eq user.global_id
78
78
  end
79
79
  end
80
80
 
81
81
  describe ".shard_category=" do
82
82
  it "should set up connection pools correctly for a model on a different db in the default shard" do
83
- pending "remove_connection working properly"
83
+ skip "remove_connection working properly"
84
84
  ::Rails.env.stubs(:test?).returns(false)
85
85
  begin
86
86
  config = { :adapter => 'sqlite3', :database => ':memory:', :something_unique_in_the_spec => true }
87
87
  MirrorUser.establish_connection(config)
88
88
 
89
- MirrorUser.connection.should_not == ::ActiveRecord::Base.connection
89
+ expect(MirrorUser.connection).not_to eq ::ActiveRecord::Base.connection
90
90
  ::Shackles.activate(:slave) do
91
- MirrorUser.connection.should_not == ::ActiveRecord::Base.connection
91
+ expect(MirrorUser.connection).not_to eq ::ActiveRecord::Base.connection
92
92
  end
93
93
  ensure
94
94
  MirrorUser.remove_connection
@@ -18,32 +18,32 @@ module Switchman
18
18
  end
19
19
 
20
20
  it "should return non-id columns" do
21
- User.where(:id => [@user1.id, @user2.id]).pluck(:name).sort.should == ["user1", "user2"]
21
+ expect(User.where(:id => [@user1.id, @user2.id]).pluck(:name).sort).to eq ["user1", "user2"]
22
22
  end
23
23
 
24
24
  it "should return primary ids relative to current shard" do
25
- Appendage.where(:id => @appendage1).pluck(:id).should == [@appendage1.global_id]
26
- Appendage.where(:id => @appendage2).pluck(:id).should == [@appendage2.global_id]
25
+ expect(Appendage.where(:id => @appendage1).pluck(:id)).to eq [@appendage1.global_id]
26
+ expect(Appendage.where(:id => @appendage2).pluck(:id)).to eq [@appendage2.global_id]
27
27
  @shard1.activate do
28
- Appendage.where(:id => @appendage1).pluck(:id).should == [@appendage1.local_id]
29
- Appendage.where(:id => @appendage2).pluck(:id).should == [@appendage2.global_id]
28
+ expect(Appendage.where(:id => @appendage1).pluck(:id)).to eq [@appendage1.local_id]
29
+ expect(Appendage.where(:id => @appendage2).pluck(:id)).to eq [@appendage2.global_id]
30
30
  end
31
31
  @shard2.activate do
32
- Appendage.where(:id => @appendage1).pluck(:id).should == [@appendage1.global_id]
33
- Appendage.where(:id => @appendage2).pluck(:id).should == [@appendage2.local_id]
32
+ expect(Appendage.where(:id => @appendage1).pluck(:id)).to eq [@appendage1.global_id]
33
+ expect(Appendage.where(:id => @appendage2).pluck(:id)).to eq [@appendage2.local_id]
34
34
  end
35
35
  end
36
36
 
37
37
  it "should return foreign ids relative to current shard" do
38
- Appendage.where(:id => @appendage1).pluck(:user_id).should == [@user1.global_id]
39
- Appendage.where(:id => @appendage2).pluck(:user_id).should == [@user2.global_id]
38
+ expect(Appendage.where(:id => @appendage1).pluck(:user_id)).to eq [@user1.global_id]
39
+ expect(Appendage.where(:id => @appendage2).pluck(:user_id)).to eq [@user2.global_id]
40
40
  @shard1.activate do
41
- Appendage.where(:id => @appendage1).pluck(:user_id).should == [@user1.local_id]
42
- Appendage.where(:id => @appendage2).pluck(:user_id).should == [@user2.global_id]
41
+ expect(Appendage.where(:id => @appendage1).pluck(:user_id)).to eq [@user1.local_id]
42
+ expect(Appendage.where(:id => @appendage2).pluck(:user_id)).to eq [@user2.global_id]
43
43
  end
44
44
  @shard2.activate do
45
- Appendage.where(:id => @appendage1).pluck(:user_id).should == [@user1.global_id]
46
- Appendage.where(:id => @appendage2).pluck(:user_id).should == [@user2.local_id]
45
+ expect(Appendage.where(:id => @appendage1).pluck(:user_id)).to eq [@user1.global_id]
46
+ expect(Appendage.where(:id => @appendage2).pluck(:user_id)).to eq [@user2.local_id]
47
47
  end
48
48
  end
49
49
  end
@@ -65,53 +65,53 @@ module Switchman
65
65
  end
66
66
 
67
67
  it "should calculate average across shards" do
68
- @user1.appendages.average(:value).should == 1.5
69
- @shard1.activate {Appendage.average(:value)}.should == 1.5
68
+ expect(@user1.appendages.average(:value)).to eq 1.5
69
+ expect(@shard1.activate {Appendage.average(:value)}).to eq 1.5
70
70
 
71
- @user2.appendages.average(:value).should == 4
72
- @shard2.activate {Appendage.average(:value)}.should == 4
71
+ expect(@user2.appendages.average(:value)).to eq 4
72
+ expect(@shard2.activate {Appendage.average(:value)}).to eq 4
73
73
 
74
- Appendage.where(:id => @appendages).average(:value).should == 3
74
+ expect(Appendage.where(:id => @appendages).average(:value)).to eq 3
75
75
  end
76
76
 
77
77
  it "should count across shards" do
78
- @user1.appendages.count.should == 2
79
- @shard1.activate {Appendage.count}.should == 2
78
+ expect(@user1.appendages.count).to eq 2
79
+ expect(@shard1.activate {Appendage.count}).to eq 2
80
80
 
81
- @user2.appendages.count.should == 3
82
- @shard2.activate {Appendage.count}.should == 3
81
+ expect(@user2.appendages.count).to eq 3
82
+ expect(@shard2.activate {Appendage.count}).to eq 3
83
83
 
84
- Appendage.where(:id => @appendages).count.should == 5
84
+ expect(Appendage.where(:id => @appendages).count).to eq 5
85
85
  end
86
86
 
87
87
  it "should calculate minimum across shards" do
88
- @user1.appendages.minimum(:value).should == 1
89
- @shard1.activate {Appendage.minimum(:value)}.should == 1
88
+ expect(@user1.appendages.minimum(:value)).to eq 1
89
+ expect(@shard1.activate {Appendage.minimum(:value)}).to eq 1
90
90
 
91
- @user2.appendages.minimum(:value).should == 3
92
- @shard2.activate {Appendage.minimum(:value)}.should == 3
91
+ expect(@user2.appendages.minimum(:value)).to eq 3
92
+ expect(@shard2.activate {Appendage.minimum(:value)}).to eq 3
93
93
 
94
- Appendage.where(:id => @appendages).minimum(:value).should == 1
94
+ expect(Appendage.where(:id => @appendages).minimum(:value)).to eq 1
95
95
  end
96
96
 
97
97
  it "should calculate maximum across shards" do
98
- @user1.appendages.maximum(:value).should == 2
99
- @shard1.activate {Appendage.maximum(:value)}.should == 2
98
+ expect(@user1.appendages.maximum(:value)).to eq 2
99
+ expect(@shard1.activate {Appendage.maximum(:value)}).to eq 2
100
100
 
101
- @user2.appendages.maximum(:value).should == 5
102
- @shard2.activate {Appendage.maximum(:value)}.should == 5
101
+ expect(@user2.appendages.maximum(:value)).to eq 5
102
+ expect(@shard2.activate {Appendage.maximum(:value)}).to eq 5
103
103
 
104
- Appendage.where(:id => @appendages).maximum(:value).should == 5
104
+ expect(Appendage.where(:id => @appendages).maximum(:value)).to eq 5
105
105
  end
106
106
 
107
107
  it "should calculate sum across shards" do
108
- @user1.appendages.sum(:value).should == 3
109
- @shard1.activate {Appendage.sum(:value)}.should == 3
108
+ expect(@user1.appendages.sum(:value)).to eq 3
109
+ expect(@shard1.activate {Appendage.sum(:value)}).to eq 3
110
110
 
111
- @user2.appendages.sum(:value).should == 12
112
- @shard2.activate {Appendage.sum(:value)}.should == 12
111
+ expect(@user2.appendages.sum(:value)).to eq 12
112
+ expect(@shard2.activate {Appendage.sum(:value)}).to eq 12
113
113
 
114
- Appendage.where(:id => @appendages).sum(:value).should == 15
114
+ expect(Appendage.where(:id => @appendages).sum(:value)).to eq 15
115
115
  end
116
116
  end
117
117
 
@@ -133,93 +133,113 @@ module Switchman
133
133
  end
134
134
 
135
135
  it "should calculate average across shards" do
136
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value).should ==
136
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value)).to eq(
137
137
  {@user1.global_id => 1.5, @user2.global_id => 4}
138
+ )
138
139
 
139
140
  @shard1.activate do
140
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value).should ==
141
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value)).to eq(
141
142
  {@user1.local_id => 1.5, @user2.global_id => 4}
143
+ )
142
144
  end
143
145
 
144
146
  @shard2.activate do
145
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value).should ==
147
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value)).to eq(
146
148
  {@user1.global_id => 1.5, @user2.local_id => 4}
149
+ )
147
150
  end
148
151
 
149
- Appendage.shard([@shard1, @shard2]).group(:user).average(:value).should ==
152
+ expect(Appendage.shard([@shard1, @shard2]).group(:user).average(:value)).to eq(
150
153
  {@user1 => 1.5, @user2 => 4}
154
+ )
151
155
  end
152
156
 
153
157
  it "should count across shards" do
154
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count.should ==
158
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count).to eq(
155
159
  {@user1.global_id => 2, @user2.global_id => 3}
160
+ )
156
161
 
157
162
  @shard1.activate do
158
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count.should ==
163
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count).to eq(
159
164
  {@user1.local_id => 2, @user2.global_id => 3}
165
+ )
160
166
  end
161
167
 
162
168
  @shard2.activate do
163
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count.should ==
169
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count).to eq(
164
170
  {@user1.global_id => 2, @user2.local_id => 3}
171
+ )
165
172
  end
166
173
 
167
- Appendage.shard([@shard1, @shard2]).group(:user).count.should ==
174
+ expect(Appendage.shard([@shard1, @shard2]).group(:user).count).to eq(
168
175
  {@user1 => 2, @user2 => 3}
176
+ )
169
177
  end
170
178
 
171
179
  it "should calculate minimum across shards" do
172
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value).should ==
180
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value)).to eq(
173
181
  {@user1.global_id => 1, @user2.global_id => 3}
182
+ )
174
183
 
175
184
  @shard1.activate do
176
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value).should ==
185
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value)).to eq(
177
186
  {@user1.local_id => 1, @user2.global_id => 3}
187
+ )
178
188
  end
179
189
 
180
190
  @shard2.activate do
181
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value).should ==
191
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value)).to eq(
182
192
  {@user1.global_id => 1, @user2.local_id => 3}
193
+ )
183
194
  end
184
195
 
185
- Appendage.shard([@shard1, @shard2]).group(:user).minimum(:value).should ==
196
+ expect(Appendage.shard([@shard1, @shard2]).group(:user).minimum(:value)).to eq(
186
197
  {@user1 => 1, @user2 => 3}
198
+ )
187
199
  end
188
200
 
189
201
  it "should calculate maximum across shards" do
190
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value).should ==
202
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value)).to eq(
191
203
  {@user1.global_id => 2, @user2.global_id => 5}
204
+ )
192
205
 
193
206
  @shard1.activate do
194
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value).should ==
207
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value)).to eq(
195
208
  {@user1.local_id => 2, @user2.global_id => 5}
209
+ )
196
210
  end
197
211
 
198
212
  @shard2.activate do
199
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value).should ==
213
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value)).to eq(
200
214
  {@user1.global_id => 2, @user2.local_id => 5}
215
+ )
201
216
  end
202
217
 
203
- Appendage.shard([@shard1, @shard2]).group(:user).maximum(:value).should ==
218
+ expect(Appendage.shard([@shard1, @shard2]).group(:user).maximum(:value)).to eq(
204
219
  {@user1 => 2, @user2 => 5}
220
+ )
205
221
  end
206
222
 
207
223
  it "should calculate sum across shards" do
208
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value).should ==
224
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value)).to eq(
209
225
  {@user1.global_id => 3, @user2.global_id => 12}
226
+ )
210
227
 
211
228
  @shard1.activate do
212
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value).should ==
229
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value)).to eq(
213
230
  {@user1.local_id => 3, @user2.global_id => 12}
231
+ )
214
232
  end
215
233
 
216
234
  @shard2.activate do
217
- Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value).should ==
235
+ expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value)).to eq(
218
236
  {@user1.global_id => 3, @user2.local_id => 12}
237
+ )
219
238
  end
220
239
 
221
- Appendage.shard([@shard1, @shard2]).group(:user).sum(:value).should ==
240
+ expect(Appendage.shard([@shard1, @shard2]).group(:user).sum(:value)).to eq(
222
241
  {@user1 => 3, @user2 => 12}
242
+ )
223
243
  end
224
244
 
225
245
  it "should respect order for a single shard" do
@@ -227,7 +247,7 @@ module Switchman
227
247
  @user1.appendages.create!
228
248
  user2 = User.create!
229
249
  user2.appendages.create!
230
- Appendage.group(:user_id).order("COUNT(*) DESC").limit(1).count.should == { @user1.id => 2 }
250
+ expect(Appendage.group(:user_id).order("COUNT(*) DESC").limit(1).count).to eq({ @user1.id => 2 })
231
251
  end
232
252
  end
233
253
  end