Commit 22b539ed authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent aca5a274eed5
......@@ -286,19 +286,4 @@ describe('Issue card component', () => {
.catch(done.fail);
});
});
describe('weights', () => {
it('shows weight component is greater than 0', () => {
expect(component.$el.querySelector('.board-card-weight')).not.toBeNull();
});
it('shows weight component when weight is 0', done => {
component.issue.weight = 0;
Vue.nextTick(() => {
expect(component.$el.querySelector('.board-card-weight')).not.toBeNull();
done();
});
});
});
});
# frozen_string_literal: true
require 'spec_helper'
describe API::Helpers::GraphqlHelpers do
describe 'run_graphql!' do
let(:query) { '{ metadata { version } }' }
let(:graphql_helper) do
Class.new do
include API::Helpers::GraphqlHelpers
end.new
end
context 'when transform function is provided' do
let(:result) { { 'data' => { 'metadata' => { 'version' => '1.0.0' } } } }
before do
allow(GitlabSchema).to receive(:execute).and_return(result)
end
it 'returns the expected result' do
expect(
graphql_helper.run_graphql!(
query: query,
transform: ->(result) { result.dig('data', 'metadata') }
)
).to eq({ 'version' => '1.0.0' })
end
end
context 'when a transform function is not provided' do
let(:result) { double('result') }
before do
allow(GitlabSchema).to receive(:execute).and_return(result)
end
it 'returns the expected result' do
expect(graphql_helper.run_graphql!(query: query)).to eq(result)
end
end
end
end
......@@ -17,32 +17,27 @@ def link_to_image(path)
let(:project) { create(:project, :repository) }
shared_examples 'replaces the image tag with a video tag' do |ext|
it "replaces the image tag 'path/video.#{ext}' with a video tag" do
container = filter(link_to_image("/path/video.#{ext}")).children.first
expect(container.name).to eq 'div'
expect(container['class']).to eq 'video-container'
context 'when the element src has a video extension' do
UploaderHelper::SAFE_VIDEO_EXT.each do |ext|
it "replaces the image tag 'path/video.#{ext}' with a video tag" do
container = filter(link_to_image("/path/video.#{ext}")).children.first
video, paragraph = container.children
expect(container.name).to eq 'div'
expect(container['class']).to eq 'video-container'
expect(video.name).to eq 'video'
expect(video['src']).to eq "/path/video.#{ext}"
video, paragraph = container.children
expect(paragraph.name).to eq 'p'
expect(video.name).to eq 'video'
expect(video['src']).to eq "/path/video.#{ext}"
link = paragraph.children.first
expect(paragraph.name).to eq 'p'
expect(link.name).to eq 'a'
expect(link['href']).to eq "/path/video.#{ext}"
expect(link['target']).to eq '_blank'
end
end
link = paragraph.children.first
context 'when the element src has a video extension' do
UploaderHelper::SAFE_VIDEO_EXT.each do |ext|
it_behaves_like 'replaces the image tag with a video tag', ext
it_behaves_like 'replaces the image tag with a video tag', ext.upcase
expect(link.name).to eq 'a'
expect(link['href']).to eq "/path/video.#{ext}"
expect(link['target']).to eq '_blank'
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::BackgroundMigration::MigratePagesMetadata, :migration, schema: 20190919040324 do
let(:projects) { table(:projects) }
subject(:migrate_pages_metadata) { described_class.new }
describe '#perform_on_relation' do
let(:namespaces) { table(:namespaces) }
let(:builds) { table(:ci_builds) }
let(:pages_metadata) { table(:project_pages_metadata) }
it 'marks specified projects with successful pages deployment' do
namespace = namespaces.create!(name: 'gitlab', path: 'gitlab-org')
not_migrated_with_pages = projects.create!(namespace_id: namespace.id, name: 'Not Migrated With Pages')
builds.create!(project_id: not_migrated_with_pages.id, type: 'GenericCommitStatus', status: 'success', stage: 'deploy', name: 'pages:deploy')
migrated = projects.create!(namespace_id: namespace.id, name: 'Migrated')
pages_metadata.create!(project_id: migrated.id, deployed: true)
not_migrated_no_pages = projects.create!(namespace_id: namespace.id, name: 'Not Migrated No Pages')
project_not_in_relation_scope = projects.create!(namespace_id: namespace.id, name: 'Other')
projects_relation = projects.where(id: [not_migrated_with_pages, not_migrated_no_pages, migrated])
migrate_pages_metadata.perform_on_relation(projects_relation)
expect(pages_metadata.find_by_project_id(not_migrated_with_pages.id).deployed).to eq(true)
expect(pages_metadata.find_by_project_id(not_migrated_no_pages.id).deployed).to eq(false)
expect(pages_metadata.find_by_project_id(migrated.id).deployed).to eq(true)
expect(pages_metadata.find_by_project_id(project_not_in_relation_scope.id)).to be_nil
end
end
describe '#perform' do
it 'creates relation and delegates to #perform_on_relation' do
expect(migrate_pages_metadata).to receive(:perform_on_relation).with(projects.where(id: 3..5))
migrate_pages_metadata.perform(3, 5)
end
end
end
require 'spec_helper'
describe Gitlab::Ci::Status::Composite do
set(:pipeline) { create(:ci_pipeline) }
before(:all) do
@statuses = HasStatus::STATUSES_ENUM.map do |status, idx|
[status, create(:ci_build, pipeline: pipeline, status: status, importing: true)]
end.to_h
@statuses_with_allow_failure = HasStatus::STATUSES_ENUM.map do |status, idx|
[status, create(:ci_build, pipeline: pipeline, status: status, allow_failure: true, importing: true)]
end.to_h
end
describe '#status' do
shared_examples 'compares composite with SQL status' do
it 'returns exactly the same result' do
builds = Ci::Build.where(id: all_statuses)
expect(composite_status.status).to eq(builds.legacy_status)
expect(composite_status.warnings?).to eq(builds.failed_but_allowed.any?)
end
end
shared_examples 'validate all combinations' do |perms|
HasStatus::STATUSES_ENUM.keys.combination(perms).each do |statuses|
context "with #{statuses.join(",")}" do
it_behaves_like 'compares composite with SQL status' do
let(:all_statuses) do
statuses.map { |status| @statuses[status] }
end
let(:composite_status) do
described_class.new(all_statuses)
end
end
HasStatus::STATUSES_ENUM.each do |allow_failure_status, _|
context "and allow_failure #{allow_failure_status}" do
it_behaves_like 'compares composite with SQL status' do
let(:all_statuses) do
statuses.map { |status| @statuses[status] } +
[@statuses_with_allow_failure[allow_failure_status]]
end
let(:composite_status) do
described_class.new(all_statuses)
end
end
end
end
end
end
end
it_behaves_like 'validate all combinations', 0
it_behaves_like 'validate all combinations', 1
it_behaves_like 'validate all combinations', 2
end
end
......@@ -96,6 +96,17 @@
expect(Ci::Pipeline.where(ref: nil)).not_to be_empty
end
it 'restores pipeline for merge request' do
pipeline = Ci::Pipeline.find_by_sha('048721d90c449b244b7b4c53a9186b04330174ec')
expect(pipeline).to be_valid
expect(pipeline.tag).to be_falsey
expect(pipeline.source).to eq('merge_request_event')
expect(pipeline.merge_request.id).to be > 0
expect(pipeline.merge_request.target_branch).to eq('feature')
expect(pipeline.merge_request.source_branch).to eq('feature_conflict')
end
it 'preserves updated_at on issues' do
issue = Issue.where(description: 'Aliquam enim illo et possimus.').first
......
......@@ -3,12 +3,14 @@
describe Gitlab::ImportExport::RelationFactory do
let(:project) { create(:project) }
let(:members_mapper) { double('members_mapper').as_null_object }
let(:merge_requests_mapping) { {} }
let(:user) { create(:admin) }
let(:excluded_keys) { [] }
let(:created_object) do
described_class.create(relation_sym: relation_sym,
relation_hash: relation_hash,
members_mapper: members_mapper,
merge_requests_mapping: merge_requests_mapping,
user: user,
project: project,
excluded_keys: excluded_keys)
......
......@@ -22,6 +22,32 @@
end
end
describe '#status' do
let(:jobs) do
[create(:ci_build, :failed)]
end
context 'when ci_composite_status is enabled' do
before do
stub_feature_flags(ci_composite_status: true)
end
it 'returns a failed status' do
expect(subject.status).to eq('failed')
end
end
context 'when ci_composite_status is disabled' do
before do
stub_feature_flags(ci_composite_status: false)
end
it 'returns a failed status' do
expect(subject.status).to eq('failed')
end
end
end
describe '#detailed_status' do
context 'when there is only one item in the group' do
it 'calls the status from the object itself' do
......
......@@ -216,7 +216,7 @@
context 'when stage has warnings' do
context 'when using memoized warnings flag' do
context 'when there are warnings' do
let(:stage) { build(:ci_stage, warnings: 2) }
let(:stage) { build(:ci_stage, warnings: true) }
it 'returns true using memoized value' do
expect(stage).not_to receive(:statuses)
......@@ -225,22 +225,13 @@
end
context 'when there are no warnings' do
let(:stage) { build(:ci_stage, warnings: 0) }
let(:stage) { build(:ci_stage, warnings: false) }
it 'returns false using memoized value' do
expect(stage).not_to receive(:statuses)
expect(stage).not_to have_warnings
end
end
context 'when number of warnings is not a valid value' do
let(:stage) { build(:ci_stage, warnings: true) }
it 'calculates statuses using database queries' do
expect(stage).to receive(:statuses).and_call_original
expect(stage).not_to have_warnings
end
end
end
context 'when calculating warnings from statuses' do
......
......@@ -1136,59 +1136,71 @@ def create_build(name, status)
end
describe '#legacy_stages' do
using RSpec::Parameterized::TableSyntax
subject { pipeline.legacy_stages }
context 'stages list' do
it 'returns ordered list of stages' do
expect(subject.map(&:name)).to eq(%w[build test deploy])
end
where(:ci_composite_status) do
[false, true]
end
context 'stages with statuses' do
let(:statuses) do
subject.map { |stage| [stage.name, stage.status] }
with_them do
before do
stub_feature_flags(ci_composite_status: ci_composite_status)
end
it 'returns list of stages with correct statuses' do
expect(statuses).to eq([%w(build failed),
%w(test success),
%w(deploy running)])
context 'stages list' do
it 'returns ordered list of stages' do
expect(subject.map(&:name)).to eq(%w[build test deploy])
end
end
context 'when commit status is retried' do
before do
create(:commit_status, pipeline: pipeline,
stage: 'build',
name: 'mac',
stage_idx: 0,
status: 'success')
pipeline.process!
context 'stages with statuses' do
let(:statuses) do
subject.map { |stage| [stage.name, stage.status] }
end
it 'ignores the previous state' do
expect(statuses).to eq([%w(build success),
it 'returns list of stages with correct statuses' do
expect(statuses).to eq([%w(build failed),
%w(test success),
%w(deploy running)])
end
end
end
context 'when there is a stage with warnings' do
before do
create(:commit_status, pipeline: pipeline,
stage: 'deploy',
name: 'prod:2',
stage_idx: 2,
status: 'failed',
allow_failure: true)
context 'when commit status is retried' do
before do
create(:commit_status, pipeline: pipeline,
stage: 'build',
name: 'mac',
stage_idx: 0,
status: 'success')
pipeline.process!
end
it 'ignores the previous state' do
expect(statuses).to eq([%w(build success),
%w(test success),
%w(deploy running)])
end
end
end
it 'populates stage with correct number of warnings' do
deploy_stage = pipeline.legacy_stages.third
context 'when there is a stage with warnings' do
before do
create(:commit_status, pipeline: pipeline,
stage: 'deploy',
name: 'prod:2',
stage_idx: 2,
status: 'failed',
allow_failure: true)
end
expect(deploy_stage).not_to receive(:statuses)
expect(deploy_stage).to have_warnings
it 'populates stage with correct number of warnings' do
deploy_stage = pipeline.legacy_stages.third
expect(deploy_stage).not_to receive(:statuses)
expect(deploy_stage).to have_warnings
end
end
end
end
......@@ -2326,36 +2338,38 @@ def create_pipeline(status, ref, sha, project)
describe '#update_status' do
context 'when pipeline is empty' do
it 'updates does not change pipeline status' do
expect(pipeline.statuses.latest.status).to be_nil
expect(pipeline.statuses.latest.slow_composite_status).to be_nil
expect { pipeline.update_status }
.to change { pipeline.reload.status }.to 'skipped'
.to change { pipeline.reload.status }
.from('created')
.to('skipped')
end
end
context 'when updating status to pending' do
before do
allow(pipeline)
.to receive_message_chain(:statuses, :latest, :status)
.and_return(:running)
create(:ci_build, pipeline: pipeline, status: :running)
end
it 'updates pipeline status to running' do
expect { pipeline.update_status }
.to change { pipeline.reload.status }.to 'running'
.to change { pipeline.reload.status }
.from('created')
.to('running')
end
end
context 'when updating status to scheduled' do
before do
allow(pipeline)
.to receive_message_chain(:statuses, :latest, :status)
.and_return(:scheduled)
create(:ci_build, pipeline: pipeline, status: :scheduled)
end
it 'updates pipeline status to scheduled' do
expect { pipeline.update_status }
.to change { pipeline.reload.status }.to 'scheduled'
.to change { pipeline.reload.status }
.from('created')
.to('scheduled')
end
end
......
......@@ -130,7 +130,7 @@
context 'when statuses status was not recognized' do
before do
allow(stage)
.to receive_message_chain(:statuses, :latest, :status)
.to receive(:latest_stage_status)
.and_return(:unknown)
end
......
......@@ -321,7 +321,7 @@ def create_status(**opts)
end
it 'returns a correct compound status' do
expect(described_class.all.status).to eq 'running'
expect(described_class.all.slow_composite_status).to eq 'running'
end
end
......@@ -331,7 +331,7 @@ def create_status(**opts)
end
it 'returns status that indicates success' do
expect(described_class.all.status).to eq 'success'
expect(described_class.all.slow_composite_status).to eq 'success'
end
end
......@@ -342,7 +342,7 @@ def create_status(**opts)
end
it 'returns status according to the scope' do
expect(described_class.latest.status).to eq 'success'
expect(described_class.latest.slow_composite_status).to eq 'success'
end
end
end
......
......@@ -3,12 +3,15 @@
require 'spec_helper'
describe HasStatus do
describe '.status' do
subject { CommitStatus.status }
describe '.slow_composite_status' do
using RSpec::Parameterized::TableSyntax
subject { CommitStatus.slow_composite_status }
shared_examples 'build status summary' do
context 'all successful' do
let!(:statuses) { Array.new(2) { create(type, status: :success) } }
it { is_expected.to eq 'success' }
end
......@@ -165,16 +168,26 @@
end
end
context 'ci build statuses' do
let(:type) { :ci_build }
it_behaves_like 'build status summary'
where(:ci_composite_status) do
[false, true]
end
context 'generic commit statuses' do
let(:type) { :generic_commit_status }
with_them do
before do
stub_feature_flags(ci_composite_status: ci_composite_status)
end
context 'ci build statuses' do
let(:type) { :ci_build }
it_behaves_like 'build status summary'
it_behaves_like 'build status summary'
end
context 'generic commit statuses' do
let(:type) { :generic_commit_status }
it_behaves_like 'build status summary'
end
end
end
......@@ -372,8 +385,8 @@
end
end
describe '.status_sql' do
subject { Ci::Build.status_sql }
describe '.legacy_status_sql' do
subject { Ci::Build.legacy_status_sql }
it 'returns SQL' do
puts subject
......
......@@ -928,12 +928,34 @@ def project_rugged(project)
let(:project) { create(:project, namespace: namespace) }
context 'when there are pages deployed for the project' do
before do
project.mark_pages_as_deployed
context 'but pages metadata is not migrated' do
before do
generic_commit_status = create(:generic_commit_status, :success, stage: 'deploy', name: 'pages:deploy')
generic_commit_status.update!(project: project)
project.pages_metadatum.destroy!
end
it 'migrates pages metadata and returns the virual domain' do
virtual_domain = namespace.pages_virtual_domain