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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
49dc5e3c
Commit
49dc5e3c
authored
Jul 28, 2020
by
ddash2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First Commit
parent
d52bcf32
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
7 deletions
+62
-7
app/controllers/concerns/wiki_actions.rb
app/controllers/concerns/wiki_actions.rb
+4
-2
app/services/wiki_pages/create_service.rb
app/services/wiki_pages/create_service.rb
+5
-1
lib/api/wikis.rb
lib/api/wikis.rb
+3
-2
locale/gitlab.pot
locale/gitlab.pot
+3
-0
spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb
...ared_examples/controllers/wiki_actions_shared_examples.rb
+38
-0
spec/support/shared_examples/services/wiki_pages/create_service_shared_examples.rb
...les/services/wiki_pages/create_service_shared_examples.rb
+9
-2
No files found.
app/controllers/concerns/wiki_actions.rb
View file @
49dc5e3c
...
...
@@ -111,14 +111,16 @@ module WikiActions
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def
create
@page
=
WikiPages
::
CreateService
.
new
(
container:
container
,
current_user:
current_user
,
params:
wiki_params
).
execute
response
=
WikiPages
::
CreateService
.
new
(
container:
container
,
current_user:
current_user
,
params:
wiki_params
).
execute
@page
=
response
.
payload
[
:page
]
if
page
.
persisted
?
if
response
.
success
?
redirect_to
(
wiki_page_path
(
wiki
,
page
),
notice:
_
(
'Wiki was successfully updated.'
)
)
else
flash
[
:alert
]
=
response
.
message
render
'shared/wikis/edit'
end
rescue
Gitlab
::
Git
::
Wiki
::
OperationError
=>
e
...
...
app/services/wiki_pages/create_service.rb
View file @
49dc5e3c
...
...
@@ -10,7 +10,11 @@ module WikiPages
execute_hooks
(
page
)
end
page
if
page
.
persisted?
ServiceResponse
.
success
(
payload:
{
page:
page
})
else
ServiceResponse
.
error
(
message:
_
(
'Could not create wiki page'
),
payload:
{
page:
page
})
end
end
def
usage_counter_action
...
...
lib/api/wikis.rb
View file @
49dc5e3c
...
...
@@ -61,9 +61,10 @@ module API
post
':id/wikis'
do
authorize!
:create_wiki
,
container
page
=
WikiPages
::
CreateService
.
new
(
container:
container
,
current_user:
current_user
,
params:
params
).
execute
response
=
WikiPages
::
CreateService
.
new
(
container:
container
,
current_user:
current_user
,
params:
params
).
execute
page
=
response
.
payload
[
:page
]
if
page
.
valid
?
if
response
.
success
?
present
page
,
with:
Entities
::
WikiPage
else
render_validation_error!
(
page
)
...
...
locale/gitlab.pot
View file @
49dc5e3c
...
...
@@ -6922,6 +6922,9 @@ msgstr ""
msgid "Could not create project"
msgstr ""
msgid "Could not create wiki page"
msgstr ""
msgid "Could not delete %{design}. Please try again."
msgstr ""
...
...
spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb
View file @
49dc5e3c
...
...
@@ -355,6 +355,44 @@ RSpec.shared_examples 'wiki controller actions' do
end
end
describe
'POST #create'
do
let
(
:new_title
)
{
'New title'
}
let
(
:new_content
)
{
'New content'
}
subject
do
post
(
:create
,
params:
routing_params
.
merge
(
wiki:
{
title:
new_title
,
content:
new_content
}
))
end
context
'when page is valid'
do
it
'creates the page'
do
expect
do
subject
end
.
to
change
{
wiki
.
list_pages
.
size
}.
by
1
wiki_page
=
wiki
.
find_page
(
new_title
)
expect
(
wiki_page
.
title
).
to
eq
new_title
expect
(
wiki_page
.
content
).
to
eq
new_content
end
end
context
'when page is not valid'
do
let
(
:new_title
)
{
''
}
it
'renders the edit state'
do
expect
do
subject
end
.
not_to
change
{
wiki
.
list_pages
.
size
}
expect
(
response
).
to
render_template
(
'shared/wikis/edit'
)
expect
(
flash
[
:alert
]).
to
eq
(
'Could not create wiki page'
)
end
end
end
def
redirect_to_wiki
(
wiki
,
page
)
redirect_to
(
controller
.
wiki_page_path
(
wiki
,
page
))
end
...
...
spec/support/shared_examples/services/wiki_pages/create_service_shared_examples.rb
View file @
49dc5e3c
...
...
@@ -16,8 +16,10 @@ RSpec.shared_examples 'WikiPages::CreateService#execute' do |container_type|
subject
(
:service
)
{
described_class
.
new
(
container:
container
,
current_user:
user
,
params:
opts
)
}
it
'creates wiki page with valid attributes'
do
page
=
service
.
execute
response
=
service
.
execute
page
=
response
.
payload
[
:page
]
expect
(
response
).
to
be_success
expect
(
page
).
to
be_valid
expect
(
page
).
to
be_persisted
expect
(
page
.
title
).
to
eq
(
opts
[
:title
])
...
...
@@ -77,7 +79,12 @@ RSpec.shared_examples 'WikiPages::CreateService#execute' do |container_type|
end
it
'reports the error'
do
expect
(
service
.
execute
).
to
be_invalid
response
=
service
.
execute
page
=
response
.
payload
[
:page
]
expect
(
response
).
to
be_error
expect
(
page
).
to
be_invalid
.
and
have_attributes
(
errors:
be_present
)
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