Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.2-stable] Fallback to @page var if no Current.page is set #3020

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/alchemy/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module ElementsHelper
#
def render_elements(options = {}, &blk)
options = {
from_page: Current.page,
from_page: Current.page || @page,
render_format: "html"
}.update(options)

Expand Down
27 changes: 24 additions & 3 deletions spec/helpers/alchemy/elements_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,30 @@ module Alchemy
context "without any options" do
let(:options) { {} }

it "should render all elements from current pages public version." do
is_expected.to have_selector("##{element.dom_id}")
is_expected.to have_selector("##{another_element.dom_id}")
context "with Current.page set" do
before { Current.page = page }

it "should render all elements from current pages public version." do
is_expected.to have_selector("##{element.dom_id}")
is_expected.to have_selector("##{another_element.dom_id}")
end
end

context "with Current.page not set" do
before { Current.page = nil }

it "should not render any elements." do
is_expected.to be_empty
end

context "but with @page set" do
before { helper.instance_variable_set(:@page, page) }

it "should render all elements from current pages public version." do
is_expected.to have_selector("##{element.dom_id}")
is_expected.to have_selector("##{another_element.dom_id}")
end
end
end

context "in preview_mode" do
Expand Down