mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge pull request #1294 from beauby/fix-serializer-lookup-non-ams
Only use subclasses of ActiveModel::Serializer during lookup.
This commit is contained in:
commit
48b041ecae
@ -202,7 +202,7 @@ module ActiveModel
|
|||||||
def self.get_serializer_for(klass)
|
def self.get_serializer_for(klass)
|
||||||
serializers_cache.fetch_or_store(klass) do
|
serializers_cache.fetch_or_store(klass) do
|
||||||
# NOTE(beauby): When we drop 1.9.3 support we can lazify the map for perfs.
|
# NOTE(beauby): When we drop 1.9.3 support we can lazify the map for perfs.
|
||||||
serializer_class = serializer_lookup_chain_for(klass).map(&:safe_constantize).find { |x| x }
|
serializer_class = serializer_lookup_chain_for(klass).map(&:safe_constantize).find { |x| x && x < ActiveModel::Serializer }
|
||||||
|
|
||||||
if serializer_class
|
if serializer_class
|
||||||
serializer_class
|
serializer_class
|
||||||
|
|||||||
@ -44,11 +44,20 @@ module ActiveModel
|
|||||||
def serializer_class; ProfileSerializer; end
|
def serializer_class; ProfileSerializer; end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Tweet = Class.new(::Model)
|
||||||
|
TweetSerializer = Class.new
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@profile = Profile.new
|
@profile = Profile.new
|
||||||
@my_profile = MyProfile.new
|
@my_profile = MyProfile.new
|
||||||
@custom_profile = CustomProfile.new
|
@custom_profile = CustomProfile.new
|
||||||
@model = ::Model.new
|
@model = ::Model.new
|
||||||
|
@tweet = Tweet.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_serializer_for_non_ams_serializer
|
||||||
|
serializer = ActiveModel::Serializer.serializer_for(@tweet)
|
||||||
|
assert_nil(serializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_serializer_for_existing_serializer
|
def test_serializer_for_existing_serializer
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user