Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

comparing different classes returns nil

  • Loading branch information...
commit f170045c591f6a13e04ff30532269f9dee620b5a 1 parent c5b43af
@dmathieu dmathieu authored tenderlove committed
View
6 activerecord/lib/active_record/base.rb
@@ -1827,7 +1827,11 @@ def frozen?
# Allows sort on objects
def <=>(other_object)
- self.to_key <=> other_object.to_key
+ if other_object.is_a?(self.class)
+ self.to_key <=> other_object.to_key
+ else
+ nil
+ end
end
# Backport dup from 1.9 so that initialize_dup() gets called
View
6 activerecord/test/cases/base_test.rb
@@ -486,6 +486,12 @@ def test_comparison
assert_equal [topic_2, topic_1].sort, [topic_1, topic_2]
end
+ def test_comparison_with_different_objects
+ topic = Topic.create
+ category = Category.create(:name => "comparison")
+ assert_nil topic <=> category
+ end
+
def test_readonly_attributes
assert_equal Set.new([ 'title' , 'comments_count' ]), ReadonlyTitlePost.readonly_attributes
Please sign in to comment.
Something went wrong with that request. Please try again.