diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/services/work_items/create_service_spec.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/services/work_items/create_service_spec.rb')
-rw-r--r-- | spec/services/work_items/create_service_spec.rb | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/spec/services/work_items/create_service_spec.rb b/spec/services/work_items/create_service_spec.rb index 2c054ae59a0..f495e967b26 100644 --- a/spec/services/work_items/create_service_spec.rb +++ b/spec/services/work_items/create_service_spec.rb @@ -5,34 +5,46 @@ require 'spec_helper' RSpec.describe WorkItems::CreateService do include AfterNextHelpers - let_it_be(:group) { create(:group) } - let_it_be_with_reload(:project) { create(:project, group: group) } - let_it_be(:user) { create(:user) } + let_it_be_with_reload(:project) { create(:project) } + let_it_be(:guest) { create(:user) } + let_it_be(:user_with_no_access) { create(:user) } let(:spam_params) { double } + let(:current_user) { guest } + let(:opts) do + { + title: 'Awesome work_item', + description: 'please fix' + } + end + + before_all do + project.add_guest(guest) + end describe '#execute' do - let(:work_item) { described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute } + subject(:service_result) { described_class.new(project: project, current_user: current_user, params: opts, spam_params: spam_params).execute } before do stub_spam_services end - context 'when params are valid' do - before_all do - project.add_guest(user) - end + context 'when user is not allowed to create a work item in the project' do + let(:current_user) { user_with_no_access } + + it { is_expected.to be_error } - let(:opts) do - { - title: 'Awesome work_item', - description: 'please fix' - } + it 'returns an access error' do + expect(service_result.errors).to contain_exactly('Operation not allowed') end + end + context 'when params are valid' do it 'created instance is a WorkItem' do expect(Issuable::CommonSystemNotesService).to receive_message_chain(:new, :execute) + work_item = service_result[:work_item] + expect(work_item).to be_persisted expect(work_item).to be_a(::WorkItem) expect(work_item.title).to eq('Awesome work_item') @@ -41,17 +53,17 @@ RSpec.describe WorkItems::CreateService do end end - context 'checking spam' do - let(:params) do - { - title: 'Spam work_item' - } - end + context 'when params are invalid' do + let(:opts) { { title: '' } } - subject do - described_class.new(project: project, current_user: user, params: params, spam_params: spam_params) + it { is_expected.to be_error } + + it 'returns validation errors' do + expect(service_result.errors).to contain_exactly("Title can't be blank") end + end + context 'checking spam' do it 'executes SpamActionService' do expect_next_instance_of( Spam::SpamActionService, @@ -65,7 +77,7 @@ RSpec.describe WorkItems::CreateService do expect(instance).to receive(:execute) end - subject.execute + service_result end end end |