Skip to content

Commit

Permalink
MONGOID-5737 Fix issue where <=> errors if there's a non-document (#5910
Browse files Browse the repository at this point in the history
)

* bug fix and test update

* typo
  • Loading branch information
DarshanaVenkatesh authored Dec 5, 2024
1 parent c2ae3fe commit 6be82fb
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 @@ -18,6 +18,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 @@ -189,6 +189,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 6be82fb

Please sign in to comment.