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
c8356813
Commit
c8356813
authored
Apr 20, 2020
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add exportable getter/setter to Vulnerabilities::Export model
parent
8c90aba2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
12 deletions
+69
-12
ee/app/models/vulnerabilities/export.rb
ee/app/models/vulnerabilities/export.rb
+16
-2
ee/spec/factories/vulnerabilities/exports.rb
ee/spec/factories/vulnerabilities/exports.rb
+5
-0
ee/spec/models/vulnerabilities/export_spec.rb
ee/spec/models/vulnerabilities/export_spec.rb
+48
-10
No files found.
ee/app/models/vulnerabilities/export.rb
View file @
c8356813
...
@@ -16,8 +16,6 @@ module Vulnerabilities
...
@@ -16,8 +16,6 @@ module Vulnerabilities
csv:
0
csv:
0
}
}
validates
:project
,
presence:
true
,
unless: :group
validates
:group
,
presence:
true
,
unless: :project
validates
:status
,
presence:
true
validates
:status
,
presence:
true
validates
:format
,
presence:
true
validates
:format
,
presence:
true
validates
:file
,
presence:
true
,
if: :finished?
validates
:file
,
presence:
true
,
if: :finished?
...
@@ -49,6 +47,22 @@ module Vulnerabilities
...
@@ -49,6 +47,22 @@ module Vulnerabilities
end
end
end
end
def
exportable
project
||
author
end
def
exportable
=
(
value
)
case
value
when
Project
self
.
project
=
value
when
User
self
.
project
=
nil
self
.
author
=
value
else
raise
"Can not assign
#{
value
.
class
}
as exportable"
end
end
def
completed?
def
completed?
finished?
||
failed?
finished?
||
failed?
end
end
...
...
ee/spec/factories/vulnerabilities/exports.rb
View file @
c8356813
...
@@ -38,5 +38,10 @@ FactoryBot.define do
...
@@ -38,5 +38,10 @@ FactoryBot.define do
project
{
nil
}
project
{
nil
}
group
group
end
end
trait
:user
do
project
{
nil
}
group
{
nil
}
end
end
end
end
end
ee/spec/models/vulnerabilities/export_spec.rb
View file @
c8356813
...
@@ -23,16 +23,6 @@ describe Vulnerabilities::Export do
...
@@ -23,16 +23,6 @@ describe Vulnerabilities::Export do
it
{
is_expected
.
to
validate_presence_of
(
:file
)
}
it
{
is_expected
.
to
validate_presence_of
(
:file
)
}
end
end
context
'when the group is not set'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
end
context
'when the project is not set'
do
subject
{
build
(
:vulnerability_export
,
:group
)
}
it
{
is_expected
.
to
validate_presence_of
(
:group
)
}
end
end
end
describe
'#status'
do
describe
'#status'
do
...
@@ -77,6 +67,54 @@ describe Vulnerabilities::Export do
...
@@ -77,6 +67,54 @@ describe Vulnerabilities::Export do
end
end
end
end
describe
'#exportable'
do
subject
{
vulnerability_export
.
exportable
}
context
'when the export has project assigned'
do
let
(
:project
)
{
build
(
:project
)
}
let
(
:vulnerability_export
)
{
build
(
:vulnerability_export
,
project:
project
)
}
it
{
is_expected
.
to
eql
(
project
)
}
end
context
'when the export does not have project assigned'
do
let
(
:author
)
{
build
(
:user
)
}
let
(
:vulnerability_export
)
{
build
(
:vulnerability_export
,
:user
,
author:
author
)
}
it
{
is_expected
.
to
eql
(
author
)
}
end
end
describe
'#exportable='
do
let
(
:vulnerability_export
)
{
build
(
:vulnerability_export
)
}
subject
(
:set_exportable
)
{
vulnerability_export
.
exportable
=
exportable
}
context
'when the exportable is a Project'
do
let
(
:exportable
)
{
build
(
:project
)
}
it
'changes the exportable of the export to given project'
do
expect
{
set_exportable
}.
to
change
{
vulnerability_export
.
exportable
}.
to
(
exportable
)
end
end
context
'when the exportable is a User'
do
let
(
:exportable
)
{
build
(
:user
)
}
it
'changes the exportable of the export to given user'
do
expect
{
set_exportable
}.
to
change
{
vulnerability_export
.
exportable
}.
to
(
exportable
)
end
end
context
'when the exportable is a String'
do
let
(
:exportable
)
{
'Foo'
}
it
'raises an exception'
do
expect
{
set_exportable
}.
to
raise_error
(
RuntimeError
)
end
end
end
describe
'#completed?'
do
describe
'#completed?'
do
context
'when status is created'
do
context
'when status is created'
do
subject
{
build
(
:vulnerability_export
,
:created
)
}
subject
{
build
(
:vulnerability_export
,
:created
)
}
...
...
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