diff options
Diffstat (limited to 'spec/support/shared_examples/services')
17 files changed, 106 insertions, 25 deletions
diff --git a/spec/support/shared_examples/services/alert_management/alert_processing/alert_firing_shared_examples.rb b/spec/support/shared_examples/services/alert_management/alert_processing/alert_firing_shared_examples.rb index 6cae7d8e00f..0db9519f760 100644 --- a/spec/support/shared_examples/services/alert_management/alert_processing/alert_firing_shared_examples.rb +++ b/spec/support/shared_examples/services/alert_management/alert_processing/alert_firing_shared_examples.rb @@ -23,12 +23,10 @@ RSpec.shared_examples 'creates an alert management alert or errors' do end context 'and fails to save' do - let(:errors) { double(messages: { hosts: ['hosts array is over 255 chars'] }, '[]': [] )} - before do - allow(service).to receive(:alert).and_call_original - allow(service).to receive_message_chain(:alert, :save).and_return(false) - allow(service).to receive_message_chain(:alert, :errors).and_return(errors) + allow(AlertManagement::Alert).to receive(:new).and_wrap_original do |m, **args| + m.call(**args, hosts: ['a' * 256]) # hosts should be 255 + end end it_behaves_like 'alerts service responds with an error', :bad_request diff --git a/spec/support/shared_examples/services/boards/issues_move_service_shared_examples.rb b/spec/support/shared_examples/services/boards/issues_move_service_shared_examples.rb index a46c2f0ac5c..162be24fe8f 100644 --- a/spec/support/shared_examples/services/boards/issues_move_service_shared_examples.rb +++ b/spec/support/shared_examples/services/boards/issues_move_service_shared_examples.rb @@ -3,8 +3,8 @@ RSpec.shared_examples 'issues move service' do |group| shared_examples 'updating timestamps' do it 'updates updated_at' do - expect {described_class.new(parent, user, params).execute(issue)} - .to change {issue.reload.updated_at} + expect { described_class.new(parent, user, params).execute(issue) } + .to change { issue.reload.updated_at } end end @@ -140,6 +140,40 @@ RSpec.shared_examples 'issues move service' do |group| expect(issue2.reload.updated_at.change(usec: 0)).to eq updated_at2.change(usec: 0) end + context 'when moving to a specific list position' do + before do + [issue1, issue2, issue].each do |issue| + issue.move_to_end && issue.save! + end + end + + it 'moves issue to the top of the list' do + described_class.new(parent, user, params.merge({ position_in_list: 0 })).execute(issue) + + expect(issue.relative_position).to be < issue1.relative_position + end + + it 'moves issue to a position in the middle of the list' do + described_class.new(parent, user, params.merge({ position_in_list: 1 })).execute(issue) + + expect(issue.relative_position).to be_between(issue1.relative_position, issue2.relative_position) + end + + it 'moves issue to the bottom of the list' do + described_class.new(parent, user, params.merge({ position_in_list: -1 })).execute(issue1) + + expect(issue1.relative_position).to be > issue.relative_position + end + + context 'when given position is greater than number of issues in the list' do + it 'moves the issue to the bottom of the list' do + described_class.new(parent, user, params.merge({ position_in_list: 5 })).execute(issue1) + + expect(issue1.relative_position).to be > issue.relative_position + end + end + end + def reorder_issues(params, issues: []) issues.each do |issue| issue.move_to_end && issue.save! diff --git a/spec/support/shared_examples/services/common_system_notes_shared_examples.rb b/spec/support/shared_examples/services/common_system_notes_shared_examples.rb index ce412ef55de..1887b38b50e 100644 --- a/spec/support/shared_examples/services/common_system_notes_shared_examples.rb +++ b/spec/support/shared_examples/services/common_system_notes_shared_examples.rb @@ -42,6 +42,7 @@ RSpec.shared_examples 'a system note' do |params| it 'has the correct attributes', :aggregate_failures do exclude_project = !params.nil? && params[:exclude_project] + skip_persistence_check = !params.nil? && params[:skip_persistence_check] expect(subject).to be_valid expect(subject).to be_system @@ -50,6 +51,7 @@ RSpec.shared_examples 'a system note' do |params| expect(subject.project).to eq project unless exclude_project expect(subject.author).to eq author + expect(subject.system_note_metadata).to be_persisted unless skip_persistence_check expect(subject.system_note_metadata.action).to eq(action) expect(subject.system_note_metadata.commit_count).to eq(commit_count) end diff --git a/spec/support/shared_examples/services/container_registry_auth_service_shared_examples.rb b/spec/support/shared_examples/services/container_registry_auth_service_shared_examples.rb index 3be59af6a37..58659775d8c 100644 --- a/spec/support/shared_examples/services/container_registry_auth_service_shared_examples.rb +++ b/spec/support/shared_examples/services/container_registry_auth_service_shared_examples.rb @@ -54,6 +54,12 @@ RSpec.shared_examples 'a valid token' do end end +RSpec.shared_examples 'with auth_type' do + let(:current_params) { super().merge(auth_type: :foo) } + + it { expect(payload['auth_type']).to eq('foo') } +end + RSpec.shared_examples 'a browsable' do let(:access) do [{ 'type' => 'registry', @@ -199,8 +205,8 @@ RSpec.shared_examples 'a container registry auth service' do describe '.import_access_token' do let(:access) do [{ 'type' => 'registry', - 'name' => 'import', - 'actions' => ['*'] }] + 'name' => 'import', + 'actions' => ['*'] }] end let(:token) { described_class.import_access_token } @@ -286,6 +292,7 @@ RSpec.shared_examples 'a container registry auth service' do shared_examples 'private project' do context 'allow to use scope-less authentication' do it_behaves_like 'a valid token' + it_behaves_like 'with auth_type' end context 'allow developer to push images' do @@ -299,6 +306,7 @@ RSpec.shared_examples 'a container registry auth service' do it_behaves_like 'a pushable' it_behaves_like 'container repository factory' + it_behaves_like 'with auth_type' end context 'disallow developer to delete images' do @@ -341,6 +349,7 @@ RSpec.shared_examples 'a container registry auth service' do it_behaves_like 'a pullable' it_behaves_like 'not a container repository factory' + it_behaves_like 'with auth_type' end end @@ -381,6 +390,7 @@ RSpec.shared_examples 'a container registry auth service' do it_behaves_like 'a pullable' it_behaves_like 'not a container repository factory' + it_behaves_like 'with auth_type' end context 'disallow guest to pull or push images' do @@ -445,6 +455,7 @@ RSpec.shared_examples 'a container registry auth service' do it_behaves_like 'a pullable' it_behaves_like 'not a container repository factory' + it_behaves_like 'with auth_type' end context 'disallow anyone to push images' do @@ -495,6 +506,7 @@ RSpec.shared_examples 'a container registry auth service' do it_behaves_like 'a pullable' it_behaves_like 'not a container repository factory' + it_behaves_like 'with auth_type' end context 'disallow anyone to push images' do @@ -600,6 +612,7 @@ RSpec.shared_examples 'a container registry auth service' do end it_behaves_like 'a valid token' + it_behaves_like 'with auth_type' context 'allow to pull and push images' do let(:current_params) do @@ -944,10 +957,11 @@ RSpec.shared_examples 'a container registry auth service' do shared_examples 'able to login' do context 'registry provides read_container_image authentication_abilities' do - let(:current_params) { { deploy_token: deploy_token } } + let(:current_params) { { deploy_token: deploy_token, auth_type: :deploy_token } } let(:authentication_abilities) { [:read_container_image] } it_behaves_like 'an authenticated' + it { expect(payload['auth_type']).to eq('deploy_token') } end end diff --git a/spec/support/shared_examples/services/feature_flags/client_shared_examples.rb b/spec/support/shared_examples/services/feature_flags/client_shared_examples.rb index a62cffc0e1b..73a02905914 100644 --- a/spec/support/shared_examples/services/feature_flags/client_shared_examples.rb +++ b/spec/support/shared_examples/services/feature_flags/client_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_examples_for 'update feature flag client' do +RSpec.shared_examples_for 'update feature flag client' do let!(:client) { create(:operations_feature_flags_client, project: project) } it 'updates last feature flag updated at' do @@ -10,7 +10,7 @@ shared_examples_for 'update feature flag client' do end end -shared_examples_for 'does not update feature flag client' do +RSpec.shared_examples_for 'does not update feature flag client' do let!(:client) { create(:operations_feature_flags_client, project: project) } it 'does not update last feature flag updated at' do diff --git a/spec/support/shared_examples/services/gitlab_projects_import_service_shared_examples.rb b/spec/support/shared_examples/services/gitlab_projects_import_service_shared_examples.rb index 2aac7e328f0..366fa4763e1 100644 --- a/spec/support/shared_examples/services/gitlab_projects_import_service_shared_examples.rb +++ b/spec/support/shared_examples/services/gitlab_projects_import_service_shared_examples.rb @@ -33,7 +33,7 @@ RSpec.shared_examples 'gitlab projects import validations' do context 'when there is a project with the same path' do let(:existing_project) { create(:project, namespace: namespace) } - let(:path) { existing_project.path} + let(:path) { existing_project.path } it 'does not create the project' do project = subject.execute diff --git a/spec/support/shared_examples/services/issuable/destroy_service_shared_examples.rb b/spec/support/shared_examples/services/issuable/destroy_service_shared_examples.rb index 31571b1ffb9..92681b8ba79 100644 --- a/spec/support/shared_examples/services/issuable/destroy_service_shared_examples.rb +++ b/spec/support/shared_examples/services/issuable/destroy_service_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_examples_for 'service scheduling async deletes' do +RSpec.shared_examples_for 'service scheduling async deletes' do it 'destroys associated todos asynchronously' do expect(worker_class) .to receive(:perform_async) @@ -20,13 +20,13 @@ shared_examples_for 'service scheduling async deletes' do end end -shared_examples_for 'service deleting todos' do +RSpec.shared_examples_for 'service deleting todos' do it_behaves_like 'service scheduling async deletes' do let(:worker_class) { TodosDestroyer::DestroyedIssuableWorker } end end -shared_examples_for 'service deleting label links' do +RSpec.shared_examples_for 'service deleting label links' do it_behaves_like 'service scheduling async deletes' do let(:worker_class) { Issuable::LabelLinksDestroyWorker } end diff --git a/spec/support/shared_examples/services/issuable/update_service_shared_examples.rb b/spec/support/shared_examples/services/issuable/update_service_shared_examples.rb new file mode 100644 index 00000000000..3d90885dd6f --- /dev/null +++ b/spec/support/shared_examples/services/issuable/update_service_shared_examples.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +RSpec.shared_examples_for 'issuable update service updating last_edited_at values' do + context 'when updating the title of the issuable' do + let(:update_params) { { title: 'updated title' } } + + it 'does not update last_edited values' do + expect { update_issuable }.to change(issuable, :title).from(issuable.title).to('updated title').and( + not_change(issuable, :last_edited_at) + ).and( + not_change(issuable, :last_edited_by) + ) + end + end + + context 'when updating the description of the issuable' do + let(:update_params) { { description: 'updated description' } } + + it 'updates last_edited values' do + expect do + update_issuable + end.to change(issuable, :description).from(issuable.description).to('updated description').and( + change(issuable, :last_edited_at) + ).and( + change(issuable, :last_edited_by) + ) + end + end +end diff --git a/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb b/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb index 9610cdd18a3..65351ac94ab 100644 --- a/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb +++ b/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_examples 'issuable link creation' do +RSpec.shared_examples 'issuable link creation' do describe '#execute' do subject { described_class.new(issuable, user, params).execute } diff --git a/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb b/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb index 53d637a9094..5e80014da1d 100644 --- a/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb +++ b/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_examples 'a destroyable issuable link' do +RSpec.shared_examples 'a destroyable issuable link' do context 'when successfully removes an issuable link' do before do issuable_link.source.resource_parent.add_reporter(user) diff --git a/spec/support/shared_examples/services/merge_request_shared_examples.rb b/spec/support/shared_examples/services/merge_request_shared_examples.rb index d2595b92cbc..b3ba0a1be93 100644 --- a/spec/support/shared_examples/services/merge_request_shared_examples.rb +++ b/spec/support/shared_examples/services/merge_request_shared_examples.rb @@ -123,7 +123,7 @@ end RSpec.shared_examples 'with an existing branch that has a merge request open' do |count| let(:changes) { existing_branch_changes } - let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)} + let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch) } it_behaves_like 'a service that does not create a merge request' it_behaves_like 'a service that can change assignees of a merge request', count diff --git a/spec/support/shared_examples/services/onboarding_progress_shared_examples.rb b/spec/support/shared_examples/services/onboarding_progress_shared_examples.rb index 8c6c2271af3..07025dac689 100644 --- a/spec/support/shared_examples/services/onboarding_progress_shared_examples.rb +++ b/spec/support/shared_examples/services/onboarding_progress_shared_examples.rb @@ -4,7 +4,7 @@ RSpec.shared_examples 'records an onboarding progress action' do |action| include AfterNextHelpers it do - expect_next(OnboardingProgressService, namespace) + expect_next(Onboarding::ProgressService, namespace) .to receive(:execute).with(action: action).and_call_original subject @@ -13,7 +13,7 @@ end RSpec.shared_examples 'does not record an onboarding progress action' do it do - expect(OnboardingProgressService).not_to receive(:new) + expect(Onboarding::ProgressService).not_to receive(:new) subject end diff --git a/spec/support/shared_examples/services/packages/debian/generate_distribution_shared_examples.rb b/spec/support/shared_examples/services/packages/debian/generate_distribution_shared_examples.rb index 7fd20fc3909..ea79dc674a1 100644 --- a/spec/support/shared_examples/services/packages/debian/generate_distribution_shared_examples.rb +++ b/spec/support/shared_examples/services/packages/debian/generate_distribution_shared_examples.rb @@ -190,6 +190,7 @@ RSpec.shared_examples 'Generate Debian Distribution and component files' do Codename: unstable Date: Sat, 25 Jan 2020 15:17:18 +0000 Valid-Until: Mon, 27 Jan 2020 15:17:18 +0000 + Acquire-By-Hash: yes Architectures: all amd64 arm64 Components: contrib main MD5Sum: @@ -249,6 +250,7 @@ RSpec.shared_examples 'Generate Debian Distribution and component files' do Codename: unstable Date: Sat, 25 Jan 2020 15:17:18 +0000 Valid-Until: Mon, 27 Jan 2020 15:17:18 +0000 + Acquire-By-Hash: yes MD5Sum: SHA256: EOF diff --git a/spec/support/shared_examples/services/packages_shared_examples.rb b/spec/support/shared_examples/services/packages_shared_examples.rb index 704a4bbe0b8..ca4dea90c55 100644 --- a/spec/support/shared_examples/services/packages_shared_examples.rb +++ b/spec/support/shared_examples/services/packages_shared_examples.rb @@ -227,6 +227,7 @@ RSpec.shared_examples 'filters on each package_type' do |is_project: false| let_it_be(:package10) { create(:rubygems_package, project: project) } let_it_be(:package11) { create(:helm_package, project: project) } let_it_be(:package12) { create(:terraform_module_package, project: project) } + let_it_be(:package13) { create(:rpm_package, project: project) } Packages::Package.package_types.keys.each do |package_type| context "for package type #{package_type}" do diff --git a/spec/support/shared_examples/services/resource_events/synthetic_notes_builder_shared_examples.rb b/spec/support/shared_examples/services/resource_events/synthetic_notes_builder_shared_examples.rb index 716bee39fca..a7e51408032 100644 --- a/spec/support/shared_examples/services/resource_events/synthetic_notes_builder_shared_examples.rb +++ b/spec/support/shared_examples/services/resource_events/synthetic_notes_builder_shared_examples.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.shared_examples 'filters by paginated notes' do |event_type| - let(:event) { create(event_type) } # rubocop:disable Rails/SaveBang + let(:event) { create(event_type, issue: create(:issue)) } before do create(event_type, issue: event.issue) diff --git a/spec/support/shared_examples/services/snippets_shared_examples.rb b/spec/support/shared_examples/services/snippets_shared_examples.rb index 5a44f739b27..65893d84798 100644 --- a/spec/support/shared_examples/services/snippets_shared_examples.rb +++ b/spec/support/shared_examples/services/snippets_shared_examples.rb @@ -14,7 +14,8 @@ RSpec.shared_examples 'checking spam' do spammable: kind_of(Snippet), spam_params: spam_params, user: an_instance_of(User), - action: action + action: action, + extra_features: { files: an_instance_of(Array) } } ) do |instance| expect(instance).to receive(:execute) @@ -24,7 +25,7 @@ RSpec.shared_examples 'checking spam' do end end -shared_examples 'invalid params error response' do +RSpec.shared_examples 'invalid params error response' do before do allow_next_instance_of(described_class) do |service| allow(service).to receive(:valid_params?).and_return false diff --git a/spec/support/shared_examples/services/snowplow_tracking_shared_examples.rb b/spec/support/shared_examples/services/snowplow_tracking_shared_examples.rb index 0687be6f429..31919a4263d 100644 --- a/spec/support/shared_examples/services/snowplow_tracking_shared_examples.rb +++ b/spec/support/shared_examples/services/snowplow_tracking_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_examples 'issue_edit snowplow tracking' do +RSpec.shared_examples 'issue_edit snowplow tracking' do let(:category) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_CATEGORY } let(:action) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_ACTION } let(:label) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_LABEL } |