From 1c2ff71de8d463fcbb96b112a546ceca8f94b52a Mon Sep 17 00:00:00 2001 From: rhymes Date: Thu, 1 Aug 2019 18:14:25 +0200 Subject: [PATCH] Fix podcasts episodes surrogate key and add "/podcasts" (#3577) --- app/controllers/podcast_episodes_controller.rb | 12 +++++++++--- config/routes.rb | 3 ++- .../requests/podcasts/podcast_episodes_index_spec.rb | 11 +++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/controllers/podcast_episodes_controller.rb b/app/controllers/podcast_episodes_controller.rb index 91617dacc..e2184b685 100644 --- a/app/controllers/podcast_episodes_controller.rb +++ b/app/controllers/podcast_episodes_controller.rb @@ -4,15 +4,21 @@ class PodcastEpisodesController < ApplicationController def index @podcast_index = true + @podcasts = Podcast.available.order("title asc") - @podcast_episodes = PodcastEpisode.available.order("published_at desc").first(20) + @podcast_episodes = PodcastEpisode. + available. + includes(:podcast).order("published_at desc").first(20) + if params[:q].blank? - set_surrogate_key_header("podcast_episodes_all " + params[:q].to_s, - @podcast_episodes.map { |e| e["record_key"] }) + surrogate_keys = ["podcast_episodes_all"] + @podcast_episodes.map(&:record_key) + set_surrogate_key_header(surrogate_keys) end + @featured_story = Article.new @article_index = true @list_of = "podcast-episodes" + render template: "podcast_episodes/index" end diff --git a/config/routes.rb b/config/routes.rb index 51af46bcc..bf9dd2128 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -315,7 +315,8 @@ Rails.application.routes.draw do get "/new" => "articles#new" get "/new/:template" => "articles#new" - get "/pod" => "podcast_episodes#index" + get "/pod", to: "podcast_episodes#index" + get "/podcasts", to: redirect("pod") get "/readinglist" => "reading_list_items#index" get "/readinglist/:view" => "reading_list_items#index", constraints: { view: /archive/ } get "/history", to: "history#index", as: :history diff --git a/spec/requests/podcasts/podcast_episodes_index_spec.rb b/spec/requests/podcasts/podcast_episodes_index_spec.rb index 1b94ddd58..4afa5672a 100644 --- a/spec/requests/podcasts/podcast_episodes_index_spec.rb +++ b/spec/requests/podcasts/podcast_episodes_index_spec.rb @@ -14,5 +14,16 @@ RSpec.describe "PodcastEpisodesSpec", type: :request do expect(response.body).to include("SuperMario") expect(response.body).not_to include("unreachable") end + + it "sets proper surrogate key" do + pe = create(:podcast_episode) + get "/pod" + expect(response.headers["Surrogate-Key"]).to eq("podcast_episodes_all podcast_episodes/#{pe.id}") + end + + it "redirects /podcasts to /pod" do + get "/podcasts" + expect(response.body).to redirect_to(pod_path) + end end end