From 59c3e35fa610fc40e06eae6bb24ca68907e3ca7e Mon Sep 17 00:00:00 2001 From: Ross Kaffenberger Date: Sat, 7 Dec 2024 20:00:46 -0500 Subject: [PATCH] =?UTF-8?q?Ensure=20lazy=20page=20poll=20doesn=E2=80=99t?= =?UTF-8?q?=20blow=20up=20search=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/share/polls/lazy_page_poll.rb | 16 ++++++++++++++-- spec/jobs/pages/refresh_search_index_job_spec.rb | 8 +++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/views/share/polls/lazy_page_poll.rb b/app/views/share/polls/lazy_page_poll.rb index e6cc3eab..92c26197 100644 --- a/app/views/share/polls/lazy_page_poll.rb +++ b/app/views/share/polls/lazy_page_poll.rb @@ -13,8 +13,20 @@ def initialize(page, title, question_data = {}) end def view_template - poll = Poll.generate_for(page, title, question_data) or return - turbo_frame_tag poll, src: share_poll_path(poll), class: "poll joy-border-subtle rounded" + if render? + turbo_frame_tag poll, src: share_poll_path(poll), class: "poll joy-border-subtle rounded" + end + end + + private + + def render? + !!page && !!poll + end + + def poll + return @poll if defined?(@poll) + @poll = Poll.generate_for(page, title, question_data) end end end diff --git a/spec/jobs/pages/refresh_search_index_job_spec.rb b/spec/jobs/pages/refresh_search_index_job_spec.rb index db1fa86a..6ac2eae2 100644 --- a/spec/jobs/pages/refresh_search_index_job_spec.rb +++ b/spec/jobs/pages/refresh_search_index_job_spec.rb @@ -1,7 +1,13 @@ require "rails_helper" RSpec.describe Pages::RefreshSearchIndexJob, type: :job do - it "doesn’t blow up" do + it "doesn’t blow up when indexing the current pages" do + Page.upsert_collection_from_sitepress! + + expect { described_class.perform_now }.not_to raise_error + end + + it "indexes the right stuff" do page_1 = FactoryBot.create(:page, :published, request_path: "/articles/introducing-joy-of-rails") page_2 = FactoryBot.create(:page, :published, request_path: "/articles/custom-color-schemes-with-ruby-on-rails") page_3 = FactoryBot.create(:page, :unpublished, request_path: "/articles/joy-of-rails-2")