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/packages')
-rw-r--r--spec/models/packages/build_info_spec.rb42
-rw-r--r--spec/models/packages/conan/metadatum_spec.rb49
2 files changed, 91 insertions, 0 deletions
diff --git a/spec/models/packages/build_info_spec.rb b/spec/models/packages/build_info_spec.rb
index a4369c56fe2..db8ac605d72 100644
--- a/spec/models/packages/build_info_spec.rb
+++ b/spec/models/packages/build_info_spec.rb
@@ -6,4 +6,46 @@ RSpec.describe Packages::BuildInfo, type: :model do
it { is_expected.to belong_to(:package) }
it { is_expected.to belong_to(:pipeline) }
end
+
+ context 'with some build infos' do
+ let_it_be(:package) { create(:package) }
+ let_it_be(:build_infos) { create_list(:package_build_info, 3, :with_pipeline, package: package) }
+ let_it_be(:build_info_with_no_pipeline) { create(:package_build_info) }
+
+ describe '.pluck_pipeline_ids' do
+ subject { package.build_infos.pluck_pipeline_ids.sort }
+
+ it { is_expected.to eq(build_infos.map(&:pipeline_id).sort) }
+ end
+
+ describe '.without_empty_pipelines' do
+ subject { package.build_infos.without_empty_pipelines }
+
+ it { is_expected.to contain_exactly(*build_infos) }
+ end
+
+ describe '.order_by_pipeline_id asc' do
+ subject { package.build_infos.order_by_pipeline_id(:asc) }
+
+ it { is_expected.to eq(build_infos) }
+ end
+
+ describe '.order_by_pipeline_id desc' do
+ subject { package.build_infos.order_by_pipeline_id(:desc) }
+
+ it { is_expected.to eq(build_infos.reverse) }
+ end
+
+ describe '.with_pipeline_id_less_than' do
+ subject { package.build_infos.with_pipeline_id_less_than(build_infos[1].pipeline_id) }
+
+ it { is_expected.to contain_exactly(build_infos[0]) }
+ end
+
+ describe '.with_pipeline_id_greater_than' do
+ subject { package.build_infos.with_pipeline_id_greater_than(build_infos[1].pipeline_id) }
+
+ it { is_expected.to contain_exactly(build_infos[2]) }
+ end
+ end
end
diff --git a/spec/models/packages/conan/metadatum_spec.rb b/spec/models/packages/conan/metadatum_spec.rb
index 112f395818b..d00723e8e43 100644
--- a/spec/models/packages/conan/metadatum_spec.rb
+++ b/spec/models/packages/conan/metadatum_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Packages::Conan::Metadatum, type: :model do
+ using RSpec::Parameterized::TableSyntax
+
describe 'relationships' do
it { is_expected.to belong_to(:package) }
end
@@ -45,6 +47,30 @@ RSpec.describe Packages::Conan::Metadatum, type: :model do
it { is_expected.not_to allow_value("my@channel").for(:package_channel) }
end
+ describe '#username_channel_none_values' do
+ let_it_be(:package) { create(:conan_package) }
+
+ let(:metadatum) { package.conan_metadatum }
+
+ subject { metadatum.valid? }
+
+ where(:username, :channel, :valid) do
+ 'username' | 'channel' | true
+ 'username' | '_' | false
+ '_' | 'channel' | false
+ '_' | '_' | true
+ end
+
+ with_them do
+ before do
+ metadatum.package_username = username
+ metadatum.package_channel = channel
+ end
+
+ it { is_expected.to eq(valid) }
+ end
+ end
+
describe '#conan_package_type' do
it 'will not allow a package with a different package_type' do
package = build('package')
@@ -87,4 +113,27 @@ RSpec.describe Packages::Conan::Metadatum, type: :model do
expect(described_class.full_path_from(package_username: username)).to eq('foo/bar/baz-buz')
end
end
+
+ describe '.validate_username_and_channel' do
+ where(:username, :channel, :error_field) do
+ 'username' | 'channel' | nil
+ 'username' | '_' | :channel
+ '_' | 'channel' | :username
+ '_' | '_' | nil
+ end
+
+ with_them do
+ if params[:error_field]
+ it 'yields the block when there is an error' do
+ described_class.validate_username_and_channel(username, channel) do |none_field|
+ expect(none_field).to eq(error_field)
+ end
+ end
+ else
+ it 'does not yield the block when there is no error' do
+ expect { |b| described_class.validate_username_and_channel(username, channel, &b) }.not_to yield_control
+ end
+ end
+ end
+ end
end