Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
083442bc
Commit
083442bc
authored
Dec 17, 2016
by
Alex Braha Stoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for WikiPage.group_by_directory
parent
8bf52a4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
6 deletions
+24
-6
spec/models/wiki_page_spec.rb
spec/models/wiki_page_spec.rb
+24
-6
No files found.
spec/models/wiki_page_spec.rb
View file @
083442bc
...
...
@@ -7,19 +7,37 @@ describe WikiPage, models: true do
subject
{
WikiPage
.
new
(
wiki
)
}
describe
'
::
group_by_directory'
do
describe
'
.
group_by_directory'
do
context
'when there are no pages'
do
it
'returns an empty hash'
do
expect
(
WikiPage
.
group_by_directory
(
nil
)).
to
eq
({})
expect
(
WikiPage
.
group_by_directory
([])).
to
eq
({})
end
end
context
'when there are pages'
do
let!
(
:page_1
)
{
create_page
(
'page_1'
,
'content'
)
}
let!
(
:page_2
)
{
create_page
(
'directory/page_2'
,
'content'
)
}
let
(
:pages
)
{
[
page_1
,
page_2
]
}
before
do
create_page
(
'page_1'
,
'content'
)
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
expected_grouped_pages
=
{
'root'
=>
[
page_1
],
'directory'
=>
[
page_2
]
}
grouped_pages
=
WikiPage
.
group_by_directory
(
wiki
.
pages
)
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment