Commit 10ad2f77 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'paginate-all-the-things' into 'master'

Paginate all the things

Closes #8099

See merge request !8606
parents 827a56a4 ce54a801
---
title: 'API: Paginate all endpoints that return an array'
merge_request: 8606
author: Robert Schilling
...@@ -24,3 +24,4 @@ changes are in V4: ...@@ -24,3 +24,4 @@ changes are in V4:
- `/dockerfiles/:key` - `/dockerfiles/:key`
- Moved `/projects/fork/:id` to `/projects/:id/fork` - Moved `/projects/fork/:id` to `/projects/:id/fork`
- Endpoints `/projects/owned`, `/projects/visible`, `/projects/starred` & `/projects/all` are consolidated into `/projects` using query parameters - Endpoints `/projects/owned`, `/projects/visible`, `/projects/starred` & `/projects/all` are consolidated into `/projects` using query parameters
- Return pagination headers for all endpoints that return an array
...@@ -5,13 +5,22 @@ module API ...@@ -5,13 +5,22 @@ module API
version %w(v3 v4), using: :path version %w(v3 v4), using: :path
version 'v3', using: :path do version 'v3', using: :path do
mount ::API::V3::Boards
mount ::API::V3::Branches
mount ::API::V3::DeployKeys mount ::API::V3::DeployKeys
mount ::API::V3::Issues mount ::API::V3::Issues
mount ::API::V3::Labels
mount ::API::V3::Members mount ::API::V3::Members
mount ::API::V3::MergeRequestDiffs
mount ::API::V3::MergeRequests mount ::API::V3::MergeRequests
mount ::API::V3::ProjectHooks
mount ::API::V3::Projects mount ::API::V3::Projects
mount ::API::V3::ProjectSnippets mount ::API::V3::ProjectSnippets
mount ::API::V3::Repositories
mount ::API::V3::SystemHooks
mount ::API::V3::Tags
mount ::API::V3::Templates mount ::API::V3::Templates
mount ::API::V3::Users
end end
before { allow_access_with_scope :api } before { allow_access_with_scope :api }
......
...@@ -28,8 +28,8 @@ module API ...@@ -28,8 +28,8 @@ module API
end end
get endpoint do get endpoint do
if can_read_awardable? if can_read_awardable?
awards = paginate(awardable.award_emoji) awards = awardable.award_emoji
present awards, with: Entities::AwardEmoji present paginate(awards), with: Entities::AwardEmoji
else else
not_found!("Award Emoji") not_found!("Award Emoji")
end end
......
module API module API
# Boards API
class Boards < Grape::API class Boards < Grape::API
include PaginationParams
before { authenticate! } before { authenticate! }
params do params do
...@@ -11,9 +12,12 @@ module API ...@@ -11,9 +12,12 @@ module API
detail 'This feature was introduced in 8.13' detail 'This feature was introduced in 8.13'
success Entities::Board success Entities::Board
end end
params do
use :pagination
end
get ':id/boards' do get ':id/boards' do
authorize!(:read_board, user_project) authorize!(:read_board, user_project)
present user_project.boards, with: Entities::Board present paginate(user_project.boards), with: Entities::Board
end end
params do params do
...@@ -40,9 +44,12 @@ module API ...@@ -40,9 +44,12 @@ module API
detail 'Does not include `done` list. This feature was introduced in 8.13' detail 'Does not include `done` list. This feature was introduced in 8.13'
success Entities::List success Entities::List
end end
params do
use :pagination
end
get '/lists' do get '/lists' do
authorize!(:read_board, user_project) authorize!(:read_board, user_project)
present board_lists, with: Entities::List present paginate(board_lists), with: Entities::List
end end
desc 'Get a list of a project board' do desc 'Get a list of a project board' do
......
require 'mime/types' require 'mime/types'
module API module API
# Projects API
class Branches < Grape::API class Branches < Grape::API
include PaginationParams
before { authenticate! } before { authenticate! }
before { authorize! :download_code, user_project } before { authorize! :download_code, user_project }
...@@ -13,10 +14,13 @@ module API ...@@ -13,10 +14,13 @@ module API
desc 'Get a project repository branches' do desc 'Get a project repository branches' do
success Entities::RepoBranch success Entities::RepoBranch
end end
params do
use :pagination
end
get ":id/repository/branches" do get ":id/repository/branches" do
branches = user_project.repository.branches.sort_by(&:name) branches = ::Kaminari.paginate_array(user_project.repository.branches.sort_by(&:name))
present branches, with: Entities::RepoBranch, project: user_project present paginate(branches), with: Entities::RepoBranch, project: user_project
end end
desc 'Get a single branch' do desc 'Get a single branch' do
......
module API module API
class DeployKeys < Grape::API class DeployKeys < Grape::API
include PaginationParams
before { authenticate! } before { authenticate! }
desc 'Return all deploy keys'
params do
use :pagination
end
get "deploy_keys" do get "deploy_keys" do
authenticated_as_admin! authenticated_as_admin!
keys = DeployKey.all present paginate(DeployKey.all), with: Entities::SSHKey
present keys, with: Entities::SSHKey
end end
params do params do
...@@ -18,8 +23,11 @@ module API ...@@ -18,8 +23,11 @@ module API
desc "Get a specific project's deploy keys" do desc "Get a specific project's deploy keys" do
success Entities::SSHKey success Entities::SSHKey
end end
params do
use :pagination
end
get ":id/deploy_keys" do get ":id/deploy_keys" do
present user_project.deploy_keys, with: Entities::SSHKey present paginate(user_project.deploy_keys), with: Entities::SSHKey
end end
desc 'Get single deploy key' do desc 'Get single deploy key' do
......
module API module API
# Projects API
class Files < Grape::API class Files < Grape::API
helpers do helpers do
def commit_params(attrs) def commit_params(attrs)
......
...@@ -2,7 +2,7 @@ module API ...@@ -2,7 +2,7 @@ module API
module Helpers module Helpers
module Pagination module Pagination
def paginate(relation) def paginate(relation)
relation.page(params[:page]).per(params[:per_page].to_i).tap do |data| relation.page(params[:page]).per(params[:per_page]).tap do |data|
add_pagination_headers(data) add_pagination_headers(data)
end end
end end
......
module API module API
# Labels API
class Labels < Grape::API class Labels < Grape::API
include PaginationParams
before { authenticate! } before { authenticate! }
params do params do
...@@ -10,8 +11,11 @@ module API ...@@ -10,8 +11,11 @@ module API
desc 'Get all labels of the project' do desc 'Get all labels of the project' do
success Entities::Label success Entities::Label
end end
params do
use :pagination
end
get ':id/labels' do get ':id/labels' do
present available_labels, with: Entities::Label, current_user: current_user, project: user_project present paginate(available_labels), with: Entities::Label, current_user: current_user, project: user_project
end end
desc 'Create a new label' do desc 'Create a new label' do
......
module API module API
# MergeRequestDiff API # MergeRequestDiff API
class MergeRequestDiffs < Grape::API class MergeRequestDiffs < Grape::API
include PaginationParams
before { authenticate! } before { authenticate! }
resource :projects do resource :projects do
...@@ -12,12 +14,12 @@ module API ...@@ -12,12 +14,12 @@ module API
params do params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
requires :merge_request_id, type: Integer, desc: 'The ID of a merge request' requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
use :pagination
end end
get ":id/merge_requests/:merge_request_id/versions" do get ":id/merge_requests/:merge_request_id/versions" do
merge_request = find_merge_request_with_access(params[:merge_request_id]) merge_request = find_merge_request_with_access(params[:merge_request_id])
present merge_request.merge_request_diffs, with: Entities::MergeRequestDiff present paginate(merge_request.merge_request_diffs), with: Entities::MergeRequestDiff
end end
desc 'Get a single merge request diff version' do desc 'Get a single merge request diff version' do
......
...@@ -119,8 +119,9 @@ module API ...@@ -119,8 +119,9 @@ module API
end end
get ':id/merge_requests/:merge_request_id/commits' do get ':id/merge_requests/:merge_request_id/commits' do
merge_request = find_merge_request_with_access(params[:merge_request_id]) merge_request = find_merge_request_with_access(params[:merge_request_id])
commits = ::Kaminari.paginate_array(merge_request.commits)
present merge_request.commits, with: Entities::RepoCommit present paginate(commits), with: Entities::RepoCommit
end end
desc 'Show the merge request changes' do desc 'Show the merge request changes' do
......
...@@ -15,8 +15,8 @@ module API ...@@ -15,8 +15,8 @@ module API
included do included do
helpers do helpers do
params :pagination do params :pagination do
optional :page, type: Integer, desc: 'Current page number' optional :page, type: Integer, default: 1, desc: 'Current page number'
optional :per_page, type: Integer, desc: 'Number of items per page' optional :per_page, type: Integer, default: 20, desc: 'Number of items per page'
end end
end end
end end
......
...@@ -32,9 +32,7 @@ module API ...@@ -32,9 +32,7 @@ module API
use :pagination use :pagination
end end
get ":id/hooks" do get ":id/hooks" do
hooks = paginate user_project.hooks present paginate(user_project.hooks), with: Entities::ProjectHook
present hooks, with: Entities::ProjectHook
end end
desc 'Get a project hook' do desc 'Get a project hook' do
......
...@@ -2,6 +2,8 @@ require 'mime/types' ...@@ -2,6 +2,8 @@ require 'mime/types'
module API module API
class Repositories < Grape::API class Repositories < Grape::API
include PaginationParams
before { authorize! :download_code, user_project } before { authorize! :download_code, user_project }
params do params do
...@@ -24,6 +26,7 @@ module API ...@@ -24,6 +26,7 @@ module API
optional :ref_name, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used' optional :ref_name, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used'
optional :path, type: String, desc: 'The path of the tree' optional :path, type: String, desc: 'The path of the tree'
optional :recursive, type: Boolean, default: false, desc: 'Used to get a recursive tree' optional :recursive, type: Boolean, default: false, desc: 'Used to get a recursive tree'
use :pagination
end end
get ':id/repository/tree' do get ':id/repository/tree' do
ref = params[:ref_name] || user_project.try(:default_branch) || 'master' ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
...@@ -33,8 +36,8 @@ module API ...@@ -33,8 +36,8 @@ module API
not_found!('Tree') unless commit not_found!('Tree') unless commit
tree = user_project.repository.tree(commit.id, path, recursive: params[:recursive]) tree = user_project.repository.tree(commit.id, path, recursive: params[:recursive])
entries = ::Kaminari.paginate_array(tree.sorted_entries)
present tree.sorted_entries, with: Entities::RepoTreeObject present paginate(entries), with: Entities::RepoTreeObject
end end
desc 'Get a raw file contents' desc 'Get a raw file contents'
...@@ -100,10 +103,13 @@ module API ...@@ -100,10 +103,13 @@ module API
desc 'Get repository contributors' do desc 'Get repository contributors' do
success Entities::Contributor success Entities::Contributor
end end
params do
use :pagination
end
get ':id/repository/contributors' do get ':id/repository/contributors' do
begin begin
present user_project.repository.contributors, contributors = ::Kaminari.paginate_array(user_project.repository.contributors)
with: Entities::Contributor present paginate(contributors), with: Entities::Contributor
rescue rescue
not_found! not_found!
end end
......
module API module API
# Hooks API
class SystemHooks < Grape::API class SystemHooks < Grape::API
include PaginationParams
before do before do
authenticate! authenticate!
authenticated_as_admin! authenticated_as_admin!
...@@ -10,10 +11,11 @@ module API ...@@ -10,10 +11,11 @@ module API
desc 'Get the list of system hooks' do desc 'Get the list of system hooks' do
success Entities::Hook success Entities::Hook
end end
params do
use :pagination
end
get do get do
hooks = SystemHook.all present paginate(SystemHook.all), with: Entities::Hook
present hooks, with: Entities::Hook
end end
desc 'Create a new system hook' do desc 'Create a new system hook' do
......
module API module API
# Git Tags API
class Tags < Grape::API class Tags < Grape::API
include PaginationParams
before { authorize! :download_code, user_project } before { authorize! :download_code, user_project }
params do params do
...@@ -10,9 +11,12 @@ module API ...@@ -10,9 +11,12 @@ module API
desc 'Get a project repository tags' do desc 'Get a project repository tags' do
success Entities::RepoTag success Entities::RepoTag
end end
params do
use :pagination
end
get ":id/repository/tags" do get ":id/repository/tags" do
present user_project.repository.tags.sort_by(&:name).reverse, tags = ::Kaminari.paginate_array(user_project.repository.tags.sort_by(&:name).reverse)
with: Entities::RepoTag, project: user_project present paginate(tags), with: Entities::RepoTag, project: user_project
end end
desc 'Get a single repository tag' do desc 'Get a single repository tag' do
......
module API module API
class Templates < Grape::API class Templates < Grape::API
include PaginationParams
GLOBAL_TEMPLATE_TYPES = { GLOBAL_TEMPLATE_TYPES = {
gitignores: { gitignores: {
klass: Gitlab::Template::GitignoreTemplate, klass: Gitlab::Template::GitignoreTemplate,
...@@ -51,12 +53,14 @@ module API ...@@ -51,12 +53,14 @@ module API
end end
params do params do
optional :popular, type: Boolean, desc: 'If passed, returns only popular licenses' optional :popular, type: Boolean, desc: 'If passed, returns only popular licenses'
use :pagination
end end
get "templates/licenses" do get "templates/licenses" do
options = { options = {
featured: declared(params).popular.present? ? true : nil featured: declared(params).popular.present? ? true : nil
} }
present Licensee::License.all(options), with: ::API::Entities::RepoLicense licences = ::Kaminari.paginate_array(Licensee::License.all(options))
present paginate(licences), with: Entities::RepoLicense
end end
desc 'Get the text for a specific license' do desc 'Get the text for a specific license' do
...@@ -82,8 +86,12 @@ module API ...@@ -82,8 +86,12 @@ module API
detail "This feature was introduced in GitLab #{gitlab_version}." detail "This feature was introduced in GitLab #{gitlab_version}."
success Entities::TemplatesList success Entities::TemplatesList
end end
params do
use :pagination
end
get "templates/#{template_type}" do get "templates/#{template_type}" do
present klass.all, with: Entities::TemplatesList templates = ::Kaminari.paginate_array(klass.all)
present paginate(templates), with: Entities::TemplatesList
end end
desc 'Get the text for a specific template present in local filesystem' do desc 'Get the text for a specific template present in local filesystem' do
......
...@@ -209,6 +209,7 @@ module API ...@@ -209,6 +209,7 @@ module API
end end
params do params do
requires :id, type: Integer, desc: 'The ID of the user' requires :id, type: Integer, desc: 'The ID of the user'
use :pagination
end end
get ':id/keys' do get ':id/keys' do
authenticated_as_admin! authenticated_as_admin!
...@@ -216,7 +217,7 @@ module API ...@@ -216,7 +217,7 @@ module API
user = User.find_by(id: params[:id]) user = User.find_by(id: params[:id])
not_found!('User') unless user not_found!('User') unless user
present user.keys, with: Entities::SSHKey present paginate(user.keys), with: Entities::SSHKey
end end
desc 'Delete an existing SSH key from a specified user. Available only for admins.' do desc 'Delete an existing SSH key from a specified user. Available only for admins.' do
...@@ -266,13 +267,14 @@ module API ...@@ -266,13 +267,14 @@ module API
end end
params do params do
requires :id, type: Integer, desc: 'The ID of the user' requires :id, type: Integer, desc: 'The ID of the user'
use :pagination
end end
get ':id/emails' do get ':id/emails' do
authenticated_as_admin! authenticated_as_admin!
user = User.find_by(id: params[:id]) user = User.find_by(id: params[:id])
not_found!('User') unless user not_found!('User') unless user
present user.emails, with: Entities::Email present paginate(user.emails), with: Entities::Email
end end
desc 'Delete an email address of a specified user. Available only for admins.' do desc 'Delete an email address of a specified user. Available only for admins.' do
...@@ -373,8 +375,11 @@ module API ...@@ -373,8 +375,11 @@ module API
desc "Get the currently authenticated user's SSH keys" do desc "Get the currently authenticated user's SSH keys" do
success Entities::SSHKey success Entities::SSHKey
end end
params do
use :pagination
end
get "keys" do get "keys" do
present current_user.keys, with: Entities::SSHKey present paginate(current_user.keys), with: Entities::SSHKey
end end
desc 'Get a single key owned by currently authenticated user' do desc 'Get a single key owned by currently authenticated user' do
...@@ -423,8 +428,11 @@ module API ...@@ -423,8 +428,11 @@ module API
desc "Get the currently authenticated user's email addresses" do desc "Get the currently authenticated user's email addresses" do
success Entities::Email success Entities::Email
end end
params do
use :pagination
end
get "emails" do get "emails" do
present current_user.emails, with: Entities::Email present paginate(current_user.emails), with: Entities::Email
end end
desc 'Get a single email address owned by the currently authenticated user' do desc 'Get a single email address owned by the currently authenticated user' do
......
module API
module V3
class Boards < Grape::API
before { authenticate! }
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
desc 'Get all project boards' do
detail 'This feature was introduced in 8.13'
success ::API::Entities::Board
end
get ':id/boards' do
authorize!(:read_board, user_project)
present user_project.boards, with: ::API::Entities::Board
end
params do
requires :board_id, type: Integer, desc: 'The ID of a board'
end
segment ':id/boards/:board_id' do
helpers do
def project_board
board = user_project.boards.first
if params[:board_id] == board.id
board
else
not_found!('Board')
end
end
def board_lists
project_board.lists.destroyable
end
end
desc 'Get the lists of a project board' do
detail 'Does not include `done` list. This feature was introduced in 8.13'
success ::API::Entities::List
end
get '/lists' do
authorize!(:read_board, user_project)
present board_lists, with: ::API::Entities::List
end
end
end
end
end
end
require 'mime/types'
module API
module V3
class Branches < Grape::API
before { authenticate! }
before { authorize! :download_code, user_project }
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
desc 'Get a project repository branches' do
success ::API::Entities::RepoBranch
end
get ":id/repository/branches" do
branches = user_project.repository.branches.sort_by(&:name)
present branches, with: ::API::Entities::RepoBranch, project: user_project
end
end
end
end
end
module API
module V3
class Labels < Grape::API
before { authenticate! }
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
desc 'Get all labels of the project' do
success ::API::Entities::Label
end
get ':id/labels' do
present available_labels, with: ::API::Entities::Label, current_user: current_user, project: user_project
end
end
end
end
end
require 'mime/types'
module API
module V3
class Repositories < Grape::API
before { authorize! :download_code, user_project }
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
helpers do
def handle_project_member_errors(errors)
if errors[:project_access].any?
error!(errors[:project_access], 422)
end
not_found!
end
end
desc 'Get a project repository tree' do
success ::API::Entities::RepoTreeObject
end
params do
optional :ref_name, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used'
optional :path, type: String, desc: 'The path of the tree'
optional :recursive, type: Boolean, default: false, desc: 'Used to get a recursive tree'
end
get ':id/repository/tree' do
ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
path = params[:path] || nil
commit = user_project.commit(ref)
not_found!('Tree') unless commit
tree = user_project.repository.tree(commit.id, path, recursive: params[:recursive])
present tree.sorted_entries, with: ::API::Entities::RepoTreeObject
end
desc 'Get repository contributors' do
success ::API::Entities::Contributor
end
get ':id/repository/contributors' do
begin
present user_project.repository.contributors,
with: ::API::Entities::Contributor
rescue
not_found!
end
end
end
end
end
end
module API
module V3
class SystemHooks < Grape::API
before do
authenticate!
authenticated_as_admin!
end
resource :hooks do
desc 'Get the list of system hooks' do
success ::API::Entities::Hook
end
get do
present SystemHook.all, with: ::API::Entities::Hook
end
end
end
end
end
module API
module V3
class Tags < Grape::API
before { authorize! :download_code, user_project }
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
desc 'Get a project repository tags' do
success ::API::Entities::RepoTag
end
get ":id/repository/tags" do
tags = user_project.repository.tags.sort_by(&:name).reverse
present tags, with: ::API::Entities::RepoTag, project: user_project
end
end
end
end
end
module API
module V3
class Users < Grape::API
include PaginationParams
before do
allow_access_with_scope :read_user if request.get?
authenticate!
end
resource :users, requirements: { uid: /[0-9]*/, id: /[0-9]*/ } do
desc 'Get the SSH keys of a specified user. Available only for admins.' do
success ::API::Entities::SSHKey
end
params do
requires :id, type: Integer, desc: 'The ID of the user'
use :pagination
end
get ':id/keys' do
authenticated_as_admin!
user = User.find_by(id: params[:id])
not_found!('User') unless user
present paginate(user.keys), with: ::API::Entities::SSHKey
end
desc 'Get the emails addresses of a specified user. Available only for admins.' do
success ::API::Entities::Email
end
params do
requires :id, type: Integer, desc: 'The ID of the user'
use :pagination
end
get ':id/emails' do
authenticated_as_admin!
user = User.find_by(id: params[:id])
not_found!('User') unless user
present user.emails, with: ::API::Entities::Email
end
end
resource :user do
desc "Get the currently authenticated user's SSH keys" do
success ::API::Entities::SSHKey
end
params do
use :pagination
end
get "keys" do
present current_user.keys, with: ::API::Entities::SSHKey
end
desc "Get the currently authenticated user's email addresses" do
success ::API::Entities::Email
end
get "emails" do
present current_user.emails, with: ::API::Entities::Email
end
end
end
end
end
...@@ -48,6 +48,7 @@ describe API::AccessRequests, api: true do ...@@ -48,6 +48,7 @@ describe API::AccessRequests, api: true do
get api("/#{source_type.pluralize}/#{source.id}/access_requests", master) get api("/#{source_type.pluralize}/#{source.id}/access_requests", master)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
end end
......
...@@ -34,6 +34,7 @@ describe API::AwardEmoji, api: true do ...@@ -34,6 +34,7 @@ describe API::AwardEmoji, api: true do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(downvote.name) expect(json_response.first['name']).to eq(downvote.name)
end end
......
...@@ -55,6 +55,7 @@ describe API::Boards, api: true do ...@@ -55,6 +55,7 @@ describe API::Boards, api: true do
get api(base_url, user) get api(base_url, user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(board.id) expect(json_response.first['id']).to eq(board.id)
...@@ -72,6 +73,7 @@ describe API::Boards, api: true do ...@@ -72,6 +73,7 @@ describe API::Boards, api: true do
get api(base_url, user) get api(base_url, user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['label']['name']).to eq(dev_label.title) expect(json_response.first['label']['name']).to eq(dev_label.title)
......
...@@ -17,8 +17,10 @@ describe API::Branches, api: true do ...@@ -17,8 +17,10 @@ describe API::Branches, api: true do
it "returns an array of project branches" do it "returns an array of project branches" do
project.repository.expire_all_method_caches project.repository.expire_all_method_caches
get api("/projects/#{project.id}/repository/branches", user) get api("/projects/#{project.id}/repository/branches", user), per_page: 100
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
branch_names = json_response.map { |x| x['name'] } branch_names = json_response.map { |x| x['name'] }
expect(branch_names).to match_array(project.repository.branch_names) expect(branch_names).to match_array(project.repository.branch_names)
......
...@@ -25,6 +25,7 @@ describe API::BroadcastMessages, api: true do ...@@ -25,6 +25,7 @@ describe API::BroadcastMessages, api: true do
get api('/broadcast_messages', admin) get api('/broadcast_messages', admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_kind_of(Array) expect(json_response).to be_kind_of(Array)
expect(json_response.first.keys) expect(json_response.first.keys)
.to match_array(%w(id message starts_at ends_at color font active)) .to match_array(%w(id message starts_at ends_at color font active))
......
...@@ -22,6 +22,7 @@ describe API::Builds, api: true do ...@@ -22,6 +22,7 @@ describe API::Builds, api: true do
context 'authorized user' do context 'authorized user' do
it 'returns project builds' do it 'returns project builds' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
end end
...@@ -97,6 +98,7 @@ describe API::Builds, api: true do ...@@ -97,6 +98,7 @@ describe API::Builds, api: true do
it 'returns project jobs for specific commit' do it 'returns project jobs for specific commit' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq 2 expect(json_response.size).to eq 2
end end
......
...@@ -54,7 +54,7 @@ describe API::CommitStatuses, api: true do ...@@ -54,7 +54,7 @@ describe API::CommitStatuses, api: true do
it 'returns all commit statuses' do it 'returns all commit statuses' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(statuses_id).to contain_exactly(status1.id, status2.id, expect(statuses_id).to contain_exactly(status1.id, status2.id,
status3.id, status4.id, status3.id, status4.id,
...@@ -67,7 +67,7 @@ describe API::CommitStatuses, api: true do ...@@ -67,7 +67,7 @@ describe API::CommitStatuses, api: true do
it 'returns latest commit statuses for specific ref' do it 'returns latest commit statuses for specific ref' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(statuses_id).to contain_exactly(status3.id, status5.id) expect(statuses_id).to contain_exactly(status3.id, status5.id)
end end
...@@ -78,7 +78,7 @@ describe API::CommitStatuses, api: true do ...@@ -78,7 +78,7 @@ describe API::CommitStatuses, api: true do
it 'return latest commit statuses for specific name' do it 'return latest commit statuses for specific name' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(statuses_id).to contain_exactly(status4.id, status5.id) expect(statuses_id).to contain_exactly(status4.id, status5.id)
end end
......
...@@ -456,6 +456,7 @@ describe API::Commits, api: true do ...@@ -456,6 +456,7 @@ describe API::Commits, api: true do
it 'returns merge_request comments' do it 'returns merge_request comments' do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['note']).to eq('a comment on a commit') expect(json_response.first['note']).to eq('a comment on a commit')
......
...@@ -35,6 +35,7 @@ describe API::DeployKeys, api: true do ...@@ -35,6 +35,7 @@ describe API::DeployKeys, api: true do
get api('/deploy_keys', admin) get api('/deploy_keys', admin)
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['id']).to eq(deploy_keys_project.deploy_key.id) expect(json_response.first['id']).to eq(deploy_keys_project.deploy_key.id)
end end
...@@ -48,6 +49,7 @@ describe API::DeployKeys, api: true do ...@@ -48,6 +49,7 @@ describe API::DeployKeys, api: true do
get api("/projects/#{project.id}/deploy_keys", admin) get api("/projects/#{project.id}/deploy_keys", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(deploy_key.title) expect(json_response.first['title']).to eq(deploy_key.title)
end end
......
...@@ -22,6 +22,7 @@ describe API::Deployments, api: true do ...@@ -22,6 +22,7 @@ describe API::Deployments, api: true do
get api("/projects/#{project.id}/deployments", user) get api("/projects/#{project.id}/deployments", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response.first['iid']).to eq(deployment.iid) expect(json_response.first['iid']).to eq(deployment.iid)
......
...@@ -22,6 +22,7 @@ describe API::Environments, api: true do ...@@ -22,6 +22,7 @@ describe API::Environments, api: true do
get api("/projects/#{project.id}/environments", user) get api("/projects/#{project.id}/environments", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response.first['name']).to eq(environment.name) expect(json_response.first['name']).to eq(environment.name)
......
...@@ -33,6 +33,7 @@ describe API::Groups, api: true do ...@@ -33,6 +33,7 @@ describe API::Groups, api: true do
get api("/groups", user1) get api("/groups", user1)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response) expect(json_response)
...@@ -43,6 +44,7 @@ describe API::Groups, api: true do ...@@ -43,6 +44,7 @@ describe API::Groups, api: true do
get api("/groups", user1), statistics: true get api("/groups", user1), statistics: true
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first).not_to include 'statistics' expect(json_response.first).not_to include 'statistics'
end end
...@@ -53,6 +55,7 @@ describe API::Groups, api: true do ...@@ -53,6 +55,7 @@ describe API::Groups, api: true do
get api("/groups", admin) get api("/groups", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -61,6 +64,7 @@ describe API::Groups, api: true do ...@@ -61,6 +64,7 @@ describe API::Groups, api: true do
get api("/groups", admin) get api("/groups", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first).not_to include('statistics') expect(json_response.first).not_to include('statistics')
end end
...@@ -78,6 +82,7 @@ describe API::Groups, api: true do ...@@ -78,6 +82,7 @@ describe API::Groups, api: true do
get api("/groups", admin), statistics: true get api("/groups", admin), statistics: true
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response) expect(json_response)
.to satisfy_one { |group| group['statistics'] == attributes } .to satisfy_one { |group| group['statistics'] == attributes }
...@@ -89,6 +94,7 @@ describe API::Groups, api: true do ...@@ -89,6 +94,7 @@ describe API::Groups, api: true do
get api("/groups", admin), skip_groups: [group2.id] get api("/groups", admin), skip_groups: [group2.id]
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
...@@ -103,6 +109,7 @@ describe API::Groups, api: true do ...@@ -103,6 +109,7 @@ describe API::Groups, api: true do
get api("/groups", user1), all_available: true get api("/groups", user1), all_available: true
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_groups).to contain_exactly(public_group.name, group1.name) expect(response_groups).to contain_exactly(public_group.name, group1.name)
end end
...@@ -120,6 +127,7 @@ describe API::Groups, api: true do ...@@ -120,6 +127,7 @@ describe API::Groups, api: true do
get api("/groups", user1) get api("/groups", user1)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_groups).to eq([group3.name, group1.name]) expect(response_groups).to eq([group3.name, group1.name])
end end
...@@ -128,6 +136,7 @@ describe API::Groups, api: true do ...@@ -128,6 +136,7 @@ describe API::Groups, api: true do
get api("/groups", user1), sort: "desc" get api("/groups", user1), sort: "desc"
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_groups).to eq([group1.name, group3.name]) expect(response_groups).to eq([group1.name, group3.name])
end end
...@@ -136,6 +145,7 @@ describe API::Groups, api: true do ...@@ -136,6 +145,7 @@ describe API::Groups, api: true do
get api("/groups", user1), order_by: "path" get api("/groups", user1), order_by: "path"
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_groups).to eq([group1.name, group3.name]) expect(response_groups).to eq([group1.name, group3.name])
end end
...@@ -156,6 +166,7 @@ describe API::Groups, api: true do ...@@ -156,6 +166,7 @@ describe API::Groups, api: true do
get api('/groups/owned', user2) get api('/groups/owned', user2)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(group2.name) expect(json_response.first['name']).to eq(group2.name)
end end
...@@ -290,6 +301,7 @@ describe API::Groups, api: true do ...@@ -290,6 +301,7 @@ describe API::Groups, api: true do
get api("/groups/#{group1.id}/projects", user1) get api("/groups/#{group1.id}/projects", user1)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
project_names = json_response.map { |proj| proj['name' ] } project_names = json_response.map { |proj| proj['name' ] }
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name])
...@@ -300,6 +312,7 @@ describe API::Groups, api: true do ...@@ -300,6 +312,7 @@ describe API::Groups, api: true do
get api("/groups/#{group1.id}/projects", user1), simple: true get api("/groups/#{group1.id}/projects", user1), simple: true
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
project_names = json_response.map { |proj| proj['name' ] } project_names = json_response.map { |proj| proj['name' ] }
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name])
...@@ -312,6 +325,7 @@ describe API::Groups, api: true do ...@@ -312,6 +325,7 @@ describe API::Groups, api: true do
get api("/groups/#{group1.id}/projects", user1), visibility: 'public' get api("/groups/#{group1.id}/projects", user1), visibility: 'public'
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an(Array) expect(json_response).to be_an(Array)
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['name']).to eq(public_project.name) expect(json_response.first['name']).to eq(public_project.name)
...@@ -335,6 +349,7 @@ describe API::Groups, api: true do ...@@ -335,6 +349,7 @@ describe API::Groups, api: true do
get api("/groups/#{group1.id}/projects", user3) get api("/groups/#{group1.id}/projects", user3)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['name']).to eq(project3.name) expect(json_response.first['name']).to eq(project3.name)
end end
...@@ -365,6 +380,7 @@ describe API::Groups, api: true do ...@@ -365,6 +380,7 @@ describe API::Groups, api: true do
get api("/groups/#{group2.id}/projects", admin) get api("/groups/#{group2.id}/projects", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['name']).to eq(project2.name) expect(json_response.first['name']).to eq(project2.name)
end end
...@@ -381,6 +397,7 @@ describe API::Groups, api: true do ...@@ -381,6 +397,7 @@ describe API::Groups, api: true do
get api("/groups/#{group1.path}/projects", admin) get api("/groups/#{group1.path}/projects", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
project_names = json_response.map { |proj| proj['name' ] } project_names = json_response.map { |proj| proj['name' ] }
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name])
end end
......
...@@ -68,7 +68,9 @@ describe API::Issues, api: true do ...@@ -68,7 +68,9 @@ describe API::Issues, api: true do
context "when authenticated" do context "when authenticated" do
it "returns an array of issues" do it "returns an array of issues" do
get api("/issues", user) get api("/issues", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
expect(json_response.last).to have_key('web_url') expect(json_response.last).to have_key('web_url')
...@@ -76,7 +78,9 @@ describe API::Issues, api: true do ...@@ -76,7 +78,9 @@ describe API::Issues, api: true do
it 'returns an array of closed issues' do it 'returns an array of closed issues' do
get api('/issues?state=closed', user) get api('/issues?state=closed', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(closed_issue.id) expect(json_response.first['id']).to eq(closed_issue.id)
...@@ -84,7 +88,9 @@ describe API::Issues, api: true do ...@@ -84,7 +88,9 @@ describe API::Issues, api: true do
it 'returns an array of opened issues' do it 'returns an array of opened issues' do
get api('/issues?state=opened', user) get api('/issues?state=opened', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(issue.id) expect(json_response.first['id']).to eq(issue.id)
...@@ -92,7 +98,9 @@ describe API::Issues, api: true do ...@@ -92,7 +98,9 @@ describe API::Issues, api: true do
it 'returns an array of all issues' do it 'returns an array of all issues' do
get api('/issues?state=all', user) get api('/issues?state=all', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['id']).to eq(issue.id) expect(json_response.first['id']).to eq(issue.id)
...@@ -101,7 +109,9 @@ describe API::Issues, api: true do ...@@ -101,7 +109,9 @@ describe API::Issues, api: true do
it 'returns an array of labeled issues' do it 'returns an array of labeled issues' do
get api("/issues?labels=#{label.title}", user) get api("/issues?labels=#{label.title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label.title]) expect(json_response.first['labels']).to eq([label.title])
...@@ -111,6 +121,7 @@ describe API::Issues, api: true do ...@@ -111,6 +121,7 @@ describe API::Issues, api: true do
get api("/issues?labels=#{label.title},foo,bar", user) get api("/issues?labels=#{label.title},foo,bar", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label.title]) expect(json_response.first['labels']).to eq([label.title])
...@@ -118,14 +129,18 @@ describe API::Issues, api: true do ...@@ -118,14 +129,18 @@ describe API::Issues, api: true do
it 'returns an empty array if no issue matches labels' do it 'returns an empty array if no issue matches labels' do
get api('/issues?labels=foo,bar', user) get api('/issues?labels=foo,bar', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
it 'returns an array of labeled issues matching given state' do it 'returns an array of labeled issues matching given state' do
get api("/issues?labels=#{label.title}&state=opened", user) get api("/issues?labels=#{label.title}&state=opened", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label.title]) expect(json_response.first['labels']).to eq([label.title])
...@@ -134,7 +149,9 @@ describe API::Issues, api: true do ...@@ -134,7 +149,9 @@ describe API::Issues, api: true do
it 'returns an empty array if no issue matches labels and state filters' do it 'returns an empty array if no issue matches labels and state filters' do
get api("/issues?labels=#{label.title}&state=closed", user) get api("/issues?labels=#{label.title}&state=closed", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -143,6 +160,7 @@ describe API::Issues, api: true do ...@@ -143,6 +160,7 @@ describe API::Issues, api: true do
get api("/issues?milestone=#{empty_milestone.title}", user) get api("/issues?milestone=#{empty_milestone.title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -151,6 +169,7 @@ describe API::Issues, api: true do ...@@ -151,6 +169,7 @@ describe API::Issues, api: true do
get api("/issues?milestone=foo", user) get api("/issues?milestone=foo", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -159,6 +178,7 @@ describe API::Issues, api: true do ...@@ -159,6 +178,7 @@ describe API::Issues, api: true do
get api("/issues?milestone=#{milestone.title}", user) get api("/issues?milestone=#{milestone.title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['id']).to eq(issue.id) expect(json_response.first['id']).to eq(issue.id)
...@@ -170,6 +190,7 @@ describe API::Issues, api: true do ...@@ -170,6 +190,7 @@ describe API::Issues, api: true do
'&state=closed', user) '&state=closed', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(closed_issue.id) expect(json_response.first['id']).to eq(closed_issue.id)
...@@ -179,6 +200,7 @@ describe API::Issues, api: true do ...@@ -179,6 +200,7 @@ describe API::Issues, api: true do
get api("/issues?milestone=#{no_milestone_title}", author) get api("/issues?milestone=#{no_milestone_title}", author)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(confidential_issue.id) expect(json_response.first['id']).to eq(confidential_issue.id)
...@@ -186,36 +208,40 @@ describe API::Issues, api: true do ...@@ -186,36 +208,40 @@ describe API::Issues, api: true do
it 'sorts by created_at descending by default' do it 'sorts by created_at descending by default' do
get api('/issues', user) get api('/issues', user)
response_dates = json_response.map { |issue| issue['created_at'] }
response_dates = json_response.map { |issue| issue['created_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort.reverse) expect(response_dates).to eq(response_dates.sort.reverse)
end end
it 'sorts ascending when requested' do it 'sorts ascending when requested' do
get api('/issues?sort=asc', user) get api('/issues?sort=asc', user)
response_dates = json_response.map { |issue| issue['created_at'] }
response_dates = json_response.map { |issue| issue['created_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort) expect(response_dates).to eq(response_dates.sort)
end end
it 'sorts by updated_at descending when requested' do it 'sorts by updated_at descending when requested' do
get api('/issues?order_by=updated_at', user) get api('/issues?order_by=updated_at', user)
response_dates = json_response.map { |issue| issue['updated_at'] }
response_dates = json_response.map { |issue| issue['updated_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort.reverse) expect(response_dates).to eq(response_dates.sort.reverse)
end end
it 'sorts by updated_at ascending when requested' do it 'sorts by updated_at ascending when requested' do
get api('/issues?order_by=updated_at&sort=asc', user) get api('/issues?order_by=updated_at&sort=asc', user)
response_dates = json_response.map { |issue| issue['updated_at'] }
response_dates = json_response.map { |issue| issue['updated_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort) expect(response_dates).to eq(response_dates.sort)
end end
...@@ -269,6 +295,7 @@ describe API::Issues, api: true do ...@@ -269,6 +295,7 @@ describe API::Issues, api: true do
get api(base_url, non_member) get api(base_url, non_member)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['title']).to eq(group_issue.title) expect(json_response.first['title']).to eq(group_issue.title)
...@@ -278,6 +305,7 @@ describe API::Issues, api: true do ...@@ -278,6 +305,7 @@ describe API::Issues, api: true do
get api(base_url, author) get api(base_url, author)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -286,6 +314,7 @@ describe API::Issues, api: true do ...@@ -286,6 +314,7 @@ describe API::Issues, api: true do
get api(base_url, assignee) get api(base_url, assignee)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -294,6 +323,7 @@ describe API::Issues, api: true do ...@@ -294,6 +323,7 @@ describe API::Issues, api: true do
get api(base_url, user) get api(base_url, user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -302,6 +332,7 @@ describe API::Issues, api: true do ...@@ -302,6 +332,7 @@ describe API::Issues, api: true do
get api(base_url, admin) get api(base_url, admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -310,6 +341,7 @@ describe API::Issues, api: true do ...@@ -310,6 +341,7 @@ describe API::Issues, api: true do
get api("#{base_url}?labels=#{group_label.title}", user) get api("#{base_url}?labels=#{group_label.title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([group_label.title]) expect(json_response.first['labels']).to eq([group_label.title])
...@@ -319,6 +351,7 @@ describe API::Issues, api: true do ...@@ -319,6 +351,7 @@ describe API::Issues, api: true do
get api("#{base_url}?labels=#{group_label.title},foo,bar", user) get api("#{base_url}?labels=#{group_label.title},foo,bar", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -327,6 +360,7 @@ describe API::Issues, api: true do ...@@ -327,6 +360,7 @@ describe API::Issues, api: true do
get api("#{base_url}?labels=foo,bar", user) get api("#{base_url}?labels=foo,bar", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -335,6 +369,7 @@ describe API::Issues, api: true do ...@@ -335,6 +369,7 @@ describe API::Issues, api: true do
get api("#{base_url}?milestone=#{group_empty_milestone.title}", user) get api("#{base_url}?milestone=#{group_empty_milestone.title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -343,6 +378,7 @@ describe API::Issues, api: true do ...@@ -343,6 +378,7 @@ describe API::Issues, api: true do
get api("#{base_url}?milestone=foo", user) get api("#{base_url}?milestone=foo", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -351,6 +387,7 @@ describe API::Issues, api: true do ...@@ -351,6 +387,7 @@ describe API::Issues, api: true do
get api("#{base_url}?milestone=#{group_milestone.title}", user) get api("#{base_url}?milestone=#{group_milestone.title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(group_issue.id) expect(json_response.first['id']).to eq(group_issue.id)
...@@ -361,6 +398,7 @@ describe API::Issues, api: true do ...@@ -361,6 +398,7 @@ describe API::Issues, api: true do
'&state=closed', user) '&state=closed', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(group_closed_issue.id) expect(json_response.first['id']).to eq(group_closed_issue.id)
...@@ -370,6 +408,7 @@ describe API::Issues, api: true do ...@@ -370,6 +408,7 @@ describe API::Issues, api: true do
get api("#{base_url}?milestone=#{no_milestone_title}", user) get api("#{base_url}?milestone=#{no_milestone_title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(group_confidential_issue.id) expect(json_response.first['id']).to eq(group_confidential_issue.id)
...@@ -377,36 +416,40 @@ describe API::Issues, api: true do ...@@ -377,36 +416,40 @@ describe API::Issues, api: true do
it 'sorts by created_at descending by default' do it 'sorts by created_at descending by default' do
get api(base_url, user) get api(base_url, user)
response_dates = json_response.map { |issue| issue['created_at'] }
response_dates = json_response.map { |issue| issue['created_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort.reverse) expect(response_dates).to eq(response_dates.sort.reverse)
end end
it 'sorts ascending when requested' do it 'sorts ascending when requested' do
get api("#{base_url}?sort=asc", user) get api("#{base_url}?sort=asc", user)
response_dates = json_response.map { |issue| issue['created_at'] }
response_dates = json_response.map { |issue| issue['created_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort) expect(response_dates).to eq(response_dates.sort)
end end
it 'sorts by updated_at descending when requested' do it 'sorts by updated_at descending when requested' do
get api("#{base_url}?order_by=updated_at", user) get api("#{base_url}?order_by=updated_at", user)
response_dates = json_response.map { |issue| issue['updated_at'] }
response_dates = json_response.map { |issue| issue['updated_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort.reverse) expect(response_dates).to eq(response_dates.sort.reverse)
end end
it 'sorts by updated_at ascending when requested' do it 'sorts by updated_at ascending when requested' do
get api("#{base_url}?order_by=updated_at&sort=asc", user) get api("#{base_url}?order_by=updated_at&sort=asc", user)
response_dates = json_response.map { |issue| issue['updated_at'] }
response_dates = json_response.map { |issue| issue['updated_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort) expect(response_dates).to eq(response_dates.sort)
end end
...@@ -430,12 +473,17 @@ describe API::Issues, api: true do ...@@ -430,12 +473,17 @@ describe API::Issues, api: true do
get api("/projects/#{restricted_project.id}/issues", non_member) get api("/projects/#{restricted_project.id}/issues", non_member)
expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response).to eq([]) expect(json_response).to eq([])
end end
it 'returns project issues without confidential issues for non project members' do it 'returns project issues without confidential issues for non project members' do
get api("#{base_url}/issues", non_member) get api("#{base_url}/issues", non_member)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -443,7 +491,9 @@ describe API::Issues, api: true do ...@@ -443,7 +491,9 @@ describe API::Issues, api: true do
it 'returns project issues without confidential issues for project members with guest role' do it 'returns project issues without confidential issues for project members with guest role' do
get api("#{base_url}/issues", guest) get api("#{base_url}/issues", guest)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -451,7 +501,9 @@ describe API::Issues, api: true do ...@@ -451,7 +501,9 @@ describe API::Issues, api: true do
it 'returns project confidential issues for author' do it 'returns project confidential issues for author' do
get api("#{base_url}/issues", author) get api("#{base_url}/issues", author)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -459,7 +511,9 @@ describe API::Issues, api: true do ...@@ -459,7 +511,9 @@ describe API::Issues, api: true do
it 'returns project confidential issues for assignee' do it 'returns project confidential issues for assignee' do
get api("#{base_url}/issues", assignee) get api("#{base_url}/issues", assignee)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -467,7 +521,9 @@ describe API::Issues, api: true do ...@@ -467,7 +521,9 @@ describe API::Issues, api: true do
it 'returns project issues with confidential issues for project members' do it 'returns project issues with confidential issues for project members' do
get api("#{base_url}/issues", user) get api("#{base_url}/issues", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -475,7 +531,9 @@ describe API::Issues, api: true do ...@@ -475,7 +531,9 @@ describe API::Issues, api: true do
it 'returns project confidential issues for admin' do it 'returns project confidential issues for admin' do
get api("#{base_url}/issues", admin) get api("#{base_url}/issues", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
...@@ -483,7 +541,9 @@ describe API::Issues, api: true do ...@@ -483,7 +541,9 @@ describe API::Issues, api: true do
it 'returns an array of labeled project issues' do it 'returns an array of labeled project issues' do
get api("#{base_url}/issues?labels=#{label.title}", user) get api("#{base_url}/issues?labels=#{label.title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label.title]) expect(json_response.first['labels']).to eq([label.title])
...@@ -493,6 +553,7 @@ describe API::Issues, api: true do ...@@ -493,6 +553,7 @@ describe API::Issues, api: true do
get api("#{base_url}/issues?labels=#{label.title},foo,bar", user) get api("#{base_url}/issues?labels=#{label.title},foo,bar", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label.title]) expect(json_response.first['labels']).to eq([label.title])
...@@ -500,21 +561,27 @@ describe API::Issues, api: true do ...@@ -500,21 +561,27 @@ describe API::Issues, api: true do
it 'returns an empty array if no project issue matches labels' do it 'returns an empty array if no project issue matches labels' do
get api("#{base_url}/issues?labels=foo,bar", user) get api("#{base_url}/issues?labels=foo,bar", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
it 'returns an empty array if no issue matches milestone' do it 'returns an empty array if no issue matches milestone' do
get api("#{base_url}/issues?milestone=#{empty_milestone.title}", user) get api("#{base_url}/issues?milestone=#{empty_milestone.title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
it 'returns an empty array if milestone does not exist' do it 'returns an empty array if milestone does not exist' do
get api("#{base_url}/issues?milestone=foo", user) get api("#{base_url}/issues?milestone=foo", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -523,6 +590,7 @@ describe API::Issues, api: true do ...@@ -523,6 +590,7 @@ describe API::Issues, api: true do
get api("#{base_url}/issues?milestone=#{milestone.title}", user) get api("#{base_url}/issues?milestone=#{milestone.title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['id']).to eq(issue.id) expect(json_response.first['id']).to eq(issue.id)
...@@ -530,9 +598,10 @@ describe API::Issues, api: true do ...@@ -530,9 +598,10 @@ describe API::Issues, api: true do
end end
it 'returns an array of issues matching state in milestone' do it 'returns an array of issues matching state in milestone' do
get api("#{base_url}/issues?milestone=#{milestone.title}"\ get api("#{base_url}/issues?milestone=#{milestone.title}&state=closed", user)
'&state=closed', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(closed_issue.id) expect(json_response.first['id']).to eq(closed_issue.id)
...@@ -542,6 +611,7 @@ describe API::Issues, api: true do ...@@ -542,6 +611,7 @@ describe API::Issues, api: true do
get api("#{base_url}/issues?milestone=#{no_milestone_title}", user) get api("#{base_url}/issues?milestone=#{no_milestone_title}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(confidential_issue.id) expect(json_response.first['id']).to eq(confidential_issue.id)
...@@ -549,36 +619,40 @@ describe API::Issues, api: true do ...@@ -549,36 +619,40 @@ describe API::Issues, api: true do
it 'sorts by created_at descending by default' do it 'sorts by created_at descending by default' do
get api("#{base_url}/issues", user) get api("#{base_url}/issues", user)
response_dates = json_response.map { |issue| issue['created_at'] }
response_dates = json_response.map { |issue| issue['created_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort.reverse) expect(response_dates).to eq(response_dates.sort.reverse)
end end
it 'sorts ascending when requested' do it 'sorts ascending when requested' do
get api("#{base_url}/issues?sort=asc", user) get api("#{base_url}/issues?sort=asc", user)
response_dates = json_response.map { |issue| issue['created_at'] }
response_dates = json_response.map { |issue| issue['created_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort) expect(response_dates).to eq(response_dates.sort)
end end
it 'sorts by updated_at descending when requested' do it 'sorts by updated_at descending when requested' do
get api("#{base_url}/issues?order_by=updated_at", user) get api("#{base_url}/issues?order_by=updated_at", user)
response_dates = json_response.map { |issue| issue['updated_at'] }
response_dates = json_response.map { |issue| issue['updated_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort.reverse) expect(response_dates).to eq(response_dates.sort.reverse)
end end
it 'sorts by updated_at ascending when requested' do it 'sorts by updated_at ascending when requested' do
get api("#{base_url}/issues?order_by=updated_at&sort=asc", user) get api("#{base_url}/issues?order_by=updated_at&sort=asc", user)
response_dates = json_response.map { |issue| issue['updated_at'] }
response_dates = json_response.map { |issue| issue['updated_at'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response_dates).to eq(response_dates.sort) expect(response_dates).to eq(response_dates.sort)
end end
......
...@@ -30,6 +30,7 @@ describe API::Labels, api: true do ...@@ -30,6 +30,7 @@ describe API::Labels, api: true do
get api("/projects/#{project.id}/labels", user) get api("/projects/#{project.id}/labels", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(3) expect(json_response.size).to eq(3)
expect(json_response.first.keys).to match_array expected_keys expect(json_response.first.keys).to match_array expected_keys
......
...@@ -34,9 +34,12 @@ describe API::Members, api: true do ...@@ -34,9 +34,12 @@ describe API::Members, api: true do
context "when authenticated as a #{type}" do context "when authenticated as a #{type}" do
it 'returns 200' do it 'returns 200' do
user = public_send(type) user = public_send(type)
get api("/#{source_type.pluralize}/#{source.id}/members", user) get api("/#{source_type.pluralize}/#{source.id}/members", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id] expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id]
end end
...@@ -49,6 +52,8 @@ describe API::Members, api: true do ...@@ -49,6 +52,8 @@ describe API::Members, api: true do
get api("/#{source_type.pluralize}/#{source.id}/members", developer) get api("/#{source_type.pluralize}/#{source.id}/members", developer)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id] expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id]
end end
...@@ -57,6 +62,8 @@ describe API::Members, api: true do ...@@ -57,6 +62,8 @@ describe API::Members, api: true do
get api("/#{source_type.pluralize}/#{source.id}/members", developer), query: master.username get api("/#{source_type.pluralize}/#{source.id}/members", developer), query: master.username
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.count).to eq(1) expect(json_response.count).to eq(1)
expect(json_response.first['username']).to eq(master.username) expect(json_response.first['username']).to eq(master.username)
end end
......
...@@ -19,6 +19,8 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs', api: true do ...@@ -19,6 +19,8 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs', api: true do
merge_request_diff = merge_request.merge_request_diffs.first merge_request_diff = merge_request.merge_request_diffs.first
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(merge_request.merge_request_diffs.size) expect(json_response.size).to eq(merge_request.merge_request_diffs.size)
expect(json_response.first['id']).to eq(merge_request_diff.id) expect(json_response.first['id']).to eq(merge_request_diff.id)
expect(json_response.first['head_commit_sha']).to eq(merge_request_diff.head_commit_sha) expect(json_response.first['head_commit_sha']).to eq(merge_request_diff.head_commit_sha)
......
...@@ -27,7 +27,9 @@ describe API::MergeRequests, api: true do ...@@ -27,7 +27,9 @@ describe API::MergeRequests, api: true do
context "when authenticated" do context "when authenticated" do
it "returns an array of all merge_requests" do it "returns an array of all merge_requests" do
get api("/projects/#{project.id}/merge_requests", user) get api("/projects/#{project.id}/merge_requests", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
...@@ -43,7 +45,9 @@ describe API::MergeRequests, api: true do ...@@ -43,7 +45,9 @@ describe API::MergeRequests, api: true do
it "returns an array of all merge_requests" do it "returns an array of all merge_requests" do
get api("/projects/#{project.id}/merge_requests?state", user) get api("/projects/#{project.id}/merge_requests?state", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
...@@ -51,7 +55,9 @@ describe API::MergeRequests, api: true do ...@@ -51,7 +55,9 @@ describe API::MergeRequests, api: true do
it "returns an array of open merge_requests" do it "returns an array of open merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=opened", user) get api("/projects/#{project.id}/merge_requests?state=opened", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
...@@ -59,7 +65,9 @@ describe API::MergeRequests, api: true do ...@@ -59,7 +65,9 @@ describe API::MergeRequests, api: true do
it "returns an array of closed merge_requests" do it "returns an array of closed merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=closed", user) get api("/projects/#{project.id}/merge_requests?state=closed", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['title']).to eq(merge_request_closed.title) expect(json_response.first['title']).to eq(merge_request_closed.title)
...@@ -67,7 +75,9 @@ describe API::MergeRequests, api: true do ...@@ -67,7 +75,9 @@ describe API::MergeRequests, api: true do
it "returns an array of merged merge_requests" do it "returns an array of merged merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=merged", user) get api("/projects/#{project.id}/merge_requests?state=merged", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['title']).to eq(merge_request_merged.title) expect(json_response.first['title']).to eq(merge_request_merged.title)
...@@ -91,7 +101,9 @@ describe API::MergeRequests, api: true do ...@@ -91,7 +101,9 @@ describe API::MergeRequests, api: true do
it "returns an array of merge_requests in ascending order" do it "returns an array of merge_requests in ascending order" do
get api("/projects/#{project.id}/merge_requests?sort=asc", user) get api("/projects/#{project.id}/merge_requests?sort=asc", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
response_dates = json_response.map{ |merge_request| merge_request['created_at'] } response_dates = json_response.map{ |merge_request| merge_request['created_at'] }
...@@ -100,7 +112,9 @@ describe API::MergeRequests, api: true do ...@@ -100,7 +112,9 @@ describe API::MergeRequests, api: true do
it "returns an array of merge_requests in descending order" do it "returns an array of merge_requests in descending order" do
get api("/projects/#{project.id}/merge_requests?sort=desc", user) get api("/projects/#{project.id}/merge_requests?sort=desc", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
response_dates = json_response.map{ |merge_request| merge_request['created_at'] } response_dates = json_response.map{ |merge_request| merge_request['created_at'] }
...@@ -109,7 +123,9 @@ describe API::MergeRequests, api: true do ...@@ -109,7 +123,9 @@ describe API::MergeRequests, api: true do
it "returns an array of merge_requests ordered by updated_at" do it "returns an array of merge_requests ordered by updated_at" do
get api("/projects/#{project.id}/merge_requests?order_by=updated_at", user) get api("/projects/#{project.id}/merge_requests?order_by=updated_at", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
response_dates = json_response.map{ |merge_request| merge_request['updated_at'] } response_dates = json_response.map{ |merge_request| merge_request['updated_at'] }
...@@ -118,7 +134,9 @@ describe API::MergeRequests, api: true do ...@@ -118,7 +134,9 @@ describe API::MergeRequests, api: true do
it "returns an array of merge_requests ordered by created_at" do it "returns an array of merge_requests ordered by created_at" do
get api("/projects/#{project.id}/merge_requests?order_by=created_at&sort=asc", user) get api("/projects/#{project.id}/merge_requests?order_by=created_at&sort=asc", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
response_dates = json_response.map{ |merge_request| merge_request['created_at'] } response_dates = json_response.map{ |merge_request| merge_request['created_at'] }
...@@ -191,6 +209,8 @@ describe API::MergeRequests, api: true do ...@@ -191,6 +209,8 @@ describe API::MergeRequests, api: true do
commit = merge_request.commits.first commit = merge_request.commits.first
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(merge_request.commits.size) expect(json_response.size).to eq(merge_request.commits.size)
expect(json_response.first['id']).to eq(commit.id) expect(json_response.first['id']).to eq(commit.id)
expect(json_response.first['title']).to eq(commit.title) expect(json_response.first['title']).to eq(commit.title)
...@@ -205,6 +225,7 @@ describe API::MergeRequests, api: true do ...@@ -205,6 +225,7 @@ describe API::MergeRequests, api: true do
describe 'GET /projects/:id/merge_requests/:merge_request_id/changes' do describe 'GET /projects/:id/merge_requests/:merge_request_id/changes' do
it 'returns the change information of the merge_request' do it 'returns the change information of the merge_request' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/changes", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/changes", user)
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(json_response['changes'].size).to eq(merge_request.diffs.size) expect(json_response['changes'].size).to eq(merge_request.diffs.size)
end end
...@@ -572,7 +593,9 @@ describe API::MergeRequests, api: true do ...@@ -572,7 +593,9 @@ describe API::MergeRequests, api: true do
it "returns merge_request comments ordered by created_at" do it "returns merge_request comments ordered by created_at" do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.first['note']).to eq("a comment on a MR") expect(json_response.first['note']).to eq("a comment on a MR")
...@@ -594,7 +617,9 @@ describe API::MergeRequests, api: true do ...@@ -594,7 +617,9 @@ describe API::MergeRequests, api: true do
end end
get api("/projects/#{project.id}/merge_requests/#{mr.id}/closes_issues", user) get api("/projects/#{project.id}/merge_requests/#{mr.id}/closes_issues", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(issue.id) expect(json_response.first['id']).to eq(issue.id)
...@@ -602,7 +627,9 @@ describe API::MergeRequests, api: true do ...@@ -602,7 +627,9 @@ describe API::MergeRequests, api: true do
it 'returns an empty array when there are no issues to be closed' do it 'returns an empty array when there are no issues to be closed' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(0) expect(json_response.length).to eq(0)
end end
...@@ -616,6 +643,7 @@ describe API::MergeRequests, api: true do ...@@ -616,6 +643,7 @@ describe API::MergeRequests, api: true do
get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.id}/closes_issues", user) get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.id}/closes_issues", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
......
...@@ -14,6 +14,7 @@ describe API::Milestones, api: true do ...@@ -14,6 +14,7 @@ describe API::Milestones, api: true do
get api("/projects/#{project.id}/milestones", user) get api("/projects/#{project.id}/milestones", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(milestone.title) expect(json_response.first['title']).to eq(milestone.title)
end end
...@@ -28,6 +29,7 @@ describe API::Milestones, api: true do ...@@ -28,6 +29,7 @@ describe API::Milestones, api: true do
get api("/projects/#{project.id}/milestones?state=active", user) get api("/projects/#{project.id}/milestones?state=active", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(milestone.id) expect(json_response.first['id']).to eq(milestone.id)
...@@ -37,25 +39,18 @@ describe API::Milestones, api: true do ...@@ -37,25 +39,18 @@ describe API::Milestones, api: true do
get api("/projects/#{project.id}/milestones?state=closed", user) get api("/projects/#{project.id}/milestones?state=closed", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(closed_milestone.id) expect(json_response.first['id']).to eq(closed_milestone.id)
end end
end
describe 'GET /projects/:id/milestones/:milestone_id' do
it 'returns a project milestone by id' do
get api("/projects/#{project.id}/milestones/#{milestone.id}", user)
expect(response).to have_http_status(200)
expect(json_response['title']).to eq(milestone.title)
expect(json_response['iid']).to eq(milestone.iid)
end
it 'returns a project milestone by iid' do it 'returns a project milestone by iid' do
get api("/projects/#{project.id}/milestones?iid=#{closed_milestone.iid}", user) get api("/projects/#{project.id}/milestones?iid=#{closed_milestone.iid}", user)
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(response).to include_pagination_headers
expect(json_response.size).to eq(1)
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response.first['title']).to eq closed_milestone.title expect(json_response.first['title']).to eq closed_milestone.title
expect(json_response.first['id']).to eq closed_milestone.id expect(json_response.first['id']).to eq closed_milestone.id
...@@ -70,6 +65,26 @@ describe API::Milestones, api: true do ...@@ -70,6 +65,26 @@ describe API::Milestones, api: true do
expect(json_response.first['id']).to eq milestone.id expect(json_response.first['id']).to eq milestone.id
end end
it 'returns a project milestone by iid array' do
get api("/projects/#{project.id}/milestones", user), iid: [milestone.iid, closed_milestone.iid]
expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response.size).to eq(2)
expect(json_response.first['title']).to eq milestone.title
expect(json_response.first['id']).to eq milestone.id
end
end
describe 'GET /projects/:id/milestones/:milestone_id' do
it 'returns a project milestone by id' do
get api("/projects/#{project.id}/milestones/#{milestone.id}", user)
expect(response).to have_http_status(200)
expect(json_response['title']).to eq(milestone.title)
expect(json_response['iid']).to eq(milestone.iid)
end
it 'returns 401 error if user not authenticated' do it 'returns 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones/#{milestone.id}") get api("/projects/#{project.id}/milestones/#{milestone.id}")
...@@ -177,6 +192,7 @@ describe API::Milestones, api: true do ...@@ -177,6 +192,7 @@ describe API::Milestones, api: true do
get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user) get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['milestone']['title']).to eq(milestone.title) expect(json_response.first['milestone']['title']).to eq(milestone.title)
end end
...@@ -202,6 +218,7 @@ describe API::Milestones, api: true do ...@@ -202,6 +218,7 @@ describe API::Milestones, api: true do
get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", user) get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
expect(json_response.map { |issue| issue['id'] }).to include(issue.id, confidential_issue.id) expect(json_response.map { |issue| issue['id'] }).to include(issue.id, confidential_issue.id)
...@@ -214,6 +231,7 @@ describe API::Milestones, api: true do ...@@ -214,6 +231,7 @@ describe API::Milestones, api: true do
get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", member) get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", member)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response.map { |issue| issue['id'] }).to include(issue.id) expect(json_response.map { |issue| issue['id'] }).to include(issue.id)
...@@ -223,6 +241,7 @@ describe API::Milestones, api: true do ...@@ -223,6 +241,7 @@ describe API::Milestones, api: true do
get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", create(:user)) get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", create(:user))
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response.map { |issue| issue['id'] }).to include(issue.id) expect(json_response.map { |issue| issue['id'] }).to include(issue.id)
......
...@@ -18,17 +18,19 @@ describe API::Namespaces, api: true do ...@@ -18,17 +18,19 @@ describe API::Namespaces, api: true do
context "when authenticated as admin" do context "when authenticated as admin" do
it "admin: returns an array of all namespaces" do it "admin: returns an array of all namespaces" do
get api("/namespaces", admin) get api("/namespaces", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(Namespace.count) expect(json_response.length).to eq(Namespace.count)
end end
it "admin: returns an array of matched namespaces" do it "admin: returns an array of matched namespaces" do
get api("/namespaces?search=#{group2.name}", admin) get api("/namespaces?search=#{group2.name}", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.last['path']).to eq(group2.path) expect(json_response.last['path']).to eq(group2.path)
expect(json_response.last['full_path']).to eq(group2.full_path) expect(json_response.last['full_path']).to eq(group2.full_path)
...@@ -38,17 +40,19 @@ describe API::Namespaces, api: true do ...@@ -38,17 +40,19 @@ describe API::Namespaces, api: true do
context "when authenticated as a regular user" do context "when authenticated as a regular user" do
it "user: returns an array of namespaces" do it "user: returns an array of namespaces" do
get api("/namespaces", user) get api("/namespaces", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
it "admin: returns an array of matched namespaces" do it "admin: returns an array of matched namespaces" do
get api("/namespaces?search=#{user.username}", user) get api("/namespaces?search=#{user.username}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
end end
......
...@@ -41,6 +41,7 @@ describe API::Notes, api: true do ...@@ -41,6 +41,7 @@ describe API::Notes, api: true do
get api("/projects/#{project.id}/issues/#{issue.id}/notes", user) get api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(issue_note.note) expect(json_response.first['body']).to eq(issue_note.note)
end end
...@@ -56,6 +57,7 @@ describe API::Notes, api: true do ...@@ -56,6 +57,7 @@ describe API::Notes, api: true do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response).to be_empty expect(json_response).to be_empty
end end
...@@ -75,6 +77,7 @@ describe API::Notes, api: true do ...@@ -75,6 +77,7 @@ describe API::Notes, api: true do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", private_user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", private_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(cross_reference_note.note) expect(json_response.first['body']).to eq(cross_reference_note.note)
end end
...@@ -87,6 +90,7 @@ describe API::Notes, api: true do ...@@ -87,6 +90,7 @@ describe API::Notes, api: true do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user) get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(snippet_note.note) expect(json_response.first['body']).to eq(snippet_note.note)
end end
...@@ -109,6 +113,7 @@ describe API::Notes, api: true do ...@@ -109,6 +113,7 @@ describe API::Notes, api: true do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(merge_request_note.note) expect(json_response.first['body']).to eq(merge_request_note.note)
end end
......
...@@ -25,6 +25,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do ...@@ -25,6 +25,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response).to include_pagination_headers
expect(json_response.count).to eq(1) expect(json_response.count).to eq(1)
expect(json_response.first['url']).to eq("http://example.com") expect(json_response.first['url']).to eq("http://example.com")
expect(json_response.first['issues_events']).to eq(true) expect(json_response.first['issues_events']).to eq(true)
......
...@@ -16,9 +16,11 @@ describe API::ProjectSnippets, api: true do ...@@ -16,9 +16,11 @@ describe API::ProjectSnippets, api: true do
internal_snippet = create(:project_snippet, :internal, project: project) internal_snippet = create(:project_snippet, :internal, project: project)
private_snippet = create(:project_snippet, :private, project: project) private_snippet = create(:project_snippet, :private, project: project)
get api("/projects/#{project.id}/snippets/", user) get api("/projects/#{project.id}/snippets", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(3) expect(json_response.size).to eq(3)
expect(json_response.map{ |snippet| snippet['id']} ).to include(public_snippet.id, internal_snippet.id, private_snippet.id) expect(json_response.map{ |snippet| snippet['id']} ).to include(public_snippet.id, internal_snippet.id, private_snippet.id)
expect(json_response.last).to have_key('web_url') expect(json_response.last).to have_key('web_url')
...@@ -28,7 +30,10 @@ describe API::ProjectSnippets, api: true do ...@@ -28,7 +30,10 @@ describe API::ProjectSnippets, api: true do
create(:project_snippet, :private, project: project) create(:project_snippet, :private, project: project)
get api("/projects/#{project.id}/snippets/", user) get api("/projects/#{project.id}/snippets/", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(0) expect(json_response.size).to eq(0)
end end
end end
......
...@@ -76,6 +76,7 @@ describe API::Projects, api: true do ...@@ -76,6 +76,7 @@ describe API::Projects, api: true do
get api('/projects', user) get api('/projects', user)
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first.keys).to include('tag_list') expect(json_response.first.keys).to include('tag_list')
end end
...@@ -84,6 +85,7 @@ describe API::Projects, api: true do ...@@ -84,6 +85,7 @@ describe API::Projects, api: true do
get api('/projects', user) get api('/projects', user)
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first.keys).to include('open_issues_count') expect(json_response.first.keys).to include('open_issues_count')
end end
...@@ -94,6 +96,7 @@ describe API::Projects, api: true do ...@@ -94,6 +96,7 @@ describe API::Projects, api: true do
get api('/projects', user) get api('/projects', user)
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.find { |hash| hash['id'] == project.id }.keys).not_to include('open_issues_count') expect(json_response.find { |hash| hash['id'] == project.id }.keys).not_to include('open_issues_count')
end end
...@@ -102,6 +105,7 @@ describe API::Projects, api: true do ...@@ -102,6 +105,7 @@ describe API::Projects, api: true do
get api('/projects', user) get api('/projects', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first).not_to include('statistics') expect(json_response.first).not_to include('statistics')
end end
...@@ -110,6 +114,7 @@ describe API::Projects, api: true do ...@@ -110,6 +114,7 @@ describe API::Projects, api: true do
get api('/projects', user), statistics: true get api('/projects', user), statistics: true
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first).to include 'statistics' expect(json_response.first).to include 'statistics'
end end
...@@ -121,6 +126,7 @@ describe API::Projects, api: true do ...@@ -121,6 +126,7 @@ describe API::Projects, api: true do
get api('/projects?simple=true', user) get api('/projects?simple=true', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first.keys).to match_array expected_keys expect(json_response.first.keys).to match_array expected_keys
end end
...@@ -131,6 +137,7 @@ describe API::Projects, api: true do ...@@ -131,6 +137,7 @@ describe API::Projects, api: true do
get api('/projects', user), { search: project.name } get api('/projects', user), { search: project.name }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
...@@ -141,6 +148,7 @@ describe API::Projects, api: true do ...@@ -141,6 +148,7 @@ describe API::Projects, api: true do
get api('/projects', user), { visibility: 'private' } get api('/projects', user), { visibility: 'private' }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.map { |p| p['id'] }).to contain_exactly(project.id, project2.id, project3.id) expect(json_response.map { |p| p['id'] }).to contain_exactly(project.id, project2.id, project3.id)
end end
...@@ -151,6 +159,7 @@ describe API::Projects, api: true do ...@@ -151,6 +159,7 @@ describe API::Projects, api: true do
get api('/projects', user), { visibility: 'internal' } get api('/projects', user), { visibility: 'internal' }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.map { |p| p['id'] }).to contain_exactly(project2.id) expect(json_response.map { |p| p['id'] }).to contain_exactly(project2.id)
end end
...@@ -159,6 +168,7 @@ describe API::Projects, api: true do ...@@ -159,6 +168,7 @@ describe API::Projects, api: true do
get api('/projects', user), { visibility: 'public' } get api('/projects', user), { visibility: 'public' }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.map { |p| p['id'] }).to contain_exactly(public_project.id) expect(json_response.map { |p| p['id'] }).to contain_exactly(public_project.id)
end end
...@@ -169,6 +179,7 @@ describe API::Projects, api: true do ...@@ -169,6 +179,7 @@ describe API::Projects, api: true do
get api('/projects', user), { order_by: 'id', sort: 'desc' } get api('/projects', user), { order_by: 'id', sort: 'desc' }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['id']).to eq(project3.id) expect(json_response.first['id']).to eq(project3.id)
end end
...@@ -179,6 +190,7 @@ describe API::Projects, api: true do ...@@ -179,6 +190,7 @@ describe API::Projects, api: true do
get api('/projects', user4), owned: true get api('/projects', user4), owned: true
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(project4.name) expect(json_response.first['name']).to eq(project4.name)
expect(json_response.first['owner']['username']).to eq(user4.username) expect(json_response.first['owner']['username']).to eq(user4.username)
...@@ -197,6 +209,7 @@ describe API::Projects, api: true do ...@@ -197,6 +209,7 @@ describe API::Projects, api: true do
get api('/projects', user3), starred: true get api('/projects', user3), starred: true
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.map { |project| project['id'] }).to contain_exactly(project.id, public_project.id) expect(json_response.map { |project| project['id'] }).to contain_exactly(project.id, public_project.id)
end end
...@@ -223,6 +236,7 @@ describe API::Projects, api: true do ...@@ -223,6 +236,7 @@ describe API::Projects, api: true do
get api('/projects', user), { visibility: 'public', owned: true, starred: true, search: 'gitlab' } get api('/projects', user), { visibility: 'public', owned: true, starred: true, search: 'gitlab' }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response.first['id']).to eq(project5.id) expect(json_response.first['id']).to eq(project5.id)
...@@ -644,9 +658,10 @@ describe API::Projects, api: true do ...@@ -644,9 +658,10 @@ describe API::Projects, api: true do
get api("/projects/#{project.id}/events", current_user) get api("/projects/#{project.id}/events", current_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
first_event = json_response.first first_event = json_response.first
expect(first_event['action_name']).to eq('commented on') expect(first_event['action_name']).to eq('commented on')
expect(first_event['note']['body']).to eq('What an awesome day!') expect(first_event['note']['body']).to eq('What an awesome day!')
...@@ -699,11 +714,11 @@ describe API::Projects, api: true do ...@@ -699,11 +714,11 @@ describe API::Projects, api: true do
get api("/projects/#{project.id}/users", current_user) get api("/projects/#{project.id}/users", current_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
first_user = json_response.first first_user = json_response.first
expect(first_user['username']).to eq(member.username) expect(first_user['username']).to eq(member.username)
expect(first_user['name']).to eq(member.name) expect(first_user['name']).to eq(member.name)
expect(first_user.keys).to contain_exactly(*%w[name username id state avatar_url web_url]) expect(first_user.keys).to contain_exactly(*%w[name username id state avatar_url web_url])
...@@ -746,7 +761,9 @@ describe API::Projects, api: true do ...@@ -746,7 +761,9 @@ describe API::Projects, api: true do
it 'returns an array of project snippets' do it 'returns an array of project snippets' do
get api("/projects/#{project.id}/snippets", user) get api("/projects/#{project.id}/snippets", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(snippet.title) expect(json_response.first['title']).to eq(snippet.title)
end end
......
...@@ -19,10 +19,10 @@ describe API::Repositories, api: true do ...@@ -19,10 +19,10 @@ describe API::Repositories, api: true do
get api(route, current_user) get api(route, current_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
first_commit = json_response.first first_commit = json_response.first
expect(json_response).to be_an Array
expect(first_commit['name']).to eq('bar') expect(first_commit['name']).to eq('bar')
expect(first_commit['type']).to eq('tree') expect(first_commit['type']).to eq('tree')
expect(first_commit['mode']).to eq('040000') expect(first_commit['mode']).to eq('040000')
...@@ -49,6 +49,7 @@ describe API::Repositories, api: true do ...@@ -49,6 +49,7 @@ describe API::Repositories, api: true do
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(response).to include_pagination_headers
expect(json_response[4]['name']).to eq('html') expect(json_response[4]['name']).to eq('html')
expect(json_response[4]['path']).to eq('files/html') expect(json_response[4]['path']).to eq('files/html')
expect(json_response[4]['type']).to eq('tree') expect(json_response[4]['type']).to eq('tree')
...@@ -380,10 +381,10 @@ describe API::Repositories, api: true do ...@@ -380,10 +381,10 @@ describe API::Repositories, api: true do
get api(route, current_user) get api(route, current_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
first_contributor = json_response.first first_contributor = json_response.first
expect(first_contributor['email']).to eq('tiagonbotelho@hotmail.com') expect(first_contributor['email']).to eq('tiagonbotelho@hotmail.com')
expect(first_contributor['name']).to eq('tiagonbotelho') expect(first_contributor['name']).to eq('tiagonbotelho')
expect(first_contributor['commits']).to eq(1) expect(first_contributor['commits']).to eq(1)
......
...@@ -37,18 +37,20 @@ describe API::Runners, api: true do ...@@ -37,18 +37,20 @@ describe API::Runners, api: true do
context 'authorized user' do context 'authorized user' do
it 'returns user available runners' do it 'returns user available runners' do
get api('/runners', user) get api('/runners', user)
shared = json_response.any?{ |r| r['is_shared'] }
shared = json_response.any?{ |r| r['is_shared'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(shared).to be_falsey expect(shared).to be_falsey
end end
it 'filters runners by scope' do it 'filters runners by scope' do
get api('/runners?scope=active', user) get api('/runners?scope=active', user)
shared = json_response.any?{ |r| r['is_shared'] }
shared = json_response.any?{ |r| r['is_shared'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(shared).to be_falsey expect(shared).to be_falsey
end end
...@@ -73,9 +75,10 @@ describe API::Runners, api: true do ...@@ -73,9 +75,10 @@ describe API::Runners, api: true do
context 'with admin privileges' do context 'with admin privileges' do
it 'returns all runners' do it 'returns all runners' do
get api('/runners/all', admin) get api('/runners/all', admin)
shared = json_response.any?{ |r| r['is_shared'] }
shared = json_response.any?{ |r| r['is_shared'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(shared).to be_truthy expect(shared).to be_truthy
end end
...@@ -91,9 +94,10 @@ describe API::Runners, api: true do ...@@ -91,9 +94,10 @@ describe API::Runners, api: true do
it 'filters runners by scope' do it 'filters runners by scope' do
get api('/runners/all?scope=specific', admin) get api('/runners/all?scope=specific', admin)
shared = json_response.any?{ |r| r['is_shared'] }
shared = json_response.any?{ |r| r['is_shared'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(shared).to be_falsey expect(shared).to be_falsey
end end
...@@ -342,9 +346,10 @@ describe API::Runners, api: true do ...@@ -342,9 +346,10 @@ describe API::Runners, api: true do
context 'authorized user with master privileges' do context 'authorized user with master privileges' do
it "returns project's runners" do it "returns project's runners" do
get api("/projects/#{project.id}/runners", user) get api("/projects/#{project.id}/runners", user)
shared = json_response.any?{ |r| r['is_shared'] }
shared = json_response.any?{ |r| r['is_shared'] }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(shared).to be_truthy expect(shared).to be_truthy
end end
......
...@@ -13,6 +13,8 @@ describe API::Snippets, api: true do ...@@ -13,6 +13,8 @@ describe API::Snippets, api: true do
get api("/snippets/", user) get api("/snippets/", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.map { |snippet| snippet['id']} ).to contain_exactly( expect(json_response.map { |snippet| snippet['id']} ).to contain_exactly(
public_snippet.id, public_snippet.id,
internal_snippet.id, internal_snippet.id,
...@@ -25,7 +27,10 @@ describe API::Snippets, api: true do ...@@ -25,7 +27,10 @@ describe API::Snippets, api: true do
create(:personal_snippet, :private) create(:personal_snippet, :private)
get api("/snippets/", user) get api("/snippets/", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(0) expect(json_response.size).to eq(0)
end end
end end
...@@ -43,6 +48,8 @@ describe API::Snippets, api: true do ...@@ -43,6 +48,8 @@ describe API::Snippets, api: true do
get api("/snippets/public", user) get api("/snippets/public", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.map { |snippet| snippet['id']} ).to contain_exactly( expect(json_response.map { |snippet| snippet['id']} ).to contain_exactly(
public_snippet.id, public_snippet.id,
public_snippet_other.id) public_snippet_other.id)
......
...@@ -31,6 +31,7 @@ describe API::SystemHooks, api: true do ...@@ -31,6 +31,7 @@ describe API::SystemHooks, api: true do
get api("/hooks", admin) get api("/hooks", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['url']).to eq(hook.url) expect(json_response.first['url']).to eq(hook.url)
expect(json_response.first['push_events']).to be true expect(json_response.first['push_events']).to be true
......
...@@ -20,10 +20,9 @@ describe API::Tags, api: true do ...@@ -20,10 +20,9 @@ describe API::Tags, api: true do
get api("/projects/#{project.id}/repository/tags", current_user) get api("/projects/#{project.id}/repository/tags", current_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
first_tag = json_response.first expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(tag_name)
expect(first_tag['name']).to eq(tag_name)
end end
end end
...@@ -43,7 +42,9 @@ describe API::Tags, api: true do ...@@ -43,7 +42,9 @@ describe API::Tags, api: true do
context 'without releases' do context 'without releases' do
it "returns an array of project tags" do it "returns an array of project tags" do
get api("/projects/#{project.id}/repository/tags", user) get api("/projects/#{project.id}/repository/tags", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(tag_name) expect(json_response.first['name']).to eq(tag_name)
end end
...@@ -59,6 +60,7 @@ describe API::Tags, api: true do ...@@ -59,6 +60,7 @@ describe API::Tags, api: true do
get api("/projects/#{project.id}/repository/tags", user) get api("/projects/#{project.id}/repository/tags", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(tag_name) expect(json_response.first['name']).to eq(tag_name)
expect(json_response.first['message']).to eq('Version 1.1.0') expect(json_response.first['message']).to eq('Version 1.1.0')
......
...@@ -22,6 +22,7 @@ describe API::Templates, api: true do ...@@ -22,6 +22,7 @@ describe API::Templates, api: true do
get api('/templates/gitignores') get api('/templates/gitignores')
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to be > 15 expect(json_response.size).to be > 15
end end
...@@ -32,6 +33,7 @@ describe API::Templates, api: true do ...@@ -32,6 +33,7 @@ describe API::Templates, api: true do
get api('/templates/gitlab_ci_ymls') get api('/templates/gitlab_ci_ymls')
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).not_to be_nil expect(json_response.first['name']).not_to be_nil
end end
...@@ -69,6 +71,7 @@ describe API::Templates, api: true do ...@@ -69,6 +71,7 @@ describe API::Templates, api: true do
get api('/templates/licenses') get api('/templates/licenses')
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(15) expect(json_response.size).to eq(15)
expect(json_response.map { |l| l['key'] }).to include('agpl-3.0') expect(json_response.map { |l| l['key'] }).to include('agpl-3.0')
...@@ -80,6 +83,7 @@ describe API::Templates, api: true do ...@@ -80,6 +83,7 @@ describe API::Templates, api: true do
get api('/templates/licenses?popular=1') get api('/templates/licenses?popular=1')
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(3) expect(json_response.size).to eq(3)
expect(json_response.map { |l| l['key'] }).to include('apache-2.0') expect(json_response.map { |l| l['key'] }).to include('apache-2.0')
......
...@@ -33,6 +33,7 @@ describe API::Todos, api: true do ...@@ -33,6 +33,7 @@ describe API::Todos, api: true do
get api('/todos', john_doe) get api('/todos', john_doe)
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response[0]['id']).to eq(pending_3.id) expect(json_response[0]['id']).to eq(pending_3.id)
...@@ -52,6 +53,7 @@ describe API::Todos, api: true do ...@@ -52,6 +53,7 @@ describe API::Todos, api: true do
get api('/todos', john_doe), { author_id: author_2.id } get api('/todos', john_doe), { author_id: author_2.id }
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
end end
...@@ -64,6 +66,7 @@ describe API::Todos, api: true do ...@@ -64,6 +66,7 @@ describe API::Todos, api: true do
get api('/todos', john_doe), { type: 'MergeRequest' } get api('/todos', john_doe), { type: 'MergeRequest' }
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
...@@ -74,6 +77,7 @@ describe API::Todos, api: true do ...@@ -74,6 +77,7 @@ describe API::Todos, api: true do
get api('/todos', john_doe), { state: 'done' } get api('/todos', john_doe), { state: 'done' }
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
...@@ -84,6 +88,7 @@ describe API::Todos, api: true do ...@@ -84,6 +88,7 @@ describe API::Todos, api: true do
get api('/todos', john_doe), { project_id: project_2.id } get api('/todos', john_doe), { project_id: project_2.id }
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
...@@ -94,6 +99,7 @@ describe API::Todos, api: true do ...@@ -94,6 +99,7 @@ describe API::Todos, api: true do
get api('/todos', john_doe), { action: 'mentioned' } get api('/todos', john_doe), { action: 'mentioned' }
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
......
...@@ -100,6 +100,7 @@ describe API::Triggers do ...@@ -100,6 +100,7 @@ describe API::Triggers do
get api("/projects/#{project.id}/triggers", user) get api("/projects/#{project.id}/triggers", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_a(Array) expect(json_response).to be_a(Array)
expect(json_response[0]).to have_key('token') expect(json_response[0]).to have_key('token')
end end
......
...@@ -40,7 +40,9 @@ describe API::Users, api: true do ...@@ -40,7 +40,9 @@ describe API::Users, api: true do
it "returns an array of users" do it "returns an array of users" do
get api("/users", user) get api("/users", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
username = user.username username = user.username
expect(json_response.detect do |user| expect(json_response.detect do |user|
...@@ -55,13 +57,16 @@ describe API::Users, api: true do ...@@ -55,13 +57,16 @@ describe API::Users, api: true do
get api("/users?blocked=true", user) get api("/users?blocked=true", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response).to all(include('state' => /(blocked|ldap_blocked)/)) expect(json_response).to all(include('state' => /(blocked|ldap_blocked)/))
end end
it "returns one user" do it "returns one user" do
get api("/users?username=#{omniauth_user.username}", user) get api("/users?username=#{omniauth_user.username}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['username']).to eq(omniauth_user.username) expect(json_response.first['username']).to eq(omniauth_user.username)
end end
...@@ -70,7 +75,9 @@ describe API::Users, api: true do ...@@ -70,7 +75,9 @@ describe API::Users, api: true do
context "when admin" do context "when admin" do
it "returns an array of users" do it "returns an array of users" do
get api("/users", admin) get api("/users", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first.keys).to include 'email' expect(json_response.first.keys).to include 'email'
expect(json_response.first.keys).to include 'organization' expect(json_response.first.keys).to include 'organization'
...@@ -87,6 +94,7 @@ describe API::Users, api: true do ...@@ -87,6 +94,7 @@ describe API::Users, api: true do
get api("/users?external=true", admin) get api("/users?external=true", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response).to all(include('external' => true)) expect(json_response).to all(include('external' => true))
end end
...@@ -507,8 +515,11 @@ describe API::Users, api: true do ...@@ -507,8 +515,11 @@ describe API::Users, api: true do
it 'returns array of ssh keys' do it 'returns array of ssh keys' do
user.keys << key user.keys << key
user.save user.save
get api("/users/#{user.id}/keys", admin) get api("/users/#{user.id}/keys", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(key.title) expect(json_response.first['title']).to eq(key.title)
end end
...@@ -595,8 +606,11 @@ describe API::Users, api: true do ...@@ -595,8 +606,11 @@ describe API::Users, api: true do
it 'returns array of emails' do it 'returns array of emails' do
user.emails << email user.emails << email
user.save user.save
get api("/users/#{user.id}/emails", admin) get api("/users/#{user.id}/emails", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['email']).to eq(email.email) expect(json_response.first['email']).to eq(email.email)
end end
...@@ -774,8 +788,11 @@ describe API::Users, api: true do ...@@ -774,8 +788,11 @@ describe API::Users, api: true do
it "returns array of ssh keys" do it "returns array of ssh keys" do
user.keys << key user.keys << key
user.save user.save
get api("/user/keys", user) get api("/user/keys", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first["title"]).to eq(key.title) expect(json_response.first["title"]).to eq(key.title)
end end
...@@ -891,8 +908,11 @@ describe API::Users, api: true do ...@@ -891,8 +908,11 @@ describe API::Users, api: true do
it "returns array of emails" do it "returns array of emails" do
user.emails << email user.emails << email
user.save user.save
get api("/user/emails", user) get api("/user/emails", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first["email"]).to eq(email.email) expect(json_response.first["email"]).to eq(email.email)
end end
......
require 'spec_helper'
describe API::V3::Boards, api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:guest) { create(:user) }
let!(:project) { create(:empty_project, :public, creator_id: user.id, namespace: user.namespace ) }
let!(:dev_label) do
create(:label, title: 'Development', color: '#FFAABB', project: project)
end
let!(:test_label) do
create(:label, title: 'Testing', color: '#FFAACC', project: project)
end
let!(:dev_list) do
create(:list, label: dev_label, position: 1)
end
let!(:test_list) do
create(:list, label: test_label, position: 2)
end
let!(:board) do
create(:board, project: project, lists: [dev_list, test_list])
end
before do
project.team << [user, :reporter]
project.team << [guest, :guest]
end
describe "GET /projects/:id/boards" do
let(:base_url) { "/projects/#{project.id}/boards" }
context "when unauthenticated" do
it "returns authentication error" do
get v3_api(base_url)
expect(response).to have_http_status(401)
end
end
context "when authenticated" do
it "returns the project issue board" do
get v3_api(base_url, user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(board.id)
expect(json_response.first['lists']).to be_an Array
expect(json_response.first['lists'].length).to eq(2)
expect(json_response.first['lists'].last).to have_key('position')
end
end
end
describe "GET /projects/:id/boards/:board_id/lists" do
let(:base_url) { "/projects/#{project.id}/boards/#{board.id}/lists" }
it 'returns issue board lists' do
get v3_api(base_url, user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.length).to eq(2)
expect(json_response.first['label']['name']).to eq(dev_label.title)
end
it 'returns 404 if board not found' do
get v3_api("/projects/#{project.id}/boards/22343/lists", user)
expect(response).to have_http_status(404)
end
end
end
require 'spec_helper'
require 'mime/types'
describe API::V3::Branches, api: true do
include ApiHelpers
let(:user) { create(:user) }
let!(:project) { create(:project, :repository, creator: user) }
let!(:master) { create(:project_member, :master, user: user, project: project) }
describe "GET /projects/:id/repository/branches" do
it "returns an array of project branches" do
project.repository.expire_all_method_caches
get v3_api("/projects/#{project.id}/repository/branches", user), per_page: 100
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
branch_names = json_response.map { |x| x['name'] }
expect(branch_names).to match_array(project.repository.branch_names)
end
end
end
require 'spec_helper'
describe API::V3::Labels, api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:project) { create(:empty_project, creator_id: user.id, namespace: user.namespace) }
let!(:label1) { create(:label, title: 'label1', project: project) }
let!(:priority_label) { create(:label, title: 'bug', project: project, priority: 3) }
before do
project.team << [user, :master]
end
describe 'GET /projects/:id/labels' do
it 'returns all available labels to the project' do
group = create(:group)
group_label = create(:group_label, title: 'feature', group: group)
project.update(group: group)
create(:labeled_issue, project: project, labels: [group_label], author: user)
create(:labeled_issue, project: project, labels: [label1], author: user, state: :closed)
create(:labeled_merge_request, labels: [priority_label], author: user, source_project: project )
expected_keys = [
'id', 'name', 'color', 'description',
'open_issues_count', 'closed_issues_count', 'open_merge_requests_count',
'subscribed', 'priority'
]
get v3_api("/projects/#{project.id}/labels", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.size).to eq(3)
expect(json_response.first.keys).to match_array expected_keys
expect(json_response.map { |l| l['name'] }).to match_array([group_label.name, priority_label.name, label1.name])
label1_response = json_response.find { |l| l['name'] == label1.title }
group_label_response = json_response.find { |l| l['name'] == group_label.title }
priority_label_response = json_response.find { |l| l['name'] == priority_label.title }
expect(label1_response['open_issues_count']).to eq(0)
expect(label1_response['closed_issues_count']).to eq(1)
expect(label1_response['open_merge_requests_count']).to eq(0)
expect(label1_response['name']).to eq(label1.name)
expect(label1_response['color']).to be_present
expect(label1_response['description']).to be_nil
expect(label1_response['priority']).to be_nil
expect(label1_response['subscribed']).to be_falsey
expect(group_label_response['open_issues_count']).to eq(1)
expect(group_label_response['closed_issues_count']).to eq(0)
expect(group_label_response['open_merge_requests_count']).to eq(0)
expect(group_label_response['name']).to eq(group_label.name)
expect(group_label_response['color']).to be_present
expect(group_label_response['description']).to be_nil
expect(group_label_response['priority']).to be_nil
expect(group_label_response['subscribed']).to be_falsey
expect(priority_label_response['open_issues_count']).to eq(0)
expect(priority_label_response['closed_issues_count']).to eq(0)
expect(priority_label_response['open_merge_requests_count']).to eq(1)
expect(priority_label_response['name']).to eq(priority_label.name)
expect(priority_label_response['color']).to be_present
expect(priority_label_response['description']).to be_nil
expect(priority_label_response['priority']).to eq(3)
expect(priority_label_response['subscribed']).to be_falsey
end
end
end
require 'spec_helper'
require 'mime/types'
describe API::V3::Repositories, api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:guest) { create(:user).tap { |u| create(:project_member, :guest, user: u, project: project) } }
let!(:project) { create(:project, :repository, creator: user) }
let!(:master) { create(:project_member, :master, user: user, project: project) }
describe "GET /projects/:id/repository/tree" do
let(:route) { "/projects/#{project.id}/repository/tree" }
shared_examples_for 'repository tree' do
it 'returns the repository tree' do
get v3_api(route, current_user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
first_commit = json_response.first
expect(first_commit['name']).to eq('bar')
expect(first_commit['type']).to eq('tree')
expect(first_commit['mode']).to eq('040000')
end
context 'when ref does not exist' do
it_behaves_like '404 response' do
let(:request) { get v3_api("#{route}?ref_name=foo", current_user) }
let(:message) { '404 Tree Not Found' }
end
end
context 'when repository is disabled' do
include_context 'disabled repository'
it_behaves_like '403 response' do
let(:request) { get v3_api(route, current_user) }
end
end
context 'with recursive=1' do
it 'returns recursive project paths tree' do
get v3_api("#{route}?recursive=1", current_user)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
expect(json_response[4]['name']).to eq('html')
expect(json_response[4]['path']).to eq('files/html')
expect(json_response[4]['type']).to eq('tree')
expect(json_response[4]['mode']).to eq('040000')
end
context 'when repository is disabled' do
include_context 'disabled repository'
it_behaves_like '403 response' do
let(:request) { get v3_api(route, current_user) }
end
end
context 'when ref does not exist' do
it_behaves_like '404 response' do
let(:request) { get v3_api("#{route}?recursive=1&ref_name=foo", current_user) }
let(:message) { '404 Tree Not Found' }
end
end
end
end
context 'when unauthenticated', 'and project is public' do
it_behaves_like 'repository tree' do
let(:project) { create(:project, :public, :repository) }
let(:current_user) { nil }
end
end
context 'when unauthenticated', 'and project is private' do
it_behaves_like '404 response' do
let(:request) { get v3_api(route) }
let(:message) { '404 Project Not Found' }
end
end
context 'when authenticated', 'as a developer' do
it_behaves_like 'repository tree' do
let(:current_user) { user }
end
end
context 'when authenticated', 'as a guest' do
it_behaves_like '403 response' do
let(:request) { get v3_api(route, guest) }
end
end
end
describe 'GET /projects/:id/repository/contributors' do
let(:route) { "/projects/#{project.id}/repository/contributors" }
shared_examples_for 'repository contributors' do
it 'returns valid data' do
get v3_api(route, current_user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
first_contributor = json_response.first
expect(first_contributor['email']).to eq('tiagonbotelho@hotmail.com')
expect(first_contributor['name']).to eq('tiagonbotelho')
expect(first_contributor['commits']).to eq(1)
expect(first_contributor['additions']).to eq(0)
expect(first_contributor['deletions']).to eq(0)
end
end
context 'when unauthenticated', 'and project is public' do
it_behaves_like 'repository contributors' do
let(:project) { create(:project, :public, :repository) }
let(:current_user) { nil }
end
end
context 'when unauthenticated', 'and project is private' do
it_behaves_like '404 response' do
let(:request) { get v3_api(route) }
let(:message) { '404 Project Not Found' }
end
end
context 'when authenticated', 'as a developer' do
it_behaves_like 'repository contributors' do
let(:current_user) { user }
end
end
context 'when authenticated', 'as a guest' do
it_behaves_like '403 response' do
let(:request) { get v3_api(route, guest) }
end
end
end
end
require 'spec_helper'
describe API::V3::SystemHooks, api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:admin) { create(:admin) }
let!(:hook) { create(:system_hook, url: "http://example.com") }
before { stub_request(:post, hook.url) }
describe "GET /hooks" do
context "when no user" do
it "returns authentication error" do
get v3_api("/hooks")
expect(response).to have_http_status(401)
end
end
context "when not an admin" do
it "returns forbidden error" do
get v3_api("/hooks", user)
expect(response).to have_http_status(403)
end
end
context "when authenticated as admin" do
it "returns an array of hooks" do
get v3_api("/hooks", admin)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first['url']).to eq(hook.url)
expect(json_response.first['push_events']).to be true
expect(json_response.first['tag_push_events']).to be false
end
end
end
end
require 'spec_helper'
require 'mime/types'
describe API::V3::Tags, api: true do
include ApiHelpers
include RepoHelpers
let(:user) { create(:user) }
let(:user2) { create(:user) }
let!(:project) { create(:project, :repository, creator: user) }
let!(:master) { create(:project_member, :master, user: user, project: project) }
describe "GET /projects/:id/repository/tags" do
let(:tag_name) { project.repository.tag_names.sort.reverse.first }
let(:description) { 'Awesome release!' }
shared_examples_for 'repository tags' do
it 'returns the repository tags' do
get v3_api("/projects/#{project.id}/repository/tags", current_user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(tag_name)
end
end
context 'when unauthenticated' do
it_behaves_like 'repository tags' do
let(:project) { create(:project, :public, :repository) }
let(:current_user) { nil }
end
end
context 'when authenticated' do
it_behaves_like 'repository tags' do
let(:current_user) { user }
end
end
context 'without releases' do
it "returns an array of project tags" do
get v3_api("/projects/#{project.id}/repository/tags", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(tag_name)
end
end
context 'with releases' do
before do
release = project.releases.find_or_initialize_by(tag: tag_name)
release.update_attributes(description: description)
end
it "returns an array of project tags with release info" do
get v3_api("/projects/#{project.id}/repository/tags", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(tag_name)
expect(json_response.first['message']).to eq('Version 1.1.0')
expect(json_response.first['release']['description']).to eq(description)
end
end
end
end
require 'spec_helper'
describe API::V3::Users, api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:admin) { create(:admin) }
let(:key) { create(:key, user: user) }
let(:email) { create(:email, user: user) }
describe 'GET /user/:id/keys' do
before { admin }
context 'when unauthenticated' do
it 'returns authentication error' do
get v3_api("/users/#{user.id}/keys")
expect(response).to have_http_status(401)
end
end
context 'when authenticated' do
it 'returns 404 for non-existing user' do
get v3_api('/users/999999/keys', admin)
expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 User Not Found')
end
it 'returns array of ssh keys' do
user.keys << key
user.save
get v3_api("/users/#{user.id}/keys", admin)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(key.title)
end
end
end
describe 'GET /user/:id/emails' do
before { admin }
context 'when unauthenticated' do
it 'returns authentication error' do
get v3_api("/users/#{user.id}/emails")
expect(response).to have_http_status(401)
end
end
context 'when authenticated' do
it 'returns 404 for non-existing user' do
get v3_api('/users/999999/emails', admin)
expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 User Not Found')
end
it 'returns array of emails' do
user.emails << email
user.save
get v3_api("/users/#{user.id}/emails", admin)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first['email']).to eq(email.email)
end
it "returns a 404 for invalid ID" do
put v3_api("/users/ASDF/emails", admin)
expect(response).to have_http_status(404)
end
end
end
describe "GET /user/keys" do
context "when unauthenticated" do
it "returns authentication error" do
get v3_api("/user/keys")
expect(response).to have_http_status(401)
end
end
context "when authenticated" do
it "returns array of ssh keys" do
user.keys << key
user.save
get v3_api("/user/keys", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first["title"]).to eq(key.title)
end
end
end
describe "GET /user/emails" do
context "when unauthenticated" do
it "returns authentication error" do
get v3_api("/user/emails")
expect(response).to have_http_status(401)
end
end
context "when authenticated" do
it "returns array of emails" do
user.emails << email
user.save
get v3_api("/user/emails", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first["email"]).to eq(email.email)
end
end
end
end
RSpec::Matchers.define :include_pagination_headers do |expected|
match do |actual|
expect(actual.headers).to include('X-Total', 'X-Total-Pages', 'X-Per-Page', 'X-Page', 'X-Next-Page', 'X-Prev-Page', 'Link')
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment