Skip to content
Snippets Groups Projects
Commit 238d22c0 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 6b75320f
No related branches found
No related tags found
No related merge requests found
Showing
with 377 additions and 5 deletions
Loading
Loading
@@ -27,6 +27,7 @@ issues:
- design_versions
- prometheus_alerts
- prometheus_alert_events
- self_managed_prometheus_alert_events
events:
- author
- project
Loading
Loading
@@ -81,6 +82,7 @@ releases:
- links
- milestone_releases
- milestones
- evidence
links:
- release
project_members:
Loading
Loading
@@ -400,6 +402,7 @@ project:
- operations_feature_flags_client
- prometheus_alerts
- prometheus_alert_events
- self_managed_prometheus_alert_events
- software_license_policies
- project_registry
- packages
Loading
Loading
@@ -473,6 +476,8 @@ prometheus_alerts:
- prometheus_alert_events
prometheus_alert_events:
- project
self_managed_prometheus_alert_events:
- project
epic_issues:
- issue
- epic
Loading
Loading
@@ -506,6 +511,8 @@ lists:
milestone_releases:
- milestone
- release
evidences:
- release
design: &design
- issue
- actions
Loading
Loading
Loading
Loading
@@ -127,6 +127,12 @@ Release:
- created_at
- updated_at
- released_at
Evidence:
- id
- release_id
- summary
- created_at
- updated_at
Releases::Link:
- id
- release_id
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe Ci::BuildTrace do
let(:build) { build_stubbed(:ci_build) }
let(:state) { nil }
let(:data) { StringIO.new('the-stream') }
let(:stream) do
Gitlab::Ci::Trace::Stream.new { data }
end
subject { described_class.new(build: build, stream: stream, state: state, content_format: content_format) }
shared_examples 'delegates methods' do
it { is_expected.to delegate_method(:state).to(:trace) }
it { is_expected.to delegate_method(:append).to(:trace) }
it { is_expected.to delegate_method(:truncated).to(:trace) }
it { is_expected.to delegate_method(:offset).to(:trace) }
it { is_expected.to delegate_method(:size).to(:trace) }
it { is_expected.to delegate_method(:total).to(:trace) }
it { is_expected.to delegate_method(:id).to(:build).with_prefix }
it { is_expected.to delegate_method(:status).to(:build).with_prefix }
it { is_expected.to delegate_method(:complete?).to(:build).with_prefix }
end
context 'with :json content format' do
let(:content_format) { :json }
it_behaves_like 'delegates methods'
it { is_expected.to be_json }
it 'returns formatted trace' do
expect(subject.trace.lines).to eq([
{ offset: 0, content: [{ text: 'the-stream' }] }
])
end
end
context 'with :html content format' do
let(:content_format) { :html }
it_behaves_like 'delegates methods'
it { is_expected.to be_html }
it 'returns formatted trace' do
expect(subject.trace.html).to eq('<span>the-stream</span>')
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Evidence do
let_it_be(:project) { create(:project) }
let(:release) { create(:release, project: project) }
let(:schema_file) { 'evidences/evidence' }
let(:summary_json) { described_class.last.summary.to_json }
describe 'associations' do
it { is_expected.to belong_to(:release) }
end
describe 'summary_sha' do
it 'returns nil if summary is nil' do
expect(build(:evidence, summary: nil).summary_sha).to be_nil
end
end
describe '#generate_summary_and_sha' do
before do
described_class.create!(release: release)
end
context 'when a release name is not provided' do
let(:release) { create(:release, project: project, name: nil) }
it 'creates a valid JSON object' do
expect(release.name).to be_nil
expect(summary_json).to match_schema(schema_file)
end
end
context 'when a release is associated to a milestone' do
let(:milestone) { create(:milestone, project: project) }
let(:release) { create(:release, project: project, milestones: [milestone]) }
context 'when a milestone has no issue associated with it' do
it 'creates a valid JSON object' do
expect(milestone.issues).to be_empty
expect(summary_json).to match_schema(schema_file)
end
end
context 'when a milestone has no description' do
let(:milestone) { create(:milestone, project: project, description: nil) }
it 'creates a valid JSON object' do
expect(milestone.description).to be_nil
expect(summary_json).to match_schema(schema_file)
end
end
context 'when a milestone has no due_date' do
let(:milestone) { create(:milestone, project: project, due_date: nil) }
it 'creates a valid JSON object' do
expect(milestone.due_date).to be_nil
expect(summary_json).to match_schema(schema_file)
end
end
context 'when a milestone has an issue' do
context 'when the issue has no description' do
let(:issue) { create(:issue, project: project, description: nil, state: 'closed') }
before do
milestone.issues << issue
end
it 'creates a valid JSON object' do
expect(milestone.issues.first.description).to be_nil
expect(summary_json).to match_schema(schema_file)
end
end
end
end
context 'when a release is not associated to any milestone' do
it 'creates a valid JSON object' do
expect(release.milestones).to be_empty
expect(summary_json).to match_schema(schema_file)
end
end
end
end
Loading
Loading
@@ -1042,4 +1042,21 @@ describe Group do
expect(group.access_request_approvers_to_be_notified).to eq(active_owners_in_recent_sign_in_desc_order)
end
end
describe '.groups_including_descendants_by' do
it 'returns the expected groups for a group and its descendants' do
parent_group1 = create(:group)
child_group1 = create(:group, parent: parent_group1)
child_group2 = create(:group, parent: parent_group1)
parent_group2 = create(:group)
child_group3 = create(:group, parent: parent_group2)
create(:group)
groups = described_class.groups_including_descendants_by([parent_group2.id, parent_group1.id])
expect(groups).to contain_exactly(parent_group1, parent_group2, child_group1, child_group2, child_group3)
end
end
end
Loading
Loading
@@ -6,7 +6,7 @@ describe WebHook do
let(:hook) { build(:project_hook) }
 
