Skip to content

Commit

Permalink
MONGOID-5436 switch the meaning of legacy_triple_equals (#5404)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neilshweky authored and p committed Jul 23, 2022
1 parent 3c53cce commit b9af9b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions lib/mongoid/equality.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def ==(other)
# @return [ true, false ] True if the classes are equal, false if not.
def ===(other)
if Mongoid.legacy_triple_equals
super
else
other.class == Class ? self.class === other : self == other
else
super
end
end

Expand All @@ -73,9 +73,9 @@ module ClassMethods
# @return [ true, false ] True if the classes are equal, false if not.
def ===(other)
if Mongoid.legacy_triple_equals
other.is_a?(self)
else
other.class == Class ? self <= other : other.is_a?(self)
else
other.is_a?(self)
end
end
end
Expand Down
24 changes: 12 additions & 12 deletions spec/mongoid/equality_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@

describe ".===" do

context "when legacy_triple_equals is set" do
config_override :legacy_triple_equals, true
context "when legacy_triple_equals is not set" do
config_override :legacy_triple_equals, false

context "when comparable is an instance of this document" do

Expand Down Expand Up @@ -128,8 +128,8 @@
end
end

context "when legacy_triple_equals is not set" do
config_override :legacy_triple_equals, false
context "when legacy_triple_equals is set" do
config_override :legacy_triple_equals, true

context "when comparable is an instance of this document" do

Expand Down Expand Up @@ -205,8 +205,8 @@

context "when the class is the same" do

it "returns false" do
expect(person === Person).to be false
it "returns true" do
expect(person === Person).to be true
end
end

Expand All @@ -219,8 +219,8 @@

context "when the class is a superclass" do

it "returns false" do
expect(Doctor.new === Person).to be false
it "returns true" do
expect(Doctor.new === Person).to be true
end
end
end
Expand Down Expand Up @@ -256,8 +256,8 @@
context "when comparing to a class" do
context "when the class is the same" do

it "returns true" do
expect(person === Person).to be true
it "returns false" do
expect(person === Person).to be false
end
end

Expand All @@ -270,8 +270,8 @@

context "when the class is a superclass" do

it "returns true" do
expect(Doctor.new === Person).to be true
it "returns false" do
expect(Doctor.new === Person).to be false
end
end
end
Expand Down

0 comments on commit b9af9b7

Please sign in to comment.