debian-mirror-gitlab/spec/models/release_spec.rb

140 lines
4.3 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2015-11-26 14:37:03 +05:30
2017-09-10 17:25:29 +05:30
RSpec.describe Release do
2019-02-15 15:39:39 +05:30
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:release) { create(:release, project: project, author: user) }
2015-11-26 14:37:03 +05:30
it { expect(release).to be_valid }
describe 'associations' do
it { is_expected.to belong_to(:project) }
2019-02-15 15:39:39 +05:30
it { is_expected.to belong_to(:author).class_name('User') }
it { is_expected.to have_many(:links).class_name('Releases::Link') }
2019-12-04 20:38:33 +05:30
it { is_expected.to have_many(:milestones) }
it { is_expected.to have_many(:milestone_releases) }
2020-04-22 19:07:51 +05:30
it { is_expected.to have_many(:evidences).class_name('Releases::Evidence') }
2015-11-26 14:37:03 +05:30
end
describe 'validation' do
it { is_expected.to validate_presence_of(:project) }
2019-12-21 20:55:43 +05:30
it { is_expected.to validate_presence_of(:tag) }
2019-07-31 22:56:46 +05:30
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-12-26 22:10:19 +05:30
expect(existing_release_without_name.name).not_to be_nil
2019-07-31 22:56:46 +05:30
end
end
2019-12-04 20:38:33 +05:30
context 'when a release is tied to a milestone for another project' do
it 'creates a validation error' do
milestone = build(:milestone, project: create(:project))
expect { release.milestones << milestone }.to raise_error
end
end
context 'when a release is tied to a milestone linked to the same project' do
it 'successfully links this release to this milestone' do
milestone = build(:milestone, project: project)
expect { release.milestones << milestone }.to change { MilestoneRelease.count }.by(1)
end
end
2015-11-26 14:37:03 +05:30
end
2019-02-15 15:39:39 +05:30
describe '#assets_count' do
subject { release.assets_count }
it 'returns the number of sources' do
2019-12-26 22:10:19 +05:30
is_expected.to eq(Gitlab::Workhorse::ARCHIVE_FORMATS.count)
2019-02-15 15:39:39 +05:30
end
context 'when a links exists' do
let!(:link) { create(:release_link, release: release) }
it 'counts the link as an asset' do
2019-12-26 22:10:19 +05:30
is_expected.to eq(1 + Gitlab::Workhorse::ARCHIVE_FORMATS.count)
2019-02-15 15:39:39 +05:30
end
2019-07-31 22:56:46 +05:30
it "excludes sources count when asked" do
assets_count = release.assets_count(except: [:sources])
expect(assets_count).to eq(1)
end
2019-02-15 15:39:39 +05:30
end
end
2020-10-24 23:57:45 +05:30
describe '.create' do
it "fills released_at using created_at if it's not set" do
release = described_class.create(project: project, author: user)
expect(release.released_at).to eq(release.created_at)
end
it "does not change released_at if it's set explicitly" do
released_at = Time.zone.parse('2018-10-20T18:00:00Z')
release = described_class.create(project: project, author: user, released_at: released_at)
expect(release.released_at).to eq(released_at)
end
end
2019-02-15 15:39:39 +05:30
describe '#sources' do
subject { release.sources }
it 'returns sources' do
is_expected.to all(be_a(Releases::Source))
end
end
2019-09-30 21:07:59 +05:30
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-12-21 20:55:43 +05:30
2020-01-01 13:55:28 +05:30
describe 'evidence' do
let(:release_with_evidence) { create(:release, :with_evidence, project: project) }
2019-12-21 20:55:43 +05:30
context 'when a release is deleted' do
it 'also deletes the associated evidence' do
2020-01-01 13:55:28 +05:30
release_with_evidence
2019-12-21 20:55:43 +05:30
2020-04-22 19:07:51 +05:30
expect { release_with_evidence.destroy }.to change(Releases::Evidence, :count).by(-1)
2019-12-21 20:55:43 +05:30
end
end
end
2019-12-26 22:10:19 +05:30
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
2020-01-01 13:55:28 +05:30
2020-03-13 15:44:24 +05:30
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-26 14:37:03 +05:30
end