mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
parent
67c550f2ee
commit
c8cfe94f29
@ -107,7 +107,7 @@ end
|
||||
@root = options.fetch(:root, self.class._root)
|
||||
@meta_key = options[:meta_key] || :meta
|
||||
@meta = options[@meta_key]
|
||||
@options = options.reject{|k,v| [:scope, :root, :meta_key, :meta].include?(k) }
|
||||
@options = options.reject{|k,v| [:root, :meta_key, :meta].include?(k) }
|
||||
end
|
||||
attr_accessor :object, :scope, :meta_key, :meta, :root, :options
|
||||
|
||||
@ -166,7 +166,7 @@ end
|
||||
|
||||
def build_serializer(association)
|
||||
object = send(association.name)
|
||||
association.build_serializer(object, scope: scope)
|
||||
association.build_serializer(object, options)
|
||||
end
|
||||
|
||||
def serialize(association)
|
||||
|
||||
5
test/fixtures/poro.rb
vendored
5
test/fixtures/poro.rb
vendored
@ -50,6 +50,11 @@ class ProfileSerializer < ActiveModel::Serializer
|
||||
scope ? "#{description} - #{scope}" : description
|
||||
end
|
||||
|
||||
def name
|
||||
name = object.read_attribute_for_serialization(:name)
|
||||
options[:custom_name] ? "#{name} - #{options[:custom_name]}" : name
|
||||
end
|
||||
|
||||
attributes :name, :description
|
||||
end
|
||||
|
||||
|
||||
@ -62,6 +62,15 @@ module ActiveModel
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_allow_to_pass_options_to_associations
|
||||
@user_serializer.options.merge!(custom_name: 'custom')
|
||||
@association.embed = :objects
|
||||
|
||||
assert_equal({
|
||||
'user' => { name: 'Name 1', email: 'mail@server.com', profile: { name: 'N1 - custom', description: 'D1' } }
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_nil_ids_serialization_using_as_json
|
||||
@association.embed = :ids
|
||||
@user.instance_eval do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user