mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
merge upstream update fieldset
This commit is contained in:
@@ -26,6 +26,8 @@ module ActiveModel
|
||||
|
||||
def setup
|
||||
@author = Author.new(name: 'Steve K.')
|
||||
@author.bio = nil
|
||||
@author.roles = []
|
||||
@post = Post.new({ title: 'New Post', body: 'Body' })
|
||||
@comment = Comment.new({ id: 1, body: 'ZOMG A COMMENT' })
|
||||
@post.comments = [@comment]
|
||||
@@ -39,11 +41,25 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_has_many
|
||||
assert_equal({posts: {type: :has_many, options: {embed: :ids}}}, @author_serializer.class._associations)
|
||||
assert_equal(
|
||||
{ posts: { type: :has_many, options: { embed: :ids } },
|
||||
roles: { type: :has_many, options: { embed: :ids } },
|
||||
bio: { type: :belongs_to, options: {} } },
|
||||
@author_serializer.class._associations
|
||||
)
|
||||
@author_serializer.each_association do |name, serializer, options|
|
||||
assert_equal(:posts, name)
|
||||
assert_equal({embed: :ids}, options)
|
||||
assert_kind_of(ActiveModel::Serializer.config.array_serializer, serializer)
|
||||
if name == :posts
|
||||
assert_equal({embed: :ids}, options)
|
||||
assert_kind_of(ActiveModel::Serializer.config.array_serializer, serializer)
|
||||
elsif name == :bio
|
||||
assert_equal({}, options)
|
||||
assert_nil serializer
|
||||
elsif name == :roles
|
||||
assert_equal({embed: :ids}, options)
|
||||
assert_kind_of(ActiveModel::Serializer.config.array_serializer, serializer)
|
||||
else
|
||||
flunk "Unknown association: #{name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
23
test/serializers/attribute_test.rb
Normal file
23
test/serializers/attribute_test.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require 'test_helper'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class AttributeTest < Minitest::Test
|
||||
def setup
|
||||
@blog = Blog.new({ id: 1, name: 'AMS Hints' })
|
||||
@blog_serializer = AlternateBlogSerializer.new(@blog)
|
||||
end
|
||||
|
||||
def test_attributes_definition
|
||||
assert_equal([:id, :title],
|
||||
@blog_serializer.class._attributes)
|
||||
end
|
||||
|
||||
def test_json_serializable_hash
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(@blog_serializer)
|
||||
assert_equal({:id=>1, :title=>"AMS Hints"}, adapter.serializable_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ module ActiveModel
|
||||
assert_equal ActiveModel::Serializer::ArraySerializer, ActiveModel::Serializer.config.array_serializer
|
||||
end
|
||||
|
||||
def test_adapter
|
||||
def test_default_adapter
|
||||
assert_equal :json, ActiveModel::Serializer.config.adapter
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user