Skip to content

Commit

Permalink
ActiveRecord's relation object should respond to to_json and to_yaml
Browse files Browse the repository at this point in the history
[#4547 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Neeraj Singh authored and josevalim committed Jun 23, 2010
1 parent a3ce6fc commit eb04408
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation.rb
Expand Up @@ -10,7 +10,7 @@ class Relation

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
Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -29,6 +29,16 @@ def test_scoped
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
Expand Down

0 comments on commit eb04408

Please sign in to comment.