Skip to content

Commit

Permalink
Merge pull request #1096 from beauby/fix-attribute
Browse files Browse the repository at this point in the history
Fix definition of serializer attributes with multiple calls to `attri…
  • Loading branch information
joaomdmoura committed Sep 1, 2015
2 parents 8d3a89e + 995bbcc commit e0b74d8
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
has_many :roles
Expand Down

0 comments on commit e0b74d8

Please sign in to comment.