diff options
Diffstat (limited to 'spec/support/services')
8 files changed, 0 insertions, 585 deletions
diff --git a/spec/support/services/clusters/create_service_shared.rb b/spec/support/services/clusters/create_service_shared.rb deleted file mode 100644 index 80fa7c58515..00000000000 --- a/spec/support/services/clusters/create_service_shared.rb +++ /dev/null @@ -1,64 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_context 'valid cluster create params' do - let(:clusterable) { Clusters::Instance.new } - let(:params) do - { - name: 'test-cluster', - provider_type: :gcp, - provider_gcp_attributes: { - gcp_project_id: 'gcp-project', - zone: 'us-central1-a', - num_nodes: 1, - machine_type: 'machine_type-a', - legacy_abac: 'true' - }, - clusterable: clusterable - } - end -end - -RSpec.shared_context 'invalid cluster create params' do - let(:clusterable) { Clusters::Instance.new } - let(:params) do - { - name: 'test-cluster', - provider_type: :gcp, - provider_gcp_attributes: { - gcp_project_id: '!!!!!!!', - zone: 'us-central1-a', - num_nodes: 1, - machine_type: 'machine_type-a' - }, - clusterable: clusterable - - } - end -end - -RSpec.shared_examples 'create cluster service success' do - it 'creates a cluster object' do - expect { subject } - .to change { Clusters::Cluster.count }.by(1) - .and change { Clusters::Providers::Gcp.count }.by(1) - - expect(subject.name).to eq('test-cluster') - expect(subject.user).to eq(user) - expect(subject.project).to eq(project) - expect(subject.provider.gcp_project_id).to eq('gcp-project') - expect(subject.provider.zone).to eq('us-central1-a') - expect(subject.provider.num_nodes).to eq(1) - expect(subject.provider.machine_type).to eq('machine_type-a') - expect(subject.provider.access_token).to eq(access_token) - expect(subject.provider).to be_legacy_abac - expect(subject.platform).to be_nil - expect(subject.namespace_per_environment).to eq true - end -end - -RSpec.shared_examples 'create cluster service error' do - it 'returns an error' do - expect { subject }.to change { Clusters::Cluster.count }.by(0) - expect(subject.errors[:"provider_gcp.gcp_project_id"]).to be_present - end -end diff --git a/spec/support/services/deploy_token_shared_examples.rb b/spec/support/services/deploy_token_shared_examples.rb deleted file mode 100644 index d322b3fc81d..00000000000 --- a/spec/support/services/deploy_token_shared_examples.rb +++ /dev/null @@ -1,86 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'a deploy token creation service' do - let(:user) { create(:user) } - let(:deploy_token_params) { attributes_for(:deploy_token) } - - describe '#execute' do - subject { described_class.new(entity, user, deploy_token_params).execute } - - context 'when the deploy token is valid' do - it 'creates a new DeployToken' do - expect { subject }.to change { DeployToken.count }.by(1) - end - - it 'creates a new ProjectDeployToken' do - expect { subject }.to change { deploy_token_class.count }.by(1) - end - - it 'returns a DeployToken' do - expect(subject[:deploy_token]).to be_an_instance_of DeployToken - end - - it 'sets the creator_id as the id of the current_user' do - expect(subject[:deploy_token].read_attribute(:creator_id)).to eq(user.id) - end - end - - context 'when expires at date is not passed' do - let(:deploy_token_params) { attributes_for(:deploy_token, expires_at: '') } - - it 'sets Forever.date' do - expect(subject[:deploy_token].read_attribute(:expires_at)).to eq(Forever.date) - end - end - - context 'when username is empty string' do - let(:deploy_token_params) { attributes_for(:deploy_token, username: '') } - - it 'converts it to nil' do - expect(subject[:deploy_token].read_attribute(:username)).to be_nil - end - end - - context 'when username is provided' do - let(:deploy_token_params) { attributes_for(:deploy_token, username: 'deployer') } - - it 'keeps the provided username' do - expect(subject[:deploy_token].read_attribute(:username)).to eq('deployer') - end - end - - context 'when the deploy token is invalid' do - let(:deploy_token_params) { attributes_for(:deploy_token, read_repository: false, read_registry: false, write_registry: false) } - - it 'does not create a new DeployToken' do - expect { subject }.not_to change { DeployToken.count } - end - - it 'does not create a new ProjectDeployToken' do - expect { subject }.not_to change { deploy_token_class.count } - end - end - end -end - -RSpec.shared_examples 'a deploy token deletion service' do - let(:user) { create(:user) } - let(:deploy_token_params) { { token_id: deploy_token.id } } - - describe '#execute' do - subject { described_class.new(entity, user, deploy_token_params).execute } - - it "destroys a token record and it's associated DeployToken" do - expect { subject }.to change { deploy_token_class.count }.by(-1) - .and change { DeployToken.count }.by(-1) - end - - context 'invalid token id' do - let(:deploy_token_params) { { token_id: 9999 } } - - it 'raises an error' do - expect { subject }.to raise_error(ActiveRecord::RecordNotFound) - end - end - end -end diff --git a/spec/support/services/issuable_description_quick_actions_shared_examples.rb b/spec/support/services/issuable_description_quick_actions_shared_examples.rb deleted file mode 100644 index 1970301e4c9..00000000000 --- a/spec/support/services/issuable_description_quick_actions_shared_examples.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -# Specifications for behavior common to all objects with executable attributes. -# It can take a `default_params`. - -RSpec.shared_examples 'issuable record that supports quick actions' do - let_it_be(:project) { create(:project, :repository) } - let_it_be(:user) { create(:user) } - let_it_be(:assignee) { create(:user) } - let_it_be(:milestone) { create(:milestone, project: project) } - let_it_be(:labels) { create_list(:label, 3, project: project) } - - let(:base_params) { { title: 'My issuable title' } } - let(:params) { base_params.merge(defined?(default_params) ? default_params : {}).merge(example_params) } - - before_all do - project.add_maintainer(user) - project.add_maintainer(assignee) - end - - before do - issuable.reload - end - - context 'with labels in command only' do - let(:example_params) do - { - description: "/label ~#{labels.first.name} ~#{labels.second.name}\n/unlabel ~#{labels.third.name}" - } - end - - it 'attaches labels to issuable' do - expect(issuable.label_ids).to match_array([labels.first.id, labels.second.id]) - end - end - - context 'with labels in params and command' do - let(:example_params) do - { - label_ids: [labels.second.id], - description: "/label ~#{labels.first.name}\n/unlabel ~#{labels.third.name}" - } - end - - it 'attaches all labels to issuable' do - expect(issuable.label_ids).to match_array([labels.first.id, labels.second.id]) - end - end - - context 'with assignee and milestone in command only' do - let(:example_params) do - { - description: %(/assign @#{assignee.username}\n/milestone %"#{milestone.name}") - } - end - - it 'assigns and sets milestone to issuable' do - expect(issuable.assignees).to eq([assignee]) - expect(issuable.milestone).to eq(milestone) - end - end -end diff --git a/spec/support/services/issuable_import_csv_service_shared_examples.rb b/spec/support/services/issuable_import_csv_service_shared_examples.rb deleted file mode 100644 index 0dea6cfb729..00000000000 --- a/spec/support/services/issuable_import_csv_service_shared_examples.rb +++ /dev/null @@ -1,138 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.shared_examples 'issuable import csv service' do |issuable_type| - let_it_be_with_refind(:project) { create(:project) } - let_it_be(:user) { create(:user) } - - subject { service.execute } - - shared_examples_for 'an issuable importer' do - if issuable_type == 'issue' - it 'records the import attempt if resource is an issue' do - expect { subject } - .to change { Issues::CsvImport.where(project: project, user: user).count } - .by 1 - end - end - end - - shared_examples_for 'importer with email notification' do - it 'notifies user of import result' do - expect(Notify).to receive_message_chain(email_method, :deliver_later) - - subject - end - end - - shared_examples_for 'invalid file' do - it 'returns invalid file error' do - expect(subject[:success]).to eq(0) - expect(subject[:parse_error]).to eq(true) - end - - it_behaves_like 'importer with email notification' - it_behaves_like 'an issuable importer' - end - - describe '#execute' do - before do - project.add_developer(user) - end - - context 'invalid file extension' do - let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') } - - it_behaves_like 'invalid file' - end - - context 'empty file' do - let(:file) { fixture_file_upload('spec/fixtures/csv_empty.csv') } - - it_behaves_like 'invalid file' - end - - context 'file without headers' do - let(:file) { fixture_file_upload('spec/fixtures/csv_no_headers.csv') } - - it_behaves_like 'invalid file' - end - - context 'with a file generated by Gitlab CSV export' do - let(:file) { fixture_file_upload('spec/fixtures/csv_gitlab_export.csv') } - - it 'imports the CSV without errors' do - expect(subject[:success]).to eq(4) - expect(subject[:error_lines]).to eq([]) - expect(subject[:parse_error]).to eq(false) - end - - it 'correctly sets the issuable attributes' do - expect { subject }.to change { issuables.count }.by 4 - - expect(issuables.reload).to include(have_attributes({ title: 'Test Title', description: 'Test Description' })) - end - - it_behaves_like 'importer with email notification' - it_behaves_like 'an issuable importer' - end - - context 'comma delimited file' do - let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') } - - it 'imports CSV without errors' do - expect(subject[:success]).to eq(3) - expect(subject[:error_lines]).to eq([]) - expect(subject[:parse_error]).to eq(false) - end - - it 'correctly sets the issuable attributes' do - expect { subject }.to change { issuables.count }.by 3 - - expect(issuables.reload).to include(have_attributes(title: 'Title with quote"', description: 'Description')) - end - - it_behaves_like 'importer with email notification' - it_behaves_like 'an issuable importer' - end - - context 'tab delimited file with error row' do - let(:file) { fixture_file_upload('spec/fixtures/csv_tab.csv') } - - it 'imports CSV with some error rows' do - expect(subject[:success]).to eq(2) - expect(subject[:error_lines]).to eq([3]) - expect(subject[:parse_error]).to eq(false) - end - - it 'correctly sets the issuable attributes' do - expect { subject }.to change { issuables.count }.by 2 - - expect(issuables.reload).to include(have_attributes(title: 'Hello', description: 'World')) - end - - it_behaves_like 'importer with email notification' - it_behaves_like 'an issuable importer' - end - - context 'semicolon delimited file with CRLF' do - let(:file) { fixture_file_upload('spec/fixtures/csv_semicolon.csv') } - - it 'imports CSV with a blank row' do - expect(subject[:success]).to eq(3) - expect(subject[:error_lines]).to eq([4]) - expect(subject[:parse_error]).to eq(false) - end - - it 'correctly sets the issuable attributes' do - expect { subject }.to change { issuables.count }.by 3 - - expect(issuables.reload).to include(have_attributes(title: 'Hello', description: 'World')) - end - - it_behaves_like 'importer with email notification' - it_behaves_like 'an issuable importer' - end - end -end diff --git a/spec/support/services/issuable_update_service_shared_examples.rb b/spec/support/services/issuable_update_service_shared_examples.rb deleted file mode 100644 index feea21be428..00000000000 --- a/spec/support/services/issuable_update_service_shared_examples.rb +++ /dev/null @@ -1,99 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'issuable update service' do - def update_issuable(opts) - described_class.new(project, user, opts).execute(open_issuable) - end - - context 'changing state' do - let(:hook_event) { :"#{closed_issuable.class.name.underscore.to_sym}_hooks" } - - context 'to reopened' do - let(:expected_payload) do - include( - changes: include( - state_id: { current: 1, previous: 2 }, - updated_at: { current: kind_of(Time), previous: kind_of(Time) } - ), - object_attributes: include( - state: 'opened', - action: 'reopen' - ) - ) - end - - it 'executes hooks' do - expect(project).to receive(:execute_hooks).with(expected_payload, hook_event) - expect(project).to receive(:execute_integrations).with(expected_payload, hook_event) - - described_class.new(**described_class.constructor_container_arg(project), current_user: user, params: { state_event: 'reopen' }).execute(closed_issuable) - end - end - - context 'to closed' do - let(:expected_payload) do - include( - changes: include( - state_id: { current: 2, previous: 1 }, - updated_at: { current: kind_of(Time), previous: kind_of(Time) } - ), - object_attributes: include( - state: 'closed', - action: 'close' - ) - ) - end - - it 'executes hooks' do - expect(project).to receive(:execute_hooks).with(expected_payload, hook_event) - expect(project).to receive(:execute_integrations).with(expected_payload, hook_event) - - described_class.new(**described_class.constructor_container_arg(project), current_user: user, params: { state_event: 'close' }).execute(open_issuable) - end - end - end -end - -RSpec.shared_examples 'keeps issuable labels sorted after update' do - before do - update_issuable(label_ids: [label_b.id]) - end - - context 'when label is changed' do - it 'keeps the labels sorted by title ASC' do - update_issuable({ add_label_ids: [label_a.id] }) - - expect(issuable.labels).to eq([label_a, label_b]) - end - end -end - -RSpec.shared_examples 'broadcasting issuable labels updates' do - before do - update_issuable(label_ids: [label_a.id]) - end - - context 'when label is added' do - it 'triggers the GraphQL subscription' do - expect(GraphqlTriggers).to receive(:issuable_labels_updated).with(issuable) - - update_issuable(add_label_ids: [label_b.id]) - end - end - - context 'when label is removed' do - it 'triggers the GraphQL subscription' do - expect(GraphqlTriggers).to receive(:issuable_labels_updated).with(issuable) - - update_issuable(remove_label_ids: [label_a.id]) - end - end - - context 'when label is unchanged' do - it 'does not trigger the GraphQL subscription' do - expect(GraphqlTriggers).not_to receive(:issuable_labels_updated).with(issuable) - - update_issuable(label_ids: [label_a.id]) - end - end -end diff --git a/spec/support/services/issues/move_and_clone_services_shared_examples.rb b/spec/support/services/issues/move_and_clone_services_shared_examples.rb deleted file mode 100644 index 2b2e90c0461..00000000000 --- a/spec/support/services/issues/move_and_clone_services_shared_examples.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'copy or reset relative position' do - before do - # ensure we have a relative position and it is known - old_issue.update!(relative_position: 1000) - end - - context 'when moved to a project within same group hierarchy' do - it 'does not reset the relative_position' do - expect(subject.relative_position).to eq(1000) - end - end - - context 'when moved to a project in a different group hierarchy' do - let_it_be(:new_project) { create(:project, group: create(:group)) } - - it 'does reset the relative_position' do - expect(subject.relative_position).to be_nil - end - end -end diff --git a/spec/support/services/migrate_to_ghost_user_service_shared_examples.rb b/spec/support/services/migrate_to_ghost_user_service_shared_examples.rb deleted file mode 100644 index ae98ce689e3..00000000000 --- a/spec/support/services/migrate_to_ghost_user_service_shared_examples.rb +++ /dev/null @@ -1,89 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples "migrating a deleted user's associated records to the ghost user" do |record_class, fields| - record_class_name = record_class.to_s.titleize.downcase - - let(:project) do - case record_class - when MergeRequest - create(:project, :repository) - else - create(:project) - end - end - - before do - project.add_developer(user) - end - - context "for a #{record_class_name} the user has created" do - let!(:record) { created_record } - let(:migrated_fields) { fields || [:author] } - - it "does not delete the #{record_class_name}" do - service.execute - - expect(record_class.find_by_id(record.id)).to be_present - end - - it "blocks the user before migrating #{record_class_name}s to the 'Ghost User'" do - service.execute - - expect(user).to be_blocked - end - - it 'migrates all associated fields to the "Ghost user"' do - service.execute - - migrated_record = record_class.find_by_id(record.id) - - migrated_fields.each do |field| - expect(migrated_record.public_send(field)).to eq(User.ghost) - end - end - - it 'will only migrate specific records during a hard_delete' do - service.execute(hard_delete: true) - - migrated_record = record_class.find_by_id(record.id) - - check_user = always_ghost ? User.ghost : user - - migrated_fields.each do |field| - expect(migrated_record.public_send(field)).to eq(check_user) - end - end - - context "race conditions" do - context "when #{record_class_name} migration fails and is rolled back" do - before do - allow_any_instance_of(ActiveRecord::Associations::CollectionProxy) - .to receive(:update_all).and_raise(ActiveRecord::StatementTimeout) - end - - it 'rolls back the user block' do - expect { service.execute }.to raise_error(ActiveRecord::StatementTimeout) - - expect(user.reload).not_to be_blocked - end - - it "doesn't unblock a previously-blocked user" do - expect(user.starred_projects).to receive(:update_all).and_call_original - user.block - - expect { service.execute }.to raise_error(ActiveRecord::StatementTimeout) - - expect(user.reload).to be_blocked - end - end - - it "blocks the user before #{record_class_name} migration begins" do - expect(service).to receive("migrate_#{record_class_name.parameterize(separator: '_').pluralize}".to_sym) do - expect(user.reload).to be_blocked - end - - service.execute - end - end - end -end diff --git a/spec/support/services/service_response_shared_examples.rb b/spec/support/services/service_response_shared_examples.rb deleted file mode 100644 index 186627347fb..00000000000 --- a/spec/support/services/service_response_shared_examples.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'returning an error service response' do |message: nil| - it 'returns an error service response' do - result = subject - - expect(result).to be_error - - if message - expect(result.message).to eq(message) - end - end -end - -RSpec.shared_examples 'returning a success service response' do |message: nil| - it 'returns a success service response' do - result = subject - - expect(result).to be_success - - if message - expect(result.message).to eq(message) - end - end -end |