From 82520c063cc81e750c8f645c3bc2c771285f0b9e Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 26 Mar 2026 08:58:13 +0100 Subject: [PATCH] feat: Store alchemy_preview_time in current global We need that to return content for given preview time for the admin addition we made to alchemy. Signed-off-by: Thomas von Deyen --- Gemfile | 2 +- .../alchemy/json_api/admin/pages_controller.rb | 3 +++ .../json_api/admin/pages_controller_spec.rb | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c8bcb7b..ff723a3 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,7 @@ gemspec gem "sqlite3", "~> 2.2" alchemy_branch = ENV.fetch("ALCHEMY_BRANCH", "main") -gem "alchemy_cms", github: "AlchemyCMS/alchemy_cms", branch: alchemy_branch +gem "alchemy_cms", github: "AlchemyCMS/alchemy_cms", branch: "preview-time-select" gem "alchemy-devise", github: "AlchemyCMS/alchemy-devise", branch: alchemy_branch gem "rubocop", require: false diff --git a/app/controllers/alchemy/json_api/admin/pages_controller.rb b/app/controllers/alchemy/json_api/admin/pages_controller.rb index 833f4b5..536cfd6 100644 --- a/app/controllers/alchemy/json_api/admin/pages_controller.rb +++ b/app/controllers/alchemy/json_api/admin/pages_controller.rb @@ -7,6 +7,9 @@ class PagesController < JsonApi::PagesController prepend_before_action { authorize! :edit_content, Alchemy::Page } before_action :set_current_preview, only: :show + include Alchemy::Admin::Timezone + include Alchemy::Admin::PreviewTime + private def cache_duration diff --git a/spec/controllers/alchemy/json_api/admin/pages_controller_spec.rb b/spec/controllers/alchemy/json_api/admin/pages_controller_spec.rb index cd782dc..19f00f4 100644 --- a/spec/controllers/alchemy/json_api/admin/pages_controller_spec.rb +++ b/spec/controllers/alchemy/json_api/admin/pages_controller_spec.rb @@ -19,5 +19,19 @@ get :show, params: {path: page.urlname} expect(Alchemy::Current.preview_page).to eq(page) end + + context "with alchemy_preview_time param" do + it "stores preview time" do + preview_time = 1.day.from_now + get :show, params: {path: page.urlname, alchemy_preview_time: preview_time.iso8601} + expect(Alchemy::Current.preview_time).to be_within(1.second).of(preview_time) + end + end + + it "runs action in given timezone" do + allow(Time).to receive(:use_zone).and_yield + get :show, params: {path: page.urlname, admin_timezone: "Hawaii"} + expect(Time).to have_received(:use_zone).with("Hawaii") + end end end