* feat: add a route to the async_info for display ads * feat: load the billboard asyncronously * feat: move the methods to the display_ads controller * feat: handle params better * feat: cache control headers * feat: test fastly caching headers on display ads * fix: surrogate key test * feat: use safe navigation operator to handle cases where there is no article id * fix: article id present then find the article * feat: add a response test * Fragment caching * feat: update the article decorator * feat: update cache keys for fragment * feat: remove an empty line * feat: add article id * feat: bust cache * feat: setup dropdown for billboard * chore: add chunk to same line * feat: add to safe params for caching * Update app/controllers/display_ads_controller.rb Co-authored-by: Joshua Wehner <joshua@forem.com> * feat: remove the cache deletion * feat: update the routes to follow a new scope * feat: update the cache params --------- Co-authored-by: Joshua Wehner <joshua@forem.com>
67 lines
2.3 KiB
Ruby
67 lines
2.3 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "DisplayAds" do
|
|
let(:user) { create(:user) }
|
|
let(:article) { create(:article, user: user) }
|
|
|
|
let(:max_age) { 15.minutes.to_i }
|
|
let(:stale_if_error) { 26_400 }
|
|
|
|
describe "GET /:username/:slug/display_ads/:placement_area" do
|
|
before do
|
|
create(:display_ad, placement_area: "post_comments", published: true, approved: true)
|
|
end
|
|
|
|
it "returns the correct response" do
|
|
get article_display_ad_path(username: article.username, slug: article.slug, placement_area: "post_comments")
|
|
display_ad = DisplayAd.find_by(placement_area: "post_comments")
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
expect(response.parsed_body).to include(display_ad.processed_html)
|
|
end
|
|
|
|
context "when signed in" do
|
|
before do
|
|
sign_in user
|
|
get article_display_ad_path(username: article.username, slug: article.slug, placement_area: "post_comments")
|
|
end
|
|
|
|
it "does not set surrogate key headers" do
|
|
expect(response.headers["Surrogate-key"]).to be_nil
|
|
end
|
|
|
|
it "does not set x-accel-expires headers" do
|
|
expect(response.headers["x-accel-expires"]).to be_nil
|
|
end
|
|
|
|
it "does not set Fastly cache control and surrogate control headers" do
|
|
expect(response.headers.to_hash).not_to include(
|
|
"Cache-Control" => "public, no-cache",
|
|
"Surrogate-Control" => "max-age=#{max_age}, stale-if-error=#{stale_if_error}",
|
|
)
|
|
end
|
|
end
|
|
|
|
context "when signed out" do
|
|
before do
|
|
get article_display_ad_path(username: article.username, slug: article.slug, placement_area: "post_comments")
|
|
end
|
|
|
|
it "sets the surrogate key header equal to params for article" do
|
|
display_ad = DisplayAd.find_by(placement_area: "post_comments")
|
|
expect(response.headers["Surrogate-Key"]).to eq("display_ads/#{display_ad.id}")
|
|
end
|
|
|
|
it "sets the x-accel-expires header equal to max-age for article" do
|
|
expect(response.headers["X-Accel-Expires"]).to eq(max_age.to_s)
|
|
end
|
|
|
|
it "sets Fastly cache control and surrogate control headers" do
|
|
expect(response.headers.to_hash).to include(
|
|
"Cache-Control" => "public, no-cache",
|
|
"Surrogate-Control" => "max-age=#{max_age}, stale-if-error=#{stale_if_error}",
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|