FIX: featured links are 'undefined' in suggested topics

This commit is contained in:
Neil Lalonde 2018-01-25 14:39:55 -05:00
parent feec968801
commit 179ecee11e
2 changed files with 40 additions and 1 deletions

View File

@ -7,7 +7,7 @@ class SuggestedTopicSerializer < ListableTopicSerializer
has_one :user, serializer: BasicUserSerializer, embed: :objects
end
attributes :archetype, :like_count, :views, :category_id, :tags, :featured_link
attributes :archetype, :like_count, :views, :category_id, :tags, :featured_link, :featured_link_root_domain
has_many :posters, serializer: SuggestedPosterSerializer, embed: :objects
def posters
@ -29,4 +29,8 @@ class SuggestedTopicSerializer < ListableTopicSerializer
def featured_link
object.featured_link
end
def include_featured_link_root_domain?
SiteSetting.topic_featured_link_enabled && object.featured_link
end
end

View File

@ -0,0 +1,35 @@
require 'rails_helper'
describe SuggestedTopicSerializer do
let(:user) { Fabricate(:user) }
describe '#featured_link and #featured_link_root_domain' do
let(:featured_link) { 'http://meta.discourse.org' }
let(:topic) { Fabricate(:topic, featured_link: featured_link, category: Fabricate(:category, topic_featured_link_allowed: true)) }
subject(:json) { described_class.new(topic, scope: Guardian.new(user), root: false).as_json }
context 'when topic featured link is disable' do
before do
SiteSetting.topic_featured_link_enabled = true
topic
SiteSetting.topic_featured_link_enabled = false
end
it 'should not return featured link attrs' do
expect(json[:featured_link]).to eq(nil)
expect(json[:featured_link_root_domain]).to eq(nil)
end
end
context 'when topic featured link is enabled' do
before do
SiteSetting.topic_featured_link_enabled = true
end
it 'should return featured link attrs' do
expect(json[:featured_link]).to eq(featured_link)
expect(json[:featured_link_root_domain]).to eq('discourse.org')
end
end
end
end