From 02ad8c26b06f2c4a483b6ebf60259f38c4705a99 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Wed, 20 Apr 2016 10:13:02 -0500 Subject: [PATCH] Fix CachingPostSerializer defining associations twice --- test/benchmark/fixtures.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/benchmark/fixtures.rb b/test/benchmark/fixtures.rb index 039adb02..abe56a42 100644 --- a/test/benchmark/fixtures.rb +++ b/test/benchmark/fixtures.rb @@ -52,11 +52,28 @@ class CachingCommentSerializer < CommentSerializer end Rails.configuration.serializers << CachingCommentSerializer -class CachingPostSerializer < PostSerializer +# see https://github.com/rails-api/active_model_serializers/pull/1690/commits/68715b8f99bc29677e8a47bb3f305f23c077024b#r60344532 +class CachingPostSerializer < ActiveModel::Serializer cache key: 'post', expires_in: 0.1, skip_digest: true + + attributes :id, :title, :body + + has_many :comments, serializer: CommentSerializer belongs_to :blog, serializer: BlogSerializer - belongs_to :author, serializer: CachingAuthorSerializer - has_many :comments, serializer: CachingCommentSerializer + belongs_to :author, serializer: AuthorSerializer + + link(:post_authors) { 'https://example.com/post_authors' } + + meta do + { + rating: 5, + favorite_count: 10 + } + end + + def blog + Blog.new(id: 999, name: 'Custom blog') + end end Rails.configuration.serializers << CachingPostSerializer