2022-08-17 11:11:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2022-09-19 17:13:43 -04:00
|
|
|
RSpec.describe Ml::Candidate, factory_default: :keep do
|
2022-09-22 20:10:38 -04:00
|
|
|
let_it_be(:candidate) { create_default(:ml_candidates, :with_metrics_and_params) }
|
2022-09-19 17:13:43 -04:00
|
|
|
|
2022-08-17 11:11:57 -04:00
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:experiment) }
|
|
|
|
it { is_expected.to belong_to(:user) }
|
|
|
|
it { is_expected.to have_many(:params) }
|
|
|
|
it { is_expected.to have_many(:metrics) }
|
|
|
|
end
|
2022-09-12 08:12:09 -04:00
|
|
|
|
|
|
|
describe '#new' do
|
|
|
|
it 'iid is not null' do
|
2022-09-19 17:13:43 -04:00
|
|
|
expect(candidate.iid).not_to be_nil
|
2022-09-12 08:12:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-19 17:13:43 -04:00
|
|
|
describe '#by_project_id_and_iid' do
|
2022-09-12 08:12:09 -04:00
|
|
|
let(:project_id) { candidate.experiment.project_id }
|
|
|
|
let(:iid) { candidate.iid }
|
|
|
|
|
|
|
|
subject { described_class.with_project_id_and_iid(project_id, iid) }
|
|
|
|
|
|
|
|
context 'when iid exists', 'and belongs to project' do
|
|
|
|
it { is_expected.to eq(candidate) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when iid exists', 'and does not belong to project' do
|
|
|
|
let(:project_id) { non_existing_record_id }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when iid does not exist' do
|
|
|
|
let(:iid) { 'a' }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
2022-08-17 11:11:57 -04:00
|
|
|
end
|