describe 'associations' do
it { is_expected.to have_many(:web_hook_logs).dependent(:destroy) }
it { is_expected.to have_many(:web_hook_logs) }
end
 
describe 'validations' do
Loading
Loading
@@ -85,4 +85,13 @@ describe WebHook do
hook.async_execute(data, hook_name)
end
end
describe '#destroy' do
it 'cascades to web_hook_logs' do
web_hook = create(:project_hook)
create_list(:web_hook_log, 3, web_hook: web_hook)
expect { web_hook.destroy }.to change(web_hook.web_hook_logs, :count).by(-3)
end
end
end
Loading
Loading
@@ -15,11 +15,13 @@ RSpec.describe Release do
it { is_expected.to have_many(:links).class_name('Releases::Link') }
it { is_expected.to have_many(:milestones) }
it { is_expected.to have_many(:milestone_releases) }
it { is_expected.to have_one(:evidence) }
end
 
describe 'validation' do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:description) }
it { is_expected.to validate_presence_of(:tag) }
 
context 'when a release exists in the database without a name' do
it 'does not require name' do
Loading
Loading
@@ -89,4 +91,22 @@ RSpec.describe Release do
end
end
end
describe 'evidence' do
describe '#create_evidence!' do
context 'when a release is created' do
it 'creates one Evidence object too' do
expect { release }.to change(Evidence, :count).by(1)
end
end
end
context 'when a release is deleted' do
it 'also deletes the associated evidence' do
release = create(:release)
expect { release.destroy }.to change(Evidence, :count).by(-1)
end
end
end
end
Loading
Loading
@@ -253,14 +253,14 @@ describe Todo do
end
end
 
describe '.for_group_and_descendants' do
describe '.for_group_ids_and_descendants' do
it 'returns the todos for a group and its descendants' do
parent_group = create(:group)
child_group = create(:group, parent: parent_group)
 
todo1 = create(:todo, group: parent_group)
todo2 = create(:todo, group: child_group)
todos = described_class.for_group_and_descendants(parent_group)
todos = described_class.for_group_ids_and_descendants([parent_group.id])
 
