@@ -617,16 +617,27 @@ class ShardedModel < ActiveRecord::Base
617617 end
618618
619619 it "supports implicit joins" do
620- accounts = Account . includes ( :tickets )
621- accounts = accounts . references ( :tickets ) if ActiveRecord ::VERSION ::MAJOR >= 4
622- assert_equal [ "slave_name" , "slave_name2" ] , accounts . order ( 'tickets .id' ) . map ( &:name ) . sort
620+ accounts = Account . includes ( :account_things )
621+ accounts = accounts . references ( :account_things ) if ActiveRecord ::VERSION ::MAJOR >= 4
622+ assert_equal [ "slave_name" , "slave_name2" ] , accounts . order ( 'account_things .id' ) . map ( &:name ) . sort
623623 end
624624
625625 it "supports joins" do
626- accounts = Account . joins ( 'LEFT OUTER JOIN tickets ON tickets .account_id = accounts.id' ) . map ( &:name ) . sort
626+ accounts = Account . joins ( 'LEFT OUTER JOIN account_things ON account_things .account_id = accounts.id' ) . map ( &:name ) . sort
627627 assert_equal [ "slave_name" , "slave_name2" ] , accounts
628628 end
629629
630+ it "does not support implicit joins between an unsharded and a sharded table" do
631+ accounts = Account . includes ( :tickets ) . order ( 'tickets.id' )
632+ accounts = accounts . references ( :tickets ) if ActiveRecord ::VERSION ::MAJOR >= 4
633+ assert_raises ( ActiveRecord ::StatementInvalid ) { accounts . first }
634+ end
635+
636+ it "does not support explicit joins between an unsharded and a sharded table" do
637+ accounts = Account . joins ( 'LEFT OUTER JOIN tickets ON tickets.account_id = accounts.id' )
638+ assert_raises ( ActiveRecord ::StatementInvalid ) { accounts . first }
639+ end
640+
630641 after do
631642 Account . on_slave_by_default = false
632643 Person . on_slave_by_default = false
@@ -643,10 +654,10 @@ class ShardedModel < ActiveRecord::Base
643654 end
644655
645656 it "work on association collections" do
646- begin
647- assert_using_master_db
648- account = Account . create!
657+ assert_using_master_db
658+ account = Account . create!
649659
660+ ActiveRecord ::Base . on_shard ( 0 ) do
650661 account . tickets . create! title : 'master ticket'
651662
652663 Ticket . on_slave do
@@ -655,11 +666,6 @@ class ShardedModel < ActiveRecord::Base
655666
656667 assert_equal "master ticket" , account . tickets . first . title
657668 assert_equal "slave ticket" , account . tickets . on_slave . first . title
658- rescue StandardError
659- retried ||= 0
660- retried += 1
661- puts "Failed in #{ __LINE__ } ##{ retried } "
662- retry if retried < 3
663669 end
664670 end
665671 end
0 commit comments