ar-octopus 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -132,7 +132,7 @@ module Octopus
132
132
  end
133
133
 
134
134
  def initialize_shards(config)
135
- self.config = config
135
+ @original_config = config
136
136
 
137
137
  self.shards = HashWithIndifferentAccess.new
138
138
  self.shards_slave_groups = HashWithIndifferentAccess.new
@@ -210,6 +210,10 @@ module Octopus
210
210
  @slaves_load_balancer = Octopus.load_balancer.new(@slaves_list)
211
211
  end
212
212
 
213
+ def reinitialize_shards
214
+ initialize_shards(@original_config)
215
+ end
216
+
213
217
  private
214
218
 
215
219
  def connection_pool_for(config, adapter)
@@ -224,13 +228,8 @@ module Octopus
224
228
  end
225
229
 
226
230
  def resolve_string_connection(spec)
227
- if Octopus.rails41? || Octopus.rails50? || Octopus.rails51?
228
- resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new({})
229
- HashWithIndifferentAccess.new(resolver.spec(spec).config)
230
- else
231
- resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(spec, {})
232
- HashWithIndifferentAccess.new(resolver.spec.config)
233
- end
231
+ resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new({})
232
+ HashWithIndifferentAccess.new(resolver.spec(spec).config)
234
233
  end
235
234
 
236
235
  def structurally_slave?(config)
@@ -0,0 +1,24 @@
1
+ # query cache methods are moved to ConnectionPool for Rails >= 5.0
2
+ module Octopus
3
+ module ConnectionPool
4
+ module QueryCacheForShards
5
+ %i(enable_query_cache! disable_query_cache!).each do |method|
6
+ define_method(method) do
7
+ if(Octopus.enabled? && (shards = ActiveRecord::Base.connection.shards)['master'] == self)
8
+ shards.each do |shard_name, v|
9
+ if shard_name == 'master'
10
+ super()
11
+ else
12
+ v.public_send(method)
13
+ end
14
+ end
15
+ else
16
+ super()
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ ActiveRecord::ConnectionAdapters::ConnectionPool.send(:prepend, Octopus::ConnectionPool::QueryCacheForShards)
@@ -20,8 +20,17 @@ module Octopus
20
20
  method_missing(:respond_to?, *args)
21
21
  end
22
22
 
23
+ # methods redefined in ActiveRecord that should run_on_shard
24
+ ENUM_METHODS = (::Enumerable.instance_methods - ::Object.instance_methods).reject do |m|
25
+ ::ActiveRecord::Relation.instance_method(m).source_location rescue nil
26
+ end + [:each, :map, :index_by]
27
+ # `find { ... }` etc. should run_on_shard, `find(id)` should be sent to relation
28
+ ENUM_WITH_BLOCK_METHODS = [:find, :select, :none?, :any?, :one?, :many?, :sum]
29
+
23
30
  def method_missing(method, *args, &block)
24
- if block
31
+ if ENUM_METHODS.include?(method) || block && ENUM_WITH_BLOCK_METHODS.include?(method)
32
+ run_on_shard { @ar_relation.to_a }.public_send(method, *args, &block)
33
+ elsif block
25
34
  @ar_relation.public_send(method, *args, &block)
26
35
  else
27
36
  run_on_shard do
@@ -44,7 +44,7 @@ module Octopus
44
44
  end
45
45
 
46
46
  def method_missing(method, *args, &block)
47
- result = run_on_shard { @klass.send(method, *args, &block) }
47
+ result = run_on_shard { @klass.__send__(method, *args, &block) }
48
48
  if result.respond_to?(:all)
49
49
  return ::Octopus::ScopeProxy.new(current_shard, result)
50
50
  end
@@ -1,3 +1,3 @@
1
1
  module Octopus
2
- VERSION = '0.9.2'
2
+ VERSION = '0.10.0'
3
3
  end
