Skip to content

Commit f702081

Browse files
committed
Apply batch upsert to all sitepress pages
1 parent e054df7 commit f702081

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

app/models/page.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ def data = NullData.new(title: nil, description: nil)
4444
# the split personality for now.
4545
#
4646
def self.upsert_collection_from_sitepress!(limit: nil)
47-
# Targeting specific Sitepress models until we have a better way to make
48-
# Page model aware of published state
49-
enum = [
50-
SitepressArticle,
51-
SitepressSlashPage
52-
].lazy.flat_map { |model| model.all.resources }
47+
enum = SitepressPage.all.resources.lazy
5348

5449
if limit
5550
enum = enum.filter do |sitepress_resource|
@@ -104,4 +99,8 @@ def meta_image = resource.data.meta_image
10499
def toc = resource.data.toc
105100

106101
def enable_twitter_widgets = resource.data.toc
102+
103+
def upsert_page_from_sitepress!
104+
self.class.upsert_page_from_sitepress!(resource)
105+
end
107106
end

spec/jobs/pages/batch_upsert_pages_job_spec.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
it "creates pages for sitepress resources" do
55
described_class.perform_now
66

7-
expect(Page.count).to eq(
8-
SitepressArticle.all.resources.size +
9-
SitepressSlashPage.all.resources.size
10-
)
7+
expect(Page.count).to eq(SitepressPage.all.resources.size)
118

129
expect(Page.pluck(:request_path)).to include("/articles/custom-color-schemes-with-ruby-on-rails")
1310
end

spec/system/articles_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
end
99

1010
it "displays a single article" do
11-
Page.upsert_collection_from_sitepress!(limit: 1)
11+
article = FactoryBot.create(:page, :published, request_path: "/articles/custom-color-schemes-with-ruby-on-rails")
1212

13-
article = Page.first
1413
article.topics << FactoryBot.create_list(:topic, 2, :approved)
1514
article.topics << FactoryBot.create_list(:topic, 1, :pending)
1615
article.topics << FactoryBot.create_list(:topic, 1, :rejected)

0 commit comments

Comments
 (0)