2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-10-28 00:55:27 -04:00
|
|
|
require_dependency 'post_action'
|
|
|
|
|
|
|
|
describe TopicListItemSerializer do
|
2017-11-29 08:52:41 -05:00
|
|
|
let(:topic) do
|
2013-10-28 00:55:27 -04:00
|
|
|
date = Time.zone.now
|
|
|
|
|
2017-11-29 08:52:41 -05:00
|
|
|
Fabricate.build(:topic,
|
|
|
|
title: 'test',
|
|
|
|
created_at: date - 2.minutes,
|
|
|
|
bumped_at: date,
|
|
|
|
posters: [],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "correctly serializes topic" do
|
|
|
|
SiteSetting.topic_featured_link_enabled = true
|
2013-10-28 00:55:27 -04:00
|
|
|
serialized = TopicListItemSerializer.new(topic, scope: Guardian.new, root: false).as_json
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(serialized[:title]).to eq("test")
|
|
|
|
expect(serialized[:bumped]).to eq(true)
|
2017-11-29 08:52:41 -05:00
|
|
|
expect(serialized[:featured_link]).to eq(nil)
|
|
|
|
expect(serialized[:featured_link_root_domain]).to eq(nil)
|
|
|
|
|
|
|
|
featured_link = 'http://meta.discourse.org'
|
|
|
|
topic.featured_link = featured_link
|
|
|
|
serialized = TopicListItemSerializer.new(topic, scope: Guardian.new, root: false).as_json
|
|
|
|
|
|
|
|
expect(serialized[:featured_link]).to eq(featured_link)
|
|
|
|
expect(serialized[:featured_link_root_domain]).to eq('discourse.org')
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when topic featured link is disable' do
|
|
|
|
before do
|
|
|
|
SiteSetting.topic_featured_link_enabled = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not include the topic's featured link" do
|
|
|
|
topic.featured_link = 'http://meta.discourse.org'
|
|
|
|
serialized = TopicListItemSerializer.new(topic, scope: Guardian.new, root: false).as_json
|
|
|
|
|
|
|
|
expect(serialized[:featured_link]).to eq(nil)
|
|
|
|
expect(serialized[:featured_link_root_domain]).to eq(nil)
|
|
|
|
end
|
2013-10-28 00:55:27 -04:00
|
|
|
end
|
|
|
|
end
|