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

Decide locale prefix with page language in show_alchemy_page_url helper #2366

Merged
merged 1 commit into from Sep 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/helpers/alchemy/url_helper.rb
Expand Up @@ -20,8 +20,8 @@ def show_alchemy_page_url(page, optional_params = {})
def show_page_path_params(page, optional_params = {})
raise ArgumentError, "Page is nil" if page.nil?

url_params = {urlname: page.urlname}.update(optional_params)
prefix_locale? ? url_params.update(locale: page.language_code) : url_params
url_params = { urlname: page.urlname }.update(optional_params)
prefix_locale?(page.language_code) ? url_params.update(locale: page.language_code) : url_params
end

# Returns the path for downloading an alchemy attachment
Expand Down
14 changes: 7 additions & 7 deletions spec/helpers/alchemy/url_helper_spec.rb
Expand Up @@ -14,15 +14,15 @@ module Alchemy

context "if prefix_locale? is false" do
before do
expect(helper).to receive(:prefix_locale?) { false }
expect(helper).to receive(:prefix_locale?).with(page.language_code) { false }
end

it "returns a Hash with urlname and no locale parameter" do
expect(show_page_path_params).to include(urlname: "testpage")
expect(show_page_path_params).to_not include(locale: "en")
end

context "with addiitonal parameters" do
context "with additional parameters" do
subject(:show_page_path_params) do
helper.show_page_path_params(page, { query: "test" })
end
Expand All @@ -38,7 +38,7 @@ module Alchemy

context "if prefix_locale? is false" do
before do
expect(helper).to receive(:prefix_locale?) { true }
expect(helper).to receive(:prefix_locale?).with(page.language_code) { true }
end

it "returns a Hash with urlname and locale parameter" do
Expand All @@ -62,7 +62,7 @@ module Alchemy
describe "#show_alchemy_page_path" do
context "when prefix_locale? set to true" do
before do
expect(helper).to receive(:prefix_locale?) { true }
expect(helper).to receive(:prefix_locale?).with(page.language_code) { true }
end

it "should return the correct relative path string" do
Expand All @@ -77,7 +77,7 @@ module Alchemy

context "when prefix_locale? set to false" do
before do
expect(helper).to receive(:prefix_locale?) { false }
expect(helper).to receive(:prefix_locale?).with(page.language_code) { false }
end

it "should return the correct relative path string" do
Expand All @@ -94,7 +94,7 @@ module Alchemy
describe "#show_alchemy_page_url" do
context "when prefix_locale? set to true" do
before do
expect(helper).to receive(:prefix_locale?) { true }
expect(helper).to receive(:prefix_locale?).with(page.language_code) { true }
end

it "should return the correct url string" do
Expand All @@ -110,7 +110,7 @@ module Alchemy

context "when prefix_locale? set to false" do
before do
expect(helper).to receive(:prefix_locale?) { false }
expect(helper).to receive(:prefix_locale?).with(page.language_code) { false }
end

it "should return the correct url string" do
Expand Down