Bugfix/redefine associations on inherited serializers (#1848)

* replace reflection collection type with hash to prevent duplicated associations in some cases

* include tests

* Fix robucup offenses

* Improve test

* Remove usless requirement

* improve tests

* remove custom_options option from Post and InheritedPost serializer

* Improve tests

* update changelog

* update changelog
This commit is contained in:
Avon
2016-07-18 00:55:43 +04:30
committed by L. Preston Sego III
parent 9a206a1f5d
commit 3ad2457aaf
4 changed files with 64 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ module ActiveModel
included do
with_options instance_writer: false, instance_reader: true do |serializer|
serializer.class_attribute :_reflections
self._reflections ||= []
self._reflections ||= {}
end
extend ActiveSupport::Autoload
@@ -74,7 +74,8 @@ module ActiveModel
# @api private
#
def associate(reflection)
self._reflections << reflection
key = reflection.options[:key]
key ? self._reflections[key] = reflection : self._reflections[reflection.name] = reflection
end
end
@@ -86,7 +87,7 @@ module ActiveModel
return unless object
Enumerator.new do |y|
self.class._reflections.each do |reflection|
self.class._reflections.values.each do |reflection|
next if reflection.excluded?(self)
key = reflection.options.fetch(:key, reflection.name)
next unless include_directive.key?(key)