diff options
Diffstat (limited to 'spec/services')
25 files changed, 176 insertions, 91 deletions
diff --git a/spec/services/auth/container_registry_authentication_service_spec.rb b/spec/services/auth/container_registry_authentication_service_spec.rb index 2807b8c8c85..5003dfcc951 100644 --- a/spec/services/auth/container_registry_authentication_service_spec.rb +++ b/spec/services/auth/container_registry_authentication_service_spec.rb @@ -20,7 +20,9 @@ describe Auth::ContainerRegistryAuthenticationService do before do allow(Gitlab.config.registry).to receive_messages(enabled: true, issuer: 'rspec', key: nil) - allow_any_instance_of(JSONWebToken::RSAToken).to receive(:key).and_return(rsa_key) + allow_next_instance_of(JSONWebToken::RSAToken) do |instance| + allow(instance).to receive(:key).and_return(rsa_key) + end end shared_examples 'an authenticated' do diff --git a/spec/services/boards/issues/create_service_spec.rb b/spec/services/boards/issues/create_service_spec.rb index ef7b7fdbaac..3520630dd83 100644 --- a/spec/services/boards/issues/create_service_spec.rb +++ b/spec/services/boards/issues/create_service_spec.rb @@ -17,7 +17,9 @@ describe Boards::Issues::CreateService do end it 'delegates the create proceedings to Issues::CreateService' do - expect_any_instance_of(Issues::CreateService).to receive(:execute).once + expect_next_instance_of(Issues::CreateService) do |instance| + expect(instance).to receive(:execute).once + end service.execute end diff --git a/spec/services/ci/archive_trace_service_spec.rb b/spec/services/ci/archive_trace_service_spec.rb index 64fa74ccce5..ba94013b574 100644 --- a/spec/services/ci/archive_trace_service_spec.rb +++ b/spec/services/ci/archive_trace_service_spec.rb @@ -41,7 +41,9 @@ describe Ci::ArchiveTraceService, '#execute' do context 'when job failed to archive trace but did not raise an exception' do before do - allow_any_instance_of(Gitlab::Ci::Trace).to receive(:archive!) {} + allow_next_instance_of(Gitlab::Ci::Trace) do |instance| + allow(instance).to receive(:archive!) {} + end end it 'leaves a warning message in sidekiq log' do @@ -59,7 +61,7 @@ describe Ci::ArchiveTraceService, '#execute' do let(:job) { create(:ci_build, :running, :trace_live) } it 'increments Prometheus counter, sends crash report to Sentry and ignore an error for continuing to archive' do - expect(Gitlab::Sentry) + expect(Gitlab::ErrorTracking) .to receive(:track_and_raise_for_dev_exception) .with(::Gitlab::Ci::Trace::ArchiveError, issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/51502', diff --git a/spec/services/ci/create_pipeline_service/rules_spec.rb b/spec/services/ci/create_pipeline_service/rules_spec.rb index 2c93007f8e8..0a2c5724ce4 100644 --- a/spec/services/ci/create_pipeline_service/rules_spec.rb +++ b/spec/services/ci/create_pipeline_service/rules_spec.rb @@ -13,7 +13,9 @@ describe Ci::CreatePipelineService do context 'job:rules' do before do stub_ci_pipeline_yaml_file(config) - allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true) + allow_next_instance_of(Ci::BuildScheduleWorker) do |instance| + allow(instance).to receive(:perform).and_return(true) + end end context 'exists:' do @@ -98,6 +100,17 @@ describe Ci::CreatePipelineService do stub_ci_pipeline_yaml_file(config) end + shared_examples 'workflow:rules feature disabled' do + before do + stub_feature_flags(workflow_rules: false) + end + + it 'presents a message that rules are disabled' do + expect(pipeline.errors[:base]).to include('Workflow rules are disabled') + expect(pipeline).to be_persisted + end + end + context 'with a single regex-matching if: clause' do let(:config) do <<-EOY @@ -229,16 +242,7 @@ describe Ci::CreatePipelineService do expect(pipeline).not_to be_persisted end - context 'with workflow:rules shut off' do - before do - stub_feature_flags(workflow_rules: false) - end - - it 'invalidates the pipeline with an empty jobs error' do - expect(pipeline.errors[:base]).to include('No stages / jobs for this pipeline.') - expect(pipeline).not_to be_persisted - end - end + it_behaves_like 'workflow:rules feature disabled' end context 'where workflow passes and the job passes' do @@ -249,16 +253,7 @@ describe Ci::CreatePipelineService do expect(pipeline).to be_persisted end - context 'with workflow:rules shut off' do - before do - stub_feature_flags(workflow_rules: false) - end - - it 'saves a pending pipeline' do - expect(pipeline).to be_pending - expect(pipeline).to be_persisted - end - end + it_behaves_like 'workflow:rules feature disabled' end context 'where workflow fails and the job fails' do @@ -269,16 +264,7 @@ describe Ci::CreatePipelineService do expect(pipeline).not_to be_persisted end - context 'with workflow:rules shut off' do - before do - stub_feature_flags(workflow_rules: false) - end - - it 'invalidates the pipeline with an empty jobs error' do - expect(pipeline.errors[:base]).to include('No stages / jobs for this pipeline.') - expect(pipeline).not_to be_persisted - end - end + it_behaves_like 'workflow:rules feature disabled' end context 'where workflow fails and the job passes' do @@ -289,16 +275,7 @@ describe Ci::CreatePipelineService do expect(pipeline).not_to be_persisted end - context 'with workflow:rules shut off' do - before do - stub_feature_flags(workflow_rules: false) - end - - it 'saves a pending pipeline' do - expect(pipeline).to be_pending - expect(pipeline).to be_persisted - end - end + it_behaves_like 'workflow:rules feature disabled' end end end diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index c4274f0bd17..4f624368215 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -528,7 +528,7 @@ describe Ci::CreatePipelineService do end it 'logs error' do - expect(Gitlab::Sentry).to receive(:track_exception).and_call_original + expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original execute_service end @@ -613,7 +613,7 @@ describe Ci::CreatePipelineService do end it 'logs error' do - expect(Gitlab::Sentry).to receive(:track_exception).and_call_original + expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original execute_service end diff --git a/spec/services/ci/pipeline_trigger_service_spec.rb b/spec/services/ci/pipeline_trigger_service_spec.rb index 24d42f402f4..44ce1ff699b 100644 --- a/spec/services/ci/pipeline_trigger_service_spec.rb +++ b/spec/services/ci/pipeline_trigger_service_spec.rb @@ -45,7 +45,9 @@ describe Ci::PipelineTriggerService do context 'when commit message has [ci skip]' do before do - allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { '[ci skip]' } + allow_next_instance_of(Ci::Pipeline) do |instance| + allow(instance).to receive(:git_commit_message) { '[ci skip]' } + end end it 'ignores [ci skip] and create as general' do @@ -124,7 +126,9 @@ describe Ci::PipelineTriggerService do context 'when commit message has [ci skip]' do before do - allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { '[ci skip]' } + allow_next_instance_of(Ci::Pipeline) do |instance| + allow(instance).to receive(:git_commit_message) { '[ci skip]' } + end end it 'ignores [ci skip] and create as general' do diff --git a/spec/services/ci/play_manual_stage_service_spec.rb b/spec/services/ci/play_manual_stage_service_spec.rb index 5d812745c7f..e2946111a13 100644 --- a/spec/services/ci/play_manual_stage_service_spec.rb +++ b/spec/services/ci/play_manual_stage_service_spec.rb @@ -51,8 +51,9 @@ describe Ci::PlayManualStageService, '#execute' do context 'when user does not have permission on a specific build' do before do - allow_any_instance_of(Ci::Build).to receive(:play) - .and_raise(Gitlab::Access::AccessDeniedError) + allow_next_instance_of(Ci::Build) do |instance| + allow(instance).to receive(:play).and_raise(Gitlab::Access::AccessDeniedError) + end service.execute(stage) end diff --git a/spec/services/ci/prepare_build_service_spec.rb b/spec/services/ci/prepare_build_service_spec.rb index 87061b3b15a..3c3d8b90bb0 100644 --- a/spec/services/ci/prepare_build_service_spec.rb +++ b/spec/services/ci/prepare_build_service_spec.rb @@ -51,7 +51,7 @@ describe Ci::PrepareBuildService do it 'drops the build and notifies Sentry' do expect(build).to receive(:drop).with(:unmet_prerequisites).once - expect(Gitlab::Sentry).to receive(:track_exception) + expect(Gitlab::ErrorTracking).to receive(:track_exception) .with(instance_of(Kubeclient::HttpError), hash_including(build_id: build.id)) subject diff --git a/spec/services/ci/process_pipeline_service_spec.rb b/spec/services/ci/process_pipeline_service_spec.rb index a15a0afc526..ba5891c8694 100644 --- a/spec/services/ci/process_pipeline_service_spec.rb +++ b/spec/services/ci/process_pipeline_service_spec.rb @@ -426,7 +426,9 @@ describe Ci::ProcessPipelineService, '#execute' do before do successful_build('test', stage_idx: 0) - allow_any_instance_of(Ci::PersistentRef).to receive(:delete_refs) { raise ArgumentError } + allow_next_instance_of(Ci::PersistentRef) do |instance| + allow(instance).to receive(:delete_refs) { raise ArgumentError } + end end it 'process the pipeline' do diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb index aa31d98c4fb..0339c6cc2d6 100644 --- a/spec/services/ci/register_job_service_spec.rb +++ b/spec/services/ci/register_job_service_spec.rb @@ -514,7 +514,7 @@ module Ci subject { execute(specific_runner, {}) } it 'does drop the build and logs both failures' do - expect(Gitlab::Sentry).to receive(:track_exception) + expect(Gitlab::ErrorTracking).to receive(:track_exception) .with(anything, a_hash_including(build_id: pending_job.id)) .twice .and_call_original @@ -540,7 +540,7 @@ module Ci subject { execute(specific_runner, {}) } it 'does drop the build and logs failure' do - expect(Gitlab::Sentry).to receive(:track_exception) + expect(Gitlab::ErrorTracking).to receive(:track_exception) .with(anything, a_hash_including(build_id: pending_job.id)) .once .and_call_original diff --git a/spec/services/clusters/applications/check_installation_progress_service_spec.rb b/spec/services/clusters/applications/check_installation_progress_service_spec.rb index 335397ee9f5..7b37eb97800 100644 --- a/spec/services/clusters/applications/check_installation_progress_service_spec.rb +++ b/spec/services/clusters/applications/check_installation_progress_service_spec.rb @@ -144,10 +144,9 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do end it 'removes the installation POD' do - expect_any_instance_of(Gitlab::Kubernetes::Helm::Api) - .to receive(:delete_pod!) - .with(kind_of(String)) - .once + expect_next_instance_of(Gitlab::Kubernetes::Helm::Api) do |instance| + expect(instance).to receive(:delete_pod!).with(kind_of(String)).once + end expect(service).to receive(:remove_installation_pod).and_call_original service.execute diff --git a/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb b/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb index a70b94a6fd6..93557c6b229 100644 --- a/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb +++ b/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb @@ -48,10 +48,9 @@ describe Clusters::Applications::CheckUninstallProgressService do let(:phase) { Gitlab::Kubernetes::Pod::SUCCEEDED } before do - expect_any_instance_of(Gitlab::Kubernetes::Helm::Api) - .to receive(:delete_pod!) - .with(kind_of(String)) - .once + expect_next_instance_of(Gitlab::Kubernetes::Helm::Api) do |instance| + expect(instance).to receive(:delete_pod!).with(kind_of(String)).once + end expect(service).to receive(:pod_phase).once.and_return(phase) end diff --git a/spec/services/clusters/gcp/verify_provision_status_service_spec.rb b/spec/services/clusters/gcp/verify_provision_status_service_spec.rb index 9611b2080ba..584f9b8367f 100644 --- a/spec/services/clusters/gcp/verify_provision_status_service_spec.rb +++ b/spec/services/clusters/gcp/verify_provision_status_service_spec.rb @@ -21,7 +21,9 @@ describe Clusters::Gcp::VerifyProvisionStatusService do shared_examples 'finalize_creation' do it 'schedules a worker for status minitoring' do - expect_any_instance_of(Clusters::Gcp::FinalizeCreationService).to receive(:execute) + expect_next_instance_of(Clusters::Gcp::FinalizeCreationService) do |instance| + expect(instance).to receive(:execute) + end described_class.new.execute(provider) end diff --git a/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb b/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb index 1f520c4849d..5dc4a1dc0b3 100644 --- a/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb +++ b/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb @@ -60,7 +60,9 @@ describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute' do end it 'creates project service account' do - expect_any_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService).to receive(:execute).once + expect_next_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService) do |instance| + expect(instance).to receive(:execute).once + end subject end @@ -127,7 +129,9 @@ describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute' do end it 'creates project service account' do - expect_any_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService).to receive(:execute).once + expect_next_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService) do |instance| + expect(instance).to receive(:execute).once + end subject end diff --git a/spec/services/discussions/resolve_service_spec.rb b/spec/services/discussions/resolve_service_spec.rb index 5b99430cb75..2e9a7a293d1 100644 --- a/spec/services/discussions/resolve_service_spec.rb +++ b/spec/services/discussions/resolve_service_spec.rb @@ -29,7 +29,9 @@ describe Discussions::ResolveService do end it 'executes the notification service' do - expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(discussion.noteable) + expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance| + expect(instance).to receive(:execute).with(discussion.noteable) + end service.execute(discussion) end diff --git a/spec/services/event_create_service_spec.rb b/spec/services/event_create_service_spec.rb index eb738ac80b1..a8ddca0cdf3 100644 --- a/spec/services/event_create_service_spec.rb +++ b/spec/services/event_create_service_spec.rb @@ -131,9 +131,9 @@ describe EventCreateService do end it 'caches the last push event for the user' do - expect_any_instance_of(Users::LastPushEventService) - .to receive(:cache_last_push_event) - .with(an_instance_of(PushEvent)) + expect_next_instance_of(Users::LastPushEventService) do |instance| + expect(instance).to receive(:cache_last_push_event).with(an_instance_of(PushEvent)) + end subject end diff --git a/spec/services/groups/destroy_service_spec.rb b/spec/services/groups/destroy_service_spec.rb index 055d0243d4b..a45c7cdffa6 100644 --- a/spec/services/groups/destroy_service_spec.rb +++ b/spec/services/groups/destroy_service_spec.rb @@ -41,7 +41,9 @@ describe Groups::DestroyService do let!(:chat_team) { create(:chat_team, namespace: group) } it 'destroys the team too' do - expect_any_instance_of(Mattermost::Team).to receive(:destroy) + expect_next_instance_of(Mattermost::Team) do |instance| + expect(instance).to receive(:destroy) + end destroy_group(group, user, async) end diff --git a/spec/services/groups/transfer_service_spec.rb b/spec/services/groups/transfer_service_spec.rb index 9a490dfd779..bbf5bbbf814 100644 --- a/spec/services/groups/transfer_service_spec.rb +++ b/spec/services/groups/transfer_service_spec.rb @@ -13,7 +13,9 @@ describe Groups::TransferService do let(:new_parent_group) { create(:group, :public) } before do - allow_any_instance_of(described_class).to receive(:update_group_attributes).and_raise(Gitlab::UpdatePathError, 'namespace directory cannot be moved') + allow_next_instance_of(described_class) do |instance| + allow(instance).to receive(:update_group_attributes).and_raise(Gitlab::UpdatePathError, 'namespace directory cannot be moved') + end create(:group_member, :owner, group: new_parent_group, user: user) end diff --git a/spec/services/issues/import_csv_service_spec.rb b/spec/services/issues/import_csv_service_spec.rb index 516a1137319..e7370407d4c 100644 --- a/spec/services/issues/import_csv_service_spec.rb +++ b/spec/services/issues/import_csv_service_spec.rb @@ -18,7 +18,9 @@ describe Issues::ImportCsvService do let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') } it 'returns invalid file error' do - expect_any_instance_of(Notify).to receive(:import_issues_csv_email) + expect_next_instance_of(Notify) do |instance| + expect(instance).to receive(:import_issues_csv_email) + end expect(subject[:success]).to eq(0) expect(subject[:parse_error]).to eq(true) @@ -29,7 +31,9 @@ describe Issues::ImportCsvService do let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') } it 'imports CSV without errors' do - expect_any_instance_of(Notify).to receive(:import_issues_csv_email) + expect_next_instance_of(Notify) do |instance| + expect(instance).to receive(:import_issues_csv_email) + end expect(subject[:success]).to eq(3) expect(subject[:error_lines]).to eq([]) @@ -41,7 +45,9 @@ describe Issues::ImportCsvService do let(:file) { fixture_file_upload('spec/fixtures/csv_tab.csv') } it 'imports CSV with some error rows' do - expect_any_instance_of(Notify).to receive(:import_issues_csv_email) + expect_next_instance_of(Notify) do |instance| + expect(instance).to receive(:import_issues_csv_email) + end expect(subject[:success]).to eq(2) expect(subject[:error_lines]).to eq([3]) @@ -53,7 +59,9 @@ describe Issues::ImportCsvService do let(:file) { fixture_file_upload('spec/fixtures/csv_semicolon.csv') } it 'imports CSV with a blank row' do - expect_any_instance_of(Notify).to receive(:import_issues_csv_email) + expect_next_instance_of(Notify) do |instance| + expect(instance).to receive(:import_issues_csv_email) + end expect(subject[:success]).to eq(3) expect(subject[:error_lines]).to eq([4]) diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb index e39af7bbb72..ee809aabac0 100644 --- a/spec/services/issues/move_service_spec.rb +++ b/spec/services/issues/move_service_spec.rb @@ -131,7 +131,9 @@ describe Issues::MoveService do let!(:hook) { create(:project_hook, project: old_project, issues_events: true) } it 'executes project issue hooks' do - allow_any_instance_of(WebHookService).to receive(:execute) + allow_next_instance_of(WebHookService) do |instance| + allow(instance).to receive(:execute) + end # Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1, # but since the entire spec run takes place in a transaction, we never diff --git a/spec/services/lfs/lock_file_service_spec.rb b/spec/services/lfs/lock_file_service_spec.rb index 15dbc3231a3..2bd62b96083 100644 --- a/spec/services/lfs/lock_file_service_spec.rb +++ b/spec/services/lfs/lock_file_service_spec.rb @@ -54,7 +54,9 @@ describe Lfs::LockFileService do context 'when an error is raised' do it "doesn't succeed" do - allow_any_instance_of(described_class).to receive(:create_lock!).and_raise(StandardError) + allow_next_instance_of(described_class) do |instance| + allow(instance).to receive(:create_lock!).and_raise(StandardError) + end expect(subject.execute[:status]).to eq(:error) end diff --git a/spec/services/lfs/locks_finder_service_spec.rb b/spec/services/lfs/locks_finder_service_spec.rb index 0fc2c593d94..fdc60e2c03f 100644 --- a/spec/services/lfs/locks_finder_service_spec.rb +++ b/spec/services/lfs/locks_finder_service_spec.rb @@ -91,7 +91,9 @@ describe Lfs::LocksFinderService do context 'when an error is raised' do it "doesn't succeed" do - allow_any_instance_of(described_class).to receive(:find_locks).and_raise(StandardError) + allow_next_instance_of(described_class) do |instance| + allow(instance).to receive(:find_locks).and_raise(StandardError) + end result = subject.execute diff --git a/spec/services/merge_requests/create_pipeline_service_spec.rb b/spec/services/merge_requests/create_pipeline_service_spec.rb index 576e8498e4d..25f5c54a413 100644 --- a/spec/services/merge_requests/create_pipeline_service_spec.rb +++ b/spec/services/merge_requests/create_pipeline_service_spec.rb @@ -62,13 +62,65 @@ describe MergeRequests::CreatePipelineService do end end - context 'when .gitlab-ci.yml does not have only: [merge_requests] keyword' do - let(:config) do - { rspec: { script: 'echo' } } + context 'when .gitlab-ci.yml does not use workflow:rules' do + context 'without only: [merge_requests] keyword' do + let(:config) do + { rspec: { script: 'echo' } } + end + + it 'does not create a pipeline' do + expect { subject }.not_to change { Ci::Pipeline.count } + end + end + + context 'with rules that specify creation on a tag' do + let(:config) do + { + rspec: { + script: 'echo', + rules: [{ if: '$CI_COMMIT_TAG' }] + } + } + end + + it 'does not create a pipeline' do + expect { subject }.not_to change { Ci::Pipeline.count } + end + end + end + + context 'when workflow:rules are specified' do + context 'when rules request creation on merge request' do + let(:config) do + { + workflow: { + rules: [{ if: '$CI_MERGE_REQUEST_ID' }] + }, + rspec: { script: 'echo' } + } + end + + it 'creates a detached merge request pipeline' do + expect { subject }.to change { Ci::Pipeline.count }.by(1) + + expect(subject).to be_persisted + expect(subject).to be_detached_merge_request_pipeline + end end - it 'does not create a pipeline' do - expect { subject }.not_to change { Ci::Pipeline.count } + context 'with rules do specify creation on a tag' do + let(:config) do + { + workflow: { + rules: [{ if: '$CI_COMMIT_TAG' }] + }, + rspec: { script: 'echo' } + } + end + + it 'does not create a pipeline' do + expect { subject }.not_to change { Ci::Pipeline.count } + end end end end diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb index 5a3796fec3d..fc01c93b5cf 100644 --- a/spec/services/projects/fork_service_spec.rb +++ b/spec/services/projects/fork_service_spec.rb @@ -6,6 +6,16 @@ describe Projects::ForkService do include ProjectForksHelper include Gitlab::ShellAdapter + shared_examples 'forks count cache refresh' do + it 'flushes the forks count cache of the source project', :clean_gitlab_redis_cache do + expect(from_project.forks_count).to be_zero + + fork_project(from_project, to_user) + + expect(from_project.forks_count).to eq(1) + end + end + context 'when forking a new project' do describe 'fork by user' do before do @@ -40,6 +50,11 @@ describe Projects::ForkService do end end + it_behaves_like 'forks count cache refresh' do + let(:from_project) { @from_project } + let(:to_user) { @to_user } + end + describe "successfully creates project in the user namespace" do let(:to_project) { fork_project(@from_project, @to_user, namespace: @to_user.namespace) } @@ -62,12 +77,9 @@ describe Projects::ForkService do expect(@from_project.avatar.file).to be_exists end - it 'flushes the forks count cache of the source project' do - expect(@from_project.forks_count).to be_zero - - fork_project(@from_project, @to_user) - - expect(@from_project.forks_count).to eq(1) + it_behaves_like 'forks count cache refresh' do + let(:from_project) { @from_project } + let(:to_user) { @to_user } end it 'creates a fork network with the new project and the root project set' do @@ -102,6 +114,11 @@ describe Projects::ForkService do it 'sets the forked_from_project on the membership' do expect(to_project.fork_network_member.forked_from_project).to eq(from_forked_project) end + + it_behaves_like 'forks count cache refresh' do + let(:from_project) { from_forked_project } + let(:to_user) { @to_user } + end end end diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index bb457217b3f..a952e26e338 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -467,7 +467,9 @@ describe SystemNoteService do before do allow(JIRA::Resource::Remotelink).to receive(:all).and_return([]) message = "[#{author.name}|http://localhost/#{author.username}] mentioned this issue in [a commit of #{project.full_path}|http://localhost/#{project.full_path}/commit/#{commit.id}]:\n'#{commit.title.chomp}'" - allow_any_instance_of(JIRA::Resource::Issue).to receive(:comments).and_return([OpenStruct.new(body: message)]) + allow_next_instance_of(JIRA::Resource::Issue) do |instance| + allow(instance).to receive(:comments).and_return([OpenStruct.new(body: message)]) + end end it "does not return success message" do |