Skip to content

Commit 8cf67ea

Browse files
authored
MONGOID-5436 switch the meaning of legacy_triple_equals (#5404)
1 parent ecf3842 commit 8cf67ea

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

lib/mongoid/equality.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def ==(other)
4444
# @return [ true | false ] True if the classes are equal, false if not.
4545
def ===(other)
4646
if Mongoid.legacy_triple_equals
47-
super
48-
else
4947
other.class == Class ? self.class === other : self == other
48+
else
49+
super
5050
end
5151
end
5252

@@ -73,9 +73,9 @@ module ClassMethods
7373
# @return [ true | false ] True if the classes are equal, false if not.
7474
def ===(other)
7575
if Mongoid.legacy_triple_equals
76-
other.is_a?(self)
77-
else
7876
other.class == Class ? self <= other : other.is_a?(self)
77+
else
78+
other.is_a?(self)
7979
end
8080
end
8181
end

spec/mongoid/equality_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585

8686
describe ".===" do
8787

88-
context "when legacy_triple_equals is set" do
89-
config_override :legacy_triple_equals, true
88+
context "when legacy_triple_equals is not set" do
89+
config_override :legacy_triple_equals, false
9090

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

@@ -128,8 +128,8 @@
128128
end
129129
end
130130

131-
context "when legacy_triple_equals is not set" do
132-
config_override :legacy_triple_equals, false
131+
context "when legacy_triple_equals is set" do
132+
config_override :legacy_triple_equals, true
133133

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

@@ -205,8 +205,8 @@
205205

206206
context "when the class is the same" do
207207

208-
it "returns false" do
209-
expect(person === Person).to be false
208+
it "returns true" do
209+
expect(person === Person).to be true
210210
end
211211
end
212212

@@ -219,8 +219,8 @@
219219

220220
context "when the class is a superclass" do
221221

222-
it "returns false" do
223-
expect(Doctor.new === Person).to be false
222+
it "returns true" do
223+
expect(Doctor.new === Person).to be true
224224
end
225225
end
226226
end
@@ -256,8 +256,8 @@
256256
context "when comparing to a class" do
257257
context "when the class is the same" do
258258

259-
it "returns true" do
260-
expect(person === Person).to be true
259+
it "returns false" do
260+
expect(person === Person).to be false
261261
end
262262
end
263263

@@ -270,8 +270,8 @@
270270

271271
context "when the class is a superclass" do
272272

273-
it "returns true" do
274-
expect(Doctor.new === Person).to be true
273+
it "returns false" do
274+
expect(Doctor.new === Person).to be false
275275
end
276276
end
277277
end

0 commit comments

Comments
 (0)