summaryrefslogtreecommitdiff
path: root/spec/models/wiki_page_spec.rb
diff options
context:
space:
mode:
authorIgor <idrozdov@gitlab.com>2019-04-12 13:25:17 +0000
committerDouwe Maan <douwe@gitlab.com>2019-04-12 13:25:17 +0000
commitcfb94bca6f804c0dc762c5df2ed0a2c0d7c4c973 (patch)
treeb052d191a73155b141ee77f93a4290e2523a7558 /spec/models/wiki_page_spec.rb
parent004e8627218dc7621b5ff2e66b2b510c0afdcefc (diff)
downloadgitlab-ce-cfb94bca6f804c0dc762c5df2ed0a2c0d7c4c973.tar.gz
Fix grouping wiki pages by directory
If a page has the same name as a directory the WikiPage#group_by_directory method can have a wrong behaviour This commit fixes it
Diffstat (limited to 'spec/models/wiki_page_spec.rb')
-rw-r--r--spec/models/wiki_page_spec.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb
index cacdb0e0595..d5c85c11195 100644
--- a/spec/models/wiki_page_spec.rb
+++ b/spec/models/wiki_page_spec.rb
@@ -22,6 +22,7 @@ describe WikiPage do
create_page('dir_1/dir_1_1/page_3', 'content')
create_page('page_1', 'content')
create_page('dir_1/page_2', 'content')
+ create_page('dir_2', 'page with dir name')
create_page('dir_2/page_5', 'content')
create_page('page_6', 'content')
create_page('dir_2/page_4', 'content')
@@ -29,6 +30,7 @@ describe WikiPage do
let(:page_1) { wiki.find_page('page_1') }
let(:page_6) { wiki.find_page('page_6') }
+ let(:page_dir_2) { wiki.find_page('dir_2') }
let(:dir_1) do
WikiDirectory.new('dir_1', [wiki.find_page('dir_1/page_2')])
@@ -44,7 +46,7 @@ describe WikiPage do
context 'sort by title' do
let(:grouped_entries) { described_class.group_by_directory(wiki.pages) }
- let(:expected_grouped_entries) { [dir_1_1, dir_1, dir_2, page_1, page_6] }
+ let(:expected_grouped_entries) { [dir_1_1, dir_1, page_dir_2, dir_2, page_1, page_6] }
it 'returns an array with pages and directories' do
grouped_entries.each_with_index do |page_or_dir, i|
@@ -59,7 +61,7 @@ describe WikiPage do
context 'sort by created_at' do
let(:grouped_entries) { described_class.group_by_directory(wiki.pages(sort: 'created_at')) }
- let(:expected_grouped_entries) { [dir_1_1, page_1, dir_1, dir_2, page_6] }
+ let(:expected_grouped_entries) { [dir_1_1, page_1, dir_1, page_dir_2, dir_2, page_6] }
it 'returns an array with pages and directories' do
grouped_entries.each_with_index do |page_or_dir, i|
@@ -73,7 +75,7 @@ describe WikiPage do
end
it 'returns an array with retained order with directories at the top' do
- expected_order = ['dir_1/dir_1_1/page_3', 'dir_1/page_2', 'dir_2/page_4', 'dir_2/page_5', 'page_1', 'page_6']
+ expected_order = ['dir_1/dir_1_1/page_3', 'dir_1/page_2', 'dir_2', 'dir_2/page_4', 'dir_2/page_5', 'page_1', 'page_6']
grouped_entries = described_class.group_by_directory(wiki.pages)