From f2ee544a88ad58d3dcab02651e4f14a762041c58 Mon Sep 17 00:00:00 2001 From: Will Jordan Date: Tue, 24 Feb 2015 16:01:43 -0800 Subject: [PATCH 1/2] Fix explicit serializer for associations --- lib/active_model/serializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index b083e40d..d0b70516 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -176,7 +176,7 @@ module ActiveModel def serializer_from_options(options) opts = {} - serializer = options.fetch(:options, {}).fetch(:serializer, nil) + serializer = options.fetch(:association_options, {}).fetch(:serializer, nil) opts[:serializer] = serializer if serializer opts end From f4eb33d6e9d5bb21d742304f0bf8a5bbc135b9fe Mon Sep 17 00:00:00 2001 From: Will Jordan Date: Tue, 24 Feb 2015 18:46:04 -0800 Subject: [PATCH 2/2] Update test_includes_linked_comments with correct expected result --- test/adapter/json_api/has_many_explicit_serializer_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/adapter/json_api/has_many_explicit_serializer_test.rb b/test/adapter/json_api/has_many_explicit_serializer_test.rb index 29e73c4a..8d21b3fd 100644 --- a/test/adapter/json_api/has_many_explicit_serializer_test.rb +++ b/test/adapter/json_api/has_many_explicit_serializer_test.rb @@ -34,8 +34,9 @@ module ActiveModel end def test_includes_linked_comments - assert_equal([{ id: '1', body: "ZOMG A COMMENT", links: { post: @post.id.to_s, author: nil }}, - { id: '2', body: "ZOMG ANOTHER COMMENT", links: { post: @post.id.to_s, author: nil }}], + # If CommentPreviewSerializer is applied correctly the body text will not be present in the output + assert_equal([{ id: '1', links: { post: @post.id.to_s}}, + { id: '2', links: { post: @post.id.to_s}}], @adapter.serializable_hash[:linked][:comments]) end