Skip to content

Commit eb0011b

Browse files
authored
Merge pull request #3020 from AlchemyCMS/backport/7.2-stable/pr-3011
[7.2-stable] Fallback to @page var if no Current.page is set
2 parents 8667749 + 8ec7b62 commit eb0011b

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

app/helpers/alchemy/elements_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module ElementsHelper
7272
#
7373
def render_elements(options = {}, &blk)
7474
options = {
75-
from_page: Current.page,
75+
from_page: Current.page || @page,
7676
render_format: "html"
7777
}.update(options)
7878

spec/helpers/alchemy/elements_helper_spec.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,30 @@ module Alchemy
7575
context "without any options" do
7676
let(:options) { {} }
7777

78-
it "should render all elements from current pages public version." do
79-
is_expected.to have_selector("##{element.dom_id}")
80-
is_expected.to have_selector("##{another_element.dom_id}")
78+
context "with Current.page set" do
79+
before { Current.page = page }
80+
81+
it "should render all elements from current pages public version." do
82+
is_expected.to have_selector("##{element.dom_id}")
83+
is_expected.to have_selector("##{another_element.dom_id}")
84+
end
85+
end
86+
87+
context "with Current.page not set" do
88+
before { Current.page = nil }
89+
90+
it "should not render any elements." do
91+
is_expected.to be_empty
92+
end
93+
94+
context "but with @page set" do
95+
before { helper.instance_variable_set(:@page, page) }
96+
97+
it "should render all elements from current pages public version." do
98+
is_expected.to have_selector("##{element.dom_id}")
99+
is_expected.to have_selector("##{another_element.dom_id}")
100+
end
101+
end
81102
end
82103

83104
context "in preview_mode" do

0 commit comments

Comments
 (0)