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
a2187cb2
Commit
a2187cb2
authored
Jul 15, 2020
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorganize resource state events api specs
Fix some incorrect specs and move the shared example inline
parent
822883b0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
104 deletions
+99
-104
spec/finders/resource_state_event_finder_spec.rb
spec/finders/resource_state_event_finder_spec.rb
+17
-21
spec/requests/api/resource_state_events_spec.rb
spec/requests/api/resource_state_events_spec.rb
+82
-3
spec/support/shared_examples/requests/api/resource_state_events_api_shared_examples.rb
...requests/api/resource_state_events_api_shared_examples.rb
+0
-80
No files found.
spec/finders/resource_state_event_finder_spec.rb
View file @
a2187cb2
...
@@ -4,39 +4,35 @@ require 'spec_helper'
...
@@ -4,39 +4,35 @@ require 'spec_helper'
RSpec
.
describe
ResourceStateEventFinder
do
RSpec
.
describe
ResourceStateEventFinder
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:issue_project
)
{
create
(
:project
)
}
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
issue_project
)
}
describe
'#execute'
do
describe
'#execute'
do
subject
{
described_class
.
new
(
user
,
issue
).
execute
}
subject
{
described_class
.
new
(
user
,
issue
).
execute
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let!
(
:event
)
{
create
(
:resource_state_event
,
issue:
issue
)
}
it
'returns events accessible by user'
do
it
'returns events accessible by user'
do
event
=
create
(
:resource_state_event
,
issue:
issue
)
project
.
add_guest
(
user
)
issue_project
.
add_guest
(
user
)
expect
(
subject
).
to
eq
[
event
]
expect
(
subject
).
to
eq
[
event
]
end
end
it
'filters events if issues and MRs are private'
do
context
'when issues are private'
do
project
=
create
(
:project
,
:public
,
:issues_private
,
:merge_requests_private
)
let
(
:project
)
{
create
(
:project
,
:public
,
:issues_private
)
}
issue
=
create
(
:issue
,
project:
project
)
merge_request
=
create
(
:merge_request
,
source_project:
project
)
create
(
:resource_state_event
,
issue:
issue
)
create
(
:resource_state_event
,
merge_request:
merge_request
)
expect
(
subject
).
to
be_empty
it
'does not return any events'
do
expect
(
subject
).
to
be_empty
end
end
end
it
'filters events not accessible by user'
do
context
'when issue is not accesible to the user'
do
project
=
create
(
:project
,
:private
)
let
(
:project
)
{
create
(
:project
,
:private
)
}
issue
=
create
(
:issue
,
project:
project
)
merge_request
=
create
(
:merge_request
,
source_project:
project
)
create
(
:resource_state_event
,
issue:
issue
)
create
(
:resource_state_event
,
merge_request:
merge_request
)
expect
(
subject
).
to
be_empty
it
'does not return any events'
do
expect
(
subject
).
to
be_empty
end
end
end
end
end
...
@@ -45,7 +41,7 @@ RSpec.describe ResourceStateEventFinder do
...
@@ -45,7 +41,7 @@ RSpec.describe ResourceStateEventFinder do
subject
{
described_class
.
new
(
user
,
eventable
).
can_read_eventable?
}
subject
{
described_class
.
new
(
user
,
eventable
).
can_read_eventable?
}
context
'when eventable is a Issue'
do
context
'when eventable is a
n
Issue'
do
let
(
:eventable
)
{
create
(
:issue
,
project:
project
)
}
let
(
:eventable
)
{
create
(
:issue
,
project:
project
)
}
context
'when issue is readable'
do
context
'when issue is readable'
do
...
...
spec/requests/api/resource_state_events_spec.rb
View file @
a2187cb2
...
@@ -3,13 +3,92 @@
...
@@ -3,13 +3,92 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
API
::
ResourceStateEvents
do
RSpec
.
describe
API
::
ResourceStateEvents
do
let
!
(
:user
)
{
create
(
:user
)
}
let
_it_be
(
:user
)
{
create
(
:user
)
}
let
!
(
:project
)
{
create
(
:project
,
:public
,
namespace:
user
.
namespace
)
}
let
_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
:public
,
namespace:
user
.
namespace
)
}
before
do
before
_all
do
project
.
add_developer
(
user
)
project
.
add_developer
(
user
)
end
end
shared_examples
'resource_state_events API'
do
|
parent_type
,
eventable_type
,
id_name
|
describe
"GET /
#{
parent_type
}
/:id/
#{
eventable_type
}
/:noteable_id/resource_state_events"
do
let!
(
:event
)
{
create_event
}
it
"returns an array of resource state events"
do
url
=
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events"
get
api
(
url
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
event
.
id
)
expect
(
json_response
.
first
[
'state'
]).
to
eq
(
event
.
state
.
to_s
)
end
it
"returns a 404 error when eventable id not found"
do
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
non_existing_record_id
}
/resource_state_events"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
it
"returns 404 when not authorized"
do
parent
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
private_user
=
create
(
:user
)
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events"
,
private_user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
describe
"GET /
#{
parent_type
}
/:id/
#{
eventable_type
}
/:noteable_id/resource_state_events/:event_id"
do
let!
(
:event
)
{
create_event
}
it
"returns a resource state event by id"
do
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events/
#{
event
.
id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'id'
]).
to
eq
(
event
.
id
)
expect
(
json_response
[
'state'
]).
to
eq
(
event
.
state
.
to_s
)
end
it
"returns 404 when not authorized"
do
parent
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
private_user
=
create
(
:user
)
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events/
#{
event
.
id
}
"
,
private_user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
it
"returns a 404 error if resource state event not found"
do
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events/
#{
non_existing_record_id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
describe
'pagination'
do
# https://gitlab.com/gitlab-org/gitlab/-/issues/220192
it
'returns the second page'
do
create_event
event2
=
create_event
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events?page=2&per_page=1"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
include_pagination_headers
expect
(
response
.
headers
[
'X-Total'
]).
to
eq
'2'
expect
(
json_response
.
count
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
event2
.
id
)
end
end
def
create_event
(
state: :opened
)
create
(
:resource_state_event
,
eventable
.
class
.
name
.
underscore
=>
eventable
,
state:
state
)
end
end
context
'when eventable is an Issue'
do
context
'when eventable is an Issue'
do
it_behaves_like
'resource_state_events API'
,
'projects'
,
'issues'
,
'iid'
do
it_behaves_like
'resource_state_events API'
,
'projects'
,
'issues'
,
'iid'
do
let
(
:parent
)
{
project
}
let
(
:parent
)
{
project
}
...
...
spec/support/shared_examples/requests/api/resource_state_events_api_shared_examples.rb
deleted
100644 → 0
View file @
822883b0
# frozen_string_literal: true
RSpec
.
shared_examples
'resource_state_events API'
do
|
parent_type
,
eventable_type
,
id_name
|
describe
"GET /
#{
parent_type
}
/:id/
#{
eventable_type
}
/:noteable_id/resource_state_events"
do
let!
(
:event
)
{
create_event
}
it
"returns an array of resource state events"
do
url
=
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events"
get
api
(
url
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
event
.
id
)
expect
(
json_response
.
first
[
'state'
]).
to
eq
(
event
.
state
.
to_s
)
end
it
"returns a 404 error when eventable id not found"
do
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
non_existing_record_id
}
/resource_state_events"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
it
"returns 404 when not authorized"
do
parent
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
private_user
=
create
(
:user
)
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events"
,
private_user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
describe
"GET /
#{
parent_type
}
/:id/
#{
eventable_type
}
/:noteable_id/resource_state_events/:event_id"
do
let!
(
:event
)
{
create_event
}
it
"returns a resource state event by id"
do
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events/
#{
event
.
id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'id'
]).
to
eq
(
event
.
id
)
expect
(
json_response
[
'state'
]).
to
eq
(
event
.
state
.
to_s
)
end
it
"returns 404 when not authorized"
do
parent
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
private_user
=
create
(
:user
)
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events/
#{
event
.
id
}
"
,
private_user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
it
"returns a 404 error if resource state event not found"
do
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events/
#{
non_existing_record_id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
describe
'pagination'
do
# https://gitlab.com/gitlab-org/gitlab/-/issues/220192
it
'returns the second page'
do
create_event
event2
=
create_event
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
eventable_type
}
/
#{
eventable
[
id_name
]
}
/resource_state_events?page=2&per_page=1"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
include_pagination_headers
expect
(
response
.
headers
[
'X-Total'
]).
to
eq
'2'
expect
(
json_response
.
count
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
event2
.
id
)
end
end
def
create_event
(
state: :opened
)
create
(
:resource_state_event
,
eventable
.
class
.
name
.
underscore
=>
eventable
,
state:
state
)
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