diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/models/ml/candidate_spec.rb | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/models/ml/candidate_spec.rb')
-rw-r--r-- | spec/models/ml/candidate_spec.rb | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/spec/models/ml/candidate_spec.rb b/spec/models/ml/candidate_spec.rb index 3bf1e80a152..b35496363fe 100644 --- a/spec/models/ml/candidate_spec.rb +++ b/spec/models/ml/candidate_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Ml::Candidate, factory_default: :keep do - let_it_be(:candidate) { create_default(:ml_candidates, :with_metrics_and_params) } + let_it_be(:candidate) { create(:ml_candidates, :with_metrics_and_params) } describe 'associations' do it { is_expected.to belong_to(:experiment) } @@ -12,10 +12,14 @@ RSpec.describe Ml::Candidate, factory_default: :keep do it { is_expected.to have_many(:metrics) } end - describe '#new' do - it 'iid is not null' do - expect(candidate.iid).not_to be_nil - end + describe '.artifact_root' do + subject { candidate.artifact_root } + + it { is_expected.to eq("/ml_candidate_#{candidate.iid}/-/") } + end + + describe 'default values' do + it { expect(described_class.new.iid).to be_present } end describe '#by_project_id_and_iid' do @@ -40,4 +44,26 @@ RSpec.describe Ml::Candidate, factory_default: :keep do it { is_expected.to be_nil } end end + + describe "#latest_metrics" do + let_it_be(:candidate2) { create(:ml_candidates, experiment: candidate.experiment) } + let!(:metric1) { create(:ml_candidate_metrics, candidate: candidate2) } + let!(:metric2) { create(:ml_candidate_metrics, candidate: candidate2 ) } + let!(:metric3) { create(:ml_candidate_metrics, name: metric1.name, candidate: candidate2) } + + subject { candidate2.latest_metrics } + + it 'fetches only the last metric for the name' do + expect(subject).to match_array([metric2, metric3] ) + end + end + + describe "#including_metrics_and_params" do + subject { described_class.including_metrics_and_params.find_by(id: candidate.id) } + + it 'loads latest metrics and params', :aggregate_failures do + expect(subject.association_cached?(:latest_metrics)).to be(true) + expect(subject.association_cached?(:params)).to be(true) + end + end end |