mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Make test attributes explicit
- Organize test poros with associations and by serializer - Freeze derived attributes/associations against mutation - Cleanup PORO fixtures
This commit is contained in:
55
test/fixtures/active_record.rb
vendored
55
test/fixtures/active_record.rb
vendored
@@ -47,16 +47,6 @@ module ARModels
|
||||
has_many :comments
|
||||
belongs_to :author
|
||||
end
|
||||
|
||||
class Comment < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
belongs_to :author
|
||||
end
|
||||
|
||||
class Author < ActiveRecord::Base
|
||||
has_many :posts
|
||||
end
|
||||
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
attributes :id, :title, :body
|
||||
|
||||
@@ -64,15 +54,60 @@ module ARModels
|
||||
belongs_to :author
|
||||
end
|
||||
|
||||
class Comment < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
belongs_to :author
|
||||
end
|
||||
class CommentSerializer < ActiveModel::Serializer
|
||||
attributes :id, :contents
|
||||
|
||||
belongs_to :author
|
||||
end
|
||||
|
||||
class Author < ActiveRecord::Base
|
||||
has_many :posts
|
||||
end
|
||||
class AuthorSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name
|
||||
|
||||
has_many :posts
|
||||
end
|
||||
end
|
||||
|
||||
class Employee < ActiveRecord::Base
|
||||
has_many :pictures, as: :imageable
|
||||
has_many :object_tags, as: :taggable
|
||||
end
|
||||
|
||||
class PolymorphicSimpleSerializer < ActiveModel::Serializer
|
||||
attributes :id
|
||||
end
|
||||
|
||||
class ObjectTag < ActiveRecord::Base
|
||||
belongs_to :poly_tag
|
||||
belongs_to :taggable, polymorphic: true
|
||||
end
|
||||
class PolymorphicObjectTagSerializer < ActiveModel::Serializer
|
||||
attributes :id
|
||||
has_many :taggable, serializer: PolymorphicSimpleSerializer, polymorphic: true
|
||||
end
|
||||
|
||||
class PolyTag < ActiveRecord::Base
|
||||
has_many :object_tags
|
||||
end
|
||||
class PolymorphicTagSerializer < ActiveModel::Serializer
|
||||
attributes :id, :phrase
|
||||
has_many :object_tags, serializer: PolymorphicObjectTagSerializer
|
||||
end
|
||||
|
||||
class Picture < ActiveRecord::Base
|
||||
belongs_to :imageable, polymorphic: true
|
||||
has_many :object_tags, as: :taggable
|
||||
end
|
||||
class PolymorphicHasManySerializer < ActiveModel::Serializer
|
||||
attributes :id, :name
|
||||
end
|
||||
class PolymorphicBelongsToSerializer < ActiveModel::Serializer
|
||||
attributes :id, :title
|
||||
has_one :imageable, serializer: PolymorphicHasManySerializer, polymorphic: true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user