Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/ci/build_trace_spec.rb53
-rw-r--r--spec/models/evidence_spec.rb87
-rw-r--r--spec/models/group_spec.rb17
-rw-r--r--spec/models/hooks/web_hook_spec.rb11
-rw-r--r--spec/models/release_spec.rb20
-rw-r--r--spec/models/todo_spec.rb4
6 files changed, 189 insertions, 3 deletions
diff --git a/spec/models/ci/build_trace_spec.rb b/spec/models/ci/build_trace_spec.rb
new file mode 100644
index 00000000000..2471a6fa827
--- /dev/null
+++ b/spec/models/ci/build_trace_spec.rb
@@ -0,0 +1,53 @@
+# 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
diff --git a/spec/models/evidence_spec.rb b/spec/models/evidence_spec.rb
new file mode 100644
index 00000000000..00788c2c391
--- /dev/null
+++ b/spec/models/evidence_spec.rb
@@ -0,0 +1,87 @@
+# 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
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index 892c31a9204..520421ac5e3 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -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
diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb
index fe08dc4f5e6..025c11d6407 100644
--- a/spec/models/hooks/web_hook_spec.rb
+++ b/spec/models/hooks/web_hook_spec.rb
@@ -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
@@ -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
diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb
index e7a8d27a036..64799421eb6 100644
--- a/spec/models/release_spec.rb
+++ b/spec/models/release_spec.rb
@@ -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
@@ -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
diff --git a/spec/models/todo_spec.rb b/spec/models/todo_spec.rb
index c2566ccd047..487a1c619c6 100644
--- a/spec/models/todo_spec.rb
+++ b/spec/models/todo_spec.rb
@@ -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