Skip to content

Commit

Permalink
MONGOID-5737 Fix issue where <=> errors if there's a non-document (ba…
Browse files Browse the repository at this point in the history
…ckport for 8.1)
  • Loading branch information
DarshanaVenkatesh authored Dec 13, 2024
1 parent c2f078f commit 77e2a09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/mongoid/equality.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Equality
#
# @return [ Integer ] -1, 0, 1.
def <=>(other)
return super unless other.is_a?(Mongoid::Equality)
attributes["_id"].to_s <=> other.attributes["_id"].to_s
end

Expand Down
6 changes: 6 additions & 0 deletions spec/mongoid/equality_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@
it "compares based on the document id" do
expect(first <=> second).to eq(-1)
end

it "doesn't break if one isn't a document" do
expect do
first <=> "Foo"
end.to_not raise_error
end
end

describe "#eql?" do
Expand Down

0 comments on commit 77e2a09

Please sign in to comment.