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/ml/candidate_spec.rb')
-rw-r--r--spec/models/ml/candidate_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/models/ml/candidate_spec.rb b/spec/models/ml/candidate_spec.rb
index fa19b723ee2..d5b71e2c3f7 100644
--- a/spec/models/ml/candidate_spec.rb
+++ b/spec/models/ml/candidate_spec.rb
@@ -16,6 +16,7 @@ RSpec.describe Ml::Candidate, factory_default: :keep, feature_category: :mlops d
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:package) }
it { is_expected.to belong_to(:ci_build).class_name('Ci::Build') }
+ it { is_expected.to belong_to(:model_version).class_name('Ml::ModelVersion') }
it { is_expected.to have_many(:params) }
it { is_expected.to have_many(:metrics) }
it { is_expected.to have_many(:metadata) }
@@ -35,6 +36,45 @@ RSpec.describe Ml::Candidate, factory_default: :keep, feature_category: :mlops d
it { expect(described_class.new.eid).to be_present }
end
+ describe 'validation' do
+ let_it_be(:model) { create(:ml_models, project: candidate.project) }
+ let_it_be(:model_version1) { create(:ml_model_versions, model: model) }
+ let_it_be(:model_version2) { create(:ml_model_versions, model: model) }
+ let_it_be(:validation_candidate) do
+ create(:ml_candidates, model_version: model_version1, project: candidate.project)
+ end
+
+ let(:params) do
+ {
+ model_version: nil
+ }
+ end
+
+ subject(:errors) do
+ candidate = described_class.new(**params)
+ candidate.validate
+ candidate.errors
+ end
+
+ describe 'model_version' do
+ context 'when model_version is nil' do
+ it { expect(errors).not_to include(:model_version_id) }
+ end
+
+ context 'when no other candidate is associated to the model_version' do
+ let(:params) { { model_version: model_version2 } }
+
+ it { expect(errors).not_to include(:model_version_id) }
+ end
+
+ context 'when another candidate has model_version_id' do
+ let(:params) { { model_version: validation_candidate.model_version } }
+
+ it { expect(errors).to include(:model_version_id) }
+ end
+ end
+ end
+
describe '.destroy' do
let_it_be(:candidate_to_destroy) do
create(:ml_candidates, :with_metrics_and_params, :with_metadata, :with_artifact)