@@ -196,6 +196,92 @@ describe Octopus::AssociationShardTracking, :shards => [:brazil, :master, :canad
196
196
  expect(@permission_brazil_2.roles.first).to be_nil
197
197
  end
198
198
 
199
+ it 'where' do
200
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
201
+ expect(@permission_brazil_2.roles.where('1=1')).to eq([role])
202
+ @permission_brazil_2.roles.destroy_all
203
+ expect(@permission_brazil_2.roles.where('1=1')).to be_empty
204
+ end
205
+
206
+ it 'map' do
207
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
208
+ expect(@permission_brazil_2.roles.map(&:id)).to eq([role.id])
209
+ @permission_brazil_2.roles.destroy_all
210
+ expect(@permission_brazil_2.roles.map(&:id)).to be_empty
211
+ end
212
+
213
+ it 'where + map' do
214
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
215
+ expect(@permission_brazil_2.roles.where('1=1').map(&:id)).to eq([role.id])
216
+ @permission_brazil_2.roles.destroy_all
217
+ expect(@permission_brazil_2.roles.where('1=1').map(&:id)).to be_empty
218
+ end
219
+
220
+ # each_with_index is not listed in active_record/relation/delegation.rb
221
+ it 'where + each_with_index + map (enum method chain)' do
222
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
223
+ expect(@permission_brazil_2.roles.where('1=1').each_with_index.map { |r, i| [r.id, i]}).to eq([[role.id, 0]])
224
+ @permission_brazil_2.roles.destroy_all
225
+ expect(@permission_brazil_2.roles.where('1=1').each_with_index.map { |r, i| [r.id, i]}).to be_empty
226
+ end
227
+
228
+ # sum & index_by is specialized in active_support/core_ext/enumerable.rb
229
+ it 'where + sum' do
230
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
231
+ expect(@permission_brazil_2.roles.where('1=1').sum(&:id)).to eq(role.id)
232
+ @permission_brazil_2.roles.destroy_all
233
+ expect(@permission_brazil_2.roles.where('1=1').sum(&:id)).to eq(0)
234
+ end
235
+
236
+ it 'where + index_by' do
237
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
238
+ expect(@permission_brazil_2.roles.where('1=1').index_by(&:id)).to eq(role.id => role)
239
+ @permission_brazil_2.roles.destroy_all
240
+ expect(@permission_brazil_2.roles.where('1=1').index_by(&:id)).to be_empty
241
+ end
242
+
243
+ it 'where + find' do
244
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
245
+ expect(@permission_brazil_2.roles.where('1=1').find([role.id])).to eq([role])
246
+ @permission_brazil_2.roles.destroy_all
247
+ expect { @permission_brazil_2.roles.where('1=1').find([role.id]) }.to raise_error ActiveRecord::RecordNotFound
248
+ end
249
+
250
+ it 'where + find with block' do
251
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
252
+ expect(@permission_brazil_2.roles.where('1=1').find { |r| r.id == role.id }).to eq(role)
253
+ @permission_brazil_2.roles.destroy_all
254
+ expect(@permission_brazil_2.roles.where('1=1').find { |r| r.id == role.id }).to be_nil
255
+ end
256
+
257
+ it 'where + select' do
258
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
259
+ expect(@permission_brazil_2.roles.where('1=1').select(:name).first.name).to eq(role.name)
260
+ @permission_brazil_2.roles.destroy_all
261
+ expect(@permission_brazil_2.roles.where('1=1').select(:name)).to be_empty
262
+ end
263
+
264
+ it 'where + select with block' do
265
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
266
+ expect(@permission_brazil_2.roles.where('1=1').select { |r| r.id == role.id }).to eq([role])
267
+ @permission_brazil_2.roles.destroy_all
268
+ expect(@permission_brazil_2.roles.where('1=1').select { |r| r.id == role.id }).to be_empty
269
+ end
270
+
271
+ it 'where + any?' do
272
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
273
+ expect(@permission_brazil_2.roles.where('1=1').any?).to be true
274
+ @permission_brazil_2.roles.destroy_all
275
+ expect(@permission_brazil_2.roles.where('1=1').any?).to be false
276
+ end
277
+
278
+ it 'where + any? with block' do
279
+ role = @permission_brazil_2.roles.create(:name => 'Builded Role')
280
+ expect(@permission_brazil_2.roles.where('1=1').any? { |r| r.id == role.id }).to be true
281
+ @permission_brazil_2.roles.destroy_all
282
+ expect(@permission_brazil_2.roles.where('1=1').any? { |r| r.id == role.id }).to be false
283
+ end
284
+
199
285
  it 'exists?' do
200
286
  role = @permission_brazil_2.roles.create(:name => 'Builded Role')
201
287
  expect(@permission_brazil_2.roles.exists?(role.id)).to be true
@@ -350,6 +436,90 @@ describe Octopus::AssociationShardTracking, :shards => [:brazil, :master, :canad
350
436
  expect(@new_brazil_programmer.projects.first).to be_nil
351
437
  end
352
438
 
439
+ it 'where' do
440
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
441
+ expect(@new_brazil_programmer.projects.where('1=1')).to eq([role])
442
+ @new_brazil_programmer.projects.destroy_all
443
+ expect(@new_brazil_programmer.projects.where('1=1')).to be_empty
444
+ end
445
+
446
+ it 'map' do
447
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
448
+ expect(@new_brazil_programmer.projects.map(&:id)).to eq([role.id])
449
+ @new_brazil_programmer.projects.destroy_all
450
+ expect(@new_brazil_programmer.projects.map(&:id)).to be_empty
451
+ end
452
+
453
+ it 'where + map' do
454
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
455
+ expect(@new_brazil_programmer.projects.where('1=1').map(&:id)).to eq([role.id])
456
+ @new_brazil_programmer.projects.destroy_all
457
+ expect(@new_brazil_programmer.projects.where('1=1').map(&:id)).to be_empty
458
+ end
459
+
460
+ it 'where + each_with_index + map (enum method chain)' do
461
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
462
+ expect(@new_brazil_programmer.projects.where('1=1').each_with_index.map { |r, i| [r.id, i] }).to eq([[role.id, 0]])
463
+ @new_brazil_programmer.projects.destroy_all
464
+ expect(@new_brazil_programmer.projects.where('1=1').each_with_index.map { |r, i| [r.id, i] }).to be_empty
465
+ end
466
+
467
+ it 'where + sum' do
468
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
469
+ expect(@new_brazil_programmer.projects.where('1=1').sum(&:id)).to eq(role.id)
470
+ @new_brazil_programmer.projects.destroy_all
471
+ expect(@new_brazil_programmer.projects.where('1=1').sum(&:id)).to eq(0)
472
+ end
473
+
474
+ it 'where + index_by' do
475
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
476
+ expect(@new_brazil_programmer.projects.where('1=1').index_by(&:id)).to eq(role.id => role)
477
+ @new_brazil_programmer.projects.destroy_all
478
+ expect(@new_brazil_programmer.projects.where('1=1').index_by(&:id)).to be_empty
479
+ end
480
+
481
+ it 'where + find' do
482
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
483
+ expect(@new_brazil_programmer.projects.where('1=1').find(role.id)).to eq(role)
484
+ @new_brazil_programmer.projects.destroy_all
485
+ expect { @new_brazil_programmer.projects.where('1=1').find(role.id) }.to raise_error ActiveRecord::RecordNotFound
486
+ end
487
+
488
+ it 'where + find with block' do
489
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
490
+ expect(@new_brazil_programmer.projects.where('1=1').find { |r| r.id == role.id }).to eq(role)
491
+ @new_brazil_programmer.projects.destroy_all
492
+ expect(@new_brazil_programmer.projects.where('1=1').find { |r| r.id == role.id }).to be_nil
493
+ end
494
+
495
+ it 'where + select' do
496
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
497
+ expect(@new_brazil_programmer.projects.where('1=1').select(:name).first.name).to eq(role.name)
498
+ @new_brazil_programmer.projects.destroy_all
499
+ expect(@new_brazil_programmer.projects.where('1=1').select(:name)).to be_empty
500
+ end
501
+
502
+ it 'where + select with block' do
503
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
504
+ expect(@new_brazil_programmer.projects.where('1=1').select { |r| r.id == role.id }).to eq([role])
505
+ @new_brazil_programmer.projects.destroy_all
506
+ expect(@new_brazil_programmer.projects.where('1=1').select { |r| r.id == role.id }).to be_empty
507
+ end
508
+
509
+ it 'where + any?' do
510
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
511
+ expect(@new_brazil_programmer.projects.where('1=1').any?).to be true
512
+ @new_brazil_programmer.projects.destroy_all
513
+ expect(@new_brazil_programmer.projects.where('1=1').any?).to be false
514
+ end
515
+
516
+ it 'where + any? with block' do
517
+ role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
518
+ expect(@new_brazil_programmer.projects.where('1=1').any? { |r| r.id == role.id }).to be true
519
+ @new_brazil_programmer.projects.destroy_all
520
+ expect(@new_brazil_programmer.projects.where('1=1').any? { |r| r.id == role.id }).to be false
521
+ end
522
+
353
523
  it 'exists?' do
354
524
  role = @new_brazil_programmer.projects.create(:name => 'New VB App :-/')
355
525
  expect(@new_brazil_programmer.projects.exists?(role.id)).to be true
@@ -545,6 +715,78 @@ describe Octopus::AssociationShardTracking, :shards => [:brazil, :master, :canad
545
715
  expect(@brazil_client.items.first).to be_nil
546
716
  end
547
717
 
718
+ it 'where' do
719
+ expect(@brazil_client.items.where('1=1')).to eq([@item_brazil])
720
+ @brazil_client.items.destroy_all
721
+ expect(@brazil_client.items.where('1=1')).to be_empty
722
+ end
723
+
724
+ it 'map' do
725
+ expect(@brazil_client.items.map(&:id)).to eq([@item_brazil.id])
726
+ @brazil_client.items.destroy_all
727
+ expect(@brazil_client.items.map(&:id)).to be_empty
728
+ end
729
+
730
+ it 'where + map' do
731
+ expect(@brazil_client.items.where('1=1').map(&:id)).to eq([@item_brazil.id])
732
+ @brazil_client.items.destroy_all
733
+ expect(@brazil_client.items.where('1=1').map(&:id)).to be_empty
734
+ end
735
+
736
+ it 'where + each_with_index + map (enum method chain)' do
737
+ expect(@brazil_client.items.where('1=1').each_with_index.map { |r, i| [r.id, i]}).to eq([[@item_brazil.id, 0]])
738
+ @brazil_client.items.destroy_all
739
+ expect(@brazil_client.items.where('1=1').each_with_index.map { |r, i| [r.id, i]}).to be_empty
740
+ end
741
+
742
+ it 'where + sum' do
743
+ expect(@brazil_client.items.where('1=1').sum(&:id)).to eq(@item_brazil.id)
744
+ @brazil_client.items.destroy_all
745
+ expect(@brazil_client.items.where('1=1').sum(&:id)).to eq(0)
746
+ end
747
+
748
+ it 'where + index_by' do
749
+ expect(@brazil_client.items.where('1=1').index_by(&:id)).to eq(@item_brazil.id => @item_brazil)
750
+ @brazil_client.items.destroy_all
751
+ expect(@brazil_client.items.where('1=1').index_by(&:id)).to be_empty
752
+ end
753
+
754
+ it 'where + find' do
755
+ expect(@brazil_client.items.where('1=1').find(@item_brazil.id)).to eq(@item_brazil)
756
+ @brazil_client.items.destroy_all
757
+ expect { @brazil_client.items.where('1=1').find(@item_brazil.id) }.to raise_error ActiveRecord::RecordNotFound
758
+ end
759
+
760
+ it 'where + find with block' do
761
+ expect(@brazil_client.items.where('1=1').find { |i| i.id == @item_brazil.id }).to eq(@item_brazil)
762
+ @brazil_client.items.destroy_all
763
+ expect(@brazil_client.items.where('1=1').find { |i| i.id == @item_brazil.id }).to be_nil
764
+ end
765
+
766
+ it 'where + select' do
767
+ expect(@brazil_client.items.where('1=1').select(:name).first.name).to eq(@item_brazil.name)
768
+ @brazil_client.items.destroy_all
769
+ expect(@brazil_client.items.where('1=1').select(:name)).to be_empty
770
+ end
771
+
772
+ it 'where + select with block' do
773
+ expect(@brazil_client.items.where('1=1').select { |i| i.id == @item_brazil.id }).to eq([@item_brazil])
774
+ @brazil_client.items.destroy_all
775
+ expect(@brazil_client.items.where('1=1').select { |i| i.id == @item_brazil.id }).to be_empty
776
+ end
777
+
778
+ it 'where + any?' do
779
+ expect(@brazil_client.items.where('1=1').any?).to be true
780
+ @brazil_client.items.destroy_all
781
+ expect(@brazil_client.items.where('1=1').any?).to be false
782
+ end
783
+
784
+ it 'where + any? with block' do
785
+ expect(@brazil_client.items.where('1=1').any? { |i| i.id == @item_brazil.id }).to be true
786
+ @brazil_client.items.destroy_all
787
+ expect(@brazil_client.items.where('1=1').any? { |i| i.id == @item_brazil.id }).to be false
788
+ end
789
+
548
790
  it 'exists?' do
549
791
  expect(@brazil_client.items.exists?(@item_brazil.id)).to be true
550
792
  @brazil_client.items.destroy_all
@@ -695,6 +937,78 @@ describe Octopus::AssociationShardTracking, :shards => [:brazil, :master, :canad
695
937
  expect(@brazil_client.comments.first).to be_nil
696
938
  end
697
939
 
940
+ it 'where' do
941
+ expect(@brazil_client.comments.where('1=1')).to eq([@comment_brazil])
942
+ @brazil_client.comments.destroy_all
943
+ expect(@brazil_client.comments.where('1=1')).to be_empty
944
+ end
945
+
946
+ it 'map' do
947
+ expect(@brazil_client.comments.map(&:id)).to eq([@comment_brazil.id])
948
+ @brazil_client.comments.destroy_all
949
+ expect(@brazil_client.comments.map(&:id)).to be_empty
950
+ end
951
+
952
+ it 'where + map' do
953
+ expect(@brazil_client.comments.where('1=1').map(&:id)).to eq([@comment_brazil.id])
954
+ @brazil_client.comments.destroy_all
955
+ expect(@brazil_client.comments.where('1=1').map(&:id)).to be_empty
956
+ end
957
+
958
+ it 'where + each_with_index + map (enum method chain)' do
959
+ expect(@brazil_client.comments.where('1=1').each_with_index.map { |r, i| [r.id, i]}).to eq([[@comment_brazil.id, 0]])
960
+ @brazil_client.comments.destroy_all
961
+ expect(@brazil_client.comments.where('1=1').each_with_index.map { |r, i| [r.id, i]}).to be_empty
962
+ end
963
+
964
+ it 'where + sum' do
965
+ expect(@brazil_client.comments.where('1=1').sum(&:id)).to eq(@comment_brazil.id)
966
+ @brazil_client.comments.destroy_all
967
+ expect(@brazil_client.comments.where('1=1').sum(&:id)).to eq(0)
968
+ end
969
+
970
+ it 'where + index_by' do
971
+ expect(@brazil_client.comments.where('1=1').index_by(&:id)).to eq(@comment_brazil.id => @comment_brazil)
972
+ @brazil_client.comments.destroy_all
973
+ expect(@brazil_client.comments.where('1=1').index_by(&:id)).to be_empty
974
+ end
975
+
976
+ it 'where + find' do
977
+ expect(@brazil_client.comments.where('1=1').find(@comment_brazil.id)).to eq(@comment_brazil)
978
+ @brazil_client.comments.destroy_all
979
+ expect { @brazil_client.comments.where('1=1').find(@comment_brazil.id) }.to raise_error ActiveRecord::RecordNotFound
980
+ end
981
+
982
+ it 'where + find with block' do
983
+ expect(@brazil_client.comments.where('1=1').find { |c| c.id == @comment_brazil.id }).to eq(@comment_brazil)
984
+ @brazil_client.comments.destroy_all
985
+ expect(@brazil_client.comments.where('1=1').find { |c| c.id == @comment_brazil.id }).to be_nil
986
+ end
987
+
988
+ it 'where + select' do
989
+ expect(@brazil_client.comments.where('1=1').select(:name).first.name).to eq(@comment_brazil.name)
990
+ @brazil_client.comments.destroy_all
991
+ expect(@brazil_client.comments.where('1=1').select(:name)).to be_empty
992
+ end
993
+
994
+ it 'where + select with block' do
995
+ expect(@brazil_client.comments.where('1=1').select { |c| c.id == @comment_brazil.id }).to eq([@comment_brazil])
996
+ @brazil_client.comments.destroy_all
997
+ expect(@brazil_client.comments.where('1=1').select { |c| c.id == @comment_brazil.id }).to be_empty
998
+ end
999
+
1000
+ it 'where + any?' do
1001
+ expect(@brazil_client.comments.where('1=1').any?).to be true
1002
+ @brazil_client.comments.destroy_all
1003
+ expect(@brazil_client.comments.where('1=1').any?).to be false
1004
+ end
1005
+
1006
+ it 'where + any? with block' do
1007
+ expect(@brazil_client.comments.where('1=1').any? { |c| c.id == @comment_brazil.id }).to be true
1008
+ @brazil_client.comments.destroy_all
1009
+ expect(@brazil_client.comments.where('1=1').any? { |c| c.id == @comment_brazil.id }).to be false
1010
+ end
1011
+
698
1012
  it 'exists?' do
699
1013
  expect(@brazil_client.comments.exists?(@comment_brazil.id)).to be true
700
1014
  @brazil_client.comments.destroy_all
@@ -1,5 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
+ def get_all_versions
4
+ if Octopus.atleast_rails52?
5
+ migrations_root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'migrations'))
6
+ ActiveRecord::MigrationContext.new(migrations_root).get_all_versions
7
+ else
8
+ ActiveRecord::Migrator.get_all_versions
9
+ end
10
+ end
11
+
3
12
  describe Octopus::Migration do
4
13
  it 'should run just in the master shard' do
5
14
  OctopusHelper.migrating_to_version 1 do
@@ -32,8 +41,11 @@ describe Octopus::Migration do
32
41
 
33
42
  it "should rollback correctly migrations" do
34
43
  migrations_root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'migrations'))
