Welcome to mirror list, hosted at ThFree Co, Russian Federation.

find_or_create_experiment_service_spec.rb « ml « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a8c533d13203532180cd16e564f1230a759f3580 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Ml::FindOrCreateExperimentService, feature_category: :mlops do
  let_it_be(:project) { create(:project) }
  let_it_be(:user) { project.first_owner }
  let_it_be(:existing_experiment) { create(:ml_experiments, project: project, user: user) }

  let(:name) { 'new_experiment' }

  subject(:new_experiment) { described_class.new(project, name, user).execute }

  describe '#execute' do
    it 'creates an experiment using Ml::Experiment.find_or_create', :aggregate_failures do
      expect(Ml::Experiment).to receive(:find_or_create).and_call_original

      expect(new_experiment.name).to eq('new_experiment')
      expect(new_experiment.project).to eq(project)
      expect(new_experiment.user).to eq(user)
    end

    context 'when experiment already exists' do
      let(:name) { existing_experiment.name }

      it 'fetches existing experiment', :aggregate_failures do
        expect { new_experiment }.not_to change { Ml::Experiment.count }

        expect(new_experiment).to eq(existing_experiment)
      end
    end
  end
end