test/fixtures/poro.rb in active_model_serializers-0.9.4 vs test/fixtures/poro.rb in active_model_serializers-0.9.5
- old
+ new
@@ -51,10 +51,30 @@
def special_comment
@speical_comment ||= Comment.new(content: 'special')
end
end
+class Type < Model
+end
+
+class SelfReferencingUser < Model
+ def type
+ @type ||= Type.new(name: 'N1')
+ end
+ def parent
+ @parent ||= SelfReferencingUserParent.new(name: 'N1')
+ end
+end
+
+class SelfReferencingUserParent < Model
+ def type
+ @type ||= Type.new(name: 'N2')
+ end
+ def parent
+ end
+end
+
class Comment < Model
end
class WebLog < Model
end
@@ -85,10 +105,26 @@
attributes :name, :email
has_one :profile
end
+class TypeSerializer < ActiveModel::Serializer
+ attributes :name
+end
+
+class SelfReferencingUserParentSerializer < ActiveModel::Serializer
+ attributes :name
+ has_one :type, serializer: TypeSerializer, embed: :ids, include: true
+end
+
+class SelfReferencingUserSerializer < ActiveModel::Serializer
+ attributes :name
+
+ has_one :type, serializer: TypeSerializer, embed: :ids, include: true
+ has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids, include: true
+end
+
class UserInfoSerializer < ActiveModel::Serializer
has_one :user, serializer: UserSerializer
end
class ProfileSerializer < ActiveModel::Serializer
@@ -174,10 +210,10 @@
has_one :profile
end
class NameKeyPostSerializer < ActiveModel::Serializer
attributes :title, :body
-
+
has_many :comments
end
ActiveModel::Serializer.setup do |config|
config.default_key_type = nil