Skip to content

Commit 59c3e35

Browse files
committed
Ensure lazy page poll doesn’t blow up search index
1 parent d4f8612 commit 59c3e35

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

app/views/share/polls/lazy_page_poll.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,20 @@ def initialize(page, title, question_data = {})
1313
end
1414

1515
def view_template
16-
poll = Poll.generate_for(page, title, question_data) or return
17-
turbo_frame_tag poll, src: share_poll_path(poll), class: "poll joy-border-subtle rounded"
16+
if render?
17+
turbo_frame_tag poll, src: share_poll_path(poll), class: "poll joy-border-subtle rounded"
18+
end
19+
end
20+
21+
private
22+
23+
def render?
24+
!!page && !!poll
25+
end
26+
27+
def poll
28+
return @poll if defined?(@poll)
29+
@poll = Poll.generate_for(page, title, question_data)
1830
end
1931
end
2032
end

spec/jobs/pages/refresh_search_index_job_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
require "rails_helper"
22

33
RSpec.describe Pages::RefreshSearchIndexJob, type: :job do
4-
it "doesn’t blow up" do
4+
it "doesn’t blow up when indexing the current pages" do
5+
Page.upsert_collection_from_sitepress!
6+
7+
expect { described_class.perform_now }.not_to raise_error
8+
end
9+
10+
it "indexes the right stuff" do
511
page_1 = FactoryBot.create(:page, :published, request_path: "/articles/introducing-joy-of-rails")
612
page_2 = FactoryBot.create(:page, :published, request_path: "/articles/custom-color-schemes-with-ruby-on-rails")
713
page_3 = FactoryBot.create(:page, :unpublished, request_path: "/articles/joy-of-rails-2")

0 commit comments

Comments
 (0)