Fix podcasts episodes surrogate key and add "/podcasts" (#3577)

This commit is contained in:
rhymes 2019-08-01 18:14:25 +02:00 committed by Mac Siri
parent 757e969bed
commit 1c2ff71de8
3 changed files with 22 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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