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
0d478400
Commit
0d478400
authored
Aug 06, 2020
by
Arturo Herrero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use RSpec parameterized syntax
parent
7b8ed2c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
34 deletions
+21
-34
spec/models/service_spec.rb
spec/models/service_spec.rb
+21
-34
No files found.
spec/models/service_spec.rb
View file @
0d478400
...
...
@@ -11,45 +11,32 @@ RSpec.describe Service do
end
describe
'validations'
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:type
)
}
it
'validates presence of project_id if not template, instance or group_id'
,
:aggregate_failures
do
expect
(
build
(
:service
,
project_id:
nil
,
template:
true
)).
to
be_valid
expect
(
build
(
:service
,
project_id:
nil
,
instance:
true
)).
to
be_valid
expect
(
build
(
:service
,
project_id:
nil
,
group_id:
group
.
id
)).
to
be_valid
expect
(
build
(
:service
,
project_id:
nil
,
template:
false
)).
to
be_invalid
expect
(
build
(
:service
,
project_id:
nil
,
instance:
false
)).
to
be_invalid
expect
(
build
(
:service
,
project_id:
nil
,
group_id:
nil
)).
to
be_invalid
end
it
'validates presence of group_id if not template, instance or project_id'
,
:aggregate_failures
do
expect
(
build
(
:service
,
group_id:
nil
,
project_id:
nil
,
template:
true
)).
to
be_valid
expect
(
build
(
:service
,
group_id:
nil
,
project_id:
nil
,
instance:
true
)).
to
be_valid
expect
(
build
(
:service
,
group_id:
nil
,
project_id:
project
.
id
)).
to
be_valid
expect
(
build
(
:service
,
group_id:
nil
,
project_id:
nil
,
template:
false
)).
to
be_invalid
expect
(
build
(
:service
,
group_id:
nil
,
project_id:
nil
,
instance:
false
)).
to
be_invalid
expect
(
build
(
:service
,
group_id:
nil
,
project_id:
nil
)).
to
be_invalid
end
it
'validates absence of project_id if instance or template'
,
:aggregate_failures
do
expect
(
build
(
:service
,
instance:
true
)).
to
validate_absence_of
(
:project_id
)
expect
(
build
(
:service
,
template:
true
)).
to
validate_absence_of
(
:project_id
)
expect
(
build
(
:service
,
instance:
false
)).
not_to
validate_absence_of
(
:project_id
)
expect
(
build
(
:service
,
template:
false
)).
not_to
validate_absence_of
(
:project_id
)
end
it
'validates absence of group_id if instance or template'
,
:aggregate_failures
do
expect
(
build
(
:service
,
instance:
true
)).
to
validate_absence_of
(
:group_id
)
expect
(
build
(
:service
,
template:
true
)).
to
validate_absence_of
(
:group_id
)
expect
(
build
(
:service
,
instance:
false
)).
not_to
validate_absence_of
(
:group_id
)
expect
(
build
(
:service
,
template:
false
)).
not_to
validate_absence_of
(
:group_id
)
end
it
'validates service is template or instance'
do
expect
(
build
(
:service
,
project_id:
nil
,
template:
true
,
instance:
true
)).
to
be_invalid
# We need to use a Proc object because let variables are not available on
# this context, see: https://github.com/tomykaira/rspec-parameterized/issues/8
where
(
:project_id
,
:group_id
,
:template
,
:instance
,
:valid
)
do
->
{
project
.
id
}
|
nil
|
false
|
false
|
true
nil
|
->
{
group
.
id
}
|
false
|
false
|
true
nil
|
nil
|
true
|
false
|
true
nil
|
nil
|
false
|
true
|
true
nil
|
nil
|
false
|
false
|
false
nil
|
nil
|
true
|
true
|
false
->
{
project
.
id
}
|
nil
|
true
|
false
|
false
->
{
project
.
id
}
|
nil
|
false
|
true
|
false
nil
|
->
{
group
.
id
}
|
true
|
false
|
false
nil
|
->
{
group
.
id
}
|
false
|
true
|
false
end
with_them
do
it
'validates the service'
do
expect
(
build
(
:service
,
project_id:
project_id
.
try
(
:call
),
group_id:
group_id
.
try
(
:call
),
template:
template
,
instance:
instance
).
valid?
).
to
eq
(
valid
)
end
end
context
'with an existing service template'
do
...
...
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