Commit e2a2acd8 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents 82d7b5a0 e5c7027f
...@@ -7,7 +7,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -7,7 +7,7 @@ class Admin::UsersController < Admin::ApplicationController
before_action :check_impersonation_availability, only: :impersonate before_action :check_impersonation_availability, only: :impersonate
def index def index
@users = User.order_name_asc.filter(params[:filter]) @users = User.filter_items(params[:filter]).order_name_asc
@users = @users.search_with_secondary_emails(params[:search_query]) if params[:search_query].present? @users = @users.search_with_secondary_emails(params[:search_query]) if params[:search_query].present?
@users = @users.sort_by_attribute(@sort = params[:sort]) @users = @users.sort_by_attribute(@sort = params[:sort])
@users = @users.page(params[:page]) @users = @users.page(params[:page])
......
...@@ -595,6 +595,14 @@ class Project < ActiveRecord::Base ...@@ -595,6 +595,14 @@ class Project < ActiveRecord::Base
end end
end end
def ci_pipelines
if builds_enabled?
super
else
super.external
end
end
# returns all ancestor-groups upto but excluding the given namespace # returns all ancestor-groups upto but excluding the given namespace
# when no namespace is given, all ancestors upto the top are returned # when no namespace is given, all ancestors upto the top are returned
def ancestors_upto(top = nil, hierarchy_order: nil) def ancestors_upto(top = nil, hierarchy_order: nil)
......
...@@ -388,7 +388,7 @@ class User < ApplicationRecord ...@@ -388,7 +388,7 @@ class User < ApplicationRecord
find_by(id: user_id) find_by(id: user_id)
end end
def filter(filter_name) def filter_items(filter_name)
case filter_name case filter_name
when 'admins' when 'admins'
admins admins
......
---
title: Hide pipeline status when pipelines are disabled on project.
merge_request: 25204
author:
type: fixed
---
title: Allow configuring POSTGRES_VERSION in Auto DevOps
merge_request: 25500
author:
type: added
...@@ -697,6 +697,7 @@ also be customized, and you can easily use a [custom buildpack](#custom-buildpac ...@@ -697,6 +697,7 @@ also be customized, and you can easily use a [custom buildpack](#custom-buildpac
| `POSTGRES_USER` | The PostgreSQL user; defaults to `user`. Set it to use a custom username. | | `POSTGRES_USER` | The PostgreSQL user; defaults to `user`. Set it to use a custom username. |
| `POSTGRES_PASSWORD` | The PostgreSQL password; defaults to `testing-password`. Set it to use a custom password. | | `POSTGRES_PASSWORD` | The PostgreSQL password; defaults to `testing-password`. Set it to use a custom password. |
| `POSTGRES_DB` | The PostgreSQL database name; defaults to the value of [`$CI_ENVIRONMENT_SLUG`](../../ci/variables/README.md#predefined-environment-variables). Set it to use a custom database name. | | `POSTGRES_DB` | The PostgreSQL database name; defaults to the value of [`$CI_ENVIRONMENT_SLUG`](../../ci/variables/README.md#predefined-environment-variables). Set it to use a custom database name. |
| `POSTGRES_VERSION` | The PostgreSQL version; defaults to `9.6.2` |
| `BUILDPACK_URL` | The buildpack's full URL. It can point to either Git repositories or a tarball URL. For Git repositories, it is possible to point to a specific `ref`, for example `https://github.com/heroku/heroku-buildpack-ruby.git#v142` | | `BUILDPACK_URL` | The buildpack's full URL. It can point to either Git repositories or a tarball URL. For Git repositories, it is possible to point to a specific `ref`, for example `https://github.com/heroku/heroku-buildpack-ruby.git#v142` |
| `SAST_CONFIDENCE_LEVEL` | The minimum confidence level of security issues you want to be reported; `1` for Low, `2` for Medium, `3` for High; defaults to `3`.| | `SAST_CONFIDENCE_LEVEL` | The minimum confidence level of security issues you want to be reported; `1` for Low, `2` for Medium, `3` for High; defaults to `3`.|
| `DEP_SCAN_DISABLE_REMOTE_CHECKS` | Whether remote Dependency Scanning checks are disabled; defaults to `"false"`. Set to `"true"` to disable checks that send data to GitLab central servers. [Read more about remote checks](https://gitlab.com/gitlab-org/security-products/dependency-scanning#remote-checks).| | `DEP_SCAN_DISABLE_REMOTE_CHECKS` | Whether remote Dependency Scanning checks are disabled; defaults to `"false"`. Set to `"true"` to disable checks that send data to GitLab central servers. [Read more about remote checks](https://gitlab.com/gitlab-org/security-products/dependency-scanning#remote-checks).|
......
...@@ -13,6 +13,33 @@ module API ...@@ -13,6 +13,33 @@ module API
strategy.new(self).paginate(relation) strategy.new(self).paginate(relation)
end end
class Base
private
def per_page
@per_page ||= params[:per_page]
end
def base_request_uri
@base_request_uri ||= URI.parse(request.url).tap do |uri|
uri.host = Gitlab.config.gitlab.host
uri.port = nil
end
end
def build_page_url(query_params:)
base_request_uri.tap do |uri|
uri.query = query_params
end.to_s
end
def page_href(next_page_params = {})
query_params = params.merge(**next_page_params, per_page: per_page).to_query
build_page_url(query_params: query_params)
end
end
class KeysetPaginationInfo class KeysetPaginationInfo
attr_reader :relation, :request_context attr_reader :relation, :request_context
...@@ -85,7 +112,7 @@ module API ...@@ -85,7 +112,7 @@ module API
end end
end end
class KeysetPaginationStrategy class KeysetPaginationStrategy < Base
attr_reader :request_context attr_reader :request_context
delegate :params, :header, :request, to: :request_context delegate :params, :header, :request, to: :request_context
...@@ -141,10 +168,6 @@ module API ...@@ -141,10 +168,6 @@ module API
] ]
end end
def per_page
params[:per_page]
end
def add_default_pagination_headers def add_default_pagination_headers
header 'X-Per-Page', per_page.to_s header 'X-Per-Page', per_page.to_s
end end
...@@ -154,22 +177,12 @@ module API ...@@ -154,22 +177,12 @@ module API
header 'Link', link_for('next', next_page_params) header 'Link', link_for('next', next_page_params)
end end
def page_href(next_page_params)
request_url = request.url.split('?').first
request_params = params.dup
request_params[:per_page] = per_page
request_params.merge!(next_page_params) if next_page_params
"#{request_url}?#{request_params.to_query}"
end
def link_for(rel, next_page_params) def link_for(rel, next_page_params)
%(<#{page_href(next_page_params)}>; rel="#{rel}") %(<#{page_href(next_page_params)}>; rel="#{rel}")
end end
end end
class DefaultPaginationStrategy class DefaultPaginationStrategy < Base
attr_reader :request_context attr_reader :request_context
delegate :params, :header, :request, to: :request_context delegate :params, :header, :request, to: :request_context
...@@ -198,15 +211,13 @@ module API ...@@ -198,15 +211,13 @@ module API
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def add_default_order(relation) def add_default_order(relation)
if relation.is_a?(ActiveRecord::Relation) && relation.order_values.empty? if relation.is_a?(ActiveRecord::Relation) && relation.order_values.empty?
relation = relation.order(:id) relation = relation.order(:id) # rubocop: disable CodeReuse/ActiveRecord
end end
relation relation
end end
# rubocop: enable CodeReuse/ActiveRecord
def add_pagination_headers(paginated_data) def add_pagination_headers(paginated_data)
header 'X-Per-Page', paginated_data.limit_value.to_s header 'X-Per-Page', paginated_data.limit_value.to_s
...@@ -222,27 +233,13 @@ module API ...@@ -222,27 +233,13 @@ module API
end end
def pagination_links(paginated_data) def pagination_links(paginated_data)
request_url = request.url.split('?').first [].tap do |links|
request_params = params.clone links << %(<#{page_href(page: paginated_data.prev_page)}>; rel="prev") if paginated_data.prev_page
request_params[:per_page] = paginated_data.limit_value links << %(<#{page_href(page: paginated_data.next_page)}>; rel="next") if paginated_data.next_page
links << %(<#{page_href(page: 1)}>; rel="first")
links = []
request_params[:page] = paginated_data.prev_page
links << %(<#{request_url}?#{request_params.to_query}>; rel="prev") if request_params[:page]
request_params[:page] = paginated_data.next_page
links << %(<#{request_url}?#{request_params.to_query}>; rel="next") if request_params[:page]
request_params[:page] = 1
links << %(<#{request_url}?#{request_params.to_query}>; rel="first")
unless data_without_counts?(paginated_data)
request_params[:page] = total_pages(paginated_data)
links << %(<#{request_url}?#{request_params.to_query}>; rel="last")
end
links.join(', ') links << %(<#{page_href(page: total_pages(paginated_data))}>; rel="last") unless data_without_counts?(paginated_data)
end.join(', ')
end end
def total_pages(paginated_data) def total_pages(paginated_data)
......
...@@ -48,6 +48,7 @@ variables: ...@@ -48,6 +48,7 @@ variables:
POSTGRES_PASSWORD: testing-password POSTGRES_PASSWORD: testing-password
POSTGRES_ENABLED: "true" POSTGRES_ENABLED: "true"
POSTGRES_DB: $CI_ENVIRONMENT_SLUG POSTGRES_DB: $CI_ENVIRONMENT_SLUG
POSTGRES_VERSION: 9.6.2
KUBERNETES_VERSION: 1.11.7 KUBERNETES_VERSION: 1.11.7
HELM_VERSION: 2.12.3 HELM_VERSION: 2.12.3
...@@ -700,6 +701,7 @@ rollout 100%: ...@@ -700,6 +701,7 @@ rollout 100%:
--set postgresql.postgresUser="$POSTGRES_USER" \ --set postgresql.postgresUser="$POSTGRES_USER" \
--set postgresql.postgresPassword="$POSTGRES_PASSWORD" \ --set postgresql.postgresPassword="$POSTGRES_PASSWORD" \
--set postgresql.postgresDatabase="$POSTGRES_DB" \ --set postgresql.postgresDatabase="$POSTGRES_DB" \
--set postgresql.imageTag="$POSTGRES_VERSION" \
--set application.initializeCommand="$DB_INITIALIZE" \ --set application.initializeCommand="$DB_INITIALIZE" \
--namespace="$KUBE_NAMESPACE" \ --namespace="$KUBE_NAMESPACE" \
"$name" \ "$name" \
......
...@@ -8,6 +8,20 @@ describe Admin::UsersController do ...@@ -8,6 +8,20 @@ describe Admin::UsersController do
sign_in(admin) sign_in(admin)
end end
describe 'GET #index' do
it 'retrieves all users' do
get :index
expect(assigns(:users)).to match_array([user, admin])
end
it 'filters by admins' do
get :index, params: { filter: 'admins' }
expect(assigns(:users)).to eq([admin])
end
end
describe 'GET :id' do describe 'GET :id' do
it 'finds a user case-insensitively' do it 'finds a user case-insensitively' do
user = create(:user, username: 'CaseSensitive') user = create(:user, username: 'CaseSensitive')
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
describe API::Helpers::Pagination do describe API::Helpers::Pagination do
let(:resource) { Project.all } let(:resource) { Project.all }
let(:incoming_api_projects_url) { "#{Gitlab.config.gitlab.url}:8080/api/v4/projects" }
let(:canonical_api_projects_url) { "#{Gitlab.config.gitlab.url}/api/v4/projects" }
subject do subject do
Class.new.include(described_class).new Class.new.include(described_class).new
...@@ -9,13 +11,19 @@ describe API::Helpers::Pagination do ...@@ -9,13 +11,19 @@ describe API::Helpers::Pagination do
describe '#paginate (keyset pagination)' do describe '#paginate (keyset pagination)' do
let(:value) { spy('return value') } let(:value) { spy('return value') }
let(:base_query) do
{
pagination: 'keyset',
foo: 'bar',
bar: 'baz'
}
end
let(:query) { base_query }
before do before do
allow(value).to receive(:to_query).and_return(value)
allow(subject).to receive(:header).and_return(value) allow(subject).to receive(:header).and_return(value)
allow(subject).to receive(:params).and_return(value) allow(subject).to receive(:params).and_return(query)
allow(subject).to receive(:request).and_return(value) allow(subject).to receive(:request).and_return(double(url: "#{incoming_api_projects_url}?#{query.to_query}"))
end end
context 'when resource can be paginated' do context 'when resource can be paginated' do
...@@ -28,10 +36,7 @@ describe API::Helpers::Pagination do ...@@ -28,10 +36,7 @@ describe API::Helpers::Pagination do
end end
describe 'first page' do describe 'first page' do
before do let(:query) { base_query.merge(per_page: 2) }
allow(subject).to receive(:params)
.and_return({ pagination: 'keyset', per_page: 2 })
end
it 'returns appropriate amount of resources' do it 'returns appropriate amount of resources' do
expect(subject.paginate(resource).count).to eq 2 expect(subject.paginate(resource).count).to eq 2
...@@ -43,7 +48,7 @@ describe API::Helpers::Pagination do ...@@ -43,7 +48,7 @@ describe API::Helpers::Pagination do
it 'adds appropriate headers' do it 'adds appropriate headers' do
expect_header('X-Per-Page', '2') expect_header('X-Per-Page', '2')
expect_header('X-Next-Page', "#{value}?ks_prev_id=#{projects[1].id}&pagination=keyset&per_page=2") expect_header('X-Next-Page', "#{canonical_api_projects_url}?#{query.merge(ks_prev_id: projects[1].id).to_query}")
expect_header('Link', anything) do |_key, val| expect_header('Link', anything) do |_key, val|
expect(val).to include('rel="next"') expect(val).to include('rel="next"')
...@@ -54,10 +59,7 @@ describe API::Helpers::Pagination do ...@@ -54,10 +59,7 @@ describe API::Helpers::Pagination do
end end
describe 'second page' do describe 'second page' do
before do let(:query) { base_query.merge(per_page: 2, ks_prev_id: projects[1].id) }
allow(subject).to receive(:params)
.and_return({ pagination: 'keyset', per_page: 2, ks_prev_id: projects[1].id })
end
it 'returns appropriate amount of resources' do it 'returns appropriate amount of resources' do
expect(subject.paginate(resource).count).to eq 1 expect(subject.paginate(resource).count).to eq 1
...@@ -69,7 +71,7 @@ describe API::Helpers::Pagination do ...@@ -69,7 +71,7 @@ describe API::Helpers::Pagination do
it 'adds appropriate headers' do it 'adds appropriate headers' do
expect_header('X-Per-Page', '2') expect_header('X-Per-Page', '2')
expect_header('X-Next-Page', "#{value}?ks_prev_id=#{projects[2].id}&pagination=keyset&per_page=2") expect_header('X-Next-Page', "#{canonical_api_projects_url}?#{query.merge(ks_prev_id: projects[2].id).to_query}")
expect_header('Link', anything) do |_key, val| expect_header('Link', anything) do |_key, val|
expect(val).to include('rel="next"') expect(val).to include('rel="next"')
...@@ -80,10 +82,7 @@ describe API::Helpers::Pagination do ...@@ -80,10 +82,7 @@ describe API::Helpers::Pagination do
end end
describe 'third page' do describe 'third page' do
before do let(:query) { base_query.merge(per_page: 2, ks_prev_id: projects[2].id) }
allow(subject).to receive(:params)
.and_return({ pagination: 'keyset', per_page: 2, ks_prev_id: projects[2].id })
end
it 'returns appropriate amount of resources' do it 'returns appropriate amount of resources' do
expect(subject.paginate(resource).count).to eq 0 expect(subject.paginate(resource).count).to eq 0
...@@ -91,6 +90,7 @@ describe API::Helpers::Pagination do ...@@ -91,6 +90,7 @@ describe API::Helpers::Pagination do
it 'adds appropriate headers' do it 'adds appropriate headers' do
expect_header('X-Per-Page', '2') expect_header('X-Per-Page', '2')
expect_no_header('X-Next-Page')
expect(subject).not_to receive(:header).with('Link') expect(subject).not_to receive(:header).with('Link')
subject.paginate(resource) subject.paginate(resource)
...@@ -99,10 +99,7 @@ describe API::Helpers::Pagination do ...@@ -99,10 +99,7 @@ describe API::Helpers::Pagination do
context 'if order' do context 'if order' do
context 'is not present' do context 'is not present' do
before do let(:query) { base_query.merge(per_page: 2) }
allow(subject).to receive(:params)
.and_return({ pagination: 'keyset', per_page: 2 })
end
it 'is not present it adds default order(:id) desc' do it 'is not present it adds default order(:id) desc' do
resource.order_values = [] resource.order_values = []
...@@ -144,9 +141,7 @@ describe API::Helpers::Pagination do ...@@ -144,9 +141,7 @@ describe API::Helpers::Pagination do
# (key is the id) # (key is the id)
end end
it 'it also orders by primary key' do it 'also orders by primary key' do
allow(subject).to receive(:params)
.and_return({ pagination: 'keyset', per_page: 2 })
paginated_relation = subject.paginate(resource) paginated_relation = subject.paginate(resource)
expect(paginated_relation.order_values).to be_present expect(paginated_relation.order_values).to be_present
...@@ -157,46 +152,45 @@ describe API::Helpers::Pagination do ...@@ -157,46 +152,45 @@ describe API::Helpers::Pagination do
expect(paginated_relation.order_values.second.expr.name).to eq :id expect(paginated_relation.order_values.second.expr.name).to eq :id
end end
it 'it returns the right records (first page)' do it 'returns the right records (first page)' do
allow(subject).to receive(:params)
.and_return({ pagination: 'keyset', per_page: 2 })
result = subject.paginate(resource) result = subject.paginate(resource)
expect(result.first).to eq(projects[1]) expect(result.first).to eq(projects[1])
expect(result.second).to eq(projects[3]) expect(result.second).to eq(projects[3])
end end
it 'it returns the right records (second page)' do describe 'second page' do
allow(subject).to receive(:params) let(:query) { base_query.merge(ks_prev_id: projects[3].id, ks_prev_name: projects[3].name, per_page: 2) }
.and_return({ pagination: 'keyset', ks_prev_id: projects[3].id, ks_prev_name: projects[3].name, per_page: 2 })
result = subject.paginate(resource)
expect(result.first).to eq(projects[2]) it 'returns the right records (second page)' do
expect(result.second).to eq(projects[6]) result = subject.paginate(resource)
end
it 'it returns the right records (third page), note increased per_page' do expect(result.first).to eq(projects[2])
allow(subject).to receive(:params) expect(result.second).to eq(projects[6])
.and_return({ pagination: 'keyset', ks_prev_id: projects[6].id, ks_prev_name: projects[6].name, per_page: 5 }) end
result = subject.paginate(resource)
expect(result.size).to eq(3) it 'returns the right link to the next page' do
expect(result.first).to eq(projects[0]) expect_header('X-Per-Page', '2')
expect(result.second).to eq(projects[4]) expect_header('X-Next-Page', "#{canonical_api_projects_url}?#{query.merge(ks_prev_id: projects[6].id, ks_prev_name: projects[6].name).to_query}")
expect(result.last).to eq(projects[5]) expect_header('Link', anything) do |_key, val|
expect(val).to include('rel="next"')
end
subject.paginate(resource)
end
end end
it 'it returns the right link to the next page' do describe 'third page' do
allow(subject).to receive(:params) let(:query) { base_query.merge(ks_prev_id: projects[6].id, ks_prev_name: projects[6].name, per_page: 5) }
.and_return({ pagination: 'keyset', ks_prev_id: projects[3].id, ks_prev_name: projects[3].name, per_page: 2 })
expect_header('X-Per-Page', '2') it 'returns the right records (third page), note increased per_page' do
expect_header('X-Next-Page', "#{value}?ks_prev_id=#{projects[6].id}&ks_prev_name=#{projects[6].name}&pagination=keyset&per_page=2") result = subject.paginate(resource)
expect_header('Link', anything) do |_key, val|
expect(val).to include('rel="next"')
end
subject.paginate(resource) expect(result.size).to eq(3)
expect(result.first).to eq(projects[0])
expect(result.second).to eq(projects[4])
expect(result.last).to eq(projects[5])
end
end end
end end
end end
...@@ -205,25 +199,13 @@ describe API::Helpers::Pagination do ...@@ -205,25 +199,13 @@ describe API::Helpers::Pagination do
describe '#paginate (default offset-based pagination)' do describe '#paginate (default offset-based pagination)' do
let(:value) { spy('return value') } let(:value) { spy('return value') }
let(:base_query) { { foo: 'bar', bar: 'baz' } }
let(:query) { base_query }
before do before do
allow(value).to receive(:to_query).and_return(value)
allow(subject).to receive(:header).and_return(value) allow(subject).to receive(:header).and_return(value)
allow(subject).to receive(:params).and_return(value) allow(subject).to receive(:params).and_return(query)
allow(subject).to receive(:request).and_return(value) allow(subject).to receive(:request).and_return(double(url: "#{incoming_api_projects_url}?#{query.to_query}"))
end
describe 'required instance methods' do
let(:return_spy) { spy }
it 'requires some instance methods' do
expect_message(:header)
expect_message(:params)
expect_message(:request)
subject.paginate(resource)
end
end end
context 'when resource can be paginated' do context 'when resource can be paginated' do
...@@ -232,11 +214,6 @@ describe API::Helpers::Pagination do ...@@ -232,11 +214,6 @@ describe API::Helpers::Pagination do
end end
describe 'first page' do describe 'first page' do
before do
allow(subject).to receive(:params)
.and_return({ page: 1, per_page: 2 })
end
shared_examples 'response with pagination headers' do shared_examples 'response with pagination headers' do
it 'adds appropriate headers' do it 'adds appropriate headers' do
expect_header('X-Total', '3') expect_header('X-Total', '3')
...@@ -247,9 +224,9 @@ describe API::Helpers::Pagination do ...@@ -247,9 +224,9 @@ describe API::Helpers::Pagination do
expect_header('X-Prev-Page', '') expect_header('X-Prev-Page', '')
expect_header('Link', anything) do |_key, val| expect_header('Link', anything) do |_key, val|
expect(val).to include('rel="first"') expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first"))
expect(val).to include('rel="last"') expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="last"))
expect(val).to include('rel="next"') expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="next"))
expect(val).not_to include('rel="prev"') expect(val).not_to include('rel="prev"')
end end
...@@ -267,6 +244,8 @@ describe API::Helpers::Pagination do ...@@ -267,6 +244,8 @@ describe API::Helpers::Pagination do
end end
end end
let(:query) { base_query.merge(page: 1, per_page: 2) }
context 'when the api_kaminari_count_with_limit feature flag is unset' do context 'when the api_kaminari_count_with_limit feature flag is unset' do
it_behaves_like 'paginated response' it_behaves_like 'paginated response'
it_behaves_like 'response with pagination headers' it_behaves_like 'response with pagination headers'
...@@ -311,9 +290,9 @@ describe API::Helpers::Pagination do ...@@ -311,9 +290,9 @@ describe API::Helpers::Pagination do
expect_header('X-Prev-Page', '') expect_header('X-Prev-Page', '')
expect_header('Link', anything) do |_key, val| expect_header('Link', anything) do |_key, val|
expect(val).to include('rel="first"') expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first"))
expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="next"))
expect(val).not_to include('rel="last"') expect(val).not_to include('rel="last"')
expect(val).to include('rel="next"')
expect(val).not_to include('rel="prev"') expect(val).not_to include('rel="prev"')
end end
...@@ -324,10 +303,7 @@ describe API::Helpers::Pagination do ...@@ -324,10 +303,7 @@ describe API::Helpers::Pagination do
end end
describe 'second page' do describe 'second page' do
before do let(:query) { base_query.merge(page: 2, per_page: 2) }
allow(subject).to receive(:params)
.and_return({ page: 2, per_page: 2 })
end
it 'returns appropriate amount of resources' do it 'returns appropriate amount of resources' do
expect(subject.paginate(resource).count).to eq 1 expect(subject.paginate(resource).count).to eq 1
...@@ -342,9 +318,9 @@ describe API::Helpers::Pagination do ...@@ -342,9 +318,9 @@ describe API::Helpers::Pagination do
expect_header('X-Prev-Page', '1') expect_header('X-Prev-Page', '1')
expect_header('Link', anything) do |_key, val| expect_header('Link', anything) do |_key, val|
expect(val).to include('rel="first"') expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first"))
expect(val).to include('rel="last"') expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 2).to_query}>; rel="last"))
expect(val).to include('rel="prev"') expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="prev"))
expect(val).not_to include('rel="next"') expect(val).not_to include('rel="next"')
end end
...@@ -376,10 +352,7 @@ describe API::Helpers::Pagination do ...@@ -376,10 +352,7 @@ describe API::Helpers::Pagination do
context 'when resource empty' do context 'when resource empty' do
describe 'first page' do describe 'first page' do
before do let(:query) { base_query.merge(page: 1, per_page: 2) }
allow(subject).to receive(:params)
.and_return({ page: 1, per_page: 2 })
end
it 'returns appropriate amount of resources' do it 'returns appropriate amount of resources' do
expect(subject.paginate(resource).count).to eq 0 expect(subject.paginate(resource).count).to eq 0
...@@ -394,8 +367,8 @@ describe API::Helpers::Pagination do ...@@ -394,8 +367,8 @@ describe API::Helpers::Pagination do
expect_header('X-Prev-Page', '') expect_header('X-Prev-Page', '')
expect_header('Link', anything) do |_key, val| expect_header('Link', anything) do |_key, val|
expect(val).to include('rel="first"') expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="first"))
expect(val).to include('rel="last"') expect(val).to include(%Q(<#{canonical_api_projects_url}?#{query.merge(page: 1).to_query}>; rel="last"))
expect(val).not_to include('rel="prev"') expect(val).not_to include('rel="prev"')
expect(val).not_to include('rel="next"') expect(val).not_to include('rel="next"')
expect(val).not_to include('page=0') expect(val).not_to include('page=0')
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Serializer::Pagination do describe Gitlab::Serializer::Pagination do
let(:request) { spy('request') } let(:request) { double(url: "#{Gitlab.config.gitlab.url}:8080/api/v4/projects?#{query.to_query}", query_parameters: query) }
let(:response) { spy('response') } let(:response) { spy('response') }
let(:headers) { spy('headers') } let(:headers) { spy('headers') }
before do before do
allow(request).to receive(:query_parameters) allow(response).to receive(:headers).and_return(headers)
.and_return(params)
allow(response).to receive(:headers)
.and_return(headers)
end end
let(:pagination) { described_class.new(request, response) } let(:pagination) { described_class.new(request, response) }
...@@ -19,7 +15,7 @@ describe Gitlab::Serializer::Pagination do ...@@ -19,7 +15,7 @@ describe Gitlab::Serializer::Pagination do
subject { pagination.paginate(resource) } subject { pagination.paginate(resource) }
let(:resource) { User.all } let(:resource) { User.all }
let(:params) { { page: 1, per_page: 2 } } let(:query) { { page: 1, per_page: 2 } }
context 'when a multiple resources are present in relation' do context 'when a multiple resources are present in relation' do
before do before do
......
...@@ -462,6 +462,30 @@ describe Project do ...@@ -462,6 +462,30 @@ describe Project do
end end
end end
describe '#ci_pipelines' do
let(:project) { create(:project) }
before do
create(:ci_pipeline, project: project, ref: 'master', source: :web)
create(:ci_pipeline, project: project, ref: 'master', source: :external)
end
it 'has ci pipelines' do
expect(project.ci_pipelines.size).to eq(2)
end
context 'when builds are disabled' do
before do
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::DISABLED)
end
it 'should return .external pipelines' do
expect(project.ci_pipelines).to all(have_attributes(source: 'external'))
expect(project.ci_pipelines.size).to eq(1)
end
end
end
describe 'project token' do describe 'project token' do
it 'sets an random token if none provided' do it 'sets an random token if none provided' do
project = FactoryBot.create(:project, runners_token: '') project = FactoryBot.create(:project, runners_token: '')
......
...@@ -1004,43 +1004,43 @@ describe User do ...@@ -1004,43 +1004,43 @@ describe User do
end end
end end
describe '.filter' do describe '.filter_items' do
let(:user) { double } let(:user) { double }
it 'filters by active users by default' do it 'filters by active users by default' do
expect(described_class).to receive(:active).and_return([user]) expect(described_class).to receive(:active).and_return([user])
expect(described_class.filter(nil)).to include user expect(described_class.filter_items(nil)).to include user
end end
it 'filters by admins' do it 'filters by admins' do
expect(described_class).to receive(:admins).and_return([user]) expect(described_class).to receive(:admins).and_return([user])
expect(described_class.filter('admins')).to include user expect(described_class.filter_items('admins')).to include user
end end
it 'filters by blocked' do it 'filters by blocked' do
expect(described_class).to receive(:blocked).and_return([user]) expect(described_class).to receive(:blocked).and_return([user])
expect(described_class.filter('blocked')).to include user expect(described_class.filter_items('blocked')).to include user
end end
it 'filters by two_factor_disabled' do it 'filters by two_factor_disabled' do
expect(described_class).to receive(:without_two_factor).and_return([user]) expect(described_class).to receive(:without_two_factor).and_return([user])
expect(described_class.filter('two_factor_disabled')).to include user expect(described_class.filter_items('two_factor_disabled')).to include user
end end
it 'filters by two_factor_enabled' do it 'filters by two_factor_enabled' do
expect(described_class).to receive(:with_two_factor).and_return([user]) expect(described_class).to receive(:with_two_factor).and_return([user])
expect(described_class.filter('two_factor_enabled')).to include user expect(described_class.filter_items('two_factor_enabled')).to include user
end end
it 'filters by wop' do it 'filters by wop' do
expect(described_class).to receive(:without_projects).and_return([user]) expect(described_class).to receive(:without_projects).and_return([user])
expect(described_class.filter('wop')).to include user expect(described_class.filter_items('wop')).to include user
end end
end end
......
...@@ -124,10 +124,10 @@ describe EnvironmentSerializer do ...@@ -124,10 +124,10 @@ describe EnvironmentSerializer do
end end
context 'when used with pagination' do context 'when used with pagination' do
let(:request) { spy('request') } let(:request) { double(url: "#{Gitlab.config.gitlab.url}:8080/api/v4/projects?#{query.to_query}", query_parameters: query) }
let(:response) { spy('response') } let(:response) { spy('response') }
let(:resource) { Environment.all } let(:resource) { Environment.all }
let(:pagination) { { page: 1, per_page: 2 } } let(:query) { { page: 1, per_page: 2 } }
let(:serializer) do let(:serializer) do
described_class described_class
...@@ -135,11 +135,6 @@ describe EnvironmentSerializer do ...@@ -135,11 +135,6 @@ describe EnvironmentSerializer do
.with_pagination(request, response) .with_pagination(request, response)
end end
before do
allow(request).to receive(:query_parameters)
.and_return(pagination)
end
subject { serializer.represent(resource) } subject { serializer.represent(resource) }
it 'creates a paginated serializer' do it 'creates a paginated serializer' do
......
...@@ -38,15 +38,9 @@ describe PipelineSerializer do ...@@ -38,15 +38,9 @@ describe PipelineSerializer do
end end
context 'when used with pagination' do context 'when used with pagination' do
let(:request) { spy('request') } let(:request) { double(url: "#{Gitlab.config.gitlab.url}:8080/api/v4/projects?#{query.to_query}", query_parameters: query) }
let(:response) { spy('response') } let(:response) { spy('response') }
let(:pagination) { {} } let(:query) { {} }
before do
allow(request)
.to receive(:query_parameters)
.and_return(pagination)
end
let(:serializer) do let(:serializer) do
described_class.new(current_user: user) described_class.new(current_user: user)
...@@ -60,7 +54,7 @@ describe PipelineSerializer do ...@@ -60,7 +54,7 @@ describe PipelineSerializer do
context 'when resource is not paginatable' do context 'when resource is not paginatable' do
context 'when a single pipeline object is being serialized' do context 'when a single pipeline object is being serialized' do
let(:resource) { create(:ci_empty_pipeline) } let(:resource) { create(:ci_empty_pipeline) }
let(:pagination) { { page: 1, per_page: 1 } } let(:query) { { page: 1, per_page: 1 } }
it 'raises error' do it 'raises error' do
expect { subject }.to raise_error( expect { subject }.to raise_error(
...@@ -71,7 +65,7 @@ describe PipelineSerializer do ...@@ -71,7 +65,7 @@ describe PipelineSerializer do
context 'when resource is paginatable relation' do context 'when resource is paginatable relation' do
let(:resource) { Ci::Pipeline.all } let(:resource) { Ci::Pipeline.all }
let(:pagination) { { page: 1, per_page: 2 } } let(:query) { { page: 1, per_page: 2 } }
context 'when a single pipeline object is present in relation' do context 'when a single pipeline object is present in relation' do
before do before do
......
require 'spec_helper' require 'spec_helper'
describe 'projects/commits/_commit.html.haml' do describe 'projects/commits/_commit.html.haml' do
let(:project) { create(:project, :repository) }
let(:commit) { project.repository.commit(ref) }
before do before do
allow(view).to receive(:current_application_settings).and_return(Gitlab::CurrentSettings.current_application_settings) allow(view).to receive(:current_application_settings).and_return(Gitlab::CurrentSettings.current_application_settings)
end end
context 'with a singed commit' do context 'with a signed commit' do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:ref) { GpgHelpers::SIGNED_COMMIT_SHA } let(:ref) { GpgHelpers::SIGNED_COMMIT_SHA }
let(:commit) { repository.commit(ref) }
it 'does not display a loading spinner for GPG status' do it 'does not display a loading spinner for GPG status' do
render partial: 'projects/commits/commit', locals: { render partial: 'projects/commits/commit', locals: {
...@@ -23,4 +23,55 @@ describe 'projects/commits/_commit.html.haml' do ...@@ -23,4 +23,55 @@ describe 'projects/commits/_commit.html.haml' do
end end
end end
end end
context 'with ci status' do
let(:ref) { 'master' }
let(:user) { create(:user) }
before do
allow(view).to receive(:current_user).and_return(user)
project.add_developer(user)
create(
:ci_empty_pipeline,
ref: 'master',
sha: commit.id,
status: 'success',
project: project
)
end
context 'when pipelines are disabled' do
before do
allow(project).to receive(:builds_enabled?).and_return(false)
end
it 'does not display a ci status icon' do
render partial: 'projects/commits/commit', locals: {
project: project,
ref: ref,
commit: commit
}
expect(rendered).not_to have_css('.ci-status-link')
end
end
context 'when pipelines are enabled' do
before do
allow(project).to receive(:builds_enabled?).and_return(true)
end
it 'does display a ci status icon when pipelines are enabled' do
render partial: 'projects/commits/commit', locals: {
project: project,
ref: ref,
commit: commit
}
expect(rendered).to have_css('.ci-status-link')
end
end
end
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