Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
b10c05e7
Unverified
Commit
b10c05e7
authored
1 year ago
by
Daniel M Brasil
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Migrate to request specs in `/api/v1/lists` (#25443)
parent
8b2048d0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
spec/controllers/api/v1/lists_controller_spec.rb
+0
-80
0 additions, 80 deletions
spec/controllers/api/v1/lists_controller_spec.rb
spec/requests/api/v1/lists_spec.rb
+247
-0
247 additions, 0 deletions
spec/requests/api/v1/lists_spec.rb
with
247 additions
and
80 deletions
spec/controllers/api/v1/lists_controller_spec.rb
deleted
100644 → 0
+
0
−
80
View file @
8b2048d0
# frozen_string_literal: true
require
'rails_helper'
RSpec
.
describe
Api
::
V1
::
ListsController
do
render_views
let!
(
:user
)
{
Fabricate
(
:user
)
}
let!
(
:token
)
{
Fabricate
(
:accessible_access_token
,
resource_owner_id:
user
.
id
,
scopes:
scopes
)
}
let!
(
:list
)
{
Fabricate
(
:list
,
account:
user
.
account
)
}
before
{
allow
(
controller
).
to
receive
(
:doorkeeper_token
)
{
token
}
}
describe
'GET #index'
do
let
(
:scopes
)
{
'read:lists'
}
it
'returns http success'
do
get
:index
expect
(
response
).
to
have_http_status
(
200
)
end
end
describe
'GET #show'
do
let
(
:scopes
)
{
'read:lists'
}
it
'returns http success'
do
get
:show
,
params:
{
id:
list
.
id
}
expect
(
response
).
to
have_http_status
(
200
)
end
end
describe
'POST #create'
do
let
(
:scopes
)
{
'write:lists'
}
before
do
post
:create
,
params:
{
title:
'Foo bar'
}
end
it
'returns http success'
do
expect
(
response
).
to
have_http_status
(
200
)
end
it
'creates list'
do
expect
(
List
.
where
(
account:
user
.
account
).
count
).
to
eq
2
expect
(
List
.
last
.
title
).
to
eq
'Foo bar'
end
end
describe
'PUT #update'
do
let
(
:scopes
)
{
'write:lists'
}
before
do
put
:update
,
params:
{
id:
list
.
id
,
title:
'Updated title'
}
end
it
'returns http success'
do
expect
(
response
).
to
have_http_status
(
200
)
end
it
'updates the list'
do
expect
(
list
.
reload
.
title
).
to
eq
'Updated title'
end
end
describe
'DELETE #destroy'
do
let
(
:scopes
)
{
'write:lists'
}
before
do
delete
:destroy
,
params:
{
id:
list
.
id
}
end
it
'returns http success'
do
expect
(
response
).
to
have_http_status
(
200
)
end
it
'deletes the list'
do
expect
(
List
.
find_by
(
id:
list
.
id
)).
to
be_nil
end
end
end
This diff is collapsed.
Click to expand it.
spec/requests/api/v1/lists_spec.rb
0 → 100644
+
247
−
0
View file @
b10c05e7
# frozen_string_literal: true
require
'rails_helper'
RSpec
.
describe
'Lists'
do
let
(
:user
)
{
Fabricate
(
:user
)
}
let
(
:token
)
{
Fabricate
(
:accessible_access_token
,
resource_owner_id:
user
.
id
,
scopes:
scopes
)
}
let
(
:scopes
)
{
'read:lists write:lists'
}
let
(
:headers
)
{
{
'Authorization'
=>
"Bearer
#{
token
.
token
}
"
}
}
describe
'GET /api/v1/lists'
do
subject
do
get
'/api/v1/lists'
,
headers:
headers
end
let!
(
:lists
)
do
[
Fabricate
(
:list
,
account:
user
.
account
,
title:
'first list'
,
replies_policy: :followed
),
Fabricate
(
:list
,
account:
user
.
account
,
title:
'second list'
,
replies_policy: :list
),
Fabricate
(
:list
,
account:
user
.
account
,
title:
'third list'
,
replies_policy: :none
),
Fabricate
(
:list
,
account:
user
.
account
,
title:
'fourth list'
,
exclusive:
true
),
]
end
let
(
:expected_response
)
do
lists
.
map
do
|
list
|
{
id:
list
.
id
.
to_s
,
title:
list
.
title
,
replies_policy:
list
.
replies_policy
,
exclusive:
list
.
exclusive
,
}
end
end
before
do
Fabricate
(
:list
)
end
it_behaves_like
'forbidden for wrong scope'
,
'write write:lists'
it
'returns http success'
do
subject
expect
(
response
).
to
have_http_status
(
200
)
end
it
'returns the expected lists'
do
subject
expect
(
body_as_json
).
to
match_array
(
expected_response
)
end
end
describe
'GET /api/v1/lists/:id'
do
subject
do
get
"/api/v1/lists/
#{
list
.
id
}
"
,
headers:
headers
end
let
(
:list
)
{
Fabricate
(
:list
,
account:
user
.
account
)
}
it_behaves_like
'forbidden for wrong scope'
,
'write write:lists'
it
'returns http success'
do
subject
expect
(
response
).
to
have_http_status
(
200
)
end
it
'returns the requested list correctly'
do
subject
expect
(
body_as_json
).
to
eq
({
id:
list
.
id
.
to_s
,
title:
list
.
title
,
replies_policy:
list
.
replies_policy
,
exclusive:
list
.
exclusive
,
})
end
context
'when the list belongs to a different user'
do
let
(
:list
)
{
Fabricate
(
:list
)
}
it
'returns http not found'
do
subject
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'when the list does not exist'
do
it
'returns http not found'
do
get
'/api/v1/lists/-1'
,
headers:
headers
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
'POST /api/v1/lists'
do
subject
do
post
'/api/v1/lists'
,
headers:
headers
,
params:
params
end
let
(
:params
)
{
{
title:
'my list'
,
replies_policy:
'none'
,
exclusive:
'true'
}
}
it_behaves_like
'forbidden for wrong scope'
,
'read read:lists'
it
'returns http success'
do
subject
expect
(
response
).
to
have_http_status
(
200
)
end
it
'returns the new list'
do
subject
expect
(
body_as_json
).
to
match
(
a_hash_including
(
title:
'my list'
,
replies_policy:
'none'
,
exclusive:
true
))
end
it
'creates a list'
do
subject
expect
(
List
.
where
(
account:
user
.
account
).
count
).
to
eq
(
1
)
end
context
'when a title is not given'
do
let
(
:params
)
{
{
title:
''
}
}
it
'returns http unprocessable entity'
do
subject
expect
(
response
).
to
have_http_status
(
422
)
end
end
context
'when the given replies_policy is invalid'
do
let
(
:params
)
{
{
title:
'a list'
,
replies_policy:
'whatever'
}
}
it
'returns http unprocessable entity'
do
subject
expect
(
response
).
to
have_http_status
(
422
)
end
end
end
describe
'PUT /api/v1/lists/:id'
do
subject
do
put
"/api/v1/lists/
#{
list
.
id
}
"
,
headers:
headers
,
params:
params
end
let
(
:list
)
{
Fabricate
(
:list
,
account:
user
.
account
,
title:
'my list'
)
}
let
(
:params
)
{
{
title:
'list'
,
replies_policy:
'followed'
,
exclusive:
'true'
}
}
it_behaves_like
'forbidden for wrong scope'
,
'read read:lists'
it
'returns http success'
do
subject
expect
(
response
).
to
have_http_status
(
200
)
end
it
'returns the updated list'
do
subject
list
.
reload
expect
(
body_as_json
).
to
eq
({
id:
list
.
id
.
to_s
,
title:
list
.
title
,
replies_policy:
list
.
replies_policy
,
exclusive:
list
.
exclusive
,
})
end
it
'updates the list title'
do
expect
{
subject
}.
to
change
{
list
.
reload
.
title
}.
from
(
'my list'
).
to
(
'list'
)
end
it
'updates the list replies_policy'
do
expect
{
subject
}.
to
change
{
list
.
reload
.
replies_policy
}.
from
(
'list'
).
to
(
'followed'
)
end
it
'updates the list exclusive'
do
expect
{
subject
}.
to
change
{
list
.
reload
.
exclusive
}.
from
(
false
).
to
(
true
)
end
context
'when the list does not exist'
do
it
'returns http not found'
do
put
'/api/v1/lists/-1'
,
headers:
headers
,
params:
params
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'when the list belongs to another user'
do
let
(
:list
)
{
Fabricate
(
:list
)
}
it
'returns http not found'
do
subject
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
'DELETE /api/v1/lists/:id'
do
subject
do
delete
"/api/v1/lists/
#{
list
.
id
}
"
,
headers:
headers
end
let
(
:list
)
{
Fabricate
(
:list
,
account:
user
.
account
)
}
it_behaves_like
'forbidden for wrong scope'
,
'read read:lists'
it
'returns http success'
do
subject
expect
(
response
).
to
have_http_status
(
200
)
end
it
'deletes the list'
do
subject
expect
(
List
.
where
(
id:
list
.
id
)).
to_not
exist
end
context
'when the list does not exist'
do
it
'returns http not found'
do
delete
'/api/v1/lists/-1'
,
headers:
headers
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'when the list belongs to another user'
do
let
(
:list
)
{
Fabricate
(
:list
)
}
it
'returns http not found'
do
subject
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment