Skip to content

Commit debcad5

Browse files
committed
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 <thomas@vondeyen.com>
1 parent 5644e44 commit debcad5

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

app/controllers/alchemy/json_api/admin/pages_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class PagesController < JsonApi::PagesController
77
prepend_before_action { authorize! :edit_content, Alchemy::Page }
88
before_action :set_current_preview, only: :show
99

10+
include Alchemy::Admin::Timezone
11+
include Alchemy::Admin::PreviewTime
12+
1013
private
1114

1215
def cache_duration

spec/controllers/alchemy/json_api/admin/pages_controller_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,19 @@
1919
get :show, params: {path: page.urlname}
2020
expect(Alchemy::Current.preview_page).to eq(page)
2121
end
22+
23+
context "with alchemy_preview_time param" do
24+
it "stores preview time" do
25+
preview_time = 1.day.from_now
26+
get :show, params: {path: page.urlname, alchemy_preview_time: preview_time.iso8601}
27+
expect(Alchemy::Current.preview_time).to be_within(1.second).of(preview_time)
28+
end
29+
end
30+
31+
it "runs action in given timezone" do
32+
allow(Time).to receive(:use_zone).and_yield
33+
get :show, params: {path: page.urlname, admin_timezone: "Hawaii"}
34+
expect(Time).to have_received(:use_zone).with("Hawaii")
35+
end
2236
end
2337
end

0 commit comments

Comments
 (0)