aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-09-18 15:53:38 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-09-18 15:53:38 -0700
commit096a57b7f340884175f724b55c7bbeda6318b356 (patch)
tree04a281d078e2b9058e6c85f2b8d99c70594eac4f
parent56bfd8a8c9c356573a7af033f88587bbd0c5a267 (diff)
downloadrails-096a57b7f340884175f724b55c7bbeda6318b356.tar.gz
rails-096a57b7f340884175f724b55c7bbeda6318b356.tar.bz2
rails-096a57b7f340884175f724b55c7bbeda6318b356.zip
do what the superclass does in the case that objects do not match
-rw-r--r--activerecord/lib/active_record/core.rb2
-rw-r--r--activerecord/test/cases/base_test.rb8
2 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index b4d6474caa..07d997b719 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -312,6 +312,8 @@ module ActiveRecord
def <=>(other_object)
if other_object.is_a?(self.class)
self.to_key <=> other_object.to_key
+ else
+ super
end
end
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index e3b441280b..20c3a2b6a4 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -579,6 +579,14 @@ class BasicsTest < ActiveRecord::TestCase
assert_nil topic <=> category
end
+ def test_comparison_with_different_objects_in_array
+ topic = Topic.create
+ category = Category.create(:name => "comparison")
+ assert_raises(ArgumentError) do
+ [1, topic].sort
+ end
+ end
+
def test_readonly_attributes
assert_equal Set.new([ 'title' , 'comments_count' ]), ReadonlyTitlePost.readonly_attributes