diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-20 03:11:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-20 03:11:14 +0300 |
commit | 1533e64a2ca36d119ba2f229f591e4b50c436338 (patch) | |
tree | 36ff2c216e0b899189207f760a8d58396a87a54d /spec/requests | |
parent | b6bf52d3e274bd060a7b7e7a2812fda30e0d66d5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/admin/users_controller_spec.rb | 50 | ||||
-rw-r--r-- | spec/requests/projects/ml/model_versions_controller_spec.rb | 72 |
2 files changed, 122 insertions, 0 deletions
diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rb index e525d615b50..2f8025691f4 100644 --- a/spec/requests/admin/users_controller_spec.rb +++ b/spec/requests/admin/users_controller_spec.rb @@ -74,4 +74,54 @@ RSpec.describe Admin::UsersController, :enable_admin_mode, feature_category: :us expect { request }.to change { user.reload.access_locked? }.from(true).to(false) end end + + describe 'PUT #trust' do + subject(:request) { put trust_admin_user_path(user) } + + it 'trusts the user' do + expect { request }.to change { user.reload.trusted? }.from(false).to(true) + end + + context 'when setting trust fails' do + before do + allow_next_instance_of(Users::TrustService) do |instance| + allow(instance).to receive(:execute).and_return({ status: :failed }) + end + end + + it 'displays a flash alert' do + request + + expect(response).to redirect_to(admin_user_path(user)) + expect(flash[:alert]).to eq(s_('Error occurred. User was not updated')) + end + end + end + + describe 'PUT #untrust' do + before do + user.custom_attributes.create!(key: UserCustomAttribute::TRUSTED_BY, value: "placeholder") + end + + subject(:request) { put untrust_admin_user_path(user) } + + it 'trusts the user' do + expect { request }.to change { user.reload.trusted? }.from(true).to(false) + end + + context 'when untrusting fails' do + before do + allow_next_instance_of(Users::UntrustService) do |instance| + allow(instance).to receive(:execute).and_return({ status: :failed }) + end + end + + it 'displays a flash alert' do + request + + expect(response).to redirect_to(admin_user_path(user)) + expect(flash[:alert]).to eq(s_('Error occurred. User was not updated')) + end + end + end end diff --git a/spec/requests/projects/ml/model_versions_controller_spec.rb b/spec/requests/projects/ml/model_versions_controller_spec.rb new file mode 100644 index 00000000000..bd9d798c275 --- /dev/null +++ b/spec/requests/projects/ml/model_versions_controller_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::Ml::ModelVersionsController, feature_category: :mlops do + let_it_be(:project) { create(:project) } + let_it_be(:another_project) { create(:project) } + let_it_be(:user) { project.first_owner } + let_it_be(:model) { create(:ml_models, :with_versions, project: project) } + let_it_be(:version) { model.versions.first } + + let(:model_registry_enabled) { true } + + before do + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?) + .with(user, :read_model_registry, project) + .and_return(model_registry_enabled) + + sign_in(user) + end + + describe 'show' do + let(:model_id) { model.id } + let(:version_id) { version.id } + let(:request_project) { model.project } + + subject(:show_request) do + show_model_version + response + end + + before do + show_request + end + + it 'renders the template' do + is_expected.to render_template('projects/ml/model_versions/show') + end + + it 'fetches the correct model_version' do + show_request + + expect(assigns(:model)).to eq(model) + expect(assigns(:model_version)).to eq(version) + end + + context 'when version id does not exist' do + let(:version_id) { non_existing_record_id } + + it { is_expected.to have_gitlab_http_status(:not_found) } + end + + context 'when version and model id are correct but project is not' do + let(:request_project) { another_project } + + it { is_expected.to have_gitlab_http_status(:not_found) } + end + + context 'when user does not have access' do + let(:model_registry_enabled) { false } + + it { is_expected.to have_gitlab_http_status(:not_found) } + end + end + + private + + def show_model_version + get project_ml_model_version_path(request_project, model_id, version_id) + end +end |