test/fixtures/poro.rb in active_model_serializers-0.10.0.rc5 vs test/fixtures/poro.rb in active_model_serializers-0.10.0

- old
+ new

@@ -68,16 +68,27 @@ end end class Employee < ActiveRecord::Base has_many :pictures, as: :imageable + has_many :object_tags, as: :taggable end +class ObjectTag < ActiveRecord::Base + belongs_to :poly_tag + belongs_to :taggable, polymorphic: true +end + class Picture < ActiveRecord::Base belongs_to :imageable, polymorphic: true + has_many :object_tags, as: :taggable end +class PolyTag < ActiveRecord::Base + has_many :object_tags +end + module Spam; end Spam::UnrelatedLink = Class.new(Model) PostSerializer = Class.new(ActiveModel::Serializer) do cache key: 'post', expires_in: 0.1, skip_digest: true @@ -225,12 +236,13 @@ end VirtualValueSerializer = Class.new(ActiveModel::Serializer) do attributes :id - has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }] - has_one :maker, virtual_value: { id: 1 } + has_many :reviews, virtual_value: [{ type: 'reviews', id: '1' }, + { type: 'reviews', id: '2' }] + has_one :maker, virtual_value: { type: 'makers', id: '1' } def reviews end def maker @@ -242,10 +254,26 @@ end PolymorphicBelongsToSerializer = Class.new(ActiveModel::Serializer) do attributes :id, :title - has_one :imageable, serializer: PolymorphicHasManySerializer + has_one :imageable, serializer: PolymorphicHasManySerializer, polymorphic: true +end + +PolymorphicSimpleSerializer = Class.new(ActiveModel::Serializer) do + attributes :id +end + +PolymorphicObjectTagSerializer = Class.new(ActiveModel::Serializer) do + attributes :id + + has_many :taggable, serializer: PolymorphicSimpleSerializer, polymorphic: true +end + +PolymorphicTagSerializer = Class.new(ActiveModel::Serializer) do + attributes :id, :phrase + + has_many :object_tags, serializer: PolymorphicObjectTagSerializer end Spam::UnrelatedLinkSerializer = Class.new(ActiveModel::Serializer) do cache only: [:id] attributes :id