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:
parent
ef0fe51e05
commit
3201613f13
|
@ -39,7 +39,8 @@ class TopicViewSerializer < ApplicationSerializer
|
|||
:featured_link_root_domain,
|
||||
:pinned_globally,
|
||||
:pinned_at,
|
||||
:pinned_until
|
||||
:pinned_until,
|
||||
:image_url
|
||||
)
|
||||
|
||||
attributes(
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue