From 2646eb5e1d56856d1ab2626a094bb8435a78bd27 Mon Sep 17 00:00:00 2001 From: scossar Date: Wed, 17 Jan 2018 10:40:21 -0800 Subject: [PATCH 1/3] Add topic.posts_count to web_hook_posts_serializer --- app/serializers/web_hook_post_serializer.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/serializers/web_hook_post_serializer.rb b/app/serializers/web_hook_post_serializer.rb index 5d79ef5f483..623e8ab9df6 100644 --- a/app/serializers/web_hook_post_serializer.rb +++ b/app/serializers/web_hook_post_serializer.rb @@ -1,4 +1,7 @@ class WebHookPostSerializer < PostSerializer + + attributes :topic_posts_count + def include_topic_title? true end @@ -14,4 +17,9 @@ class WebHookPostSerializer < PostSerializer false end end + + def topic_posts_count + object.topic && object.topic.posts_count + end + end From 22ca5a772d1e4571e21fabc6fdaee6b15865871d Mon Sep 17 00:00:00 2001 From: scossar Date: Wed, 17 Jan 2018 11:48:00 -0800 Subject: [PATCH 2/3] Expect 41 keys in the serializer --- spec/serializers/web_hook_post_serializer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/serializers/web_hook_post_serializer_spec.rb b/spec/serializers/web_hook_post_serializer_spec.rb index 2f1f4870603..6190f8e27ef 100644 --- a/spec/serializers/web_hook_post_serializer_spec.rb +++ b/spec/serializers/web_hook_post_serializer_spec.rb @@ -7,7 +7,7 @@ RSpec.describe WebHookPostSerializer do it 'should only include the required keys' do count = serializer.as_json.keys.count - difference = count - 40 + difference = count - 41 expect(difference).to eq(0), lambda { message = "" From 841a988454fa30c63dc8b9217fcf0fb42dfb27e4 Mon Sep 17 00:00:00 2001 From: scossar Date: Mon, 22 Jan 2018 09:54:11 -0800 Subject: [PATCH 3/3] Return 0 if there is no topic associated with the post --- app/serializers/web_hook_post_serializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/serializers/web_hook_post_serializer.rb b/app/serializers/web_hook_post_serializer.rb index 623e8ab9df6..31e214cecc7 100644 --- a/app/serializers/web_hook_post_serializer.rb +++ b/app/serializers/web_hook_post_serializer.rb @@ -19,7 +19,7 @@ class WebHookPostSerializer < PostSerializer end def topic_posts_count - object.topic && object.topic.posts_count + object.topic ? object.topic.posts_count : 0 end end