diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /spec/support/shared_examples/models | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'spec/support/shared_examples/models')
5 files changed, 40 insertions, 28 deletions
diff --git a/spec/support/shared_examples/models/atomic_internal_id_shared_examples.rb b/spec/support/shared_examples/models/atomic_internal_id_shared_examples.rb index 03f565e0aac..fe85daa7235 100644 --- a/spec/support/shared_examples/models/atomic_internal_id_shared_examples.rb +++ b/spec/support/shared_examples/models/atomic_internal_id_shared_examples.rb @@ -80,15 +80,22 @@ RSpec.shared_examples 'AtomicInternalId' do |validate_presence: true| it 'calls InternalId.generate_next and sets internal id attribute' do iid = rand(1..1000) - expect(InternalId).to receive(:generate_next).with(instance, scope_attrs, usage, any_args).and_return(iid) + # Need to do this before evaluating instance otherwise it gets set + # already in factory + allow(InternalId).to receive(:generate_next).and_return(iid) + subject expect(read_internal_id).to eq(iid) + + expect(InternalId).to have_received(:generate_next).with(instance, scope_attrs, usage, any_args) end it 'does not overwrite an existing internal id' do write_internal_id(4711) - expect { subject }.not_to change { read_internal_id } + allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/347091') do + expect { subject }.not_to change { read_internal_id } + end end context 'when the instance has an internal ID set' do @@ -101,6 +108,7 @@ RSpec.shared_examples 'AtomicInternalId' do |validate_presence: true| .to receive(:track_greatest) .with(instance, scope_attrs, usage, internal_id, any_args) .and_return(internal_id) + subject end end @@ -110,7 +118,11 @@ RSpec.shared_examples 'AtomicInternalId' do |validate_presence: true| context 'when the internal id has been changed' do context 'when the internal id is automatically set' do it 'clears it on the instance' do - expect_iid_to_be_set_and_rollback + write_internal_id(nil) + + allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/347091') do + expect_iid_to_be_set_and_rollback + end expect(read_internal_id).to be_nil end @@ -120,7 +132,9 @@ RSpec.shared_examples 'AtomicInternalId' do |validate_presence: true| it 'does not clear it on the instance' do write_internal_id(100) - expect_iid_to_be_set_and_rollback + allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/347091') do + expect_iid_to_be_set_and_rollback + end expect(read_internal_id).not_to be_nil end diff --git a/spec/support/shared_examples/models/chat_integration_shared_examples.rb b/spec/support/shared_examples/models/chat_integration_shared_examples.rb index 72659dd5f3b..e6b270c6188 100644 --- a/spec/support/shared_examples/models/chat_integration_shared_examples.rb +++ b/spec/support/shared_examples/models/chat_integration_shared_examples.rb @@ -71,7 +71,7 @@ RSpec.shared_examples "chat integration" do |integration_name| it "does not call #{integration_name} API" do result = subject.execute(sample_data) - expect(result).to be(false) + expect(result).to be_falsy expect(WebMock).not_to have_requested(:post, webhook_url) end end @@ -113,7 +113,7 @@ RSpec.shared_examples "chat integration" do |integration_name| context "with protected branch" do before do - create(:protected_branch, project: project, name: "a-protected-branch") + create(:protected_branch, :create_branch_on_repository, project: project, name: "a-protected-branch") end let(:sample_data) do @@ -309,7 +309,7 @@ RSpec.shared_examples "chat integration" do |integration_name| context "with protected branch" do before do - create(:protected_branch, project: project, name: "a-protected-branch") + create(:protected_branch, :create_branch_on_repository, project: project, name: "a-protected-branch") end let(:sample_data) do @@ -355,5 +355,11 @@ RSpec.shared_examples "chat integration" do |integration_name| end end end + + context 'deployment events' do + let(:sample_data) { Gitlab::DataBuilder::Deployment.build(create(:deployment), Time.now) } + + it_behaves_like "untriggered #{integration_name} integration" + end end end diff --git a/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb b/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb index 2d4c0b60f2b..ad15f82be5e 100644 --- a/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb @@ -305,7 +305,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch' do before do - create(:protected_branch, project: project, name: 'a-protected-branch') + create(:protected_branch, :create_branch_on_repository, project: project, name: 'a-protected-branch') end let(:data) do @@ -347,7 +347,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch with protected branches defined using wildcards' do before do - create(:protected_branch, project: project, name: '*-stable') + create(:protected_branch, :create_branch_on_repository, repository_branch_name: '1-stable', project: project, name: '*-stable') end let(:data) do @@ -560,7 +560,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch' do before do - create(:protected_branch, project: project, name: 'a-protected-branch') + create(:protected_branch, :create_branch_on_repository, project: project, name: 'a-protected-branch') end let(:pipeline) do @@ -590,7 +590,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch with protected branches defined usin wildcards' do before do - create(:protected_branch, project: project, name: '*-stable') + create(:protected_branch, :create_branch_on_repository, repository_branch_name: '1-stable', project: project, name: '*-stable') end let(:pipeline) do diff --git a/spec/support/shared_examples/models/member_shared_examples.rb b/spec/support/shared_examples/models/member_shared_examples.rb index a2909c66e22..d5d137922eb 100644 --- a/spec/support/shared_examples/models/member_shared_examples.rb +++ b/spec/support/shared_examples/models/member_shared_examples.rb @@ -301,10 +301,6 @@ RSpec.shared_examples_for "member creation" do end context 'when `tasks_to_be_done` and `tasks_project_id` are passed' do - before do - stub_experiments(invite_members_for_task: true) - end - it 'creates a member_task with the correct attributes', :aggregate_failures do task_project = source.is_a?(Group) ? create(:project, group: source) : source described_class.new(source, user, :developer, tasks_to_be_done: %w(ci code), tasks_project_id: task_project.id).execute @@ -397,10 +393,6 @@ RSpec.shared_examples_for "bulk member creation" do end context 'when `tasks_to_be_done` and `tasks_project_id` are passed' do - before do - stub_experiments(invite_members_for_task: true) - end - it 'creates a member_task with the correct attributes', :aggregate_failures do task_project = source.is_a?(Group) ? create(:project, group: source) : source members = described_class.add_users(source, [user1], :developer, tasks_to_be_done: %w(ci code), tasks_project_id: task_project.id) diff --git a/spec/support/shared_examples/models/packages/debian/component_file_shared_example.rb b/spec/support/shared_examples/models/packages/debian/component_file_shared_example.rb index f08ee820463..23026167b19 100644 --- a/spec/support/shared_examples/models/packages/debian/component_file_shared_example.rb +++ b/spec/support/shared_examples/models/packages/debian/component_file_shared_example.rb @@ -23,7 +23,7 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze| let_it_be(:component_file_other_file_md5, freeze: can_freeze) { create("debian_#{container_type}_component_file", component: component1_1, architecture: architecture1_1, file_md5: 'other_md5') } let_it_be(:component_file_other_file_sha256, freeze: can_freeze) { create("debian_#{container_type}_component_file", component: component1_1, architecture: architecture1_1, file_sha256: 'other_sha256') } let_it_be(:component_file_other_container, freeze: can_freeze) { create("debian_#{container_type}_component_file", component: component2_1, architecture: architecture2_1) } - let_it_be_with_refind(:component_file_with_file_type_source) { create("debian_#{container_type}_component_file", :source, component: component1_1) } + let_it_be_with_refind(:component_file_with_file_type_sources) { create("debian_#{container_type}_component_file", :sources, component: component1_1) } let_it_be(:component_file_with_file_type_di_packages, freeze: can_freeze) { create("debian_#{container_type}_component_file", :di_packages, component: component1_1, architecture: architecture1_1) } subject { component_file_with_architecture } @@ -43,8 +43,8 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze| it { is_expected.to belong_to(:architecture).class_name("Packages::Debian::#{container_type.capitalize}Architecture").inverse_of(:files) } end - context 'with :source file_type' do - subject { component_file_with_file_type_source } + context 'with :sources file_type' do + subject { component_file_with_file_type_sources } it { is_expected.to belong_to(:architecture).class_name("Packages::Debian::#{container_type.capitalize}Architecture").inverse_of(:files).optional } end @@ -66,8 +66,8 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze| it { is_expected.to validate_presence_of(:architecture) } end - context 'with :source file_type' do - subject { component_file_with_file_type_source } + context 'with :sources file_type' do + subject { component_file_with_file_type_sources } it { is_expected.to validate_absence_of(:architecture) } end @@ -135,10 +135,10 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze| end describe '.with_file_type' do - subject { described_class.with_file_type(:source) } + subject { described_class.with_file_type(:sources) } it do - expect(subject.to_a).to contain_exactly(component_file_with_file_type_source) + expect(subject.to_a).to contain_exactly(component_file_with_file_type_sources) end end @@ -214,9 +214,9 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze| end context 'with a Source file_type' do - subject { component_file_with_file_type_source.relative_path } + subject { component_file_with_file_type_sources.relative_path } - it { is_expected.to eq("#{component1_1.name}/source/Source") } + it { is_expected.to eq("#{component1_1.name}/source/Sources") } end context 'with a DI Packages file_type' do |