From 4a9dadb646d8f23f8dfc1bd4c6eaa8a819b07210 Mon Sep 17 00:00:00 2001 From: OsamaSayegh Date: Tue, 12 Jun 2018 08:21:41 +0300 Subject: [PATCH] Add test case for topic embed CSS --- spec/requests/embed_controller_spec.rb | 36 +++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/spec/requests/embed_controller_spec.rb b/spec/requests/embed_controller_spec.rb index f6cb42e88cf..f7f5c11eee7 100644 --- a/spec/requests/embed_controller_spec.rb +++ b/spec/requests/embed_controller_spec.rb @@ -71,19 +71,43 @@ describe EmbedController do context "with a host" do let!(:embeddable_host) { Fabricate(:embeddable_host) } + let(:headers) { { 'REFERER' => embed_url } } + + before do + SiteSetting.queue_jobs = false + end it "raises an error with no referer" do get '/embed/comments', params: { embed_url: embed_url } expect(response.body).to match(I18n.t('embed.error')) end + it "includes CSS from embedded_scss field" do + theme = Theme.create!(name: "Awesome blog", user_id: -1) + theme.set_default! + + ThemeField.create!( + theme_id: theme.id, + name: "embedded_scss", + target_id: 0, + type_id: 1, + value: ".test-osama-15 {\n" + " color: red;\n" + "}\n" + ) + + topic_embed = Fabricate(:topic_embed, embed_url: embed_url) + post = Fabricate(:post, topic: topic_embed.topic) + + get '/embed/comments', params: { embed_url: embed_url }, headers: headers + + html = Nokogiri::HTML.fragment(response.body) + css_link = html.at("link[data-target=embedded_theme]").attribute("href").value + + get css_link + expect(response.status).to eq(200) + expect(response.body).to include(".test-osama-15") + end + context "success" do - let(:headers) { { 'REFERER' => embed_url } } - - before do - SiteSetting.queue_jobs = false - end - after do expect(response.status).to eq(200) expect(response.headers['X-Frame-Options']).to eq("ALLOWALL")