mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
commit
1a7395b1d1
@ -12,7 +12,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def serializer_class(object, options = {})
|
||||
serializer_from_options || serializer_from_object(object, options) || default_serializer
|
||||
(serializer_from_options unless object.nil?) || serializer_from_object(object, options) || default_serializer
|
||||
end
|
||||
|
||||
def build_serializer(object, options = {})
|
||||
|
||||
2
test/fixtures/poro.rb
vendored
2
test/fixtures/poro.rb
vendored
@ -88,7 +88,7 @@ class UserSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
class UserInfoSerializer < ActiveModel::Serializer
|
||||
has_one :user
|
||||
has_one :user, serializer: UserSerializer
|
||||
end
|
||||
|
||||
class ProfileSerializer < ActiveModel::Serializer
|
||||
|
||||
@ -176,6 +176,20 @@ module ActiveModel
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_objects_with_nil_values
|
||||
user_info = UserInfo.new
|
||||
user_info.instance_eval do
|
||||
def user
|
||||
nil
|
||||
end
|
||||
end
|
||||
user_info_serializer = UserInfoSerializer.new(user_info)
|
||||
|
||||
assert_equal({
|
||||
'user_info' => { user: nil }
|
||||
}, user_info_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_ids_using_embed_namespace
|
||||
@association.embed_namespace = :links
|
||||
@association.embed = :ids
|
||||
|
||||
Loading…
Reference in New Issue
Block a user