fix order of update/delete_all extensions interacting with sharding
make sure that switchman's extension is still active Change-Id: I8d9d06103f1eb4b09f529b634fba758c72da371a Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/339249 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Jacob Burroughs <jburroughs@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
be89b444d6
commit
b525c0f700
|
@ -1472,7 +1472,7 @@ module UpdateAndDeleteWithJoins
|
|||
connection.delete(sql, "SQL", [])
|
||||
end
|
||||
end
|
||||
ActiveRecord::Relation.prepend(UpdateAndDeleteWithJoins)
|
||||
Switchman::ActiveRecord::Relation.include(UpdateAndDeleteWithJoins)
|
||||
|
||||
module UpdateAndDeleteAllWithLimit
|
||||
def delete_all(*args)
|
||||
|
@ -1491,7 +1491,7 @@ module UpdateAndDeleteAllWithLimit
|
|||
super
|
||||
end
|
||||
end
|
||||
ActiveRecord::Relation.prepend(UpdateAndDeleteAllWithLimit)
|
||||
Switchman::ActiveRecord::Relation.include(UpdateAndDeleteAllWithLimit)
|
||||
|
||||
ActiveRecord::Associations::CollectionProxy.class_eval do
|
||||
def respond_to?(name, include_private = false)
|
||||
|
|
|
@ -285,6 +285,27 @@ module ActiveRecord
|
|||
end.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "update_all" do
|
||||
context "with shard_value" do
|
||||
specs_require_sharding
|
||||
|
||||
it "iterates all shards" do
|
||||
u1 = u2 = nil
|
||||
@shard1.activate do
|
||||
u1 = User.create!(name: "u1")
|
||||
u1.communication_channels.create!(path: "email@domain.com")
|
||||
end
|
||||
@shard2.activate do
|
||||
u2 = User.create!(name: "u2")
|
||||
u2.communication_channels.create!(path: "email@domain.com")
|
||||
end
|
||||
User.joins(:communication_channel).shard([@shard1, @shard2]).update_all(name: "changed")
|
||||
expect(u1.reload.name).to eql "changed"
|
||||
expect(u2.reload.name).to eql "changed"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "update_all with limit" do
|
||||
|
@ -297,6 +318,18 @@ module ActiveRecord
|
|||
expect(e1.reload.name).to eq "changed"
|
||||
expect(e2.reload.name).not_to eq "changed"
|
||||
end
|
||||
|
||||
context "with shard_value" do
|
||||
specs_require_sharding
|
||||
|
||||
it "iterates all shards" do
|
||||
u1 = @shard1.activate { User.create!(name: "u1") }
|
||||
u2 = @shard2.activate { User.create!(name: "u2") }
|
||||
User.shard([@shard1, @shard2]).limit(10).update_all(name: "changed")
|
||||
expect(u1.reload.name).to eql "changed"
|
||||
expect(u2.reload.name).to eql "changed"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".parse_asset_string" do
|
||||
|
|
Loading…
Reference in New Issue