Commit 083442bc authored by Alex Braha Stoll's avatar Alex Braha Stoll

Add specs for WikiPage.group_by_directory

parent 8bf52a4a
...@@ -7,19 +7,37 @@ describe WikiPage, models: true do ...@@ -7,19 +7,37 @@ describe WikiPage, models: true do
subject { WikiPage.new(wiki) } subject { WikiPage.new(wiki) }
describe '::group_by_directory' do describe '.group_by_directory' do
context 'when there are no pages' do context 'when there are no pages' do
it 'returns an empty hash' do it 'returns an empty hash' do
expect(WikiPage.group_by_directory(nil)).to eq({})
expect(WikiPage.group_by_directory([])).to eq({})
end end
end end
context 'when there are pages' do context 'when there are pages' do
let!(:page_1) { create_page('page_1', 'content') } before do
let!(:page_2) { create_page('directory/page_2', 'content') } create_page('page_1', 'content')
let(:pages) { [page_1, page_2] } create_page('dir_1/page_2', 'content')
create_page('dir_1/dir_2/page_3', 'content')
end
it 'returns a hash in which keys are directories and values are their pages' do
page_1 = wiki.find_page('page_1')
page_2 = wiki.find_page('dir_1/page_2')
page_3 = wiki.find_page('dir_1/dir_2/page_3')
expected_grouped_pages = {
'/' => [page_1], 'dir_1' => [page_2], 'dir_1/dir_2' => [page_3]
}
xit 'returns a hash in which keys are directories and values are their pages' do grouped_pages = WikiPage.group_by_directory(wiki.pages)
expected_grouped_pages = { 'root' => [page_1], 'directory' => [page_2] }
grouped_pages.each do |dir, pages|
expected_slugs = expected_grouped_pages.fetch(dir).map(&:slug)
slugs = pages.map(&:slug)
expect(slugs).to match_array(expected_slugs)
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment