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
e0be98cf
Commit
e0be98cf
authored
May 31, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a push event on Geo event log when wiki is updated through UI
parent
d8bd743e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
104 additions
and
39 deletions
+104
-39
app/services/wiki_pages/base_service.rb
app/services/wiki_pages/base_service.rb
+10
-0
app/services/wiki_pages/create_service.rb
app/services/wiki_pages/create_service.rb
+1
-0
app/services/wiki_pages/destroy_service.rb
app/services/wiki_pages/destroy_service.rb
+1
-3
app/services/wiki_pages/update_service.rb
app/services/wiki_pages/update_service.rb
+1
-0
spec/services/wiki_pages/create_service_spec.rb
spec/services/wiki_pages/create_service_spec.rb
+31
-13
spec/services/wiki_pages/destroy_service_spec.rb
spec/services/wiki_pages/destroy_service_spec.rb
+28
-9
spec/services/wiki_pages/update_service_spec.rb
spec/services/wiki_pages/update_service_spec.rb
+32
-14
No files found.
app/services/wiki_pages/base_service.rb
View file @
e0be98cf
...
...
@@ -21,5 +21,15 @@ module WikiPages
@project
.
execute_hooks
(
page_data
,
:wiki_page_hooks
)
@project
.
execute_services
(
page_data
,
:wiki_page_hooks
)
end
def
process_wiki_changes
if
Gitlab
::
Geo
.
primary?
# Create wiki update event on Geo event log
Geo
::
PushEventStore
.
new
(
project
,
source:
Geo
::
PushEvent
::
WIKI
).
create
# Triggers repository update on secondary nodes
Gitlab
::
Geo
.
notify_wiki_update
(
project
)
end
end
end
end
app/services/wiki_pages/create_service.rb
View file @
e0be98cf
...
...
@@ -6,6 +6,7 @@ module WikiPages
if
page
.
create
(
@params
)
execute_hooks
(
page
,
'create'
)
process_wiki_changes
end
page
...
...
app/services/wiki_pages/destroy_service.rb
View file @
e0be98cf
...
...
@@ -3,9 +3,7 @@ module WikiPages
def
execute
(
page
)
if
page
&
.
delete
execute_hooks
(
page
,
'delete'
)
# Triggers repository update on secondary nodes when Geo is enabled
Gitlab
::
Geo
.
notify_wiki_update
(
project
)
if
Gitlab
::
Geo
.
primary?
process_wiki_changes
end
page
...
...
app/services/wiki_pages/update_service.rb
View file @
e0be98cf
...
...
@@ -3,6 +3,7 @@ module WikiPages
def
execute
(
page
)
if
page
.
update
(
@params
[
:content
],
@params
[
:format
],
@params
[
:message
])
execute_hooks
(
page
,
'update'
)
process_wiki_changes
end
page
...
...
spec/services/wiki_pages/create_service_spec.rb
View file @
e0be98cf
...
...
@@ -2,7 +2,8 @@ require 'spec_helper'
describe
WikiPages
::
CreateService
,
services:
true
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:opts
)
do
{
title:
'Title'
,
...
...
@@ -10,26 +11,43 @@ describe WikiPages::CreateService, services: true do
format:
'markdown'
}
end
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
opts
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
,
opts
)
}
before
do
project
.
add_master
(
user
)
end
describe
'#execute'
do
context
"valid params"
do
it
'creates wiki page with valid attributes'
do
page
=
service
.
execute
expect
(
page
).
to
be_valid
expect
(
page
).
to
have_attributes
(
title:
opts
[
:title
],
content:
opts
[
:content
],
format:
opts
[
:format
].
to_sym
)
end
it
'executes webhooks'
do
expect
(
service
).
to
receive
(
:execute_hooks
).
once
.
with
(
instance_of
(
WikiPage
),
'create'
)
service
.
execute
end
context
'when running on a Geo primary node'
do
before
do
allow
(
service
).
to
receive
(
:execute_hooks
)
project
.
add_master
(
user
)
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
true
}
end
subject
{
service
.
execute
}
it
'triggers Geo::PushEventStore when Geo is enabled'
do
expect
(
Geo
::
PushEventStore
).
to
receive
(
:new
).
with
(
instance_of
(
Project
),
source:
Geo
::
PushEvent
::
WIKI
).
and_call_original
expect_any_instance_of
(
Geo
::
PushEventStore
).
to
receive
(
:create
)
it
'creates a valid wiki page'
do
is_expected
.
to
be_valid
expect
(
subject
.
title
).
to
eq
(
opts
[
:title
])
expect
(
subject
.
content
).
to
eq
(
opts
[
:content
])
expect
(
subject
.
format
).
to
eq
(
opts
[
:format
].
to_sym
)
service
.
execute
end
it
'executes webhooks'
do
expect
(
service
).
to
have_received
(
:execute_hooks
).
once
.
with
(
subject
,
'create'
)
it
'triggers wiki update on secondary nodes'
do
expect
(
Gitlab
::
Geo
).
to
receive
(
:notify_wiki_update
).
with
(
instance_of
(
Project
))
service
.
execute
end
end
end
...
...
spec/services/wiki_pages/destroy_service_spec.rb
View file @
e0be98cf
...
...
@@ -2,20 +2,39 @@ require 'spec_helper'
describe
WikiPages
::
DestroyService
,
services:
true
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:wiki_page
)
{
create
(
:wiki_page
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:page
)
{
create
(
:wiki_page
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
before
do
project
.
add_master
(
user
)
end
describe
'#execute'
do
before
do
allow
(
service
).
to
receive
(
:execute_hooks
)
project
.
add_master
(
user
)
it
'executes webhooks'
do
expect
(
service
).
to
receive
(
:execute_hooks
).
once
.
with
(
instance_of
(
WikiPage
),
'delete'
)
service
.
execute
(
page
)
end
it
'executes webhooks'
do
service
.
execute
(
wiki_page
)
context
'when running on a Geo primary node'
do
before
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
true
}
end
it
'triggers Geo::PushEventStore when Geo is enabled'
do
expect
(
Geo
::
PushEventStore
).
to
receive
(
:new
).
with
(
instance_of
(
Project
),
source:
Geo
::
PushEvent
::
WIKI
).
and_call_original
expect_any_instance_of
(
Geo
::
PushEventStore
).
to
receive
(
:create
)
service
.
execute
(
page
)
end
it
'triggers wiki update on secondary nodes'
do
expect
(
Gitlab
::
Geo
).
to
receive
(
:notify_wiki_update
).
with
(
instance_of
(
Project
))
expect
(
service
).
to
have_received
(
:execute_hooks
).
once
.
with
(
wiki_page
,
'delete'
)
service
.
execute
(
page
)
end
end
end
end
spec/services/wiki_pages/update_service_spec.rb
View file @
e0be98cf
...
...
@@ -2,8 +2,9 @@ require 'spec_helper'
describe
WikiPages
::
UpdateService
,
services:
true
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:wiki_page
)
{
create
(
:wiki_page
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:page
)
{
create
(
:wiki_page
)
}
let
(
:opts
)
do
{
content:
'New content for wiki page'
,
...
...
@@ -11,26 +12,43 @@ describe WikiPages::UpdateService, services: true do
message:
'New wiki message'
}
end
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
opts
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
,
opts
)
}
before
do
project
.
add_master
(
user
)
end
describe
'#execute'
do
context
"valid params"
do
it
'updates the wiki page'
do
updated_page
=
service
.
execute
(
page
)
expect
(
updated_page
).
to
be_valid
expect
(
updated_page
).
to
have_attributes
(
message:
opts
[
:message
],
content:
opts
[
:content
],
format:
opts
[
:format
].
to_sym
)
end
it
'executes webhooks'
do
expect
(
service
).
to
receive
(
:execute_hooks
).
once
.
with
(
instance_of
(
WikiPage
),
'update'
)
service
.
execute
(
page
)
end
context
'when running on a Geo primary node'
do
before
do
allow
(
service
).
to
receive
(
:execute_hooks
)
project
.
add_master
(
user
)
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
true
}
end
subject
{
service
.
execute
(
wiki_page
)
}
it
'triggers Geo::PushEventStore when Geo is enabled'
do
expect
(
Geo
::
PushEventStore
).
to
receive
(
:new
).
with
(
instance_of
(
Project
),
source:
Geo
::
PushEvent
::
WIKI
).
and_call_original
expect_any_instance_of
(
Geo
::
PushEventStore
).
to
receive
(
:create
)
it
'updates the wiki page'
do
is_expected
.
to
be_valid
expect
(
subject
.
content
).
to
eq
(
opts
[
:content
])
expect
(
subject
.
format
).
to
eq
(
opts
[
:format
].
to_sym
)
expect
(
subject
.
message
).
to
eq
(
opts
[
:message
])
service
.
execute
(
page
)
end
it
'executes webhooks'
do
expect
(
service
).
to
have_received
(
:execute_hooks
).
once
.
with
(
subject
,
'update'
)
it
'triggers wiki update on secondary nodes'
do
expect
(
Gitlab
::
Geo
).
to
receive
(
:notify_wiki_update
).
with
(
instance_of
(
Project
))
service
.
execute
(
page
)
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