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
c3d9d3ca
Commit
c3d9d3ca
authored
Nov 10, 2017
by
Jarka Kadlecova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor spec code
parent
b440e0fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
71 deletions
+46
-71
spec/ee/spec/services/epic_issues/create_service_spec.rb
spec/ee/spec/services/epic_issues/create_service_spec.rb
+46
-71
No files found.
spec/ee/spec/services/epic_issues/create_service_spec.rb
View file @
c3d9d3ca
...
@@ -7,12 +7,35 @@ describe EpicIssues::CreateService do
...
@@ -7,12 +7,35 @@ describe EpicIssues::CreateService do
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
let
(
:user
)
{
create
:user
}
let
(
:user
)
{
create
:user
}
let
(
:reference
)
{
issue
.
to_reference
(
full:
true
)
}
let
(
:valid_reference
)
{
issue
.
to_reference
(
full:
true
)
}
let
(
:params
)
do
{}
def
assign_issue
(
references
)
params
=
{
issue_references:
references
}
described_class
.
new
(
epic
,
user
,
params
).
execute
end
shared_examples
'returns success'
do
it
'creates relationships'
do
expect
{
subject
}.
to
change
(
EpicIssue
,
:count
).
from
(
0
).
to
(
1
)
expect
(
EpicIssue
.
find_by!
(
issue_id:
issue
.
id
)).
to
have_attributes
(
epic:
epic
)
end
it
'returns success status'
do
expect
(
subject
).
to
eq
(
status: :success
)
end
end
end
subject
{
described_class
.
new
(
epic
,
user
,
params
).
execute
}
shared_examples
'returns an error'
do
it
'returns an error'
do
expect
(
subject
).
to
eq
(
message:
'No Issue found for given params'
,
status: :error
,
http_status:
404
)
end
it
'no relationship is created'
do
expect
{
subject
}.
not_to
change
{
EpicIssue
.
count
}
end
end
context
'when user has permissions to link the issue'
do
context
'when user has permissions to link the issue'
do
before
do
before
do
...
@@ -20,83 +43,39 @@ describe EpicIssues::CreateService do
...
@@ -20,83 +43,39 @@ describe EpicIssues::CreateService do
end
end
context
'when the reference list is empty'
do
context
'when the reference list is empty'
do
let
(
:params
)
do
it
'returns an error'
do
{
issue_references:
[]
}
expect
(
assign_issue
([])).
to
eq
(
message:
'No Issue found for given params'
,
status: :error
,
http_status:
404
)
end
it
'returns error'
do
is_expected
.
to
eq
(
message:
'No Issue found for given params'
,
status: :error
,
http_status:
404
)
end
end
end
end
context
'when there is an issue to relate'
do
context
'when there is an issue to relate'
do
context
'when shortcut for Issue is given'
do
context
'when shortcut for Issue is given'
do
let
(
:params
)
do
subject
{
assign_issue
([
issue
.
to_reference
])
}
{
issue_references:
[
issue
.
to_reference
]
}
end
it
'returns error'
do
is_expected
.
to
eq
(
message:
'No Issue found for given params'
,
status: :error
,
http_status:
404
)
end
it
'no relationship is created'
do
include_examples
'returns an error'
expect
{
subject
}.
not_to
change
{
EpicIssue
.
count
}
end
end
end
context
'when a full reference is given'
do
context
'when a full reference is given'
do
let
(
:params
)
do
subject
{
assign_issue
([
valid_reference
])
}
{
issue_references:
[
reference
]
}
end
it
'creates relationships'
do
expect
{
subject
}.
to
change
(
EpicIssue
,
:count
).
from
(
0
).
to
(
1
)
expect
(
EpicIssue
.
find_by!
(
issue_id:
issue
.
id
)).
to
have_attributes
(
epic:
epic
)
end
it
'returns success status'
do
include_examples
'returns success'
is_expected
.
to
eq
(
status: :success
)
end
end
end
context
'when an issue links is given'
do
context
'when an issue links is given'
do
let
(
:params
)
do
subject
{
assign_issue
([
IssuesHelper
.
url_for_issue
(
issue
.
iid
,
issue
.
project
)])
}
{
issue_references:
[
IssuesHelper
.
url_for_issue
(
issue
.
iid
,
issue
.
project
)]
}
end
it
'creates relationships'
do
include_examples
'returns success'
expect
{
subject
}.
to
change
(
EpicIssue
,
:count
).
from
(
0
).
to
(
1
)
expect
(
EpicIssue
.
find_by!
(
issue_id:
issue
.
id
)).
to
have_attributes
(
epic:
epic
)
end
it
'returns success status'
do
is_expected
.
to
eq
(
status: :success
)
end
end
end
end
end
end
end
context
'when user does not have permissions to link the issue'
do
context
'when user does not have permissions to link the issue'
do
let
(
:params
)
do
subject
{
assign_issue
([
valid_reference
])
}
{
issue_references:
[
reference
]
}
end
it
'returns error'
do
is_expected
.
to
eq
(
message:
'No Issue found for given params'
,
status: :error
,
http_status:
404
)
end
it
'no relationship is created'
do
include_examples
'returns an error'
expect
{
subject
}.
not_to
change
{
EpicIssue
.
count
}
end
end
end
context
'when an issue is already assigned to another epic'
do
context
'when an issue is already assigned to another epic'
do
let
(
:params
)
do
{
issue_references:
[
reference
]
}
end
before
do
before
do
group
.
add_developer
(
user
)
group
.
add_developer
(
user
)
create
(
:epic_issue
,
epic:
epic
,
issue:
issue
)
create
(
:epic_issue
,
epic:
epic
,
issue:
issue
)
...
@@ -104,14 +83,18 @@ describe EpicIssues::CreateService do
...
@@ -104,14 +83,18 @@ describe EpicIssues::CreateService do
let
(
:another_epic
)
{
create
(
:epic
,
group:
group
)
}
let
(
:another_epic
)
{
create
(
:epic
,
group:
group
)
}
subject
{
described_class
.
new
(
another_epic
,
user
,
params
).
execute
}
subject
do
params
=
{
issue_references:
[
valid_reference
]
}
described_class
.
new
(
another_epic
,
user
,
params
).
execute
end
it
'does not create a new association'
do
it
'does not create a new association'
do
expect
{
subject
}.
not_to
change
(
EpicIssue
,
:count
).
from
(
1
)
expect
{
subject
}.
not_to
change
(
EpicIssue
,
:count
).
from
(
1
)
end
end
it
'updates the existing association'
do
it
'updates the existing association'
do
expect
{
subject
}.
to
change
{
EpicIssue
.
find_by!
(
issue_id:
issue
.
id
)
.
epic
}.
from
(
epic
).
to
(
another_epic
)
expect
{
subject
}.
to
change
{
EpicIssue
.
last
.
epic
}.
from
(
epic
).
to
(
another_epic
)
end
end
it
'returns success status'
do
it
'returns success status'
do
...
@@ -120,24 +103,16 @@ describe EpicIssues::CreateService do
...
@@ -120,24 +103,16 @@ describe EpicIssues::CreateService do
end
end
context
'when issue from non group project is given'
do
context
'when issue from non group project is given'
do
let
(
:another_issue
)
{
create
:issue
}
subject
{
assign_issue
([
another_issue
.
to_reference
(
full:
true
)])
}
let
(
:params
)
do
let
(
:another_issue
)
{
create
:issue
}
{
issue_references:
[
another_issue
.
to_reference
(
full:
true
)]
}
end
before
do
before
do
group
.
add_developer
(
user
)
group
.
add_developer
(
user
)
another_issue
.
project
.
add_developer
(
user
)
another_issue
.
project
.
add_developer
(
user
)
end
end
it
'returns error'
do
include_examples
'returns an error'
is_expected
.
to
eq
(
message:
'No Issue found for given params'
,
status: :error
,
http_status:
404
)
end
it
'no relationship is created'
do
expect
{
subject
}.
not_to
change
{
EpicIssue
.
count
}
end
end
end
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