expect(todos).to contain_exactly(todo1, todo2)
end
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe TodoPolicy do
let_it_be(:author) { create(:user) }
let_it_be(:user1) { create(:user) }
let_it_be(:user2) { create(:user) }
let_it_be(:user3) { create(:user) }
let_it_be(:todo1) { create(:todo, author: author, user: user1) }
let_it_be(:todo2) { create(:todo, author: author, user: user2) }
let_it_be(:todo3) { create(:todo, author: author, user: user2) }
let_it_be(:todo4) { create(:todo, author: author, user: user3) }
def permissions(user, todo)
described_class.new(user, todo)
end
describe 'own_todo' do
it 'allows owners to access their own todos' do
[
[user1, todo1],
[user2, todo2],
[user2, todo3],
[user3, todo4]
].each do |user, todo|
expect(permissions(user, todo)).to be_allowed(:read_todo)
end
end
it 'does not allow users to access todos of other users' do
[
[user1, todo2],
[user1, todo3],
[user2, todo1],
[user2, todo4],
[user3, todo1],
[user3, todo2],
[user3, todo3]
].each do |user, todo|
expect(permissions(user, todo)).to be_disallowed(:read_todo)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe BuildTraceEntity do
let(:build) { build_stubbed(:ci_build) }
let(:request) { double('request') }
let(:stream) do
Gitlab::Ci::Trace::Stream.new do
StringIO.new('the-trace')
end
end
let(:build_trace) do
Ci::BuildTrace.new(build: build, stream: stream, content_format: content_format, state: nil)
end
let(:entity) do
described_class.new(build_trace, request: request)
end
subject { entity.as_json }
shared_examples 'includes build and trace metadata' do
it 'includes build attributes' do
expect(subject[:id]).to eq(build.id)
expect(subject[:status]).to eq(build.status)
expect(subject[:complete]).to eq(build.complete?)
end
it 'includes trace metadata' do
expect(subject).to include(:state)
expect(subject).to include(:append)
expect(subject).to include(:truncated)
expect(subject).to include(:offset)
expect(subject).to include(:size)
expect(subject).to include(:total)
end
end
context 'when content format is :json' do
let(:content_format) { :json }
it_behaves_like 'includes build and trace metadata'
it 'includes the trace content in json' do
expect(subject[:lines]).to eq([
{ offset: 0, content: [{ text: 'the-trace' }] }
])
end
end
context 'when content format is :html' do
let(:content_format) { :html }
it_behaves_like 'includes build and trace metadata'
it 'includes the trace content in json' do
expect(subject[:html]).to eq('<span>the-trace</span>')
end
end
end
Loading
Loading
@@ -2,12 +2,13 @@
 
require 'spec_helper'
 
describe Evidences::AuthorEntity do
let(:entity) { described_class.new(build(:author)) }
describe Evidences::EvidenceEntity do
let(:evidence) { build(:evidence) }
let(:entity) { described_class.new(evidence) }
 
subject { entity.as_json }
 
it 'exposes the expected fields' do
expect(subject.keys).to contain_exactly(:id, :name, :email)
expect(subject.keys).to contain_exactly(:release)
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Evidences::EvidenceSerializer do
it 'represents an EvidenceEntity entity' do
expect(described_class.entity_class).to eq(Evidences::EvidenceEntity)
end
end
Loading
Loading
@@ -8,6 +8,6 @@ describe Evidences::IssueEntity do
subject { entity.as_json }
 
it 'exposes the expected fields' do
expect(subject.keys).to contain_exactly(:id, :title, :description, :author, :state, :iid, :confidential, :created_at, :due_date)
expect(subject.keys).to contain_exactly(:id, :title, :description, :state, :iid, :confidential, :created_at, :due_date)
end
end
Loading
Loading
@@ -12,7 +12,7 @@ describe Evidences::MilestoneEntity do
expect(subject.keys).to contain_exactly(:id, :title, :description, :state, :iid, :created_at, :due_date, :issues)
end
 
context 'when there issues linked to this milestone' do
context 'when there are issues linked to this milestone' do
let(:issue_1) { build(:issue) }
let(:issue_2) { build(:issue) }
let(:milestone) { build(:milestone, issues: [issue_1, issue_2]) }
Loading
Loading
# frozen_string_literal: true
shared_examples 'updated exposed field' do
it 'creates another Evidence object' do
model.send("#{updated_field}=", updated_value)
expect(model.evidence_summary_keys).to include(updated_field)
expect { model.save! }.to change(Evidence, :count).by(1)
expect(updated_json_field).to eq(updated_value)
end
end
shared_examples 'updated non-exposed field' do
it 'does not create any Evidence object' do
model.send("#{updated_field}=", updated_value)
expect(model.evidence_summary_keys).not_to include(updated_field)
expect { model.save! }.not_to change(Evidence, :count)
end
end
shared_examples 'updated field on non-linked entity' do
it 'does not create any Evidence object' do
model.send("#{updated_field}=", updated_value)
expect(model.evidence_summary_keys).to be_empty
expect { model.save! }.not_to change(Evidence, :count)
end
end
# frozen_string_literal: true
require 'spec_helper'
describe CreateEvidenceWorker do
let!(:release) { create(:release) }
it 'creates a new Evidence' do
expect { described_class.new.perform(release.id) }.to change(Evidence, :count).by(1)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment