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

Add support for custom mount points in Page::UrlPath #1921

Merged
merged 1 commit into from
Aug 7, 2020
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
14 changes: 8 additions & 6 deletions app/models/alchemy/page/url_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class Page
# link_to page.url
#
class UrlPath
ROOT_PATH = "/"

def initialize(page)
@page = page
@language = @page.language
Expand All @@ -41,23 +39,27 @@ def call
private

def language_root_path
@language.default? ? ROOT_PATH : language_path
@language.default? ? root_path : language_path
end

def page_path_with_language_prefix
@language.default? ? page_path : language_path + page_path
end

def page_path_with_leading_slash
@page.language_root? ? ROOT_PATH : page_path
@page.language_root? ? root_path : page_path
end

def language_path
"/#{@page.language_code}"
"#{root_path}#{@page.language_code}"
end

def page_path
"/#{@page.urlname}"
"#{root_path}#{@page.urlname}"
end

def root_path
Engine.routes.url_helpers.root_path
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/models/alchemy/page/url_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,20 @@
end
end
end

context "mounted on a non-root path" do
let(:page) do
create(:alchemy_page)
end

before do
expect(Alchemy::Engine.routes).to receive(:url_helpers) do
double(root_path: "/pages/")
end
end

it "prefixes the path" do
is_expected.to eq("/pages/#{page.urlname}")
end
end
end