diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/support/shared_examples/services | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/support/shared_examples/services')
8 files changed, 224 insertions, 71 deletions
diff --git a/spec/support/shared_examples/services/boards/boards_list_service_shared_examples.rb b/spec/support/shared_examples/services/boards/boards_list_service_shared_examples.rb index 8f7c08ed625..0e2bddc19ab 100644 --- a/spec/support/shared_examples/services/boards/boards_list_service_shared_examples.rb +++ b/spec/support/shared_examples/services/boards/boards_list_service_shared_examples.rb @@ -1,32 +1,8 @@ # frozen_string_literal: true RSpec.shared_examples 'boards list service' do - context 'when parent does not have a board' do - it 'creates a new parent board' do - expect { service.execute }.to change(parent.boards, :count).by(1) - end - - it 'delegates the parent board creation to Boards::CreateService' do - expect_any_instance_of(Boards::CreateService).to receive(:execute).once - - service.execute - end - - context 'when create_default_board is false' do - it 'does not create a new parent board' do - expect { service.execute(create_default_board: false) }.not_to change(parent.boards, :count) - end - end - end - - context 'when parent has a board' do - before do - create(:board, resource_parent: parent) - end - - it 'does not create a new board' do - expect { service.execute }.not_to change(parent.boards, :count) - end + it 'does not create a new board' do + expect { service.execute }.not_to change(parent.boards, :count) end it 'returns parent boards' do diff --git a/spec/support/shared_examples/services/boards/lists_create_service_shared_examples.rb b/spec/support/shared_examples/services/boards/lists_create_service_shared_examples.rb new file mode 100644 index 00000000000..3be002c2126 --- /dev/null +++ b/spec/support/shared_examples/services/boards/lists_create_service_shared_examples.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'board lists create service' do + describe '#execute' do + let_it_be(:user) { create(:user) } + + before_all do + parent.add_developer(user) + end + + subject(:service) { described_class.new(parent, user, label_id: label.id) } + + context 'when board lists is empty' do + it 'creates a new list at beginning of the list' do + response = service.execute(board) + + expect(response.success?).to eq(true) + expect(response.payload[:list].position).to eq 0 + end + end + + context 'when board lists has the done list' do + it 'creates a new list at beginning of the list' do + response = service.execute(board) + + expect(response.success?).to eq(true) + expect(response.payload[:list].position).to eq 0 + end + end + + context 'when board lists has labels lists' do + it 'creates a new list at end of the lists' do + create_list(position: 0) + create_list(position: 1) + + response = service.execute(board) + + expect(response.success?).to eq(true) + expect(response.payload[:list].position).to eq 2 + end + end + + context 'when board lists has label and done lists' do + it 'creates a new list at end of the label lists' do + list1 = create_list(position: 0) + + list2 = service.execute(board).payload[:list] + + expect(list1.reload.position).to eq 0 + expect(list2.reload.position).to eq 1 + end + end + + context 'when provided label does not belong to the parent' do + it 'returns an error' do + label = create(:label, name: 'in-development') + service = described_class.new(parent, user, label_id: label.id) + + response = service.execute(board) + + expect(response.success?).to eq(false) + expect(response.errors).to include('Label not found') + end + end + + context 'when backlog param is sent' do + it 'creates one and only one backlog list' do + service = described_class.new(parent, user, 'backlog' => true) + list = service.execute(board).payload[:list] + + expect(list.list_type).to eq('backlog') + expect(list.position).to be_nil + expect(list).to be_valid + + another_backlog = service.execute(board).payload[:list] + + expect(another_backlog).to eq list + end + end + end +end diff --git a/spec/support/shared_examples/services/issuable_shared_examples.rb b/spec/support/shared_examples/services/issuable_shared_examples.rb index 47c7a1e7356..5b3e0f9e0b9 100644 --- a/spec/support/shared_examples/services/issuable_shared_examples.rb +++ b/spec/support/shared_examples/services/issuable_shared_examples.rb @@ -18,6 +18,27 @@ RSpec.shared_examples 'updating a single task' do update_issuable(description: "- [ ] Task 1\n- [ ] Task 2") end + context 'usage counters' do + it 'update as expected' do + if try(:merge_request) + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to receive(:track_task_item_status_changed).once.with(user: user) + else + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .not_to receive(:track_task_item_status_changed) + end + + update_issuable( + update_task: { + index: 1, + checked: true, + line_source: '- [ ] Task 1', + line_number: 1 + } + ) + end + end + context 'when a task is marked as completed' do before do update_issuable(update_task: { index: 1, checked: true, line_source: '- [ ] Task 1', line_number: 1 }) diff --git a/spec/support/shared_examples/services/packages_shared_examples.rb b/spec/support/shared_examples/services/packages_shared_examples.rb index fa307d2a9a6..4e34c191306 100644 --- a/spec/support/shared_examples/services/packages_shared_examples.rb +++ b/spec/support/shared_examples/services/packages_shared_examples.rb @@ -40,6 +40,19 @@ RSpec.shared_examples 'assigns the package creator' do end end +RSpec.shared_examples 'assigns status to package' do + context 'with status param' do + let_it_be(:status) { 'hidden' } + let(:params) { super().merge(status: status) } + + it 'assigns the status to the package' do + package = subject + + expect(package.status).to eq(status) + end + end +end + RSpec.shared_examples 'returns packages' do |container_type, user_type| context "for #{user_type}" do before do @@ -190,6 +203,7 @@ RSpec.shared_examples 'filters on each package_type' do |is_project: false| let_it_be(:package7) { create(:generic_package, project: project) } let_it_be(:package8) { create(:golang_package, project: project) } let_it_be(:package9) { create(:debian_package, project: project) } + let_it_be(:package9) { create(:rubygems_package, project: project) } Packages::Package.package_types.keys.each do |package_type| context "for package type #{package_type}" do @@ -262,3 +276,41 @@ RSpec.shared_examples 'with versionless packages' do end end end + +RSpec.shared_examples 'with status param' do + context 'hidden packages' do + let!(:hidden_package) { create(:maven_package, :hidden, project: project) } + + shared_examples 'not including the hidden package' do + it 'does not return the package' do + subject + + expect(json_response.map { |package| package['id'] }).not_to include(hidden_package.id) + end + end + + context 'no status param' do + it_behaves_like 'not including the hidden package' + end + + context 'with hidden status param' do + let(:params) { super().merge(status: 'hidden') } + + it 'returns the package' do + subject + + expect(json_response.map { |package| package['id'] }).to include(hidden_package.id) + end + end + end + + context 'bad status param' do + let(:params) { super().merge(status: 'invalid') } + + it 'returns the package' do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + end + end +end diff --git a/spec/support/shared_examples/services/projects/update_repository_storage_service_shared_examples.rb b/spec/support/shared_examples/services/projects/update_repository_storage_service_shared_examples.rb index f201c7b1780..1fb1b9f79b2 100644 --- a/spec/support/shared_examples/services/projects/update_repository_storage_service_shared_examples.rb +++ b/spec/support/shared_examples/services/projects/update_repository_storage_service_shared_examples.rb @@ -71,7 +71,7 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type| it 'does not enqueue a GC run' do expect { subject.execute } - .not_to change(GitGarbageCollectWorker.jobs, :count) + .not_to change(Projects::GitGarbageCollectWorker.jobs, :count) end end @@ -84,24 +84,29 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type| stub_application_setting(housekeeping_enabled: false) expect { subject.execute } - .not_to change(GitGarbageCollectWorker.jobs, :count) + .not_to change(Projects::GitGarbageCollectWorker.jobs, :count) end it 'enqueues a GC run' do expect { subject.execute } - .to change(GitGarbageCollectWorker.jobs, :count).by(1) + .to change(Projects::GitGarbageCollectWorker.jobs, :count).by(1) end end end context 'when the filesystems are the same' do - let(:destination) { project.repository_storage } + before do + expect(Gitlab::GitalyClient).to receive(:filesystem_id).twice.and_return(SecureRandom.uuid) + end - it 'bails out and does nothing' do + it 'updates the database without trying to move the repostory', :aggregate_failures do result = subject.execute + project.reload - expect(result).to be_error - expect(result.message).to match(/SameFilesystemError/) + expect(result).to be_success + expect(project).not_to be_repository_read_only + expect(project.repository_storage).to eq('test_second_storage') + expect(project.project_repository.shard_name).to eq('test_second_storage') end end diff --git a/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb b/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb index a174ae94b75..4c00faee56b 100644 --- a/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb +++ b/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb @@ -3,16 +3,16 @@ RSpec.shared_examples 'housekeeps repository' do subject { described_class.new(resource) } - context 'with a clean redis state', :clean_gitlab_redis_shared_state do + context 'with a clean redis state', :clean_gitlab_redis_shared_state, :aggregate_failures do describe '#execute' do it 'enqueues a sidekiq job' do expect(subject).to receive(:try_obtain_lease).and_return(:the_uuid) expect(subject).to receive(:lease_key).and_return(:the_lease_key) expect(subject).to receive(:task).and_return(:incremental_repack) - expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :incremental_repack, :the_lease_key, :the_uuid).and_call_original + expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :incremental_repack, :the_lease_key, :the_uuid).and_call_original Sidekiq::Testing.fake! do - expect { subject.execute }.to change(GitGarbageCollectWorker.jobs, :size).by(1) + expect { subject.execute }.to change(resource.git_garbage_collect_worker_klass.jobs, :size).by(1) end end @@ -38,7 +38,7 @@ RSpec.shared_examples 'housekeeps repository' do end it 'does not enqueue a job' do - expect(GitGarbageCollectWorker).not_to receive(:perform_async) + expect(resource.git_garbage_collect_worker_klass).not_to receive(:perform_async) expect { subject.execute }.to raise_error(Repositories::HousekeepingService::LeaseTaken) end @@ -63,16 +63,16 @@ RSpec.shared_examples 'housekeeps repository' do allow(subject).to receive(:lease_key).and_return(:the_lease_key) # At push 200 - expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :gc, :the_lease_key, :the_uuid) + expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :gc, :the_lease_key, :the_uuid) .once # At push 50, 100, 150 - expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :full_repack, :the_lease_key, :the_uuid) + expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :full_repack, :the_lease_key, :the_uuid) .exactly(3).times # At push 10, 20, ... (except those above) - expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :incremental_repack, :the_lease_key, :the_uuid) + expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :incremental_repack, :the_lease_key, :the_uuid) .exactly(16).times # At push 6, 12, 18, ... (except those above) - expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :pack_refs, :the_lease_key, :the_uuid) + expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :pack_refs, :the_lease_key, :the_uuid) .exactly(27).times 201.times do @@ -90,7 +90,7 @@ RSpec.shared_examples 'housekeeps repository' do allow(housekeeping).to receive(:try_obtain_lease).and_return(:gc_uuid) allow(housekeeping).to receive(:lease_key).and_return(:gc_lease_key) - expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :gc, :gc_lease_key, :gc_uuid).twice + expect(resource.git_garbage_collect_worker_klass).to receive(:perform_async).with(resource.id, :gc, :gc_lease_key, :gc_uuid).twice 2.times do housekeeping.execute diff --git a/spec/support/shared_examples/services/resource_events/change_milestone_service_shared_examples.rb b/spec/support/shared_examples/services/resource_events/change_milestone_service_shared_examples.rb index d70ed707822..fac9f1d6253 100644 --- a/spec/support/shared_examples/services/resource_events/change_milestone_service_shared_examples.rb +++ b/spec/support/shared_examples/services/resource_events/change_milestone_service_shared_examples.rb @@ -3,8 +3,12 @@ RSpec.shared_examples 'timebox(milestone or iteration) resource events creator' do |timebox_event_class| let_it_be(:user) { create(:user) } + before do + resource.system_note_timestamp = created_at_time + end + context 'when milestone/iteration is added' do - let(:service) { described_class.new(resource, user, add_timebox_args) } + let(:service) { described_class.new(resource, user, **add_timebox_args) } before do set_timebox(timebox_event_class, timebox) @@ -18,7 +22,7 @@ RSpec.shared_examples 'timebox(milestone or iteration) resource events creator' end context 'when milestone/iteration is removed' do - let(:service) { described_class.new(resource, user, remove_timebox_args) } + let(:service) { described_class.new(resource, user, **remove_timebox_args) } before do set_timebox(timebox_event_class, nil) diff --git a/spec/support/shared_examples/services/snippets_shared_examples.rb b/spec/support/shared_examples/services/snippets_shared_examples.rb index 4a08c0d4365..10add3a7299 100644 --- a/spec/support/shared_examples/services/snippets_shared_examples.rb +++ b/spec/support/shared_examples/services/snippets_shared_examples.rb @@ -1,42 +1,56 @@ # frozen_string_literal: true -RSpec.shared_examples 'snippets spam check is performed' do - shared_examples 'marked as spam' do - it 'marks a snippet as spam' do - expect(snippet).to be_spam - end +RSpec.shared_examples 'checking spam' do + let(:request) { double(:request) } + let(:api) { true } + let(:captcha_response) { 'abc123' } + let(:spam_log_id) { 1 } + let(:disable_spam_action_service) { false } - it 'invalidates the snippet' do - expect(snippet).to be_invalid - end + let(:extra_opts) do + { + request: request, + api: api, + captcha_response: captcha_response, + spam_log_id: spam_log_id, + disable_spam_action_service: disable_spam_action_service + } + end - it 'creates a new spam_log' do - expect { snippet } - .to have_spam_log(title: snippet.title, noteable_type: snippet.class.name) + before do + allow_next_instance_of(UserAgentDetailService) do |instance| + allow(instance).to receive(:create) end + end - it 'assigns a spam_log to an issue' do - expect(snippet.spam_log).to eq(SpamLog.last) + it 'executes SpamActionService' do + spam_params = Spam::SpamParams.new( + api: api, + captcha_response: captcha_response, + spam_log_id: spam_log_id + ) + expect_next_instance_of( + Spam::SpamActionService, + { + spammable: kind_of(Snippet), + request: request, + user: an_instance_of(User), + action: action + } + ) do |instance| + expect(instance).to receive(:execute).with(spam_params: spam_params) end - end - let(:extra_opts) do - { visibility_level: Gitlab::VisibilityLevel::PUBLIC, request: double(:request, env: {}) } + subject end - before do - expect_next_instance_of(Spam::AkismetService) do |akismet_service| - expect(akismet_service).to receive_messages(spam?: true) - end - end + context 'when spam action service is disabled' do + let(:disable_spam_action_service) { true } - [true, false, nil].each do |allow_possible_spam| - context "when allow_possible_spam flag is #{allow_possible_spam.inspect}" do - before do - stub_feature_flags(allow_possible_spam: allow_possible_spam) unless allow_possible_spam.nil? - end + it 'request parameter is not passed to the service' do + expect(Spam::SpamActionService).not_to receive(:new) - it_behaves_like 'marked as spam' + subject end end end |