Skip to content

Commit

Permalink
Ensure lazy page poll doesn’t blow up search index
Browse files Browse the repository at this point in the history
  • Loading branch information
rossta committed Dec 8, 2024
1 parent d4f8612 commit 59c3e35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 14 additions & 2 deletions app/views/share/polls/lazy_page_poll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion spec/jobs/pages/refresh_search_index_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit 59c3e35

Please sign in to comment.