mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
parent
df5ef33ae6
commit
5c6541145a
@ -7,9 +7,8 @@ module ActiveModel
|
||||
def initialize(name, options={})
|
||||
@name = name.to_s
|
||||
@options = options
|
||||
|
||||
self.embed = options[:embed] || CONFIG.embed || :objects
|
||||
@embed_in_root = @embed_ids && (options[:include] || CONFIG.include)
|
||||
self.embed = options.fetch(:embed) { CONFIG.embed }
|
||||
@embed_in_root = options.fetch(:include) { CONFIG.include }
|
||||
@embed_key = options[:embed_key] || :id
|
||||
@key = options[:key]
|
||||
@embedded_key = options[:root] || name
|
||||
|
||||
@ -48,5 +48,6 @@ module ActiveModel
|
||||
end
|
||||
|
||||
CONFIG = Config.new
|
||||
CONFIG.embed = :objects
|
||||
end
|
||||
end
|
||||
|
||||
@ -98,6 +98,20 @@ module ActiveModel
|
||||
CONFIG.clear
|
||||
end
|
||||
|
||||
def test_associations_embedding_nothing_including_objects_serialization_using_as_json
|
||||
CONFIG.embed = nil
|
||||
CONFIG.include = true
|
||||
|
||||
PostSerializer._associations[:comments].send :initialize, @association.name, @association.options
|
||||
|
||||
assert_equal({
|
||||
'post' => { title: 'Title 1', body: 'Body 1' },
|
||||
'comments' => [{ content: 'C1' }, { content: 'C2' }]
|
||||
}, @post_serializer.as_json)
|
||||
ensure
|
||||
CONFIG.clear
|
||||
end
|
||||
|
||||
def test_associations_using_a_given_serializer
|
||||
@association.embed_in_root = true
|
||||
@post_serializer.root = nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user