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
092b4d52
Commit
092b4d52
authored
May 30, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move issue link controller specs to :requests
parent
6cac6152
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
152 additions
and
0 deletions
+152
-0
spec/requests/projects/issue_links_controller_spec.rb
spec/requests/projects/issue_links_controller_spec.rb
+152
-0
No files found.
spec/
controller
s/projects/issue_links_controller_spec.rb
→
spec/
request
s/projects/issue_links_controller_spec.rb
View file @
092b4d52
require
'rails_helper'
describe
Projects
::
IssueLinksController
,
type: :controller
do
describe
Projects
::
IssueLinksController
do
let
(
:user
)
{
create
:user
}
let
(
:project
)
{
create
(
:project_empty_repo
)
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
...
...
@@ -10,66 +10,58 @@ describe Projects::IssueLinksController, type: :controller do
allow_any_instance_of
(
License
).
to
receive
(
:feature_available?
).
with
(
:related_issues
)
{
true
}
end
describe
'GET
#index
'
do
let
(
:
service
)
{
double
(
IssueLinks
::
ListService
,
execute:
service_response
)
}
let
(
:service_response
)
{
[{
'foo'
=>
'bar'
}]
}
describe
'GET
/*namespace_id/:project_id/issues/:issue_id/links
'
do
let
(
:
issue_b
)
{
create
:issue
,
project:
project
}
let
!
(
:issue_link
)
{
create
:issue_link
,
source:
issue
,
target:
issue_b
}
before
do
project
.
team
<<
[
user
,
:guest
]
sign_in
user
allow
(
IssueLinks
::
ListService
).
to
receive
(
:new
)
.
with
(
issue
,
user
)
.
and_return
(
service
)
login_as
user
end
subject
do
get
:index
,
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
format: :json
get
namespace_project_issue_links_path
(
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
format: :json
)
end
it
'returns JSON response'
do
is_expected
.
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
(
service_response
)
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
subject
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
(
list_service_response
.
as_json
)
end
end
describe
'POST #create'
do
let
(
:service
)
{
double
(
IssueLinks
::
CreateService
,
execute:
service_response
)
}
let
(
:list_service
)
{
double
(
IssueLinks
::
ListService
,
execute:
list_service_response
)
}
let
(
:service_response
)
{
{
message:
'yay'
,
status: :success
}
}
let
(
:list_service_response
)
{
[{
'foo'
=>
'bar'
}]
}
let
(
:issue_references
)
{
double
}
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let
(
:user_role
)
{
:developer
}
before
do
project
.
team
<<
[
user
,
user_role
]
sign_in
user
allow
(
IssueLinks
::
ListService
).
to
receive
(
:new
)
.
with
(
issue
,
user
)
.
and_return
(
list_service
)
allow
(
IssueLinks
::
CreateService
).
to
receive
(
:new
)
.
with
(
issue
,
user
,
{
issue_references:
issue_references
})
.
and_return
(
service
)
login_as
user
end
subject
do
post
:create
,
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
issue_references:
issue_references
,
format: :json
post
namespace_project_issue_links_path
(
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
issue_references:
[
issue_b
.
to_reference
]
,
format: :json
)
end
context
'with success'
do
it
'returns success JSON'
do
is_expected
.
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
(
'result'
=>
{
'message'
=>
'yay'
,
'status'
=>
'success'
},
'issues'
=>
list_service_response
)
subject
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'result'
]).
to
eq
(
'message'
=>
"
#{
issue_b
.
to_reference
}
was successfully related"
,
'status'
=>
'success'
)
expect
(
json_response
[
'issues'
]).
to
eq
(
list_service_response
.
as_json
)
end
end
...
...
@@ -78,17 +70,25 @@ describe Projects::IssueLinksController, type: :controller do
let
(
:user_role
)
{
:guest
}
it
'returns 403'
do
is_expected
.
to
have_http_status
(
403
)
subject
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
'when failing service result'
do
let
(
:
service_response
)
{
{
http_status:
401
,
status:
'error'
}
}
let
(
:
issue_b
)
{
issue
}
it
'returns failure JSON'
do
is_expected
.
to
have_http_status
(
401
)
expect
(
json_response
).
to
eq
(
'result'
=>
{
'http_status'
=>
401
,
'status'
=>
'error'
},
'issues'
=>
list_service_response
)
subject
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
expect
(
response
).
to
have_http_status
(
401
)
expect
(
json_response
[
'result'
]).
to
eq
(
'message'
=>
"Validation failed: Source issue cannot be related to itself"
,
'status'
=>
'error'
,
'http_status'
=>
401
)
expect
(
json_response
[
'issues'
]).
to
eq
(
list_service_response
.
as_json
)
end
end
end
...
...
@@ -97,31 +97,19 @@ describe Projects::IssueLinksController, type: :controller do
describe
'DELETE #destroy'
do
let
(
:referenced_issue
)
{
create
:issue
,
project:
project
}
let
(
:issue_link
)
{
create
:issue_link
,
target:
referenced_issue
}
let
(
:service
)
{
double
(
IssueLinks
::
DestroyService
,
execute:
service_response
)
}
let
(
:list_service
)
{
double
(
IssueLinks
::
ListService
,
execute:
list_service_response
)
}
let
(
:service_response
)
{
{
'message'
=>
'yay'
}
}
let
(
:list_service_response
)
{
[{
'foo'
=>
'bar'
}]
}
let
(
:current_project_user_role
)
{
:developer
}
subject
do
delete
:destroy
,
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
id:
issue_link
,
format: :json
delete
namespace_project_issue_link_path
(
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
id:
issue_link
.
id
,
format: :json
)
end
before
do
project
.
team
<<
[
user
,
current_project_user_role
]
sign_in
user
allow
(
IssueLinks
::
ListService
).
to
receive
(
:new
)
.
with
(
issue
,
user
)
.
and_return
(
list_service
)
allow
(
IssueLinks
::
DestroyService
).
to
receive
(
:new
)
.
with
(
issue_link
,
user
)
.
and_return
(
service
)
login_as
user
end
context
'when unauthorized'
do
...
...
@@ -129,16 +117,21 @@ describe Projects::IssueLinksController, type: :controller do
let
(
:current_project_user_role
)
{
:guest
}
it
'returns 403'
do
is_expected
.
to
have_http_status
(
403
)
subject
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
'when no authorization on the related issue project'
do
# unauthorized project issue
let
(
:referenced_issue
)
{
create
:issue
}
let
(
:current_project_user_role
)
{
:developer
}
it
'returns 403'
do
is_expected
.
to
have_http_status
(
403
)
subject
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
...
...
@@ -147,8 +140,12 @@ describe Projects::IssueLinksController, type: :controller do
let
(
:current_project_user_role
)
{
:developer
}
it
'returns success JSON'
do
is_expected
.
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
(
'result'
=>
service_response
,
'issues'
=>
list_service_response
)
subject
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
expect
(
json_response
[
'result'
]).
to
eq
(
'message'
=>
'Relation was removed'
,
'status'
=>
'success'
)
expect
(
json_response
[
'issues'
]).
to
eq
(
list_service_response
.
as_json
)
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