diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-28 21:08:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-28 21:08:35 +0300 |
commit | 6315ed9630fb1c6ade3114beb762cd1568d79219 (patch) | |
tree | 2a5d31936d09c14420c8f4c8bd752e268f0eb19f /spec | |
parent | fedf978f9aa1909ed7bb3fad767ad120a1c6bd7b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/issues_controller_spec.rb | 3 | ||||
-rw-r--r-- | spec/features/broadcast_messages_spec.rb | 30 | ||||
-rw-r--r-- | spec/helpers/broadcast_messages_helper_spec.rb | 23 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/reports_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/database/migration_helpers_spec.rb | 362 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb | 15 | ||||
-rw-r--r-- | spec/lib/gitlab/git_access_spec.rb | 26 | ||||
-rw-r--r-- | spec/migrations/backfill_operations_feature_flags_iid_spec.rb | 34 | ||||
-rw-r--r-- | spec/migrations/delete_internal_ids_where_feature_flags_usage_spec.rb | 44 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 9 | ||||
-rw-r--r-- | spec/services/ci/retry_build_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/merge_requests/reload_diffs_service_spec.rb | 31 | ||||
-rw-r--r-- | spec/services/notes/create_service_spec.rb | 24 | ||||
-rw-r--r-- | spec/support/shared_examples/models/mentionable_shared_examples.rb | 10 |
14 files changed, 537 insertions, 77 deletions
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 7cdb8989692..e2ffc595c44 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -1129,8 +1129,9 @@ describe Projects::IssuesController do sign_in(user) end - it "rejects a developer to destroy an issue" do + it "does not delete the issue, returning :not_found" do delete :destroy, params: { namespace_id: project.namespace, project_id: project, id: issue.iid } + expect(response).to have_gitlab_http_status(:not_found) end end diff --git a/spec/features/broadcast_messages_spec.rb b/spec/features/broadcast_messages_spec.rb new file mode 100644 index 00000000000..43fbf1010c9 --- /dev/null +++ b/spec/features/broadcast_messages_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Broadcast Messages' do + let!(:broadcast_message) { create(:broadcast_message, broadcast_type: 'notification', message: 'SampleMessage') } + + it 'shows broadcast message' do + visit root_path + + expect(page).to have_content 'SampleMessage' + end + + it 'hides broadcast message after dismiss', :js do + visit root_path + + find('.js-dismiss-current-broadcast-notification').click + + expect(page).not_to have_content 'SampleMessage' + end + + it 'broadcast message is still hidden after refresh', :js do + visit root_path + + find('.js-dismiss-current-broadcast-notification').click + visit root_path + + expect(page).not_to have_content 'SampleMessage' + end +end diff --git a/spec/helpers/broadcast_messages_helper_spec.rb b/spec/helpers/broadcast_messages_helper_spec.rb index a0682c0e278..7e181e429d7 100644 --- a/spec/helpers/broadcast_messages_helper_spec.rb +++ b/spec/helpers/broadcast_messages_helper_spec.rb @@ -3,6 +3,29 @@ require 'spec_helper' describe BroadcastMessagesHelper do + describe 'current_broadcast_notification_message' do + subject { helper.current_broadcast_notification_message } + + context 'with available broadcast notification messages' do + let!(:broadcast_message_1) { create(:broadcast_message, broadcast_type: 'notification', starts_at: Time.now - 1.day) } + let!(:broadcast_message_2) { create(:broadcast_message, broadcast_type: 'notification', starts_at: Time.now) } + + it { is_expected.to eq broadcast_message_2 } + + context 'when last broadcast message is hidden' do + before do + helper.request.cookies["hide_broadcast_notification_message_#{broadcast_message_2.id}"] = 'true' + end + + it { is_expected.to eq broadcast_message_1 } + end + end + + context 'without broadcast notification messages' do + it { is_expected.to be_nil } + end + end + describe 'broadcast_message' do let(:current_broadcast_message) { BroadcastMessage.new(message: 'Current Message') } diff --git a/spec/lib/gitlab/ci/config/entry/reports_spec.rb b/spec/lib/gitlab/ci/config/entry/reports_spec.rb index 8562885c90c..1ec30976284 100644 --- a/spec/lib/gitlab/ci/config/entry/reports_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/reports_spec.rb @@ -43,6 +43,7 @@ describe Gitlab::Ci::Config::Entry::Reports do :license_management | 'gl-license-management-report.json' :license_scanning | 'gl-license-scanning-report.json' :performance | 'performance.json' + :lsif | 'lsif.sqlite3' end with_them do diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index f71d3a67eb9..3797e794985 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -1531,4 +1531,366 @@ describe Gitlab::Database::MigrationHelpers do expect(buffer.read).to include("\"class\":\"#{model.class}\"") end end + + describe '#backfill_iids' do + include MigrationsHelpers + + class self::Issue < ActiveRecord::Base + include AtomicInternalId + + self.table_name = 'issues' + self.inheritance_column = :_type_disabled + + belongs_to :project + + has_internal_id :iid, + scope: :project, + init: ->(s) { s&.project&.issues&.maximum(:iid) }, + backfill: true, + presence: false + end + + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:issues) { table(:issues) } + + def setup + namespace = namespaces.create!(name: 'foo', path: 'foo') + project = projects.create!(namespace_id: namespace.id) + + project + end + + it 'generates iids properly for models created after the migration' do + project = setup + + model.backfill_iids('issues') + + issue = self.class::Issue.create!(project_id: project.id) + + expect(issue.iid).to eq(1) + end + + it 'generates iids properly for models created after the migration when iids are backfilled' do + project = setup + issue_a = issues.create!(project_id: project.id) + + model.backfill_iids('issues') + + issue_b = self.class::Issue.create!(project_id: project.id) + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.iid).to eq(2) + end + + it 'generates iids properly for models created after the migration across multiple projects' do + project_a = setup + project_b = setup + issues.create!(project_id: project_a.id) + issues.create!(project_id: project_b.id) + issues.create!(project_id: project_b.id) + + model.backfill_iids('issues') + + issue_a = self.class::Issue.create!(project_id: project_a.id) + issue_b = self.class::Issue.create!(project_id: project_b.id) + + expect(issue_a.iid).to eq(2) + expect(issue_b.iid).to eq(3) + end + + context 'when the new code creates a row post deploy but before the migration runs' do + it 'does not change the row iid' do + project = setup + issue = self.class::Issue.create!(project_id: project.id) + + model.backfill_iids('issues') + + expect(issue.reload.iid).to eq(1) + end + + it 'backfills iids for rows already in the database' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = issues.create!(project_id: project.id) + issue_c = self.class::Issue.create!(project_id: project.id) + + model.backfill_iids('issues') + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_c.reload.iid).to eq(3) + end + + it 'backfills iids across multiple projects' do + project_a = setup + project_b = setup + issue_a = issues.create!(project_id: project_a.id) + issue_b = issues.create!(project_id: project_b.id) + issue_c = self.class::Issue.create!(project_id: project_a.id) + issue_d = self.class::Issue.create!(project_id: project_b.id) + + model.backfill_iids('issues') + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(1) + expect(issue_c.reload.iid).to eq(2) + expect(issue_d.reload.iid).to eq(2) + end + + it 'generates iids properly for models created after the migration' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = issues.create!(project_id: project.id) + issue_c = self.class::Issue.create!(project_id: project.id) + + model.backfill_iids('issues') + + issue_d = self.class::Issue.create!(project_id: project.id) + issue_e = self.class::Issue.create!(project_id: project.id) + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_c.reload.iid).to eq(3) + expect(issue_d.iid).to eq(4) + expect(issue_e.iid).to eq(5) + end + + it 'backfills iids and properly generates iids for new models across multiple projects' do + project_a = setup + project_b = setup + issue_a = issues.create!(project_id: project_a.id) + issue_b = issues.create!(project_id: project_b.id) + issue_c = self.class::Issue.create!(project_id: project_a.id) + issue_d = self.class::Issue.create!(project_id: project_b.id) + + model.backfill_iids('issues') + + issue_e = self.class::Issue.create!(project_id: project_a.id) + issue_f = self.class::Issue.create!(project_id: project_b.id) + issue_g = self.class::Issue.create!(project_id: project_a.id) + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(1) + expect(issue_c.reload.iid).to eq(2) + expect(issue_d.reload.iid).to eq(2) + expect(issue_e.iid).to eq(3) + expect(issue_f.iid).to eq(3) + expect(issue_g.iid).to eq(4) + end + end + + context 'when the new code creates a model and then old code creates a model post deploy but before the migration runs' do + it 'backfills iids' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = self.class::Issue.create!(project_id: project.id) + issue_c = issues.create!(project_id: project.id) + + model.backfill_iids('issues') + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_c.reload.iid).to eq(3) + end + + it 'generates an iid for a new model after the migration' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = issues.create!(project_id: project.id) + issue_c = self.class::Issue.create!(project_id: project.id) + issue_d = issues.create!(project_id: project.id) + + model.backfill_iids('issues') + + issue_e = self.class::Issue.create!(project_id: project.id) + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_c.reload.iid).to eq(3) + expect(issue_d.reload.iid).to eq(4) + expect(issue_e.iid).to eq(5) + end + end + + context 'when the new code and old code alternate creating models post deploy but before the migration runs' do + it 'backfills iids' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = self.class::Issue.create!(project_id: project.id) + issue_c = issues.create!(project_id: project.id) + issue_d = self.class::Issue.create!(project_id: project.id) + + model.backfill_iids('issues') + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_c.reload.iid).to eq(3) + expect(issue_d.reload.iid).to eq(4) + end + + it 'generates an iid for a new model after the migration' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = issues.create!(project_id: project.id) + issue_c = self.class::Issue.create!(project_id: project.id) + issue_d = issues.create!(project_id: project.id) + issue_e = self.class::Issue.create!(project_id: project.id) + + model.backfill_iids('issues') + + issue_f = self.class::Issue.create!(project_id: project.id) + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_c.reload.iid).to eq(3) + expect(issue_d.reload.iid).to eq(4) + expect(issue_e.reload.iid).to eq(5) + expect(issue_f.iid).to eq(6) + end + end + + context 'when the new code creates and deletes a model post deploy but before the migration runs' do + it 'backfills iids for rows already in the database' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = issues.create!(project_id: project.id) + issue_c = self.class::Issue.create!(project_id: project.id) + issue_c.delete + + model.backfill_iids('issues') + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + end + + it 'successfully creates a new model after the migration' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = issues.create!(project_id: project.id) + issue_c = self.class::Issue.create!(project_id: project.id) + issue_c.delete + + model.backfill_iids('issues') + + issue_d = self.class::Issue.create!(project_id: project.id) + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_d.iid).to eq(3) + end + end + + context 'when the new code creates and deletes a model and old code creates a model post deploy but before the migration runs' do + it 'backfills iids' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = issues.create!(project_id: project.id) + issue_c = self.class::Issue.create!(project_id: project.id) + issue_c.delete + issue_d = issues.create!(project_id: project.id) + + model.backfill_iids('issues') + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_d.reload.iid).to eq(3) + end + + it 'successfully creates a new model after the migration' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = issues.create!(project_id: project.id) + issue_c = self.class::Issue.create!(project_id: project.id) + issue_c.delete + issue_d = issues.create!(project_id: project.id) + + model.backfill_iids('issues') + + issue_e = self.class::Issue.create!(project_id: project.id) + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_d.reload.iid).to eq(3) + expect(issue_e.iid).to eq(4) + end + end + + context 'when the new code creates and deletes a model and then creates another model post deploy but before the migration runs' do + it 'successfully generates an iid for a new model after the migration' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = issues.create!(project_id: project.id) + issue_c = self.class::Issue.create!(project_id: project.id) + issue_c.delete + issue_d = self.class::Issue.create!(project_id: project.id) + + model.backfill_iids('issues') + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_d.reload.iid).to eq(3) + end + + it 'successfully generates an iid for a new model after the migration' do + project = setup + issue_a = issues.create!(project_id: project.id) + issue_b = issues.create!(project_id: project.id) + issue_c = self.class::Issue.create!(project_id: project.id) + issue_c.delete + issue_d = self.class::Issue.create!(project_id: project.id) + + model.backfill_iids('issues') + + issue_e = self.class::Issue.create!(project_id: project.id) + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + expect(issue_d.reload.iid).to eq(3) + expect(issue_e.iid).to eq(4) + end + end + + context 'when the first model is created for a project after the migration' do + it 'generates an iid' do + project_a = setup + project_b = setup + issue_a = issues.create!(project_id: project_a.id) + + model.backfill_iids('issues') + + issue_b = self.class::Issue.create!(project_id: project_b.id) + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(1) + end + end + + context 'when a row already has an iid set in the database' do + it 'backfills iids' do + project = setup + issue_a = issues.create!(project_id: project.id, iid: 1) + issue_b = issues.create!(project_id: project.id, iid: 2) + + model.backfill_iids('issues') + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(2) + end + + it 'backfills for multiple projects' do + project_a = setup + project_b = setup + issue_a = issues.create!(project_id: project_a.id, iid: 1) + issue_b = issues.create!(project_id: project_b.id, iid: 1) + issue_c = issues.create!(project_id: project_a.id, iid: 2) + + model.backfill_iids('issues') + + expect(issue_a.reload.iid).to eq(1) + expect(issue_b.reload.iid).to eq(1) + expect(issue_c.reload.iid).to eq(2) + end + end + end end diff --git a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb index a4f74ddc8c2..c2b6ca4164c 100644 --- a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb +++ b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb @@ -38,21 +38,6 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do let(:diffable) { merge_request.merge_request_diff } end - context 'using Gitlab::Diff::DeprecatedHighlightCache' do - before do - stub_feature_flags(hset_redis_diff_caching: false) - end - - it 'uses a different cache key if diff line keys change' do - mr_diff = described_class.new(merge_request.merge_request_diff, diff_options: nil) - key = mr_diff.cache_key - - stub_const('Gitlab::Diff::Line::SERIALIZE_KEYS', [:foo]) - - expect(mr_diff.cache_key).not_to eq(key) - end - end - it_behaves_like 'diff statistics' do let(:collection_default_args) do { diff_options: {} } diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index 36bde9de12d..231bcb4150c 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -75,6 +75,32 @@ describe Gitlab::GitAccess do end end + describe '#check_namespace!' do + context 'when namespace exists' do + before do + project.add_maintainer(user) + end + + it 'allows push and pull access' do + aggregate_failures do + expect { push_access_check }.not_to raise_error + expect { pull_access_check }.not_to raise_error + end + end + end + + context 'when namespace does not exist' do + let(:namespace_path) { nil } + + it 'does not allow push and pull access' do + aggregate_failures do + expect { push_access_check }.to raise_not_found + expect { pull_access_check }.to raise_not_found + end + end + end + end + describe '#check_project_accessibility!' do context 'when the project exists' do context 'when actor exists' do diff --git a/spec/migrations/backfill_operations_feature_flags_iid_spec.rb b/spec/migrations/backfill_operations_feature_flags_iid_spec.rb new file mode 100644 index 00000000000..f7a223e794a --- /dev/null +++ b/spec/migrations/backfill_operations_feature_flags_iid_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200117194850_backfill_operations_feature_flags_iid.rb') + +describe BackfillOperationsFeatureFlagsIid, :migration do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:flags) { table(:operations_feature_flags) } + + def setup + namespace = namespaces.create!(name: 'foo', path: 'foo') + project = projects.create!(namespace_id: namespace.id) + + project + end + + it 'migrates successfully when there are no flags in the database' do + setup + + disable_migrations_output { migrate! } + + expect(flags.count).to eq(0) + end + + it 'migrates successfully with a row in the table in both FOSS and EE' do + project = setup + flags.create!(project_id: project.id, active: true, name: 'test_flag') + + disable_migrations_output { migrate! } + + expect(flags.count).to eq(1) + end +end diff --git a/spec/migrations/delete_internal_ids_where_feature_flags_usage_spec.rb b/spec/migrations/delete_internal_ids_where_feature_flags_usage_spec.rb new file mode 100644 index 00000000000..b9c6b489aca --- /dev/null +++ b/spec/migrations/delete_internal_ids_where_feature_flags_usage_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200117194900_delete_internal_ids_where_feature_flags_usage') + +describe DeleteInternalIdsWhereFeatureFlagsUsage, :migration do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:internal_ids) { table(:internal_ids) } + + def setup + namespace = namespaces.create!(name: 'foo', path: 'foo') + project = projects.create!(namespace_id: namespace.id) + + project + end + + it 'deletes feature flag rows from the internal_ids table' do + project = setup + internal_ids.create!(project_id: project.id, usage: 6, last_value: 1) + + disable_migrations_output { migrate! } + + expect(internal_ids.count).to eq(0) + end + + it 'does not delete issue rows from the internal_ids table' do + project = setup + internal_ids.create!(project_id: project.id, usage: 0, last_value: 1) + + disable_migrations_output { migrate! } + + expect(internal_ids.count).to eq(1) + end + + it 'does not delete merge request rows from the internal_ids table' do + project = setup + internal_ids.create!(project_id: project.id, usage: 1, last_value: 1) + + disable_migrations_output { migrate! } + + expect(internal_ids.count).to eq(1) + end +end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 845c906129f..19a45ce5f88 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -2450,15 +2450,6 @@ describe Repository do 2.times { repository.ancestor?(commit.id, ancestor.id) } end - it 'increments a counter with cache hits' do - counter = Gitlab::Metrics.counter(:repository_ancestor_calls_total, 'Repository ancestor calls') - - expect do - 2.times { repository.ancestor?(commit.id, ancestor.id) } - end.to change { counter.get(cache_hit: 'true') }.by(1) - .and change { counter.get(cache_hit: 'false') }.by(1) - end - it 'returns the value from the request store' do repository.__send__(:request_store_cache).write(cache_key, "it's apparent") diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb index b3189974440..83df54bc2ff 100644 --- a/spec/services/ci/retry_build_service_spec.rb +++ b/spec/services/ci/retry_build_service_spec.rb @@ -33,7 +33,7 @@ describe Ci::RetryBuildService do job_artifacts_sast job_artifacts_dependency_scanning job_artifacts_container_scanning job_artifacts_dast job_artifacts_license_management job_artifacts_license_scanning - job_artifacts_performance + job_artifacts_performance job_artifacts_lsif job_artifacts_codequality job_artifacts_metrics scheduled_at job_variables waiting_for_resource_at job_artifacts_metrics_referee job_artifacts_network_referee].freeze diff --git a/spec/services/merge_requests/reload_diffs_service_spec.rb b/spec/services/merge_requests/reload_diffs_service_spec.rb index c450fc0a7dc..d2444af1b0f 100644 --- a/spec/services/merge_requests/reload_diffs_service_spec.rb +++ b/spec/services/merge_requests/reload_diffs_service_spec.rb @@ -33,34 +33,13 @@ describe MergeRequests::ReloadDiffsService, :use_clean_rails_memory_store_cachin end context 'cache clearing' do - context 'using Gitlab::Diff::DeprecatedHighlightCache' do - before do - stub_feature_flags(hset_redis_diff_caching: false) - end + it 'clears the cache for older diffs on the merge request' do + old_diff = merge_request.merge_request_diff + old_cache_key = old_diff.diffs_collection.cache_key - it 'clears the cache for older diffs on the merge request' do - old_diff = merge_request.merge_request_diff - old_cache_key = old_diff.diffs_collection.cache_key + expect_any_instance_of(Redis).to receive(:del).with(old_cache_key).and_call_original - expect(Rails.cache).to receive(:delete).with(old_cache_key).and_call_original - - subject.execute - end - end - - context 'using Gitlab::Diff::HighlightCache' do - before do - stub_feature_flags(hset_redis_diff_caching: true) - end - - it 'clears the cache for older diffs on the merge request' do - old_diff = merge_request.merge_request_diff - old_cache_key = old_diff.diffs_collection.cache_key - - expect_any_instance_of(Redis).to receive(:del).with(old_cache_key).and_call_original - - subject.execute - end + subject.execute end it 'avoids N+1 queries', :request_store do diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index c5e2fe8de12..7ba069d1e39 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -87,28 +87,10 @@ describe Notes::CreateService do .to receive(:unfolded_diff?) { true } end - context 'using Gitlab::Diff::DeprecatedHighlightCache' do - before do - stub_feature_flags(hset_redis_diff_caching: false) - end - - it 'clears noteable diff cache when it was unfolded for the note position' do - expect_any_instance_of(Gitlab::Diff::DeprecatedHighlightCache).to receive(:clear) - - described_class.new(project_with_repo, user, new_opts).execute - end - end + it 'clears noteable diff cache when it was unfolded for the note position' do + expect_any_instance_of(Gitlab::Diff::HighlightCache).to receive(:clear) - context 'using Gitlab::Diff::HighlightCache' do - before do - stub_feature_flags(hset_redis_diff_caching: true) - end - - it 'clears noteable diff cache when it was unfolded for the note position' do - expect_any_instance_of(Gitlab::Diff::HighlightCache).to receive(:clear) - - described_class.new(project_with_repo, user, new_opts).execute - end + described_class.new(project_with_repo, user, new_opts).execute end it 'does not clear cache when note is not the first of the discussion' do diff --git a/spec/support/shared_examples/models/mentionable_shared_examples.rb b/spec/support/shared_examples/models/mentionable_shared_examples.rb index 0c55e9de045..0e8ee6f66f5 100644 --- a/spec/support/shared_examples/models/mentionable_shared_examples.rb +++ b/spec/support/shared_examples/models/mentionable_shared_examples.rb @@ -229,16 +229,17 @@ RSpec.shared_examples 'mentions in description' do |mentionable_type| context 'when mentionable description contains mentions' do let(:user) { create(:user) } + let(:user2) { create(:user) } let(:group) { create(:group) } - let(:mentionable_desc) { "#{user.to_reference} some description #{group.to_reference(full: true)} and @all" } + let(:mentionable_desc) { "#{user.to_reference} #{user2.to_reference} #{user.to_reference} some description #{group.to_reference(full: true)} and #{user2.to_reference} @all" } let(:mentionable) { create(mentionable_type, description: mentionable_desc) } it 'stores mentions' do add_member(user) expect(mentionable.user_mentions.count).to eq 1 - expect(mentionable.referenced_users).to match_array([user]) + expect(mentionable.referenced_users).to match_array([user, user2]) expect(mentionable.referenced_projects(user)).to match_array([mentionable.project].compact) # epic.project is nil, and we want empty [] expect(mentionable.referenced_groups(user)).to match_array([group]) end @@ -249,8 +250,9 @@ end RSpec.shared_examples 'mentions in notes' do |mentionable_type| context 'when mentionable notes contain mentions' do let(:user) { create(:user) } + let(:user2) { create(:user) } let(:group) { create(:group) } - let(:note_desc) { "#{user.to_reference} and #{group.to_reference(full: true)} and @all" } + let(:note_desc) { "#{user.to_reference} #{user2.to_reference} #{user.to_reference} and #{group.to_reference(full: true)} and #{user2.to_reference} @all" } let!(:mentionable) { note.noteable } before do @@ -261,7 +263,7 @@ RSpec.shared_examples 'mentions in notes' do |mentionable_type| it 'returns all mentionable mentions' do expect(mentionable.user_mentions.count).to eq 1 - expect(mentionable.referenced_users).to eq [user] + expect(mentionable.referenced_users).to eq [user, user2] expect(mentionable.referenced_projects(user)).to eq [mentionable.project].compact # epic.project is nil, and we want empty [] expect(mentionable.referenced_groups(user)).to eq [group] end |