This adds namespace lookup to serializer_for (#1968)

* This adds namespace lookup to serializer_for

* address rubocop issue

* address @bf4's feedback

* add docs

* update docs, add more tests

* apparently rails master doesn't have before filter

* try to address serializer cache issue between tests

* update cache for serializer lookup to include namespace in the key, and fix the tests for explicit namespace

* update docs, and use better cache key creation method

* update docs [ci skip]

* update docs [ci skip]

* add to changelog [ci skip]
This commit is contained in:
L. Preston Sego III
2016-11-09 07:57:39 -05:00
committed by GitHub
parent b709cd41e6
commit b29395b0ac
9 changed files with 295 additions and 7 deletions

View File

@@ -106,6 +106,10 @@ module ActiveModel
#
def build_association(parent_serializer, parent_serializer_options, include_slice = {})
reflection_options = options.dup
# Pass the parent's namespace onto the child serializer
reflection_options[:namespace] ||= parent_serializer_options[:namespace]
association_value = value(parent_serializer, include_slice)
serializer_class = parent_serializer.class.serializer_for(association_value, reflection_options)
reflection_options[:include_data] = include_data?(include_slice)