2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-05 05:03:02 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
RSpec.describe Release do
|
2018-12-13 06:08:53 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:release) { create(:release, project: project, author: user) }
|
2015-11-06 09:43:59 -05:00
|
|
|
|
|
|
|
it { expect(release).to be_valid }
|
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:project) }
|
2018-12-12 04:56:43 -05:00
|
|
|
it { is_expected.to belong_to(:author).class_name('User') }
|
2019-01-02 01:01:15 -05:00
|
|
|
it { is_expected.to have_many(:links).class_name('Releases::Link') }
|
2015-11-06 09:43:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validation' do
|
|
|
|
it { is_expected.to validate_presence_of(:project) }
|
|
|
|
it { is_expected.to validate_presence_of(:description) }
|
2019-04-09 02:52:15 -04:00
|
|
|
it { is_expected.to validate_presence_of(:name) }
|
|
|
|
|
|
|
|
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")
|
|
|
|
expect(existing_release_without_name.name).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2015-11-06 09:43:59 -05:00
|
|
|
end
|
2019-01-02 01:01:15 -05:00
|
|
|
|
|
|
|
describe '#assets_count' do
|
|
|
|
subject { release.assets_count }
|
|
|
|
|
|
|
|
it 'returns the number of sources' do
|
|
|
|
is_expected.to eq(Releases::Source::FORMATS.count)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a links exists' do
|
|
|
|
let!(:link) { create(:release_link, release: release) }
|
|
|
|
|
|
|
|
it 'counts the link as an asset' do
|
|
|
|
is_expected.to eq(1 + Releases::Source::FORMATS.count)
|
|
|
|
end
|
2019-05-03 09:29:20 -04: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 01:01:15 -05: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 05:12:15 -04: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
|
2015-11-05 05:03:02 -05:00
|
|
|
end
|