Skip to content

Commit fe7bf03

Browse files
committed
Add the page loading also to Admin::PagesController
The same behavior as before, except that this controller does not rescue the Alchemy::PageNotFound error. Instead the service will be initialized with the preview_mode flag, which is interesting to populate other data in the preview window.
1 parent 4144cf3 commit fe7bf03

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

app/controllers/alchemy/admin/pages_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def show
8181
Current.preview_page = @page
8282
# Setting the locale to pages language, so the page content has it's correct translations.
8383
::I18n.locale = @page.language.locale
84+
if @page.has_service?
85+
@service = @page.definition.service.new(@page, preview_mode: true)
86+
@service.call
87+
end
8488
render(layout: Alchemy.config.admin_page_preview_layout || "application")
8589
end
8690

spec/controllers/alchemy/admin/pages_controller_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@
8787
end
8888
end
8989

90+
describe "#show" do
91+
let(:page) { create(:alchemy_page, page_layout: "with_service") }
92+
93+
it "calls the page service" do
94+
expect_any_instance_of(DummyPageService).to receive(:call)
95+
get :show, params: {id: page.id}
96+
end
97+
end
98+
9099
describe "#publish" do
91100
let(:page) { create(:alchemy_page) }
92101

0 commit comments

Comments
 (0)