35
-
36
- ActiveRecord::Migrator.run(:up, migrations_root, 4)
44
+ if Octopus.atleast_rails52?
45
+ OctopusHelper.migrate_to_version(:up, migrations_root, 4)
46
+ else
47
+ ActiveRecord::Migrator.run(:up, migrations_root, 4)
48
+ end
37
49
 
38
50
  expect(User.using(:canada).find_by_name('Group')).not_to be_nil
39
51
  expect(User.using(:brazil).find_by_name('Group')).not_to be_nil
@@ -41,7 +53,11 @@ describe Octopus::Migration do
41
53
 
42
54
 
43
55
  Octopus.using(:canada) do
44
- ActiveRecord::Migrator.rollback(migrations_root, 4)
56
+ if Octopus.atleast_rails52?
57
+ OctopusHelper.migrate_to_version(:down, migrations_root, 4)
58
+ else
59
+ ActiveRecord::Migrator.rollback(migrations_root, 4)
60
+ end
45
61
  end
46
62
 
47
63
  expect(User.using(:canada).find_by_name('Group')).to be_nil
@@ -99,9 +115,9 @@ describe Octopus::Migration do
99
115
  class SchemaMigration < ActiveRecord::Base; end
100
116
 
101
117
  OctopusHelper.migrating_to_version 14 do
