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/requests/projects/ml/candidates_controller_spec.rb')
-rw-r--r--spec/requests/projects/ml/candidates_controller_spec.rb53
1 files changed, 41 insertions, 12 deletions
diff --git a/spec/requests/projects/ml/candidates_controller_spec.rb b/spec/requests/projects/ml/candidates_controller_spec.rb
index d3f9d92bc44..78c8e99e3f3 100644
--- a/spec/requests/projects/ml/candidates_controller_spec.rb
+++ b/spec/requests/projects/ml/candidates_controller_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe Projects::Ml::CandidatesController, feature_category: :mlops do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { project.first_owner }
let_it_be(:experiment) { create(:ml_experiments, project: project, user: user) }
- let_it_be(:candidate) { create(:ml_candidates, experiment: experiment, user: user) }
+ let_it_be(:candidate) { create(:ml_candidates, experiment: experiment, user: user, project: project) }
let(:ff_value) { true }
let(:candidate_iid) { candidate.iid }
@@ -18,19 +18,29 @@ RSpec.describe Projects::Ml::CandidatesController, feature_category: :mlops do
sign_in(user)
end
+ shared_examples 'renders 404' do
+ it 'renders 404' do
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ shared_examples '404 if candidate does not exist' do
+ context 'when experiment does not exist' do
+ let(:candidate_iid) { non_existing_record_id }
+
+ it_behaves_like 'renders 404'
+ end
+ end
+
shared_examples '404 if feature flag disabled' do
context 'when :ml_experiment_tracking disabled' do
let(:ff_value) { false }
- it 'is 404' do
- expect(response).to have_gitlab_http_status(:not_found)
- end
+ it_behaves_like 'renders 404'
end
end
describe 'GET show' do
- let(:params) { basic_params.merge(id: experiment.iid) }
-
before do
show_candidate
end
@@ -48,20 +58,39 @@ RSpec.describe Projects::Ml::CandidatesController, feature_category: :mlops do
expect { show_candidate }.not_to exceed_all_query_limit(control_count)
end
- context 'when candidate does not exist' do
- let(:candidate_iid) { non_existing_record_id.to_s }
+ it_behaves_like '404 if candidate does not exist'
+ it_behaves_like '404 if feature flag disabled'
+ end
+
+ describe 'DELETE #destroy' do
+ let_it_be(:candidate_for_deletion) do
+ create(:ml_candidates, project: project, experiment: experiment, user: user)
+ end
+
+ let(:candidate_iid) { candidate_for_deletion.iid }
- it 'returns 404' do
- expect(response).to have_gitlab_http_status(:not_found)
- end
+ before do
+ destroy_candidate
end
+ it 'deletes the experiment', :aggregate_failures do
+ expect(response).to have_gitlab_http_status(:found)
+ expect(flash[:notice]).to eq('Candidate removed')
+ expect(response).to redirect_to("/#{project.full_path}/-/ml/experiments/#{experiment.iid}")
+ expect { Ml::Candidate.find(id: candidate_for_deletion.id) }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+
+ it_behaves_like '404 if candidate does not exist'
it_behaves_like '404 if feature flag disabled'
end
private
def show_candidate
- get project_ml_candidate_path(project, candidate_iid)
+ get project_ml_candidate_path(project, iid: candidate_iid)
+ end
+
+ def destroy_candidate
+ delete project_ml_candidate_path(project, candidate_iid)
end
end