diff --git a/app/jobs/alchemy/publish_page_job.rb b/app/jobs/alchemy/publish_page_job.rb index 9571951dc4..f53a84351e 100644 --- a/app/jobs/alchemy/publish_page_job.rb +++ b/app/jobs/alchemy/publish_page_job.rb @@ -4,7 +4,13 @@ module Alchemy class PublishPageJob < BaseJob queue_as :default - def perform(page, public_on:) + def perform(page_or_id, public_on:) + if page_or_id.is_a? Alchemy::Page + Alchemy::Deprecation.warn("Passing an Alchemy Page into the publish Job is deprecated. Please pass a page ID instead.") + page_id = page_or_id.id + else + page_id = page_or_id + end page = Alchemy::Page.includes( draft_version: { elements: [ @@ -12,7 +18,7 @@ def perform(page, public_on:) { contents: :essence }, ], }, - ).find(page.id) + ).find(page_id) Alchemy::Page::Publisher.new(page).publish!(public_on: public_on) end end diff --git a/app/models/alchemy/page.rb b/app/models/alchemy/page.rb index d7bfd7f67f..284e79e7fb 100644 --- a/app/models/alchemy/page.rb +++ b/app/models/alchemy/page.rb @@ -465,7 +465,7 @@ def copy_children_to(new_parent) # def publish!(current_time = Time.current) update(published_at: current_time) - PublishPageJob.perform_later(self, public_on: current_time) + PublishPageJob.perform_later(id, public_on: current_time) end # Sets the public_on date on the published version diff --git a/spec/jobs/alchemy/publish_page_job_spec.rb b/spec/jobs/alchemy/publish_page_job_spec.rb index 14e4928dfc..54e9225095 100644 --- a/spec/jobs/alchemy/publish_page_job_spec.rb +++ b/spec/jobs/alchemy/publish_page_job_spec.rb @@ -9,7 +9,7 @@ it "enqueues job" do expect { - described_class.perform_later(page, public_on: public_on) + described_class.perform_later(page.id, public_on: public_on) }.to have_enqueued_job end @@ -17,7 +17,19 @@ expect_any_instance_of(Alchemy::Page::Publisher).to receive(:publish!).with( public_on: public_on, ) - described_class.new.perform(page, public_on: public_on) + described_class.new.perform(page.id, public_on: public_on) + end + + context "when called with a page object" do + subject { described_class.new.perform(page, public_on: public_on) } + + it "warns about the changing API and calls the page publisher" do + expect(Alchemy::Deprecation).to receive(:warn) + expect_any_instance_of(Alchemy::Page::Publisher).to receive(:publish!).with( + public_on: public_on, + ) + subject + end end end end