From 995bbcc18d6b270cdfb0ee443fc596bcc3d698f9 Mon Sep 17 00:00:00 2001 From: Lucas Hosseini Date: Fri, 28 Aug 2015 21:06:10 +0200 Subject: [PATCH] Fix definition of serializer attributes with multiple calls to `attribute` instead of one single call to `attributes`. --- lib/active_model/serializer.rb | 2 +- test/fixtures/poro.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index a9f0e756c..6e6833bb5 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -70,7 +70,7 @@ def self.attribute(attr, options = {}) ActiveModelSerializers.silence_warnings do define_method key do object.read_attribute_for_serialization(attr) - end unless respond_to?(key, false) || _fragmented.respond_to?(attr) + end unless (key != :id && method_defined?(key)) || _fragmented.respond_to?(attr) end end diff --git a/test/fixtures/poro.rb b/test/fixtures/poro.rb index 0c0e3a587..7293e5468 100644 --- a/test/fixtures/poro.rb +++ b/test/fixtures/poro.rb @@ -134,7 +134,8 @@ def custom_options AuthorSerializer = Class.new(ActiveModel::Serializer) do cache key:'writer', skip_digest: true - attributes :id, :name + attribute :id + attribute :name has_many :posts, embed: :ids has_many :roles, embed: :ids