diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-12 09:10:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-12 09:10:45 +0300 |
commit | d89147da045b9d00c4e35de3c7b39ed2b02ef7a6 (patch) | |
tree | e5adaeb09829e7109ccabc97fc5d395c75e47027 /spec/services | |
parent | fdc2b6184d20e767f089557f3cdc68837a6aacfb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/organizations/create_service_spec.rb | 43 | ||||
-rw-r--r-- | spec/services/organizations/update_service_spec.rb | 45 | ||||
-rw-r--r-- | spec/services/projects/update_service_spec.rb | 2 |
3 files changed, 61 insertions, 29 deletions
diff --git a/spec/services/organizations/create_service_spec.rb b/spec/services/organizations/create_service_spec.rb index 7d9bf64ddd3..9243f40921e 100644 --- a/spec/services/organizations/create_service_spec.rb +++ b/spec/services/organizations/create_service_spec.rb @@ -7,7 +7,10 @@ RSpec.describe Organizations::CreateService, feature_category: :cell do let_it_be(:user) { create(:user) } let(:current_user) { user } - let(:params) { attributes_for(:organization) } + let(:params) { attributes_for(:organization).merge(extra_params) } + let(:avatar_filename) { nil } + let(:extra_params) { {} } + let(:created_organization) { response.payload } subject(:response) { described_class.new(current_user: current_user, params: params).execute } @@ -23,17 +26,41 @@ RSpec.describe Organizations::CreateService, feature_category: :cell do end context 'when user has permission' do - it 'creates an organization' do - expect { response }.to change { Organizations::Organization.count } + shared_examples 'creating an organization' do + it 'creates the organization' do + expect { response }.to change { Organizations::Organization.count } + expect(response).to be_success + expect(created_organization.name).to eq(params[:name]) + expect(created_organization.path).to eq(params[:path]) + expect(created_organization.description).to eq(params[:description]) + expect(created_organization.avatar.filename).to eq(avatar_filename) + end + end + + it_behaves_like 'creating an organization' - expect(response).to be_success + context 'with description' do + let(:description) { 'Organization description' } + let(:extra_params) { { description: description } } + + it_behaves_like 'creating an organization' end - it 'returns an error when the organization is not persisted' do - params[:name] = nil + context 'with avatar' do + let(:avatar_filename) { 'dk.png' } + let(:avatar) { fixture_file_upload("spec/fixtures/#{avatar_filename}") } + let(:extra_params) { { avatar: avatar } } - expect(response).to be_error - expect(response.message).to match_array(["Name can't be blank"]) + it_behaves_like 'creating an organization' + end + + context 'when the organization is not persisted' do + let(:extra_params) { { name: nil } } + + it 'returns an error when the organization is not persisted' do + expect(response).to be_error + expect(response.message).to match_array(["Name can't be blank"]) + end end end end diff --git a/spec/services/organizations/update_service_spec.rb b/spec/services/organizations/update_service_spec.rb index 976df1129d5..f58cfd7d454 100644 --- a/spec/services/organizations/update_service_spec.rb +++ b/spec/services/organizations/update_service_spec.rb @@ -7,11 +7,14 @@ RSpec.describe Organizations::UpdateService, feature_category: :cell do let_it_be(:user) { create(:user) } let_it_be_with_reload(:organization) { create(:organization) } - let(:current_user) { user } + let_it_be(:current_user) { user } # due to use in before_all let(:name) { 'Name' } let(:path) { 'path' } let(:description) { nil } - let(:params) { { name: name, path: path } } + let(:avatar_filename) { nil } + let(:params) { { name: name, path: path }.merge(extra_params) } + let(:extra_params) { {} } + let(:updated_organization) { response.payload } subject(:response) do described_class.new(organization, current_user: current_user, params: params).execute @@ -28,42 +31,44 @@ RSpec.describe Organizations::UpdateService, feature_category: :cell do end context 'when user has permission' do - before do + before_all do create(:organization_user, organization: organization, user: current_user) end shared_examples 'updating an organization' do it 'updates the organization' do - response - organization.reset - expect(response).to be_success - expect(organization.name).to eq(name) - expect(organization.path).to eq(path) - expect(organization.description).to eq(description) + expect(updated_organization.name).to eq(name) + expect(updated_organization.path).to eq(path) + expect(updated_organization.description).to eq(description) + expect(updated_organization.avatar.filename).to eq(avatar_filename) end end context 'with description' do let(:description) { 'Organization description' } - let(:params) do - { - name: name, - path: path, - description: description - } - end + let(:extra_params) { { description: description } } + + it_behaves_like 'updating an organization' + end + + context 'with avatar' do + let(:avatar_filename) { 'dk.png' } + let(:avatar) { fixture_file_upload("spec/fixtures/#{avatar_filename}") } + let(:extra_params) { { avatar: avatar } } it_behaves_like 'updating an organization' end include_examples 'updating an organization' - it 'returns an error when the organization is not updated' do - params[:name] = nil + context 'when the organization is not updated' do + let(:extra_params) { { name: nil } } - expect(response).to be_error - expect(response.message).to match_array(["Name can't be blank"]) + it 'returns an error' do + expect(response).to be_error + expect(response.message).to match_array(["Name can't be blank"]) + end end end end diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb index e75a2d774a9..a3f6c472f3b 100644 --- a/spec/services/projects/update_service_spec.rb +++ b/spec/services/projects/update_service_spec.rb @@ -356,7 +356,7 @@ RSpec.describe Projects::UpdateService, feature_category: :groups_and_projects d context 'when changes project features' do # Using some sample features for testing. # Not using all the features because some of them must be enabled/disabled together - %w[issues wiki forking model_experiments].each do |feature_name| + %w[issues wiki forking model_experiments model_registry].each do |feature_name| context "with feature_name:#{feature_name}" do let(:feature) { "#{feature_name}_access_level" } let(:params) do |