From 7684c1e8b9404411c8db18a41be49e6357c7ecfb Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Mon, 16 Dec 2019 19:08:59 -0500 Subject: [PATCH] Add edge caching to shell (#5146) [deploy] * Add edge caching to shell * Add tests for shell --- app/controllers/shell_controller.rb | 4 ++++ spec/requests/shells_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 spec/requests/shells_spec.rb diff --git a/app/controllers/shell_controller.rb b/app/controllers/shell_controller.rb index ef2bd2ce2..4abefb814 100644 --- a/app/controllers/shell_controller.rb +++ b/app/controllers/shell_controller.rb @@ -1,13 +1,17 @@ class ShellController < ApplicationController + before_action :set_cache_control_headers, only: %i[top bottom] + layout false def top @shell = true + set_surrogate_key_header "shell-top" render partial: "top" end def bottom @shell = true + set_surrogate_key_header "shell-bottom" render partial: "bottom" end end diff --git a/spec/requests/shells_spec.rb b/spec/requests/shells_spec.rb new file mode 100644 index 000000000..31f57b40c --- /dev/null +++ b/spec/requests/shells_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +RSpec.describe "Shells", type: :request do + describe "GET /shell_top" do + it "renders file with proper text" do + get "/shell_top" + expect(response.body).to include("user-signed-in") + end + + it "sends a surrogate key (for Fastly's user)" do + get "/shell_top" + expect(response.header["Surrogate-Key"]).to include("shell-top") + end + end + + describe "GET /shell_bottom" do + it "renders file with proper text" do + get "/shell_bottom" + expect(response.body).to include("footer-container") + end + + it "sends a surrogate key (for Fastly's user)" do + get "/shell_bottom" + expect(response.header["Surrogate-Key"]).to include("shell-bottom") + end + end +end