102
- expect(Octopus.using(:canada) { ActiveRecord::Migrator.get_all_versions }).to include(14)
103
- expect(Octopus.using(:brazil) { ActiveRecord::Migrator.get_all_versions }).to include(14)
104
- expect(Octopus.using(:russia) { ActiveRecord::Migrator.get_all_versions }).to include(14)
118
+ expect(Octopus.using(:canada) { get_all_versions }).to include(14)
119
+ expect(Octopus.using(:brazil) { get_all_versions }).to include(14)
120
+ expect(Octopus.using(:russia) { get_all_versions }).to include(14)
105
121
  end
106
122
  end
107
123
 
@@ -112,9 +128,9 @@ describe Octopus::Migration do
112
128
  Octopus.using(:canada) { SchemaMigration.create(:version => 14) }
113
129
 
114
130
  OctopusHelper.migrating_to_version 14 do
115
- expect(Octopus.using(:canada) { ActiveRecord::Migrator.get_all_versions }).to include(14)
116
- expect(Octopus.using(:brazil) { ActiveRecord::Migrator.get_all_versions }).to include(14)
117
- expect(Octopus.using(:russia) { ActiveRecord::Migrator.get_all_versions }).to include(14)
131
+ expect(Octopus.using(:canada) { get_all_versions }).to include(14)
132
+ expect(Octopus.using(:brazil) { get_all_versions }).to include(14)
133
+ expect(Octopus.using(:russia) { get_all_versions }).to include(14)
118
134
  end
119
135
  end
120
136
 
@@ -122,13 +138,12 @@ describe Octopus::Migration do
122
138
  it 'should run migrations on all shards in the default_migration_group' do
123
139
  OctopusHelper.using_environment :octopus_with_default_migration_group do
124
140
  OctopusHelper.migrating_to_version 15 do
125
- expect(Octopus.using(:master) { ActiveRecord::Migrator.get_all_versions }).not_to include(15)
126
- expect(Octopus.using(:canada) { ActiveRecord::Migrator.get_all_versions }).to include(15)
127
- expect(Octopus.using(:brazil) { ActiveRecord::Migrator.get_all_versions }).to include(15)
128
- expect(Octopus.using(:russia) { ActiveRecord::Migrator.get_all_versions }).to include(15)
141
+ expect(Octopus.using(:master) { get_all_versions }).not_to include(15)
142
+ expect(Octopus.using(:canada) { get_all_versions }).to include(15)
143
+ expect(Octopus.using(:brazil) { get_all_versions }).to include(15)
144
+ expect(Octopus.using(:russia) { get_all_versions }).to include(15)
129
145
  end
130
146
  end
131
147
  end
132
148
  end
133
-
134
149
  end