Trim WebHookTopicSerializer further.

This commit is contained in:
Guo Xiang Tan 2018-05-21 10:28:12 +08:00
parent b229c112f6
commit 3ff0074e9d
3 changed files with 24 additions and 3 deletions

View File

@ -36,7 +36,6 @@ class TopicViewSerializer < ApplicationSerializer
:deleted_at,
:pending_posts_count,
:user_id,
:pm_with_non_human_user?,
:featured_link,
:featured_link_root_domain,
:pinned_globally,
@ -67,7 +66,8 @@ class TopicViewSerializer < ApplicationSerializer
:unicode_title,
:message_bus_last_id,
:participant_count,
:destination_category_id
:destination_category_id,
:pm_with_non_human_user,
# TODO: Split off into proper object / serializer
def details
@ -281,6 +281,10 @@ class TopicViewSerializer < ApplicationSerializer
private_message?(object.topic)
end
def pm_with_non_human_user
object.topic.pm_with_non_human_user?
end
def participant_count
object.participant_count
end

View File

@ -1,6 +1,8 @@
require_dependency 'pinned_check'
class WebHookTopicViewSerializer < TopicViewSerializer
attributes :created_by,
:last_poster
%i{
post_stream
@ -11,9 +13,24 @@ class WebHookTopicViewSerializer < TopicViewSerializer
draft_sequence
message_bus_last_id
suggested_topics
has_summary
actions_summary
current_post_number
chunk_size
topic_timer
private_topic_timer
details
}.each do |attr|
define_method("include_#{attr}?") do
false
end
end
def created_by
BasicUserSerializer.new(object.topic.user, scope: scope, root: false)
end
def last_poster
BasicUserSerializer.new(object.topic.last_poster, scope: scope, root: false)
end
end

View File

@ -13,7 +13,7 @@ RSpec.describe WebHookTopicViewSerializer do
it 'should only include the required keys' do
count = serializer.as_json.keys.count
difference = count - 35
difference = count - 30
expect(difference).to eq(0), lambda {
message = ""