Skip to content

Commit

Permalink
Fix definition of serializer attributes with multiple calls to `attri…
Browse files Browse the repository at this point in the history
…bute` instead of one single call to `attributes`.
  • Loading branch information
beauby committed Aug 28, 2015
1 parent 64168cb commit 995bbcc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/poro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 995bbcc

Please sign in to comment.