blob: c75331a2ab52371f24b23092f70b4163eaf4ac6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ml::Experiment do
let_it_be(:exp) { create(:ml_experiments) }
let_it_be(:exp2) { create(:ml_experiments, project: exp.project) }
let(:iid) { exp.iid }
let(:exp_name) { exp.name }
describe 'associations' do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:user) }
it { is_expected.to have_many(:candidates) }
it { is_expected.to have_many(:metadata) }
end
describe '#by_project_id_and_iid' do
subject { described_class.by_project_id_and_iid(exp.project_id, iid) }
context 'if exists' do
it { is_expected.to eq(exp) }
end
context 'if does not exist' do
let(:iid) { non_existing_record_id }
it { is_expected.to be(nil) }
end
end
describe '#by_project_id_and_name' do
subject { described_class.by_project_id_and_name(exp.project_id, exp_name) }
context 'if exists' do
it { is_expected.to eq(exp) }
end
context 'if does not exist' do
let(:exp_name) { 'hello' }
it { is_expected.to be_nil }
end
end
describe '#by_project_id' do
let(:project_id) { exp.project_id }
subject { described_class.by_project_id(project_id) }
it { is_expected.to match_array([exp, exp2]) }
context 'when project does not have experiment' do
let(:project_id) { non_existing_record_iid }
it { is_expected.to be_empty }
end
end
describe '#with_candidate_count' do
let_it_be(:exp3) do
create(:ml_experiments, project: exp.project).tap do |e|
create_list(:ml_candidates, 3, experiment: e, user: nil)
create(:ml_candidates, experiment: exp2, user: nil)
end
end
subject { described_class.with_candidate_count.to_h { |e| [e.id, e.candidate_count] } }
it 'fetches the candidate count', :aggregate_failures do
expect(subject[exp.id]).to eq(0)
expect(subject[exp2.id]).to eq(1)
expect(subject[exp3.id]).to eq(3)
end
end
end
|