mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Add Model#attributes helper; make test attributes explicit
This commit is contained in:
@@ -3,11 +3,8 @@ require 'test_helper'
|
||||
module ActiveModelSerializers
|
||||
module Adapter
|
||||
class AttributesTest < ActiveSupport::TestCase
|
||||
class Person
|
||||
include ActiveModel::Model
|
||||
include ActiveModel::Serialization
|
||||
|
||||
attr_accessor :first_name, :last_name
|
||||
class Person < ActiveModelSerializers::Model
|
||||
attributes :first_name, :last_name
|
||||
end
|
||||
|
||||
class PersonSerializer < ActiveModel::Serializer
|
||||
|
||||
@@ -4,9 +4,17 @@ module ActiveModelSerializers
|
||||
module Adapter
|
||||
class JsonApi
|
||||
class FieldsTest < ActiveSupport::TestCase
|
||||
class Post < ::Model; end
|
||||
class Author < ::Model; end
|
||||
class Comment < ::Model; end
|
||||
class Post < ::Model
|
||||
attributes :title, :body
|
||||
associations :author, :comments
|
||||
end
|
||||
class Author < ::Model
|
||||
attributes :name, :birthday
|
||||
end
|
||||
class Comment < ::Model
|
||||
attributes :body
|
||||
associations :author, :post
|
||||
end
|
||||
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
type 'posts'
|
||||
|
||||
@@ -5,7 +5,9 @@ module ActiveModel
|
||||
module Adapter
|
||||
class JsonApi
|
||||
class IncludeParamTest < ActiveSupport::TestCase
|
||||
IncludeParamAuthor = Class.new(::Model)
|
||||
IncludeParamAuthor = Class.new(::Model) do
|
||||
associations :tags, :posts
|
||||
end
|
||||
|
||||
class CustomCommentLoader
|
||||
def all
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'test_helper'
|
||||
|
||||
class NestedPost < ::Model; end
|
||||
class NestedPost < ::Model; associations :nested_posts end
|
||||
class NestedPostSerializer < ActiveModel::Serializer
|
||||
has_many :nested_posts
|
||||
end
|
||||
@@ -301,8 +301,8 @@ module ActiveModelSerializers
|
||||
end
|
||||
|
||||
class NoDuplicatesTest < ActiveSupport::TestCase
|
||||
class Post < ::Model; end
|
||||
class Author < ::Model; end
|
||||
class Post < ::Model; associations :author end
|
||||
class Author < ::Model; associations :posts, :roles, :bio end
|
||||
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
type 'posts'
|
||||
|
||||
@@ -4,7 +4,7 @@ module ActiveModelSerializers
|
||||
module Adapter
|
||||
class JsonApi
|
||||
class LinksTest < ActiveSupport::TestCase
|
||||
class LinkAuthor < ::Model; end
|
||||
class LinkAuthor < ::Model; associations :posts end
|
||||
class LinkAuthorSerializer < ActiveModel::Serializer
|
||||
link :self do
|
||||
href "http://example.com/link_author/#{object.id}"
|
||||
|
||||
@@ -384,7 +384,7 @@ module ActiveModelSerializers
|
||||
|
||||
def new_model(model_attributes)
|
||||
Class.new(ActiveModelSerializers::Model) do
|
||||
attr_accessor(*model_attributes.keys)
|
||||
attributes(*model_attributes.keys)
|
||||
|
||||
def self.name
|
||||
'TestModel'
|
||||
|
||||
@@ -4,9 +4,17 @@ module ActiveModelSerializers
|
||||
module Adapter
|
||||
class JsonApi
|
||||
class KeyCaseTest < ActiveSupport::TestCase
|
||||
class Post < ::Model; end
|
||||
class Author < ::Model; end
|
||||
class Comment < ::Model; end
|
||||
class Post < ::Model
|
||||
attributes :title, :body, :publish_at
|
||||
associations :author, :comments
|
||||
end
|
||||
class Author < ::Model
|
||||
attributes :first_name, :last_name
|
||||
end
|
||||
class Comment < ::Model
|
||||
attributes :body
|
||||
associations :author, :post
|
||||
end
|
||||
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
type 'posts'
|
||||
|
||||
Reference in New Issue
Block a user