mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Use more meaningful model names for tests
This commit is contained in:
47
test/fixtures/poro.rb
vendored
47
test/fixtures/poro.rb
vendored
@@ -7,30 +7,39 @@ class Model
|
||||
@attributes[name]
|
||||
end
|
||||
|
||||
def model
|
||||
@model ||= Model.new(attr1: 'v1', attr2: 'v2')
|
||||
end
|
||||
|
||||
def id
|
||||
object_id
|
||||
end
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
def attr2
|
||||
attr2 = object.read_attribute_for_serialization(:attr2)
|
||||
if scope
|
||||
attr2 + '-' + scope
|
||||
else
|
||||
attr2
|
||||
end
|
||||
|
||||
###
|
||||
## Models
|
||||
###
|
||||
class User < Model
|
||||
def profile
|
||||
@profile ||= Profile.new(name: 'N1', description: 'D1')
|
||||
end
|
||||
end
|
||||
|
||||
class Profile < Model
|
||||
end
|
||||
|
||||
|
||||
###
|
||||
## Serializers
|
||||
###
|
||||
class UserSerializer < ActiveModel::Serializer
|
||||
attributes :name, :email
|
||||
|
||||
has_one :profile
|
||||
end
|
||||
|
||||
class ProfileSerializer < ActiveModel::Serializer
|
||||
def description
|
||||
description = object.read_attribute_for_serialization(:description)
|
||||
scope ? "#{description} - #{scope}" : description
|
||||
end
|
||||
|
||||
attributes :attr1, :attr2
|
||||
end
|
||||
|
||||
class AnotherSerializer < ActiveModel::Serializer
|
||||
attributes :attr2, :attr3
|
||||
|
||||
has_one :model
|
||||
attributes :name, :description
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user