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
a616b475
Commit
a616b475
authored
Dec 20, 2016
by
Mark Fletcher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for WikiPages services
* Alter wiki_pages factory with custom creation operation
parent
109e8ef4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
0 deletions
+91
-0
spec/factories/wiki_pages.rb
spec/factories/wiki_pages.rb
+18
-0
spec/services/wiki_pages/create_service_spec.rb
spec/services/wiki_pages/create_service_spec.rb
+36
-0
spec/services/wiki_pages/update_service_spec.rb
spec/services/wiki_pages/update_service_spec.rb
+37
-0
No files found.
spec/factories/wiki_pages.rb
View file @
a616b475
...
@@ -2,8 +2,26 @@ require 'ostruct'
...
@@ -2,8 +2,26 @@ require 'ostruct'
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:wiki_page
do
factory
:wiki_page
do
transient
do
attrs
do
{
title:
'Title'
,
content:
'Content for wiki page'
,
format:
'markdown'
}
end
end
page
{
OpenStruct
.
new
(
url_path:
'some-name'
)
}
page
{
OpenStruct
.
new
(
url_path:
'some-name'
)
}
association
:wiki
,
factory: :project_wiki
,
strategy: :build
association
:wiki
,
factory: :project_wiki
,
strategy: :build
initialize_with
{
new
(
wiki
,
page
,
true
)
}
initialize_with
{
new
(
wiki
,
page
,
true
)
}
before
(
:create
)
do
|
page
,
evaluator
|
page
.
attributes
=
evaluator
.
attrs
end
to_create
do
|
page
|
page
.
create
end
end
end
end
end
spec/services/wiki_pages/create_service_spec.rb
0 → 100644
View file @
a616b475
require
'spec_helper'
describe
WikiPages
::
CreateService
,
services:
true
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:opts
)
do
{
title:
'Title'
,
content:
'Content for wiki page'
,
format:
'markdown'
}
end
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
opts
)
}
describe
'#execute'
do
context
"valid params"
do
before
do
allow
(
service
).
to
receive
(
:execute_hooks
)
project
.
add_master
(
user
)
end
subject
{
service
.
execute
}
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
)
end
it
'executes webhooks'
do
expect
(
service
).
to
have_received
(
:execute_hooks
).
once
.
with
(
subject
,
'create'
)
end
end
end
end
spec/services/wiki_pages/update_service_spec.rb
0 → 100644
View file @
a616b475
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
(
:opts
)
do
{
content:
'New content for wiki page'
,
format:
'markdown'
,
message:
'New wiki message'
}
end
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
opts
)
}
describe
'#execute'
do
context
"valid params"
do
before
do
allow
(
service
).
to
receive
(
:execute_hooks
)
project
.
add_master
(
user
)
end
subject
{
service
.
execute
(
wiki_page
)
}
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
])
end
it
'executes webhooks'
do
expect
(
service
).
to
have_received
(
:execute_hooks
).
once
.
with
(
subject
,
'update'
)
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