2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2015-11-05 10:03:02 +00:00
|
|
|
|
2017-06-29 04:13:10 +00:00
|
|
|
RSpec.describe Release do
|
2018-12-13 11:08:53 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:release) { create(:release, project: project, author: user) }
|
2015-11-06 14:43:59 +00:00
|
|
|
|
|
|
|
it { expect(release).to be_valid }
|
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:project) }
|
2018-12-12 09:56:43 +00:00
|
|
|
it { is_expected.to belong_to(:author).class_name('User') }
|
2019-01-02 06:01:15 +00:00
|
|
|
it { is_expected.to have_many(:links).class_name('Releases::Link') }
|
2019-09-16 15:06:26 +00:00
|
|
|
it { is_expected.to have_many(:milestones) }
|
|
|
|
it { is_expected.to have_many(:milestone_releases) }
|
2019-10-17 15:06:17 +00:00
|
|
|
it { is_expected.to have_one(:evidence) }
|
2015-11-06 14:43:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validation' do
|
|
|
|
it { is_expected.to validate_presence_of(:project) }
|
|
|
|
it { is_expected.to validate_presence_of(:description) }
|
2019-10-17 15:06:17 +00:00
|
|
|
it { is_expected.to validate_presence_of(:tag) }
|
2019-04-09 06:52:15 +00:00
|
|
|
|
|
|
|
context 'when a release exists in the database without a name' do
|
|
|
|
it 'does not require name' do
|
|
|
|
existing_release_without_name = build(:release, project: project, author: user, name: nil)
|
|
|
|
existing_release_without_name.save(validate: false)
|
|
|
|
|
|
|
|
existing_release_without_name.description = "change"
|
|
|
|
existing_release_without_name.save
|
|
|
|
existing_release_without_name.reload
|
|
|
|
|
|
|
|
expect(existing_release_without_name).to be_valid
|
|
|
|
expect(existing_release_without_name.description).to eq("change")
|
2019-11-12 21:06:30 +00:00
|
|
|
expect(existing_release_without_name.name).not_to be_nil
|
2019-04-09 06:52:15 +00:00
|
|
|
end
|
|
|
|
end
|
2019-09-03 09:38:59 +00:00
|
|
|
|
|
|
|
context 'when a release is tied to a milestone for another project' do
|
|
|
|
it 'creates a validation error' do
|
2019-09-16 15:06:26 +00:00
|
|
|
milestone = build(:milestone, project: create(:project))
|
|
|
|
expect { release.milestones << milestone }.to raise_error
|
2019-09-03 09:38:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a release is tied to a milestone linked to the same project' do
|
2019-09-16 15:06:26 +00:00
|
|
|
it 'successfully links this release to this milestone' do
|
|
|
|
milestone = build(:milestone, project: project)
|
|
|
|
expect { release.milestones << milestone }.to change { MilestoneRelease.count }.by(1)
|
2019-09-03 09:38:59 +00:00
|
|
|
end
|
|
|
|
end
|
2015-11-06 14:43:59 +00:00
|
|
|
end
|
2019-01-02 06:01:15 +00:00
|
|
|
|
|
|
|
describe '#assets_count' do
|
|
|
|
subject { release.assets_count }
|
|
|
|
|
|
|
|
it 'returns the number of sources' do
|
2019-10-31 15:06:41 +00:00
|
|
|
is_expected.to eq(Gitlab::Workhorse::ARCHIVE_FORMATS.count)
|
2019-01-02 06:01:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a links exists' do
|
|
|
|
let!(:link) { create(:release_link, release: release) }
|
|
|
|
|
|
|
|
it 'counts the link as an asset' do
|
2019-10-31 15:06:41 +00:00
|
|
|
is_expected.to eq(1 + Gitlab::Workhorse::ARCHIVE_FORMATS.count)
|
2019-01-02 06:01:15 +00:00
|
|
|
end
|
2019-05-03 13:29:20 +00:00
|
|
|
|
|
|
|
it "excludes sources count when asked" do
|
|
|
|
assets_count = release.assets_count(except: [:sources])
|
|
|
|
expect(assets_count).to eq(1)
|
|
|
|
end
|
2019-01-02 06:01:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#sources' do
|
|
|
|
subject { release.sources }
|
|
|
|
|
|
|
|
it 'returns sources' do
|
|
|
|
is_expected.to all(be_a(Releases::Source))
|
|
|
|
end
|
|
|
|
end
|
2019-07-03 09:12:15 +00:00
|
|
|
|
|
|
|
describe '#upcoming_release?' do
|
|
|
|
context 'during the backfill migration when released_at could be nil' do
|
|
|
|
it 'handles a nil released_at value and returns false' do
|
|
|
|
allow(release).to receive(:released_at).and_return nil
|
|
|
|
|
|
|
|
expect(release.upcoming_release?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-10-17 15:06:17 +00:00
|
|
|
|
2019-11-19 09:06:16 +00:00
|
|
|
describe 'evidence' do
|
|
|
|
let(:release_with_evidence) { create(:release, :with_evidence, project: project) }
|
|
|
|
|
2019-10-17 15:06:17 +00:00
|
|
|
describe '#create_evidence!' do
|
|
|
|
context 'when a release is created' do
|
|
|
|
it 'creates one Evidence object too' do
|
2019-11-19 09:06:16 +00:00
|
|
|
expect { release_with_evidence }.to change(Evidence, :count).by(1)
|
2019-10-17 15:06:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a release is deleted' do
|
|
|
|
it 'also deletes the associated evidence' do
|
2019-11-19 09:06:16 +00:00
|
|
|
release_with_evidence
|
2019-10-17 15:06:17 +00:00
|
|
|
|
2019-11-19 09:06:16 +00:00
|
|
|
expect { release_with_evidence.destroy }.to change(Evidence, :count).by(-1)
|
2019-10-17 15:06:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-10-17 18:08:05 +00:00
|
|
|
|
|
|
|
describe '#notify_new_release' do
|
|
|
|
context 'when a release is created' do
|
|
|
|
it 'instantiates NewReleaseWorker to send notifications' do
|
|
|
|
expect(NewReleaseWorker).to receive(:perform_async)
|
|
|
|
|
|
|
|
create(:release)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a release is updated' do
|
|
|
|
let!(:release) { create(:release) }
|
|
|
|
|
|
|
|
it 'does not send any new notification' do
|
|
|
|
expect(NewReleaseWorker).not_to receive(:perform_async)
|
|
|
|
|
|
|
|
release.update!(description: 'new description')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-12 21:06:30 +00:00
|
|
|
|
|
|
|
describe '#name' do
|
|
|
|
context 'name is nil' do
|
|
|
|
before do
|
|
|
|
release.update(name: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns tag' do
|
|
|
|
expect(release.name).to eq(release.tag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-19 09:06:16 +00:00
|
|
|
|
|
|
|
describe '#evidence_sha' do
|
|
|
|
subject { release.evidence_sha }
|
|
|
|
|
|
|
|
context 'when a release was created before evidence collection existed' do
|
|
|
|
let!(:release) { create(:release) }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a release was created with evidence collection' do
|
|
|
|
let!(:release) { create(:release, :with_evidence) }
|
|
|
|
|
|
|
|
it { is_expected.to eq(release.evidence.summary_sha) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#evidence_summary' do
|
|
|
|
subject { release.evidence_summary }
|
|
|
|
|
|
|
|
context 'when a release was created before evidence collection existed' do
|
|
|
|
let!(:release) { create(:release) }
|
|
|
|
|
|
|
|
it { is_expected.to eq({}) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a release was created with evidence collection' do
|
|
|
|
let!(:release) { create(:release, :with_evidence) }
|
|
|
|
|
|
|
|
it { is_expected.to eq(release.evidence.summary) }
|
|
|
|
end
|
|
|
|
end
|
2020-01-10 18:07:43 +00:00
|
|
|
|
|
|
|
describe '#milestone_titles' do
|
|
|
|
let(:release) { create(:release, :with_milestones) }
|
|
|
|
|
|
|
|
it { expect(release.milestone_titles).to eq(release.milestones.map {|m| m.title }.sort.join(", "))}
|
|
|
|
end
|
2015-11-05 10:03:02 +00:00
|
|
|
end
|