Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOID-5737 Fix issue where <=> errors if there's a non-document (backport for 8.1) #5917

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading