Commit 4e516dbf authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@master

parent 4f01ac5b
...@@ -79,7 +79,7 @@ star, smile, etc.). Some good tips about code reviews can be found in our ...@@ -79,7 +79,7 @@ star, smile, etc.). Some good tips about code reviews can be found in our
Overview and details of feature flag processes in development of GitLab itself is described in [feature flags process documentation](https://docs.gitlab.com/ee/development/feature_flags/process.html). Overview and details of feature flag processes in development of GitLab itself is described in [feature flags process documentation](https://docs.gitlab.com/ee/development/feature_flags/process.html).
Guides on how to include feature flags in your backend/frontend code while developing GitLab are described in [developing with feature flags documentation](https://docs.gitlab.com/ee/development/feature_flags/developing.html). Guides on how to include feature flags in your backend/frontend code while developing GitLab are described in [developing with feature flags documentation](https://docs.gitlab.com/ee/development/feature_flags/development.html).
Getting access and how to expose the feature to users is detailed in [controlling feature flags documentation](https://docs.gitlab.com/ee/development/feature_flags/controls.html). Getting access and how to expose the feature to users is detailed in [controlling feature flags documentation](https://docs.gitlab.com/ee/development/feature_flags/controls.html).
......
...@@ -124,7 +124,7 @@ export default { ...@@ -124,7 +124,7 @@ export default {
:cursor-offset="4" :cursor-offset="4"
:tag-content="lineContent" :tag-content="lineContent"
icon="doc-code" icon="doc-code"
class="qa-suggestion-btn js-suggestion-btn" class="js-suggestion-btn"
@click="handleSuggestDismissed" @click="handleSuggestDismissed"
/> />
<gl-popover <gl-popover
......
...@@ -55,7 +55,7 @@ export default { ...@@ -55,7 +55,7 @@ export default {
<gl-button <gl-button
v-else-if="canApply" v-else-if="canApply"
v-gl-tooltip.viewport="__('This also resolves the discussion')" v-gl-tooltip.viewport="__('This also resolves the discussion')"
class="btn-inverted qa-apply-btn js-apply-btn" class="btn-inverted js-apply-btn"
:disabled="isApplying" :disabled="isApplying"
variant="success" variant="success"
@click="applySuggestion" @click="applySuggestion"
......
...@@ -2,5 +2,18 @@ ...@@ -2,5 +2,18 @@
module Types module Types
class BaseEnum < GraphQL::Schema::Enum class BaseEnum < GraphQL::Schema::Enum
class << self
def value(*args, **kwargs, &block)
enum[args[0].downcase] = kwargs[:value] || args[0]
super(*args, **kwargs, &block)
end
# Returns an indifferent access hash with the key being the downcased name of the attribute
# and the value being the Ruby value (either the explicit `value` passed or the same as the value attr).
def enum
@enum_values ||= {}.with_indifferent_access
end
end
end end
end end
...@@ -40,6 +40,7 @@ class Service < ApplicationRecord ...@@ -40,6 +40,7 @@ class Service < ApplicationRecord
scope :external_wikis, -> { where(type: 'ExternalWikiService').active } scope :external_wikis, -> { where(type: 'ExternalWikiService').active }
scope :active, -> { where(active: true) } scope :active, -> { where(active: true) }
scope :without_defaults, -> { where(default: false) } scope :without_defaults, -> { where(default: false) }
scope :by_type, -> (type) { where(type: type) }
scope :push_hooks, -> { where(push_events: true, active: true) } scope :push_hooks, -> { where(push_events: true, active: true) }
scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) } scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) }
......
---
title: Add usage ping data for project services
merge_request: 19687
author:
type: added
---
title: Add index for unauthenticated requests to projects API default endpoint
merge_request: 19989
author:
type: performance
# frozen_string_literal: true
class AddIndexesForProjectsApiDefaultParams < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :projects, %i(visibility_level created_at id)
remove_concurrent_index_by_name :projects, 'index_projects_on_visibility_level'
end
def down
add_concurrent_index :projects, :visibility_level
remove_concurrent_index :projects, %i(visibility_level created_at id)
end
end
...@@ -3,34 +3,13 @@ ...@@ -3,34 +3,13 @@
# See http://doc.gitlab.com/ce/development/migration_style_guide.html # See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab. # for more information on how to write migrations for GitLab.
# TODO: remove this migration after execution on gitlab.com https://gitlab.com/gitlab-org/gitlab/issues/34018 # Code of this migration was removed after execution on gitlab.com
# https://gitlab.com/gitlab-org/gitlab/issues/34018
# Empty migration is left here to avoid any problems with rolling back
class ScheduleFixGitlabComPagesAccessLevel < ActiveRecord::Migration[5.2] class ScheduleFixGitlabComPagesAccessLevel < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false DOWNTIME = false
MIGRATION = 'FixGitlabComPagesAccessLevel'
BATCH_SIZE = 20_000
BATCH_TIME = 2.minutes
# Project
class Project < ActiveRecord::Base
include EachBatch
self.table_name = 'projects'
self.inheritance_column = :_type_disabled
end
disable_ddl_transaction!
def up def up
return unless ::Gitlab.com?
queue_background_migration_jobs_by_range_at_intervals(
Project,
MIGRATION,
BATCH_TIME,
batch_size: BATCH_SIZE)
end end
def down def down
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_11_12_115317) do ActiveRecord::Schema.define(version: 2019_11_12_214305) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm" enable_extension "pg_trgm"
...@@ -3145,7 +3145,7 @@ ActiveRecord::Schema.define(version: 2019_11_12_115317) do ...@@ -3145,7 +3145,7 @@ ActiveRecord::Schema.define(version: 2019_11_12_115317) do
t.index ["runners_token"], name: "index_projects_on_runners_token" t.index ["runners_token"], name: "index_projects_on_runners_token"
t.index ["runners_token_encrypted"], name: "index_projects_on_runners_token_encrypted" t.index ["runners_token_encrypted"], name: "index_projects_on_runners_token_encrypted"
t.index ["star_count"], name: "index_projects_on_star_count" t.index ["star_count"], name: "index_projects_on_star_count"
t.index ["visibility_level"], name: "index_projects_on_visibility_level" t.index ["visibility_level", "created_at", "id"], name: "index_projects_on_visibility_level_and_created_at_and_id"
end end
create_table "prometheus_alert_events", force: :cascade do |t| create_table "prometheus_alert_events", force: :cascade do |t|
......
# frozen_string_literal: true
module Gitlab
module BackgroundMigration
# Fixes https://gitlab.com/gitlab-org/gitlab/issues/32961
class FixGitlabComPagesAccessLevel
# Copy routable here to avoid relying on application logic
module Routable
def build_full_path
if parent && path
parent.build_full_path + '/' + path
else
path
end
end
end
# Namespace
class Namespace < ActiveRecord::Base
self.table_name = 'namespaces'
self.inheritance_column = :_type_disabled
include Routable
belongs_to :parent, class_name: "Namespace"
end
# ProjectPagesMetadatum
class ProjectPagesMetadatum < ActiveRecord::Base
self.primary_key = :project_id
belongs_to :project, inverse_of: :pages_metadatum
scope :deployed, -> { where(deployed: true) }
end
# Project
class Project < ActiveRecord::Base
self.table_name = 'projects'
self.inheritance_column = :_type_disabled
include Routable
belongs_to :namespace
alias_method :parent, :namespace
alias_attribute :parent_id, :namespace_id
has_one :project_feature, inverse_of: :project
has_one :pages_metadatum, class_name: 'ProjectPagesMetadatum', inverse_of: :project
scope :with_pages_deployed, -> do
joins(:pages_metadatum).merge(ProjectPagesMetadatum.deployed)
end
PRIVATE = 0
INTERNAL = 10
PUBLIC = 20
delegate :public_pages?, to: :project_feature
def public_pages_path
File.join(pages_path, 'public')
end
def pages_path
File.join(Settings.pages.path, build_full_path)
end
def public?
visibility_level == PUBLIC
end
end
# ProjectFeature
class ProjectFeature < ActiveRecord::Base
self.table_name = 'project_features'
belongs_to :project
DISABLED = 0
PRIVATE = 10
ENABLED = 20
PUBLIC = 30
end
def perform(start_id, stop_id)
logger = Gitlab::BackgroundMigration::Logger.build
Project.where(id: start_id..stop_id).with_pages_deployed.includes(:project_feature).find_each do |project|
config_path = File.join(project.pages_path, 'config.json')
ac_is_enabled_in_config = JSON.parse(File.read(config_path))["access_control"]
next if ac_is_enabled_in_config # we already made site private and don't want to surprise the user
next if project.project_feature.pages_access_level == ProjectFeature::DISABLED
new_access_level = project.public? ? ProjectFeature::ENABLED : ProjectFeature::PUBLIC
next if project.project_feature.pages_access_level == new_access_level
logger.info(
message: "Changing pages access control level",
project_id: project.id,
access_level_before: project.project_feature.pages_access_level,
access_level_after: new_access_level
)
project.project_feature.update_column(:pages_access_level, new_access_level)
rescue => e
Gitlab::Sentry.track_exception(e, extra: { project_id: project.id })
end
end
end
end
end
...@@ -13,7 +13,8 @@ module Gitlab ...@@ -13,7 +13,8 @@ module Gitlab
end end
def uncached_data def uncached_data
license_usage_data.merge(system_usage_data) license_usage_data
.merge(system_usage_data)
.merge(features_usage_data) .merge(features_usage_data)
.merge(components_usage_data) .merge(components_usage_data)
.merge(cycle_analytics_usage_data) .merge(cycle_analytics_usage_data)
...@@ -170,10 +171,13 @@ module Gitlab ...@@ -170,10 +171,13 @@ module Gitlab
types = { types = {
SlackService: :projects_slack_notifications_active, SlackService: :projects_slack_notifications_active,
SlackSlashCommandsService: :projects_slack_slash_active, SlackSlashCommandsService: :projects_slack_slash_active,
PrometheusService: :projects_prometheus_active PrometheusService: :projects_prometheus_active,
CustomIssueTrackerService: :projects_custom_issue_tracker_active,
JenkinsService: :projects_jenkins_active,
MattermostService: :projects_mattermost_active
} }
results = count(Service.unscoped.where(type: types.keys, active: true).group(:type), fallback: Hash.new(-1)) results = count(Service.active.by_type(types.keys).group(:type), fallback: Hash.new(-1))
types.each_with_object({}) { |(klass, key), response| response[key] = results[klass.to_s] || 0 } types.each_with_object({}) { |(klass, key), response| response[key] = results[klass.to_s] || 0 }
.merge(jira_usage) .merge(jira_usage)
end end
...@@ -188,8 +192,8 @@ module Gitlab ...@@ -188,8 +192,8 @@ module Gitlab
projects_jira_active: -1 projects_jira_active: -1
} }
Service.unscoped Service.active
.where(type: :JiraService, active: true) .by_type(:JiraService)
.includes(:jira_tracker_data) .includes(:jira_tracker_data)
.find_in_batches(batch_size: BATCH_SIZE) do |services| .find_in_batches(batch_size: BATCH_SIZE) do |services|
......
...@@ -149,7 +149,7 @@ describe Projects::PipelinesController do ...@@ -149,7 +149,7 @@ describe Projects::PipelinesController do
end end
describe 'GET show.json' do describe 'GET show.json' do
let(:pipeline) { create(:ci_pipeline_with_one_job, project: project) } let(:pipeline) { create(:ci_pipeline, project: project) }
it 'returns the pipeline' do it 'returns the pipeline' do
get_pipeline_json get_pipeline_json
......
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.define do FactoryBot.define do
# TODO: we can remove this factory in favour of :ci_pipeline
factory :ci_empty_pipeline, class: Ci::Pipeline do factory :ci_empty_pipeline, class: Ci::Pipeline do
source { :push } source { :push }
ref { 'master' } ref { 'master' }
...@@ -10,20 +11,6 @@ FactoryBot.define do ...@@ -10,20 +11,6 @@ FactoryBot.define do
project project
factory :ci_pipeline_without_jobs do
after(:build) do |pipeline|
pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump({}))
end
end
factory :ci_pipeline_with_one_job do
after(:build) do |pipeline|
allow(pipeline).to receive(:ci_yaml_file) do
pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump({ rspec: { script: "ls" } }))
end
end
end
# Persist merge request head_pipeline_id # Persist merge request head_pipeline_id
# on pipeline factories to avoid circular references # on pipeline factories to avoid circular references
transient { head_pipeline_of { nil } } transient { head_pipeline_of { nil } }
...@@ -34,24 +21,8 @@ FactoryBot.define do ...@@ -34,24 +21,8 @@ FactoryBot.define do
end end
factory :ci_pipeline do factory :ci_pipeline do
transient { config { nil } }
after(:build) do |pipeline, evaluator|
if evaluator.config
pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump(evaluator.config))
# Populates pipeline with errors
pipeline.config_processor if evaluator.config
else
pipeline.instance_variable_set(:@ci_yaml_file, File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')))
end
end
trait :invalid do trait :invalid do
config do yaml_errors { 'invalid YAML' }
{ rspec: nil }
end
failure_reason { :config_error } failure_reason { :config_error }
end end
......
...@@ -7,7 +7,7 @@ FactoryBot.define do ...@@ -7,7 +7,7 @@ FactoryBot.define do
stage_idx { 0 } stage_idx { 0 }
status { 'success' } status { 'success' }
description { 'commit status'} description { 'commit status'}
pipeline factory: :ci_pipeline_with_one_job pipeline factory: :ci_pipeline
started_at { 'Tue, 26 Jan 2016 08:21:42 +0100'} started_at { 'Tue, 26 Jan 2016 08:21:42 +0100'}
finished_at { 'Tue, 26 Jan 2016 08:23:42 +0100'} finished_at { 'Tue, 26 Jan 2016 08:23:42 +0100'}
......
...@@ -11,7 +11,7 @@ describe 'Merge request > User sees deployment widget', :js do ...@@ -11,7 +11,7 @@ describe 'Merge request > User sees deployment widget', :js do
let(:role) { :developer } let(:role) { :developer }
let(:ref) { merge_request.target_branch } let(:ref) { merge_request.target_branch }
let(:sha) { project.commit(ref).id } let(:sha) { project.commit(ref).id }
let(:pipeline) { create(:ci_pipeline_without_jobs, sha: sha, project: project, ref: ref) } let(:pipeline) { create(:ci_pipeline, sha: sha, project: project, ref: ref) }
let!(:manual) { } let!(:manual) { }
before do before do
...@@ -33,7 +33,7 @@ describe 'Merge request > User sees deployment widget', :js do ...@@ -33,7 +33,7 @@ describe 'Merge request > User sees deployment widget', :js do
end end
context 'when a user created a new merge request with the same SHA' do context 'when a user created a new merge request with the same SHA' do
let(:pipeline2) { create(:ci_pipeline_without_jobs, sha: sha, project: project, ref: 'new-patch-1') } let(:pipeline2) { create(:ci_pipeline, sha: sha, project: project, ref: 'new-patch-1') }
let(:build2) { create(:ci_build, :success, pipeline: pipeline2) } let(:build2) { create(:ci_build, :success, pipeline: pipeline2) }
let(:environment2) { create(:environment, project: project) } let(:environment2) { create(:environment, project: project) }
let!(:deployment2) { create(:deployment, environment: environment2, sha: sha, ref: 'new-patch-1', deployable: build2) } let!(:deployment2) { create(:deployment, environment: environment2, sha: sha, ref: 'new-patch-1', deployable: build2) }
......
...@@ -44,7 +44,7 @@ describe 'Merge request > User sees merge widget', :js do ...@@ -44,7 +44,7 @@ describe 'Merge request > User sees merge widget', :js do
context 'view merge request' do context 'view merge request' do
let!(:environment) { create(:environment, project: project) } let!(:environment) { create(:environment, project: project) }
let(:sha) { project.commit(merge_request.source_branch).sha } let(:sha) { project.commit(merge_request.source_branch).sha }
let(:pipeline) { create(:ci_pipeline_without_jobs, status: 'success', sha: sha, project: project, ref: merge_request.source_branch) } let(:pipeline) { create(:ci_pipeline, status: 'success', sha: sha, project: project, ref: merge_request.source_branch) }
let(:build) { create(:ci_build, :success, pipeline: pipeline) } let(:build) { create(:ci_build, :success, pipeline: pipeline) }
let!(:deployment) do let!(:deployment) do
...@@ -745,7 +745,7 @@ describe 'Merge request > User sees merge widget', :js do ...@@ -745,7 +745,7 @@ describe 'Merge request > User sees merge widget', :js do
context 'when MR has pipeline but user does not have permission' do context 'when MR has pipeline but user does not have permission' do
let(:sha) { project.commit(merge_request.source_branch).sha } let(:sha) { project.commit(merge_request.source_branch).sha }
let!(:pipeline) { create(:ci_pipeline_without_jobs, status: 'success', sha: sha, project: project, ref: merge_request.source_branch) } let!(:pipeline) { create(:ci_pipeline, status: 'success', sha: sha, project: project, ref: merge_request.source_branch) }
before do before do
project.update( project.update(
......
# frozen_string_literal: true
require 'spec_helper'
describe Types::BaseEnum do
describe '#enum' do
let(:enum) do
Class.new(described_class) do
value 'TEST', value: 3
value 'other'
value 'NORMAL'
end
end
it 'adds all enum values to #enum' do
expect(enum.enum.keys).to contain_exactly('test', 'other', 'normal')
expect(enum.enum.values).to contain_exactly(3, 'other', 'NORMAL')
end
it 'is a HashWithIndefferentAccess' do
expect(enum.enum).to be_a(HashWithIndifferentAccess)
end
end
end
...@@ -7,9 +7,7 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ...@@ -7,9 +7,7 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
set(:user) { create(:user) } set(:user) { create(:user) }
let(:pipeline) do let(:pipeline) do
build(:ci_pipeline_with_one_job, project: project, build(:ci_pipeline, project: project, ref: 'master', user: user)
ref: 'master',
user: user)
end end
let(:command) do let(:command) do
...@@ -22,6 +20,14 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ...@@ -22,6 +20,14 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
let(:step) { described_class.new(pipeline, command) } let(:step) { described_class.new(pipeline, command) }
let(:config) do
{ rspec: { script: 'rspec' } }
end
before do
stub_ci_pipeline_yaml_file(YAML.dump(config))
end
context 'when pipeline doesn not have seeds block' do context 'when pipeline doesn not have seeds block' do
before do before do
step.perform! step.perform!
...@@ -59,10 +65,6 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ...@@ -59,10 +65,6 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
} } } }
end end
let(:pipeline) do
build(:ci_pipeline, project: project, config: config)
end
before do before do
step.perform! step.perform!
end end
...@@ -202,10 +204,6 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ...@@ -202,10 +204,6 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
prod: { script: 'cap prod', stage: 'deploy', only: ['tags'] } } prod: { script: 'cap prod', stage: 'deploy', only: ['tags'] } }
end end
let(:pipeline) do
build(:ci_pipeline, ref: 'master', project: project, config: config)
end
it_behaves_like 'a correct pipeline' it_behaves_like 'a correct pipeline'
context 'when variables expression is specified' do context 'when variables expression is specified' do
......
...@@ -6,13 +6,17 @@ describe Gitlab::Ci::Pipeline::Chain::RemoveUnwantedChatJobs do ...@@ -6,13 +6,17 @@ describe Gitlab::Ci::Pipeline::Chain::RemoveUnwantedChatJobs do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:pipeline) do let(:pipeline) do
build(:ci_pipeline_with_one_job, project: project, ref: 'master') build(:ci_pipeline, project: project)
end end
let(:command) do let(:command) do
double(:command, project: project, chat_data: { command: 'echo' }) double(:command, project: project, chat_data: { command: 'echo' })
end end
before do
stub_ci_pipeline_yaml_file(YAML.dump(rspec: { script: 'rspec' }))
end
describe '#perform!' do describe '#perform!' do
it 'removes unwanted jobs for chat pipelines' do it 'removes unwanted jobs for chat pipelines' do
allow(pipeline).to receive(:chat?).and_return(true) allow(pipeline).to receive(:chat?).and_return(true)
......
...@@ -13,11 +13,13 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do ...@@ -13,11 +13,13 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
save_incompleted: true) save_incompleted: true)
end end
let(:pipeline) do
build(:ci_pipeline, project: project)
end
let!(:step) { described_class.new(pipeline, command) } let!(:step) { described_class.new(pipeline, command) }
before do subject { step.perform! }
step.perform!
end
context 'when pipeline has no YAML configuration' do context 'when pipeline has no YAML configuration' do
let(:pipeline) do let(:pipeline) do
...@@ -25,18 +27,23 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do ...@@ -25,18 +27,23 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end end
it 'appends errors about missing configuration' do it 'appends errors about missing configuration' do
subject
expect(pipeline.errors.to_a) expect(pipeline.errors.to_a)
.to include 'Missing .gitlab-ci.yml file' .to include 'Missing .gitlab-ci.yml file'
end end
it 'breaks the chain' do it 'breaks the chain' do
subject
expect(step.break?).to be true expect(step.break?).to be true
end end
end end
context 'when YAML configuration contains errors' do context 'when YAML configuration contains errors' do
let(:pipeline) do before do
build(:ci_pipeline, project: project, config: 'invalid YAML') stub_ci_pipeline_yaml_file('invalid YAML')
subject
end end
it 'appends errors about YAML errors' do it 'appends errors about YAML errors' do
...@@ -56,10 +63,14 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do ...@@ -56,10 +63,14 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end end
it 'fails the pipeline' do it 'fails the pipeline' do
subject
expect(pipeline.reload).to be_failed expect(pipeline.reload).to be_failed
end end
it 'sets a config error failure reason' do it 'sets a config error failure reason' do
subject
expect(pipeline.reload.config_error?).to eq true expect(pipeline.reload.config_error?).to eq true
end end
end end
...@@ -72,6 +83,8 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do ...@@ -72,6 +83,8 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end end
it 'does not drop pipeline' do it 'does not drop pipeline' do
subject
expect(pipeline).not_to be_failed expect(pipeline).not_to be_failed
expect(pipeline).not_to be_persisted expect(pipeline).not_to be_persisted
end end
...@@ -79,17 +92,15 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do ...@@ -79,17 +92,15 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end end
context 'when pipeline contains configuration validation errors' do context 'when pipeline contains configuration validation errors' do
let(:config) do before do
{ stub_ci_pipeline_yaml_file(YAML.dump({
rspec: { rspec: {
before_script: 10, before_script: 10,
script: 'ls -al' script: 'ls -al'
} }
} }))
end
let(:pipeline) do subject
build(:ci_pipeline, project: project, config: config)
end end
it 'appends configuration validation errors to pipeline errors' do it 'appends configuration validation errors to pipeline errors' do
...@@ -103,8 +114,13 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do ...@@ -103,8 +114,13 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end end
context 'when pipeline is correct and complete' do context 'when pipeline is correct and complete' do
let(:pipeline) do before do
build(:ci_pipeline_with_one_job, project: project) stub_ci_pipeline_yaml_file(YAML.dump({
rspec: {
script: 'rspec'
}
}))
subject
end end
it 'does not invalidate the pipeline' do it 'does not invalidate the pipeline' do
...@@ -119,6 +135,7 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do ...@@ -119,6 +135,7 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
context 'when pipeline source is merge request' do context 'when pipeline source is merge request' do
before do before do
stub_ci_pipeline_yaml_file(YAML.dump(config)) stub_ci_pipeline_yaml_file(YAML.dump(config))
subject
end end
let(:pipeline) { build_stubbed(:ci_pipeline, project: project) } let(:pipeline) { build_stubbed(:ci_pipeline, project: project) }
......
...@@ -132,10 +132,6 @@ describe Gitlab::ImportExport::FastHashSerializer do ...@@ -132,10 +132,6 @@ describe Gitlab::ImportExport::FastHashSerializer do
end end
it 'has no when YML attributes but only the DB column' do it 'has no when YML attributes but only the DB column' do
allow_any_instance_of(Ci::Pipeline)
.to receive(:ci_yaml_file)
.and_return(File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')))
expect_any_instance_of(Gitlab::Ci::YamlProcessor).not_to receive(:build_attributes) expect_any_instance_of(Gitlab::Ci::YamlProcessor).not_to receive(:build_attributes)
subject subject
......
...@@ -203,7 +203,6 @@ describe Gitlab::ImportExport::ProjectTreeSaver do ...@@ -203,7 +203,6 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
end end
it 'has no when YML attributes but only the DB column' do it 'has no when YML attributes but only the DB column' do
allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file).and_return(File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')))
expect_any_instance_of(Gitlab::Ci::YamlProcessor).not_to receive(:build_attributes) expect_any_instance_of(Gitlab::Ci::YamlProcessor).not_to receive(:build_attributes)
saved_project_json saved_project_json
......
...@@ -17,6 +17,9 @@ describe Gitlab::UsageData do ...@@ -17,6 +17,9 @@ describe Gitlab::UsageData do
create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true) create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true)
create(:service, project: projects[1], type: 'SlackService', active: true) create(:service, project: projects[1], type: 'SlackService', active: true)
create(:service, project: projects[2], type: 'SlackService', active: true) create(:service, project: projects[2], type: 'SlackService', active: true)
create(:service, project: projects[2], type: 'MattermostService', active: true)
create(:service, project: projects[2], type: 'JenkinsService', active: true)
create(:service, project: projects[2], type: 'CustomIssueTrackerService', active: true)
create(:project_error_tracking_setting, project: projects[0]) create(:project_error_tracking_setting, project: projects[0])
create(:project_error_tracking_setting, project: projects[1], enabled: false) create(:project_error_tracking_setting, project: projects[1], enabled: false)
create_list(:issue, 4, project: projects[0]) create_list(:issue, 4, project: projects[0])
...@@ -157,6 +160,9 @@ describe Gitlab::UsageData do ...@@ -157,6 +160,9 @@ describe Gitlab::UsageData do
projects_jira_cloud_active projects_jira_cloud_active
projects_slack_notifications_active projects_slack_notifications_active
projects_slack_slash_active projects_slack_slash_active
projects_custom_issue_tracker_active
projects_jenkins_active
projects_mattermost_active
projects_prometheus_active projects_prometheus_active
projects_with_repositories_enabled projects_with_repositories_enabled
projects_with_error_tracking_enabled projects_with_error_tracking_enabled
...@@ -190,6 +196,9 @@ describe Gitlab::UsageData do ...@@ -190,6 +196,9 @@ describe Gitlab::UsageData do
expect(count_data[:projects_jira_cloud_active]).to eq(2) expect(count_data[:projects_jira_cloud_active]).to eq(2)
expect(count_data[:projects_slack_notifications_active]).to eq(2) expect(count_data[:projects_slack_notifications_active]).to eq(2)
expect(count_data[:projects_slack_slash_active]).to eq(1) expect(count_data[:projects_slack_slash_active]).to eq(1)
expect(count_data[:projects_custom_issue_tracker_active]).to eq(1)
expect(count_data[:projects_jenkins_active]).to eq(1)
expect(count_data[:projects_mattermost_active]).to eq(1)
expect(count_data[:projects_with_repositories_enabled]).to eq(3) expect(count_data[:projects_with_repositories_enabled]).to eq(3)
expect(count_data[:projects_with_error_tracking_enabled]).to eq(1) expect(count_data[:projects_with_error_tracking_enabled]).to eq(1)
expect(count_data[:issues_with_associated_zoom_link]).to eq(2) expect(count_data[:issues_with_associated_zoom_link]).to eq(2)
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20191017045817_schedule_fix_gitlab_com_pages_access_level.rb')
describe ScheduleFixGitlabComPagesAccessLevel, :migration, :sidekiq_might_not_need_inline, schema: 2019_10_16_072826 do
using RSpec::Parameterized::TableSyntax
let(:migration_name) { 'FixGitlabComPagesAccessLevel' }
ProjectClass = ::Gitlab::BackgroundMigration::FixGitlabComPagesAccessLevel::Project
FeatureClass = ::Gitlab::BackgroundMigration::FixGitlabComPagesAccessLevel::ProjectFeature
let(:namespaces_table) { table(:namespaces) }
let(:projects_table) { table(:projects) }
let(:features_table) { table(:project_features) }
let(:pages_metadata_table) { table(:project_pages_metadata) }
let(:subgroup) do
root_group = namespaces_table.create(path: "group", name: "group")
namespaces_table.create!(path: "subgroup", name: "group", parent_id: root_group.id)
end
before do
allow(::Gitlab).to receive(:com?).and_return true
end
describe 'scheduling migration' do
let!(:first_project) { create_project(ProjectClass::PRIVATE, FeatureClass::PRIVATE, false, false, 'first' ) }
let!(:last_project) { create_project(ProjectClass::PRIVATE, FeatureClass::PRIVATE, false, false, 'second' ) }
subject do
Sidekiq::Testing.fake! do
migrate!
end
end
it 'schedules background migrations' do
Timecop.freeze do
subject
expect(migration_name).to be_scheduled_delayed_migration(2.minutes, first_project.id, last_project.id)
expect(BackgroundMigrationWorker.jobs.size).to eq(1)
end
end
context 'not on gitlab.com' do
before do
allow(::Gitlab).to receive(:com?).and_return false
end
it 'does not schedule background migrations' do
Timecop.freeze do
subject
expect(BackgroundMigrationWorker.jobs.size).to eq(0)
end
end
end
end
where(:visibility_level, :pages_access_level,
:pages_deployed, :ac_is_enabled_in_config,
:result_pages_access_level) do
# Does not change anything if pages are not deployed
ProjectClass::PRIVATE | FeatureClass::DISABLED | false | false | FeatureClass::DISABLED
ProjectClass::PRIVATE | FeatureClass::PRIVATE | false | false | FeatureClass::PRIVATE
ProjectClass::PRIVATE | FeatureClass::ENABLED | false | false | FeatureClass::ENABLED
ProjectClass::PRIVATE | FeatureClass::PUBLIC | false | false | FeatureClass::PUBLIC
ProjectClass::INTERNAL | FeatureClass::DISABLED | false | false | FeatureClass::DISABLED
ProjectClass::INTERNAL | FeatureClass::PRIVATE | false | false | FeatureClass::PRIVATE
ProjectClass::INTERNAL | FeatureClass::ENABLED | false | false | FeatureClass::ENABLED
ProjectClass::INTERNAL | FeatureClass::PUBLIC | false | false | FeatureClass::PUBLIC
ProjectClass::PUBLIC | FeatureClass::DISABLED | false | false | FeatureClass::DISABLED
ProjectClass::PUBLIC | FeatureClass::PRIVATE | false | false | FeatureClass::PRIVATE
ProjectClass::PUBLIC | FeatureClass::ENABLED | false | false | FeatureClass::ENABLED
ProjectClass::PUBLIC | FeatureClass::PUBLIC | false | false | FeatureClass::PUBLIC
# Does not change anything if pages are already private in config.json
# many of these cases are invalid and will not occur in production
ProjectClass::PRIVATE | FeatureClass::DISABLED | true | true | FeatureClass::DISABLED
ProjectClass::PRIVATE | FeatureClass::PRIVATE | true | true | FeatureClass::PRIVATE
ProjectClass::PRIVATE | FeatureClass::ENABLED | true | true | FeatureClass::ENABLED
ProjectClass::PRIVATE | FeatureClass::PUBLIC | true | true | FeatureClass::PUBLIC
ProjectClass::INTERNAL | FeatureClass::DISABLED | true | true | FeatureClass::DISABLED
ProjectClass::INTERNAL | FeatureClass::PRIVATE | true | true | FeatureClass::PRIVATE
ProjectClass::INTERNAL | FeatureClass::ENABLED | true | true | FeatureClass::ENABLED
ProjectClass::INTERNAL | FeatureClass::PUBLIC | true | true | FeatureClass::PUBLIC
ProjectClass::PUBLIC | FeatureClass::DISABLED | true | true | FeatureClass::DISABLED
ProjectClass::PUBLIC | FeatureClass::PRIVATE | true | true | FeatureClass::PRIVATE
ProjectClass::PUBLIC | FeatureClass::ENABLED | true | true | FeatureClass::ENABLED
ProjectClass::PUBLIC | FeatureClass::PUBLIC | true | true | FeatureClass::PUBLIC
# when pages are deployed and ac is disabled in config
ProjectClass::PRIVATE | FeatureClass::DISABLED | true | false | FeatureClass::DISABLED
ProjectClass::PRIVATE | FeatureClass::PRIVATE | true | false | FeatureClass::PUBLIC # need to update
ProjectClass::PRIVATE | FeatureClass::ENABLED | true | false | FeatureClass::PUBLIC # invalid state, need to update
ProjectClass::PRIVATE | FeatureClass::PUBLIC | true | false | FeatureClass::PUBLIC
ProjectClass::INTERNAL | FeatureClass::DISABLED | true | false | FeatureClass::DISABLED
ProjectClass::INTERNAL | FeatureClass::PRIVATE | true | false | FeatureClass::PUBLIC # need to update
ProjectClass::INTERNAL | FeatureClass::ENABLED | true | false | FeatureClass::PUBLIC # invalid state, need to update
ProjectClass::INTERNAL | FeatureClass::PUBLIC | true | false | FeatureClass::PUBLIC
ProjectClass::PUBLIC | FeatureClass::DISABLED | true | false | FeatureClass::DISABLED
ProjectClass::PUBLIC | FeatureClass::PRIVATE | true | false | FeatureClass::ENABLED # need to update
ProjectClass::PUBLIC | FeatureClass::ENABLED | true | false | FeatureClass::ENABLED
ProjectClass::PUBLIC | FeatureClass::PUBLIC | true | false | FeatureClass::ENABLED # invalid state, need to update
end
with_them do
it 'fixes settings' do
perform_enqueued_jobs do
project = create_project(visibility_level, pages_access_level, pages_deployed, ac_is_enabled_in_config)
expect(features_table.find_by(project_id: project.id).pages_access_level).to eq(pages_access_level)
migrate!
expect(features_table.find_by(project_id: project.id).pages_access_level).to eq(result_pages_access_level)
end
end
end
def create_project(visibility_level, pages_access_level, pages_deployed, ac_is_enabled_in_config, path = 'project')
project = projects_table.create!(path: path, visibility_level: visibility_level,
namespace_id: subgroup.id)
pages_metadata_table.create!(project_id: project.id, deployed: pages_deployed)
if pages_deployed
FileUtils.mkdir_p(ProjectClass.find(project.id).public_pages_path)
# write config.json
allow(project).to receive(:public_pages?).and_return(!ac_is_enabled_in_config)
allow(project).to receive(:pages_domains).and_return([])
allow(project).to receive(:project_id).and_return(project.id)
allow(project).to receive(:pages_path).and_return(ProjectClass.find(project.id).pages_path)
Projects::UpdatePagesConfigurationService.new(project).execute
end
project.update!(visibility_level: visibility_level)
features_table.create!(project_id: project.id, pages_access_level: pages_access_level)
project
end
end
...@@ -980,7 +980,11 @@ describe Ci::Pipeline, :mailer do ...@@ -980,7 +980,11 @@ describe Ci::Pipeline, :mailer do
describe 'pipeline stages' do describe 'pipeline stages' do
describe '#stage_seeds' do describe '#stage_seeds' do
let(:pipeline) { build(:ci_pipeline, config: config) } before do
stub_ci_pipeline_yaml_file(YAML.dump(config))
end
let(:pipeline) { build(:ci_pipeline) }
let(:config) { { rspec: { script: 'rake' } } } let(:config) { { rspec: { script: 'rake' } } }
it 'returns preseeded stage seeds object' do it 'returns preseeded stage seeds object' do
...@@ -1010,7 +1014,7 @@ describe Ci::Pipeline, :mailer do ...@@ -1010,7 +1014,7 @@ describe Ci::Pipeline, :mailer do
context 'when refs policy is specified' do context 'when refs policy is specified' do
let(:pipeline) do let(:pipeline) do
build(:ci_pipeline, ref: 'feature', tag: true, config: config) build(:ci_pipeline, ref: 'feature', tag: true)
end end
let(:config) do let(:config) do
...@@ -1028,7 +1032,7 @@ describe Ci::Pipeline, :mailer do ...@@ -1028,7 +1032,7 @@ describe Ci::Pipeline, :mailer do
end end
context 'when source policy is specified' do context 'when source policy is specified' do
let(:pipeline) { build(:ci_pipeline, source: :schedule, config: config) } let(:pipeline) { build(:ci_pipeline, source: :schedule) }
let(:config) do let(:config) do
{ production: { stage: 'deploy', script: 'cap prod', only: ['triggers'] }, { production: { stage: 'deploy', script: 'cap prod', only: ['triggers'] },
...@@ -1060,7 +1064,7 @@ describe Ci::Pipeline, :mailer do ...@@ -1060,7 +1064,7 @@ describe Ci::Pipeline, :mailer do
context 'when user configured kubernetes from CI/CD > Clusters' do context 'when user configured kubernetes from CI/CD > Clusters' do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) } let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project } let(:project) { cluster.project }
let(:pipeline) { build(:ci_pipeline, project: project, config: config) } let(:pipeline) { build(:ci_pipeline, project: project) }
it 'returns seeds for kubernetes dependent job' do it 'returns seeds for kubernetes dependent job' do
seeds = pipeline.stage_seeds seeds = pipeline.stage_seeds
...@@ -1098,6 +1102,10 @@ describe Ci::Pipeline, :mailer do ...@@ -1098,6 +1102,10 @@ describe Ci::Pipeline, :mailer do
end end
describe '#seeds_size' do describe '#seeds_size' do
before do
stub_ci_pipeline_yaml_file(YAML.dump(config))
end
context 'when refs policy is specified' do context 'when refs policy is specified' do
let(:config) do let(:config) do
{ production: { stage: 'deploy', script: 'cap prod', only: ['master'] }, { production: { stage: 'deploy', script: 'cap prod', only: ['master'] },
...@@ -1105,7 +1113,7 @@ describe Ci::Pipeline, :mailer do ...@@ -1105,7 +1113,7 @@ describe Ci::Pipeline, :mailer do
end end
let(:pipeline) do let(:pipeline) do
build(:ci_pipeline, ref: 'feature', tag: true, config: config) build(:ci_pipeline, ref: 'feature', tag: true)
end end
it 'returns real seeds size' do it 'returns real seeds size' do
...@@ -2886,21 +2894,25 @@ describe Ci::Pipeline, :mailer do ...@@ -2886,21 +2894,25 @@ describe Ci::Pipeline, :mailer do
end end
describe '#has_yaml_errors?' do describe '#has_yaml_errors?' do
before do
stub_ci_pipeline_yaml_file(YAML.dump(config))
end
let(:pipeline) { create(:ci_pipeline) }
context 'when pipeline has errors' do context 'when pipeline has errors' do
let(:pipeline) do let(:config) { { rspec: nil } }
create(:ci_pipeline, config: { rspec: nil })
end
it 'contains yaml errors' do it 'contains yaml errors' do
pipeline.config_processor
expect(pipeline).to have_yaml_errors expect(pipeline).to have_yaml_errors
expect(pipeline.yaml_errors).to include('contains unknown keys') expect(pipeline.yaml_errors).to include('contains unknown keys')
end end
end end
context 'when pipeline has undefined error' do context 'when pipeline has undefined error' do
let(:pipeline) do let(:config) { double(:config) }
create(:ci_pipeline, config: {})
end
it 'contains yaml errors' do it 'contains yaml errors' do
expect(::Gitlab::Ci::YamlProcessor).to receive(:new) expect(::Gitlab::Ci::YamlProcessor).to receive(:new)
...@@ -2910,14 +2922,16 @@ describe Ci::Pipeline, :mailer do ...@@ -2910,14 +2922,16 @@ describe Ci::Pipeline, :mailer do
.with(be_a(RuntimeError), anything) .with(be_a(RuntimeError), anything)
.and_call_original .and_call_original
pipeline.config_processor
expect(pipeline).to have_yaml_errors expect(pipeline).to have_yaml_errors
expect(pipeline.yaml_errors).to include('Undefined error') expect(pipeline.yaml_errors).to include('Undefined error')
end end
end end
context 'when pipeline does not have errors' do context 'when pipeline does not have errors' do
let(:pipeline) do let(:config) do
create(:ci_pipeline, config: { rspec: { script: 'rake test' } }) { rspec: { script: 'rake test' } }
end end
it 'does not contain yaml errors' do it 'does not contain yaml errors' do
......
...@@ -2807,7 +2807,7 @@ describe MergeRequest do ...@@ -2807,7 +2807,7 @@ describe MergeRequest do
describe '#mergeable_with_quick_action?' do describe '#mergeable_with_quick_action?' do
def create_pipeline(status) def create_pipeline(status)
pipeline = create(:ci_pipeline_with_one_job, pipeline = create(:ci_pipeline,
project: project, project: project,
ref: merge_request.source_branch, ref: merge_request.source_branch,
sha: merge_request.diff_head_sha, sha: merge_request.diff_head_sha,
...@@ -2922,9 +2922,9 @@ describe MergeRequest do ...@@ -2922,9 +2922,9 @@ describe MergeRequest do
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
let(:merge_request) { create(:merge_request, source_project: project) } let(:merge_request) { create(:merge_request, source_project: project) }
let!(:first_pipeline) { create(:ci_pipeline_without_jobs, pipeline_arguments) } let!(:first_pipeline) { create(:ci_pipeline, pipeline_arguments) }
let!(:last_pipeline) { create(:ci_pipeline_without_jobs, pipeline_arguments) } let!(:last_pipeline) { create(:ci_pipeline, pipeline_arguments) }
let!(:last_pipeline_with_other_ref) { create(:ci_pipeline_without_jobs, pipeline_arguments.merge(ref: 'other')) } let!(:last_pipeline_with_other_ref) { create(:ci_pipeline, pipeline_arguments.merge(ref: 'other')) }
it 'returns latest pipeline for the target branch' do it 'returns latest pipeline for the target branch' do
expect(merge_request.base_pipeline).to eq(last_pipeline) expect(merge_request.base_pipeline).to eq(last_pipeline)
......
...@@ -15,6 +15,26 @@ describe Service do ...@@ -15,6 +15,26 @@ describe Service do
end end
describe 'Scopes' do describe 'Scopes' do
describe '.by_type' do
let!(:service1) { create(:jira_service) }
let!(:service2) { create(:jira_service) }
let!(:service3) { create(:redmine_service) }
subject { described_class.by_type(type) }
context 'when type is "JiraService"' do
let(:type) { 'JiraService' }
it { is_expected.to match_array([service1, service2]) }
end
context 'when type is "RedmineService"' do
let(:type) { 'RedmineService' }
it { is_expected.to match_array([service3]) }
end
end
describe '.confidential_note_hooks' do describe '.confidential_note_hooks' do
it 'includes services where confidential_note_events is true' do it 'includes services where confidential_note_events is true' do
create(:service, active: true, confidential_note_events: true) create(:service, active: true, confidential_note_events: true)
......
...@@ -12,7 +12,7 @@ describe API::MergeRequests do ...@@ -12,7 +12,7 @@ describe API::MergeRequests do
let(:project) { create(:project, :public, :repository, creator: user, namespace: user.namespace, only_allow_merge_if_pipeline_succeeds: false) } let(:project) { create(:project, :public, :repository, creator: user, namespace: user.namespace, only_allow_merge_if_pipeline_succeeds: false) }
let(:milestone) { create(:milestone, title: '1.0.0', project: project) } let(:milestone) { create(:milestone, title: '1.0.0', project: project) }
let(:milestone1) { create(:milestone, title: '0.9', project: project) } let(:milestone1) { create(:milestone, title: '0.9', project: project) }
let!(:merge_request) { create(:merge_request, :simple, milestone: milestone1, author: user, assignees: [user], source_project: project, target_project: project, title: "Test", created_at: base_time) } let!(:merge_request) { create(:merge_request, :simple, milestone: milestone1, author: user, assignees: [user], source_project: project, target_project: project, source_branch: 'markdown', title: "Test", created_at: base_time) }
let!(:merge_request_closed) { create(:merge_request, state: "closed", milestone: milestone1, author: user, assignees: [user], source_project: project, target_project: project, title: "Closed test", created_at: base_time + 1.second) } let!(:merge_request_closed) { create(:merge_request, state: "closed", milestone: milestone1, author: user, assignees: [user], source_project: project, target_project: project, title: "Closed test", created_at: base_time + 1.second) }
let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignees: [user], source_project: project, target_project: project, title: "Merged test", created_at: base_time + 2.seconds, merge_commit_sha: '9999999999999999999999999999999999999999') } let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignees: [user], source_project: project, target_project: project, title: "Merged test", created_at: base_time + 2.seconds, merge_commit_sha: '9999999999999999999999999999999999999999') }
let!(:merge_request_locked) { create(:merge_request, state: "locked", milestone: milestone1, author: user, assignees: [user], source_project: project, target_project: project, title: "Locked test", created_at: base_time + 1.second) } let!(:merge_request_locked) { create(:merge_request, state: "locked", milestone: milestone1, author: user, assignees: [user], source_project: project, target_project: project, title: "Locked test", created_at: base_time + 1.second) }
...@@ -1330,7 +1330,7 @@ describe API::MergeRequests do ...@@ -1330,7 +1330,7 @@ describe API::MergeRequests do
context 'accepts remove_source_branch parameter' do context 'accepts remove_source_branch parameter' do
let(:params) do let(:params) do
{ title: 'Test merge_request', { title: 'Test merge_request',
source_branch: 'markdown', source_branch: 'feature_conflict',
target_branch: 'master', target_branch: 'master',
author: user } author: user }
end end
...@@ -1490,7 +1490,7 @@ describe API::MergeRequests do ...@@ -1490,7 +1490,7 @@ describe API::MergeRequests do
end end
describe "PUT /projects/:id/merge_requests/:merge_request_iid/merge" do describe "PUT /projects/:id/merge_requests/:merge_request_iid/merge" do
let(:pipeline) { create(:ci_pipeline_without_jobs) } let(:pipeline) { create(:ci_pipeline) }
it "returns merge_request in case of success" do it "returns merge_request in case of success" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user) put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user)
......
...@@ -314,7 +314,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -314,7 +314,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
let(:root_namespace) { create(:namespace) } let(:root_namespace) { create(:namespace) }
let(:namespace) { create(:namespace, parent: root_namespace) } let(:namespace) { create(:namespace, parent: root_namespace) }
let(:project) { create(:project, namespace: namespace, shared_runners_enabled: false) } let(:project) { create(:project, namespace: namespace, shared_runners_enabled: false) }
let(:pipeline) { create(:ci_pipeline_without_jobs, project: project, ref: 'master') } let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master') }
let(:runner) { create(:ci_runner, :project, projects: [project]) } let(:runner) { create(:ci_runner, :project, projects: [project]) }
let(:job) do let(:job) do
create(:ci_build, :artifacts, :extended_options, create(:ci_build, :artifacts, :extended_options,
...@@ -612,7 +612,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -612,7 +612,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end end
context 'when job is made for merge request' do context 'when job is made for merge request' do
let(:pipeline) { create(:ci_pipeline_without_jobs, source: :merge_request_event, project: project, ref: 'feature', merge_request: merge_request) } let(:pipeline) { create(:ci_pipeline, source: :merge_request_event, project: project, ref: 'feature', merge_request: merge_request) }
let!(:job) { create(:ci_build, pipeline: pipeline, name: 'spinach', ref: 'feature', stage: 'test', stage_idx: 0) } let!(:job) { create(:ci_build, pipeline: pipeline, name: 'spinach', ref: 'feature', stage: 'test', stage_idx: 0) }
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
......
...@@ -115,7 +115,7 @@ describe PipelineDetailsEntity do ...@@ -115,7 +115,7 @@ describe PipelineDetailsEntity do
context 'when pipeline has YAML errors' do context 'when pipeline has YAML errors' do
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, config: { rspec: { invalid: :value } }) create(:ci_pipeline, yaml_errors: 'Some error occurred')
end end
it 'contains information about error' do it 'contains information about error' do
......
...@@ -13,8 +13,7 @@ describe AutoMerge::MergeWhenPipelineSucceedsService do ...@@ -13,8 +13,7 @@ describe AutoMerge::MergeWhenPipelineSucceedsService do
end end
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline_with_one_job, ref: mr_merge_if_green_enabled.source_branch, create(:ci_pipeline, ref: mr_merge_if_green_enabled.source_branch, project: project)
project: project)
end end
let(:service) do let(:service) do
......
...@@ -10,9 +10,7 @@ describe MergeRequests::AddTodoWhenBuildFailsService do ...@@ -10,9 +10,7 @@ describe MergeRequests::AddTodoWhenBuildFailsService do
let(:ref) { merge_request.source_branch } let(:ref) { merge_request.source_branch }
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline_with_one_job, ref: ref, create(:ci_pipeline, ref: ref, project: project, sha: sha)
project: project,
sha: sha)
end end
let(:service) do let(:service) do
......
...@@ -190,7 +190,7 @@ describe MergeRequests::UpdateService, :mailer do ...@@ -190,7 +190,7 @@ describe MergeRequests::UpdateService, :mailer do
context 'with finished pipeline' do context 'with finished pipeline' do
before do before do
create(:ci_pipeline_with_one_job, create(:ci_pipeline,
project: project, project: project,
ref: merge_request.source_branch, ref: merge_request.source_branch,
sha: merge_request.diff_head_sha, sha: merge_request.diff_head_sha,
...@@ -212,7 +212,7 @@ describe MergeRequests::UpdateService, :mailer do ...@@ -212,7 +212,7 @@ describe MergeRequests::UpdateService, :mailer do
before do before do
service_mock = double service_mock = double
create( create(
:ci_pipeline_with_one_job, :ci_pipeline,
project: project, project: project,
ref: merge_request.source_branch, ref: merge_request.source_branch,
sha: merge_request.diff_head_sha, sha: merge_request.diff_head_sha,
......
...@@ -14,7 +14,7 @@ describe ::SystemNotes::MergeRequestsService do ...@@ -14,7 +14,7 @@ describe ::SystemNotes::MergeRequestsService do
let(:service) { described_class.new(noteable: noteable, project: project, author: author) } let(:service) { described_class.new(noteable: noteable, project: project, author: author) }
describe '.merge_when_pipeline_succeeds' do describe '.merge_when_pipeline_succeeds' do
let(:pipeline) { build(:ci_pipeline_without_jobs )} let(:pipeline) { build(:ci_pipeline) }
subject { service.merge_when_pipeline_succeeds(pipeline.sha) } subject { service.merge_when_pipeline_succeeds(pipeline.sha) }
......
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