FEATURE: Multiple embeddable hosts

- Also refactors two site settings components into one, with tests
This commit is contained in:
Robin Ward
2015-06-09 12:19:41 -04:00
parent 71ee84f848
commit 7b6d6b76eb
35 changed files with 183 additions and 102 deletions

View File

@ -11,14 +11,14 @@ describe EmbedController do
end
it "raises an error with a missing host" do
SiteSetting.stubs(:embeddable_host).returns(nil)
SiteSetting.embeddable_hosts = nil
get :comments, embed_url: embed_url
expect(response).not_to be_success
end
context "with a host" do
before do
SiteSetting.stubs(:embeddable_host).returns(host)
SiteSetting.embeddable_hosts = host
end
it "raises an error with no referer" do
@ -27,7 +27,6 @@ describe EmbedController do
end
context "success" do
before do
controller.request.stubs(:referer).returns(embed_url)
end
@ -51,8 +50,31 @@ describe EmbedController do
get :comments, embed_url: embed_url
end
end
end
context "with multiple hosts" do
before do
SiteSetting.embeddable_hosts = "#{host}\nhttp://discourse.org"
end
context "success" do
it "works with the first host" do
controller.request.stubs(:referer).returns("http://eviltrout.com/wat/1-2-3.html")
get :comments, embed_url: embed_url
expect(response).to be_success
end
it "works with the second host" do
controller.request.stubs(:referer).returns("https://discourse.org/blog-entry-1")
get :comments, embed_url: embed_url
expect(response).to be_success
end
it "doesn't work with a made up host" do
controller.request.stubs(:referer).returns("http://codinghorror.com/invalid-url")
get :comments, embed_url: embed_url
expect(response).to_not be_success
end
end
end
end