From 07314e64fd62fb8e6165c8c539420160da9437e9 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 6 Jul 2012 10:39:46 +0100 Subject: Show the records in Relation#inspect The reason for removing the previous implementation of `#inspect` was that it hid from you that you were dealing with a `Relation` rather than an `Array`. But it is still useful to be able to see the records, particularly if you're writing something like the following in tests: assert_equal [foo], Post.where(:bar) If the assertion fails, you want to see what records were actually loaded. So this implementation makes it clear that you've got a `Relation`, but also shows your records. --- activerecord/test/cases/relations_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 8544d36aa8..7fdd42f150 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1311,4 +1311,9 @@ class RelationTest < ActiveRecord::TestCase relation.merge! where: 'foo' end end + + test "relations show the records in #inspect" do + relation = Post.limit(2) + assert_equal "#", relation.inspect + end end -- cgit v1.2.3