FEATURE: Include image url in topic serializer

The `image_url` is already included when fetching a list of topics, and
this commit adds it to the individual topic serializer so that it is
available via the api.

See

https://meta.discourse.org/t/single-topic-api-endpoint-should-contain-image-url/131020

for more details.
This commit is contained in:
Blake Erickson 2019-10-21 22:02:49 -06:00
parent ef0fe51e05
commit 3201613f13
2 changed files with 26 additions and 1 deletions

View File

@ -39,7 +39,8 @@ class TopicViewSerializer < ApplicationSerializer
:featured_link_root_domain,
:pinned_globally,
:pinned_at,
:pinned_until
:pinned_until,
:image_url
)
attributes(

View File

@ -45,6 +45,30 @@ describe TopicViewSerializer do
end
end
describe '#image_url' do
let(:image_url) { 'http://meta.discourse.org/images/welcome/discourse-edit-post-animated.gif' }
describe 'when a topic has an image' do
it 'should return the image url' do
topic.update!(image_url: image_url)
json = serialize_topic(topic, user)
expect(json[:image_url]).to eq(image_url)
end
end
describe 'when a topic does not contain an image' do
it 'should return a nil image url' do
json = serialize_topic(topic, user)
expect(json.has_key? :image_url).to eq(true)
expect(json[:image_url]).to eq(nil)
end
end
end
describe '#suggested_topics' do
let(:topic2) { Fabricate(:topic) }