From 067c5f4392594c7d3736db358440d9c196eef535 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 23 Jun 2010 10:05:30 -0400 Subject: [PATCH] ActiveRecord's relation object should respond to to_json and to_yaml [#4547 state:resolved] --- activerecord/lib/active_record/relation.rb | 2 +- activerecord/test/cases/relations_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 99c914d..a1e5a4a 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -9,7 +9,7 @@ module ActiveRecord include FinderMethods, Calculations, SpawnMethods, QueryMethods, Batches - delegate :length, :collect, :map, :each, :all?, :include?, :to => :to_a + delegate :to_json, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to => :to_a delegate :insert, :to => :arel attr_reader :table, :klass diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 43519db..365ab93 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -22,6 +22,16 @@ class RelationTest < ActiveRecord::TestCase assert_equal 4, topics.size end + def test_to_json + assert_nothing_raised { Bird.scoped.to_json } + assert_nothing_raised { Bird.scoped.all.to_json } + end + + def test_to_yaml + assert_nothing_raised { Bird.scoped.to_yaml } + assert_nothing_raised { Bird.scoped.all.to_yaml } + end + def test_scoped_all topics = Topic.scoped.all assert_kind_of Array, topics -- 1.6.5.2