Introduce #find_sidebar and use a constant to find the page
This commit is contained in:
parent
1a9d80a139
commit
ef6b3e0271
3 changed files with 24 additions and 1 deletions
|
@ -107,7 +107,7 @@ class Projects::WikisController < Projects::ApplicationController
|
|||
# Call #wiki to make sure the Wiki Repo is initialized
|
||||
@project_wiki.wiki
|
||||
|
||||
@sidebar_page = @project_wiki.find_page('_sidebar', params[:version_id])
|
||||
@sidebar_page = @project_wiki.find_sidebar(params[:version_id])
|
||||
|
||||
unless @sidebar_page # Fallback to default sidebar
|
||||
@sidebar_wiki_entries = WikiPage.group_by_directory(@project_wiki.pages(limit: 15))
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ProjectWiki
|
||||
include Gitlab::ShellAdapter
|
||||
include Storage::LegacyProjectWiki
|
||||
|
@ -9,6 +11,7 @@ class ProjectWiki
|
|||
}.freeze unless defined?(MARKUPS)
|
||||
|
||||
CouldNotCreateWikiError = Class.new(StandardError)
|
||||
SIDEBAR = '_sidebar'
|
||||
|
||||
# Returns a string describing what went wrong after
|
||||
# an operation fails.
|
||||
|
@ -95,6 +98,10 @@ class ProjectWiki
|
|||
end
|
||||
end
|
||||
|
||||
def find_sidebar(version = nil)
|
||||
find_page(SIDEBAR, version)
|
||||
end
|
||||
|
||||
def find_file(name, version = nil)
|
||||
wiki.file(name, version)
|
||||
end
|
||||
|
|
|
@ -170,6 +170,22 @@ describe ProjectWiki do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#find_sidebar' do
|
||||
before do
|
||||
create_page(described_class::SIDEBAR, 'This is an awesome Sidebar')
|
||||
end
|
||||
|
||||
after do
|
||||
subject.pages.each { |page| destroy_page(page.page) }
|
||||
end
|
||||
|
||||
it 'finds the page defined as _sidebar' do
|
||||
page = subject.find_page('_sidebar')
|
||||
|
||||
expect(page.content).to eq('This is an awesome Sidebar')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#find_file' do
|
||||
shared_examples 'finding a wiki file' do
|
||||
before do
|
||||
|
|
Loading…
Reference in a new issue