From b9a6dfac2f3a8bfb4ac239675e54730f77113e5e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 11 Oct 2013 13:54:38 -0200 Subject: [PATCH] Do not call send on associated objects, do it through elem.read_attribute_for_serialization --- lib/active_model/serializer.rb | 4 ++-- test/fixtures/poro.rb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 88f96d10..beff728a 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -160,9 +160,9 @@ module ActiveModel def serialize_ids(association) associated_data = send(association.name) if associated_data.respond_to?(:to_ary) - associated_data.map { |elem| elem.send(association.embed_key) } + associated_data.map { |elem| elem.read_attribute_for_serialization(association.embed_key) } else - associated_data.send(association.embed_key) if associated_data + associated_data.read_attribute_for_serialization(association.embed_key) if associated_data end end diff --git a/test/fixtures/poro.rb b/test/fixtures/poro.rb index e9d41da3..a43954b5 100644 --- a/test/fixtures/poro.rb +++ b/test/fixtures/poro.rb @@ -4,11 +4,11 @@ class Model end def read_attribute_for_serialization(name) - @attributes[name] - end - - def id - object_id + if name == :id || name == 'id' + object_id + else + @attributes[name] + end end end