FEATURE: Can edit category/host relationships for embedding

This commit is contained in:
Robin Ward
2015-08-18 17:15:46 -04:00
parent 913c3d6f63
commit d1c69189f3
36 changed files with 449 additions and 127 deletions

View File

@ -0,0 +1,40 @@
require 'spec_helper'
describe EmbeddableHost do
it "trims http" do
eh = EmbeddableHost.new(host: 'http://example.com')
expect(eh).to be_valid
expect(eh.host).to eq('example.com')
end
it "trims https" do
eh = EmbeddableHost.new(host: 'https://example.com')
expect(eh).to be_valid
expect(eh.host).to eq('example.com')
end
it "trims paths" do
eh = EmbeddableHost.new(host: 'https://example.com/1234/45')
expect(eh).to be_valid
expect(eh.host).to eq('example.com')
end
describe "allows_embeddable_host" do
let!(:host) { Fabricate(:embeddable_host) }
it 'works as expected' do
expect(EmbeddableHost.host_allowed?('http://eviltrout.com')).to eq(true)
expect(EmbeddableHost.host_allowed?('https://eviltrout.com')).to eq(true)
expect(EmbeddableHost.host_allowed?('https://not-eviltrout.com')).to eq(false)
end
it 'works with multiple hosts' do
Fabricate(:embeddable_host, host: 'discourse.org')
expect(EmbeddableHost.host_allowed?('http://eviltrout.com')).to eq(true)
expect(EmbeddableHost.host_allowed?('http://discourse.org')).to eq(true)
end
end
end

View File

@ -4,36 +4,6 @@ require_dependency 'site_setting_extension'
describe SiteSetting do
describe "allows_embeddable_host" do
it 'works as expected' do
SiteSetting.embeddable_hosts = 'eviltrout.com'
expect(SiteSetting.allows_embeddable_host?('http://eviltrout.com')).to eq(true)
expect(SiteSetting.allows_embeddable_host?('https://eviltrout.com')).to eq(true)
expect(SiteSetting.allows_embeddable_host?('https://not-eviltrout.com')).to eq(false)
end
it 'works with a http host' do
SiteSetting.embeddable_hosts = 'http://eviltrout.com'
expect(SiteSetting.allows_embeddable_host?('http://eviltrout.com')).to eq(true)
expect(SiteSetting.allows_embeddable_host?('https://eviltrout.com')).to eq(true)
expect(SiteSetting.allows_embeddable_host?('https://not-eviltrout.com')).to eq(false)
end
it 'works with a https host' do
SiteSetting.embeddable_hosts = 'https://eviltrout.com'
expect(SiteSetting.allows_embeddable_host?('http://eviltrout.com')).to eq(true)
expect(SiteSetting.allows_embeddable_host?('https://eviltrout.com')).to eq(true)
expect(SiteSetting.allows_embeddable_host?('https://not-eviltrout.com')).to eq(false)
end
it 'works with multiple hosts' do
SiteSetting.embeddable_hosts = "https://eviltrout.com\nhttps://discourse.org"
expect(SiteSetting.allows_embeddable_host?('http://eviltrout.com')).to eq(true)
expect(SiteSetting.allows_embeddable_host?('http://discourse.org')).to eq(true)
end
end
describe 'topic_title_length' do
it 'returns a range of min/max topic title length' do
expect(SiteSetting.topic_title_length).to eq(

View File

@ -12,6 +12,7 @@ describe TopicEmbed do
let(:title) { "How to turn a fish from good to evil in 30 seconds" }
let(:url) { 'http://eviltrout.com/123' }
let(:contents) { "hello world new post <a href='/hello'>hello</a> <img src='/images/wat.jpg'>" }
let!(:embeddable_host) { Fabricate(:embeddable_host) }
it "returns nil when the URL is malformed" do
expect(TopicEmbed.import(user, "invalid url", title, contents)).to eq(nil)
@ -33,6 +34,8 @@ describe TopicEmbed do
expect(post.topic.has_topic_embed?).to eq(true)
expect(TopicEmbed.where(topic_id: post.topic_id)).to be_present
expect(post.topic.category).to eq(embeddable_host.category)
end
it "Supports updating the post" do

View File

@ -1238,7 +1238,7 @@ describe Topic do
it "doesn't return topics from muted categories" do
user = Fabricate(:user)
category = Fabricate(:category)
topic = Fabricate(:topic, category: category)
Fabricate(:topic, category: category)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)
@ -1247,7 +1247,7 @@ describe Topic do
it "doesn't return topics from TL0 users" do
new_user = Fabricate(:user, trust_level: 0)
topic = Fabricate(:topic, user_id: new_user.id)
Fabricate(:topic, user_id: new_user.id)
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank
end
@ -1397,32 +1397,34 @@ describe Topic do
end
describe "expandable_first_post?" do
let(:topic) { Fabricate.build(:topic) }
before do
SiteSetting.embeddable_hosts = "http://eviltrout.com"
SiteSetting.embed_truncate = true
topic.stubs(:has_topic_embed?).returns(true)
end
it "is true with the correct settings and topic_embed" do
expect(topic.expandable_first_post?).to eq(true)
end
it "is false if embeddable_host is blank" do
SiteSetting.embeddable_hosts = nil
expect(topic.expandable_first_post?).to eq(false)
end
it "is false if embed_truncate? is false" do
SiteSetting.embed_truncate = false
expect(topic.expandable_first_post?).to eq(false)
describe 'with an emeddable host' do
before do
Fabricate(:embeddable_host)
SiteSetting.embed_truncate = true
topic.stubs(:has_topic_embed?).returns(true)
end
it "is true with the correct settings and topic_embed" do
expect(topic.expandable_first_post?).to eq(true)
end
it "is false if embed_truncate? is false" do
SiteSetting.embed_truncate = false
expect(topic.expandable_first_post?).to eq(false)
end
it "is false if has_topic_embed? is false" do
topic.stubs(:has_topic_embed?).returns(false)
expect(topic.expandable_first_post?).to eq(false)
end
end
it "is false if has_topic_embed? is false" do
topic.stubs(:has_topic_embed?).returns(false)
expect(topic.expandable_first_post?).to eq(false)
end
end
it "has custom fields" do