Change WikiPage#directory to always start a directory hierarchy with '/'
This commit is contained in:
parent
904aa039e5
commit
5607bb8f09
|
@ -89,7 +89,7 @@ class WikiPage
|
||||||
# The hierarchy of the directory this page is contained in.
|
# The hierarchy of the directory this page is contained in.
|
||||||
def directory
|
def directory
|
||||||
dir = wiki.page_title_and_dir(slug).last
|
dir = wiki.page_title_and_dir(slug).last
|
||||||
dir.present? ? dir : '/'
|
"/#{dir}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# The processed/formatted content of this page.
|
# The processed/formatted content of this page.
|
||||||
|
@ -106,7 +106,7 @@ class WikiPage
|
||||||
|
|
||||||
# The full path for this page, including its filename and extension.
|
# The full path for this page, including its filename and extension.
|
||||||
def full_path
|
def full_path
|
||||||
"/#{directory}/#{page.filename}".gsub(/\/+/, '/')
|
"#{directory}/#{page.filename}".gsub(/\/+/, '/')
|
||||||
end
|
end
|
||||||
|
|
||||||
# The commit message for this page version.
|
# The commit message for this page version.
|
||||||
|
|
|
@ -27,7 +27,7 @@ describe WikiPage, models: true do
|
||||||
page_2 = wiki.find_page('dir_1/page_2')
|
page_2 = wiki.find_page('dir_1/page_2')
|
||||||
page_3 = wiki.find_page('dir_1/dir_2/page_3')
|
page_3 = wiki.find_page('dir_1/dir_2/page_3')
|
||||||
expected_grouped_pages = {
|
expected_grouped_pages = {
|
||||||
'/' => [page_1], 'dir_1' => [page_2], 'dir_1/dir_2' => [page_3]
|
'/' => [page_1], '/dir_1' => [page_2], '/dir_1/dir_2' => [page_3]
|
||||||
}
|
}
|
||||||
|
|
||||||
grouped_pages = WikiPage.group_by_directory(wiki.pages)
|
grouped_pages = WikiPage.group_by_directory(wiki.pages)
|
||||||
|
@ -239,7 +239,7 @@ describe WikiPage, models: true do
|
||||||
create_page('dir_1/dir_1_1/file', 'content')
|
create_page('dir_1/dir_1_1/file', 'content')
|
||||||
page = wiki.find_page('dir_1/dir_1_1/file')
|
page = wiki.find_page('dir_1/dir_1_1/file')
|
||||||
|
|
||||||
expect(page.directory).to eq('dir_1/dir_1_1')
|
expect(page.directory).to eq('/dir_1/dir_1_1')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue