Skip to content

Commit 89f2731

Browse files
authored
feat: Store alchemy_preview_time in current global (#168)
We need that to return content for given preview time for the admin addition we made to alchemy. ~~**Needs AlchemyCMS/alchemy_cms#3789
2 parents 660ea44 + 3ae0665 commit 89f2731

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
alchemy_branch:
16+
- 8.2-stable
1617
- main
1718
ruby:
18-
- "3.2"
1919
- "3.3"
2020
- "3.4"
21+
- "4.0"
2122
env:
2223
ALCHEMY_BRANCH: ${{ matrix.alchemy_branch }}
2324
steps:

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gem "sqlite3", "~> 2.2"
1919

2020
alchemy_branch = ENV.fetch("ALCHEMY_BRANCH", "main")
2121
gem "alchemy_cms", github: "AlchemyCMS/alchemy_cms", branch: alchemy_branch
22-
gem "alchemy-devise", github: "AlchemyCMS/alchemy-devise", branch: alchemy_branch
22+
gem "alchemy-devise", github: "AlchemyCMS/alchemy-devise", branch: "main"
2323

2424
gem "rubocop", require: false
2525
gem "standard", "~> 1.25", require: false

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)