summaryrefslogtreecommitdiff
path: root/spec/models/concerns
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/models/concerns
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/models/concerns')
-rw-r--r--spec/models/concerns/access_requestable_spec.rb2
-rw-r--r--spec/models/concerns/approvable_base_spec.rb34
-rw-r--r--spec/models/concerns/atomic_internal_id_spec.rb2
-rw-r--r--spec/models/concerns/avatarable_spec.rb2
-rw-r--r--spec/models/concerns/awardable_spec.rb2
-rw-r--r--spec/models/concerns/batch_destroy_dependent_associations_spec.rb2
-rw-r--r--spec/models/concerns/blob_language_from_git_attributes_spec.rb2
-rw-r--r--spec/models/concerns/blocks_json_serialization_spec.rb2
-rw-r--r--spec/models/concerns/bulk_insert_safe_spec.rb179
-rw-r--r--spec/models/concerns/bulk_insertable_associations_spec.rb2
-rw-r--r--spec/models/concerns/cache_markdown_field_spec.rb2
-rw-r--r--spec/models/concerns/cacheable_attributes_spec.rb2
-rw-r--r--spec/models/concerns/case_sensitivity_spec.rb2
-rw-r--r--spec/models/concerns/checksummable_spec.rb2
-rw-r--r--spec/models/concerns/chronic_duration_attribute_spec.rb8
-rw-r--r--spec/models/concerns/ci/has_ref_spec.rb2
-rw-r--r--spec/models/concerns/ci/has_status_spec.rb (renamed from spec/models/concerns/has_status_spec.rb)2
-rw-r--r--spec/models/concerns/ci/has_variable_spec.rb2
-rw-r--r--spec/models/concerns/ci/maskable_spec.rb2
-rw-r--r--spec/models/concerns/delete_with_limit_spec.rb2
-rw-r--r--spec/models/concerns/deployment_platform_spec.rb237
-rw-r--r--spec/models/concerns/deprecated_assignee_spec.rb2
-rw-r--r--spec/models/concerns/discussion_on_diff_spec.rb2
-rw-r--r--spec/models/concerns/each_batch_spec.rb2
-rw-r--r--spec/models/concerns/editable_spec.rb2
-rw-r--r--spec/models/concerns/expirable_spec.rb2
-rw-r--r--spec/models/concerns/faster_cache_keys_spec.rb2
-rw-r--r--spec/models/concerns/featurable_spec.rb2
-rw-r--r--spec/models/concerns/feature_gate_spec.rb2
-rw-r--r--spec/models/concerns/from_union_spec.rb2
-rw-r--r--spec/models/concerns/group_descendant_spec.rb2
-rw-r--r--spec/models/concerns/has_environment_scope_spec.rb2
-rw-r--r--spec/models/concerns/has_user_type_spec.rb2
-rw-r--r--spec/models/concerns/ignorable_columns_spec.rb2
-rw-r--r--spec/models/concerns/issuable_spec.rb23
-rw-r--r--spec/models/concerns/limitable_spec.rb2
-rw-r--r--spec/models/concerns/loaded_in_group_list_spec.rb2
-rw-r--r--spec/models/concerns/manual_inverse_association_spec.rb2
-rw-r--r--spec/models/concerns/mentionable_spec.rb14
-rw-r--r--spec/models/concerns/milestoneable_spec.rb2
-rw-r--r--spec/models/concerns/milestoneish_spec.rb2
-rw-r--r--spec/models/concerns/noteable_spec.rb42
-rw-r--r--spec/models/concerns/optionally_search_spec.rb2
-rw-r--r--spec/models/concerns/participable_spec.rb2
-rw-r--r--spec/models/concerns/partitioned_table_spec.rb35
-rw-r--r--spec/models/concerns/presentable_spec.rb2
-rw-r--r--spec/models/concerns/project_api_compatibility_spec.rb2
-rw-r--r--spec/models/concerns/project_features_compatibility_spec.rb2
-rw-r--r--spec/models/concerns/prometheus_adapter_spec.rb2
-rw-r--r--spec/models/concerns/protected_ref_access_spec.rb2
-rw-r--r--spec/models/concerns/reactive_caching_spec.rb36
-rw-r--r--spec/models/concerns/redactable_spec.rb2
-rw-r--r--spec/models/concerns/redis_cacheable_spec.rb2
-rw-r--r--spec/models/concerns/resolvable_discussion_spec.rb2
-rw-r--r--spec/models/concerns/resolvable_note_spec.rb2
-rw-r--r--spec/models/concerns/routable_spec.rb4
-rw-r--r--spec/models/concerns/safe_url_spec.rb2
-rw-r--r--spec/models/concerns/schedulable_spec.rb2
-rw-r--r--spec/models/concerns/sha256_attribute_spec.rb2
-rw-r--r--spec/models/concerns/sha_attribute_spec.rb2
-rw-r--r--spec/models/concerns/sortable_spec.rb2
-rw-r--r--spec/models/concerns/spammable_spec.rb2
-rw-r--r--spec/models/concerns/stepable_spec.rb2
-rw-r--r--spec/models/concerns/strip_attribute_spec.rb2
-rw-r--r--spec/models/concerns/subscribable_spec.rb2
-rw-r--r--spec/models/concerns/token_authenticatable_spec.rb10
-rw-r--r--spec/models/concerns/token_authenticatable_strategies/base_spec.rb2
-rw-r--r--spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb2
-rw-r--r--spec/models/concerns/uniquify_spec.rb2
-rw-r--r--spec/models/concerns/usage_statistics_spec.rb2
-rw-r--r--spec/models/concerns/where_composite_spec.rb2
-rw-r--r--spec/models/concerns/x509_serial_number_attribute_spec.rb2
72 files changed, 553 insertions, 191 deletions
diff --git a/spec/models/concerns/access_requestable_spec.rb b/spec/models/concerns/access_requestable_spec.rb
index 5c1694e3737..24eb3e8a1e6 100644
--- a/spec/models/concerns/access_requestable_spec.rb
+++ b/spec/models/concerns/access_requestable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe AccessRequestable do
+RSpec.describe AccessRequestable do
describe 'Group' do
describe '#request_access' do
let(:group) { create(:group, :public) }
diff --git a/spec/models/concerns/approvable_base_spec.rb b/spec/models/concerns/approvable_base_spec.rb
new file mode 100644
index 00000000000..8fda8bccf09
--- /dev/null
+++ b/spec/models/concerns/approvable_base_spec.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ApprovableBase do
+ describe '#approved_by?' do
+ let(:merge_request) { create(:merge_request) }
+ let(:user) { create(:user) }
+
+ subject { merge_request.approved_by?(user) }
+
+ context 'when a user has not approved' do
+ it 'returns false' do
+ is_expected.to be_falsy
+ end
+ end
+
+ context 'when a user has approved' do
+ let!(:approval) { create(:approval, merge_request: merge_request, user: user) }
+
+ it 'returns false' do
+ is_expected.to be_truthy
+ end
+ end
+
+ context 'when a user is nil' do
+ let(:user) { nil }
+
+ it 'returns false' do
+ is_expected.to be_falsy
+ end
+ end
+ end
+end
diff --git a/spec/models/concerns/atomic_internal_id_spec.rb b/spec/models/concerns/atomic_internal_id_spec.rb
index 93bf7ec10dd..8c3537f1dcc 100644
--- a/spec/models/concerns/atomic_internal_id_spec.rb
+++ b/spec/models/concerns/atomic_internal_id_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe AtomicInternalId do
+RSpec.describe AtomicInternalId do
let(:milestone) { build(:milestone) }
let(:iid) { double('iid', to_i: 42) }
let(:external_iid) { 100 }
diff --git a/spec/models/concerns/avatarable_spec.rb b/spec/models/concerns/avatarable_spec.rb
index 96e867dbc97..8a8eeea39dc 100644
--- a/spec/models/concerns/avatarable_spec.rb
+++ b/spec/models/concerns/avatarable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Avatarable do
+RSpec.describe Avatarable do
let(:project) { create(:project, :with_avatar) }
let(:gitlab_host) { "https://gitlab.example.com" }
diff --git a/spec/models/concerns/awardable_spec.rb b/spec/models/concerns/awardable_spec.rb
index 29f911fcb04..b5b3772ecb6 100644
--- a/spec/models/concerns/awardable_spec.rb
+++ b/spec/models/concerns/awardable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Awardable do
+RSpec.describe Awardable do
let!(:issue) { create(:issue) }
let!(:award_emoji) { create(:award_emoji, :downvote, awardable: issue) }
diff --git a/spec/models/concerns/batch_destroy_dependent_associations_spec.rb b/spec/models/concerns/batch_destroy_dependent_associations_spec.rb
index d2373926802..a8fcb714c64 100644
--- a/spec/models/concerns/batch_destroy_dependent_associations_spec.rb
+++ b/spec/models/concerns/batch_destroy_dependent_associations_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe BatchDestroyDependentAssociations do
+RSpec.describe BatchDestroyDependentAssociations do
class TestProject < ActiveRecord::Base
self.table_name = 'projects'
diff --git a/spec/models/concerns/blob_language_from_git_attributes_spec.rb b/spec/models/concerns/blob_language_from_git_attributes_spec.rb
index 4cb8f042b1d..c07ee15e841 100644
--- a/spec/models/concerns/blob_language_from_git_attributes_spec.rb
+++ b/spec/models/concerns/blob_language_from_git_attributes_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe BlobLanguageFromGitAttributes do
+RSpec.describe BlobLanguageFromGitAttributes do
include FakeBlobHelpers
let(:project) { build(:project, :repository) }
diff --git a/spec/models/concerns/blocks_json_serialization_spec.rb b/spec/models/concerns/blocks_json_serialization_spec.rb
index 32870461019..d811b47fa35 100644
--- a/spec/models/concerns/blocks_json_serialization_spec.rb
+++ b/spec/models/concerns/blocks_json_serialization_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe BlocksJsonSerialization do
+RSpec.describe BlocksJsonSerialization do
before do
stub_const('DummyModel', Class.new)
DummyModel.class_eval do
diff --git a/spec/models/concerns/bulk_insert_safe_spec.rb b/spec/models/concerns/bulk_insert_safe_spec.rb
index 07d6cee487f..82b0c00b396 100644
--- a/spec/models/concerns/bulk_insert_safe_spec.rb
+++ b/spec/models/concerns/bulk_insert_safe_spec.rb
@@ -2,57 +2,7 @@
require 'spec_helper'
-describe BulkInsertSafe do
- class BulkInsertItem < ActiveRecord::Base
- include BulkInsertSafe
- include ShaAttribute
-
- validates :name, :enum_value, :secret_value, :sha_value, :jsonb_value, presence: true
-
- ENUM_VALUES = {
- case_1: 1
- }.freeze
-
- sha_attribute :sha_value
-
- enum enum_value: ENUM_VALUES
-
- attr_encrypted :secret_value,
- mode: :per_attribute_iv,
- algorithm: 'aes-256-gcm',
- key: Settings.attr_encrypted_db_key_base_32,
- insecure_mode: false
-
- default_value_for :enum_value, 'case_1'
- default_value_for :secret_value, 'my-secret'
- default_value_for :sha_value, '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12'
- default_value_for :jsonb_value, { "key" => "value" }
-
- def self.valid_list(count)
- Array.new(count) { |n| new(name: "item-#{n}") }
- end
-
- def self.invalid_list(count)
- Array.new(count) { new }
- end
- end
-
- module InheritedUnsafeMethods
- extend ActiveSupport::Concern
-
- included do
- after_save -> { "unsafe" }
- end
- end
-
- module InheritedSafeMethods
- extend ActiveSupport::Concern
-
- included do
- after_initialize -> { "safe" }
- end
- end
-
+RSpec.describe BulkInsertSafe do
before(:all) do
ActiveRecord::Schema.define do
create_table :bulk_insert_items, force: true do |t|
@@ -66,100 +16,155 @@ describe BulkInsertSafe do
t.index :name, unique: true
end
end
-
- BulkInsertItem.reset_column_information
end
after(:all) do
ActiveRecord::Schema.define do
drop_table :bulk_insert_items, force: true
end
+ end
+
+ let_it_be(:bulk_insert_item_class) do
+ Class.new(ActiveRecord::Base) do
+ self.table_name = 'bulk_insert_items'
- BulkInsertItem.reset_column_information
+ include BulkInsertSafe
+ include ShaAttribute
+
+ validates :name, :enum_value, :secret_value, :sha_value, :jsonb_value, presence: true
+
+ sha_attribute :sha_value
+
+ enum enum_value: { case_1: 1 }
+
+ attr_encrypted :secret_value,
+ mode: :per_attribute_iv,
+ algorithm: 'aes-256-gcm',
+ key: Settings.attr_encrypted_db_key_base_32,
+ insecure_mode: false
+
+ default_value_for :enum_value, 'case_1'
+ default_value_for :secret_value, 'my-secret'
+ default_value_for :sha_value, '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12'
+ default_value_for :jsonb_value, { "key" => "value" }
+
+ def self.name
+ 'BulkInsertItem'
+ end
+
+ def self.valid_list(count)
+ Array.new(count) { |n| new(name: "item-#{n}") }
+ end
+
+ def self.invalid_list(count)
+ Array.new(count) { new }
+ end
+ end
end
- describe BulkInsertItem do
- it_behaves_like 'a BulkInsertSafe model', described_class do
- let(:valid_items_for_bulk_insertion) { described_class.valid_list(10) }
- let(:invalid_items_for_bulk_insertion) { described_class.invalid_list(10) }
+ describe 'BulkInsertItem' do
+ it_behaves_like 'a BulkInsertSafe model' do
+ let(:target_class) { bulk_insert_item_class.dup }
+ let(:valid_items_for_bulk_insertion) { target_class.valid_list(10) }
+ let(:invalid_items_for_bulk_insertion) { target_class.invalid_list(10) }
end
context 'when inheriting class methods' do
+ let(:inherited_unsafe_methods_module) do
+ Module.new do
+ extend ActiveSupport::Concern
+
+ included do
+ after_save -> { "unsafe" }
+ end
+ end
+ end
+
+ let(:inherited_safe_methods_module) do
+ Module.new do
+ extend ActiveSupport::Concern
+
+ included do
+ after_initialize -> { "safe" }
+ end
+ end
+ end
+
it 'raises an error when method is not bulk-insert safe' do
- expect { described_class.include(InheritedUnsafeMethods) }
- .to raise_error(described_class::MethodNotAllowedError)
+ expect { bulk_insert_item_class.include(inherited_unsafe_methods_module) }
+ .to raise_error(bulk_insert_item_class::MethodNotAllowedError)
end
it 'does not raise an error when method is bulk-insert safe' do
- expect { described_class.include(InheritedSafeMethods) }.not_to raise_error
+ expect { bulk_insert_item_class.include(inherited_safe_methods_module) }.not_to raise_error
end
end
context 'primary keys' do
it 'raises error if primary keys are set prior to insertion' do
- item = described_class.new(name: 'valid', id: 10)
+ item = bulk_insert_item_class.new(name: 'valid', id: 10)
- expect { described_class.bulk_insert!([item]) }
- .to raise_error(described_class::PrimaryKeySetError)
+ expect { bulk_insert_item_class.bulk_insert!([item]) }
+ .to raise_error(bulk_insert_item_class::PrimaryKeySetError)
end
end
describe '.bulk_insert!' do
it 'inserts items in the given number of batches' do
- items = described_class.valid_list(10)
+ items = bulk_insert_item_class.valid_list(10)
expect(ActiveRecord::InsertAll).to receive(:new).twice.and_call_original
- described_class.bulk_insert!(items, batch_size: 5)
+ bulk_insert_item_class.bulk_insert!(items, batch_size: 5)
end
it 'items can be properly fetched from database' do
- items = described_class.valid_list(10)
+ items = bulk_insert_item_class.valid_list(10)
- described_class.bulk_insert!(items)
+ bulk_insert_item_class.bulk_insert!(items)
- attribute_names = described_class.attribute_names - %w[id created_at updated_at]
- expect(described_class.last(items.size).pluck(*attribute_names)).to eq(
+ attribute_names = bulk_insert_item_class.attribute_names - %w[id created_at updated_at]
+ expect(bulk_insert_item_class.last(items.size).pluck(*attribute_names)).to eq(
items.pluck(*attribute_names))
end
it 'rolls back the transaction when any item is invalid' do
# second batch is bad
- all_items = described_class.valid_list(10) +
- described_class.invalid_list(10)
+ all_items = bulk_insert_item_class.valid_list(10) +
+ bulk_insert_item_class.invalid_list(10)
expect do
- described_class.bulk_insert!(all_items, batch_size: 2) rescue nil
- end.not_to change { described_class.count }
+ bulk_insert_item_class.bulk_insert!(all_items, batch_size: 2) rescue nil
+ end.not_to change { bulk_insert_item_class.count }
end
it 'does nothing and returns an empty array when items are empty' do
- expect(described_class.bulk_insert!([])).to eq([])
- expect(described_class.count).to eq(0)
+ expect(bulk_insert_item_class.bulk_insert!([])).to eq([])
+ expect(bulk_insert_item_class.count).to eq(0)
end
context 'with returns option set' do
context 'when is set to :ids' do
it 'return an array with the primary key values for all inserted records' do
- items = described_class.valid_list(1)
+ items = bulk_insert_item_class.valid_list(1)
- expect(described_class.bulk_insert!(items, returns: :ids)).to contain_exactly(a_kind_of(Integer))
+ expect(bulk_insert_item_class.bulk_insert!(items, returns: :ids)).to contain_exactly(a_kind_of(Integer))
end
end
context 'when is set to nil' do
it 'returns an empty array' do
- items = described_class.valid_list(1)
+ items = bulk_insert_item_class.valid_list(1)
- expect(described_class.bulk_insert!(items, returns: nil)).to eq([])
+ expect(bulk_insert_item_class.bulk_insert!(items, returns: nil)).to eq([])
end
end
context 'when is set to anything else' do
it 'raises an error' do
- items = described_class.valid_list(1)
+ items = bulk_insert_item_class.valid_list(1)
- expect { described_class.bulk_insert!([items], returns: [:id, :name]) }
+ expect { bulk_insert_item_class.bulk_insert!([items], returns: [:id, :name]) }
.to raise_error(ArgumentError, "returns needs to be :ids or nil")
end
end
@@ -167,20 +172,20 @@ describe BulkInsertSafe do
end
context 'when duplicate items are to be inserted' do
- let!(:existing_object) { described_class.create!(name: 'duplicate', secret_value: 'old value') }
- let(:new_object) { described_class.new(name: 'duplicate', secret_value: 'new value') }
+ let!(:existing_object) { bulk_insert_item_class.create!(name: 'duplicate', secret_value: 'old value') }
+ let(:new_object) { bulk_insert_item_class.new(name: 'duplicate', secret_value: 'new value') }
describe '.bulk_insert!' do
context 'when skip_duplicates is set to false' do
it 'raises an exception' do
- expect { described_class.bulk_insert!([new_object], skip_duplicates: false) }
+ expect { bulk_insert_item_class.bulk_insert!([new_object], skip_duplicates: false) }
.to raise_error(ActiveRecord::RecordNotUnique)
end
end
context 'when skip_duplicates is set to true' do
it 'does not update existing object' do
- described_class.bulk_insert!([new_object], skip_duplicates: true)
+ bulk_insert_item_class.bulk_insert!([new_object], skip_duplicates: true)
expect(existing_object.reload.secret_value).to eq('old value')
end
@@ -189,7 +194,7 @@ describe BulkInsertSafe do
describe '.bulk_upsert!' do
it 'updates existing object' do
- described_class.bulk_upsert!([new_object], unique_by: %w[name])
+ bulk_insert_item_class.bulk_upsert!([new_object], unique_by: %w[name])
expect(existing_object.reload.secret_value).to eq('new value')
end
diff --git a/spec/models/concerns/bulk_insertable_associations_spec.rb b/spec/models/concerns/bulk_insertable_associations_spec.rb
index 6359b2c57ef..5a40639e493 100644
--- a/spec/models/concerns/bulk_insertable_associations_spec.rb
+++ b/spec/models/concerns/bulk_insertable_associations_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe BulkInsertableAssociations do
+RSpec.describe BulkInsertableAssociations do
class BulkFoo < ApplicationRecord
include BulkInsertSafe
diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb
index c46ebcf324c..5f8c65e429e 100644
--- a/spec/models/concerns/cache_markdown_field_spec.rb
+++ b/spec/models/concerns/cache_markdown_field_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe CacheMarkdownField, :clean_gitlab_redis_cache do
+RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do
let(:ar_class) do
Class.new(ActiveRecord::Base) do
self.table_name = 'issues'
diff --git a/spec/models/concerns/cacheable_attributes_spec.rb b/spec/models/concerns/cacheable_attributes_spec.rb
index 6694b2aba22..f2877bed9cf 100644
--- a/spec/models/concerns/cacheable_attributes_spec.rb
+++ b/spec/models/concerns/cacheable_attributes_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe CacheableAttributes do
+RSpec.describe CacheableAttributes do
let(:minimal_test_class) do
Class.new do
include ActiveModel::Model
diff --git a/spec/models/concerns/case_sensitivity_spec.rb b/spec/models/concerns/case_sensitivity_spec.rb
index 9819f656f0d..521b47c63fd 100644
--- a/spec/models/concerns/case_sensitivity_spec.rb
+++ b/spec/models/concerns/case_sensitivity_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe CaseSensitivity do
+RSpec.describe CaseSensitivity do
describe '.iwhere' do
let(:connection) { ActiveRecord::Base.connection }
let(:model) do
diff --git a/spec/models/concerns/checksummable_spec.rb b/spec/models/concerns/checksummable_spec.rb
index 017077bd297..b469b2e5c18 100644
--- a/spec/models/concerns/checksummable_spec.rb
+++ b/spec/models/concerns/checksummable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Checksummable do
+RSpec.describe Checksummable do
describe ".hexdigest" do
let(:fake_class) do
Class.new do
diff --git a/spec/models/concerns/chronic_duration_attribute_spec.rb b/spec/models/concerns/chronic_duration_attribute_spec.rb
index e41d75568f7..e6dbf403b63 100644
--- a/spec/models/concerns/chronic_duration_attribute_spec.rb
+++ b/spec/models/concerns/chronic_duration_attribute_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-shared_examples 'ChronicDurationAttribute reader' do
+RSpec.shared_examples 'ChronicDurationAttribute reader' do
it 'contains dynamically created reader method' do
expect(subject.class).to be_public_method_defined(virtual_field)
end
@@ -22,7 +22,7 @@ shared_examples 'ChronicDurationAttribute reader' do
end
end
-shared_examples 'ChronicDurationAttribute writer' do
+RSpec.shared_examples 'ChronicDurationAttribute writer' do
it 'contains dynamically created writer method' do
expect(subject.class).to be_public_method_defined("#{virtual_field}=")
end
@@ -94,7 +94,7 @@ shared_examples 'ChronicDurationAttribute writer' do
end
end
-describe 'ChronicDurationAttribute' do
+RSpec.describe 'ChronicDurationAttribute' do
context 'when default value is not set' do
let(:source_field) {:maximum_timeout}
let(:virtual_field) {:maximum_timeout_human_readable}
@@ -118,7 +118,7 @@ describe 'ChronicDurationAttribute' do
end
end
-describe 'ChronicDurationAttribute - reader' do
+RSpec.describe 'ChronicDurationAttribute - reader' do
let(:source_field) {:timeout}
let(:virtual_field) {:timeout_human_readable}
diff --git a/spec/models/concerns/ci/has_ref_spec.rb b/spec/models/concerns/ci/has_ref_spec.rb
index b98f915018b..69f2fdb21e1 100644
--- a/spec/models/concerns/ci/has_ref_spec.rb
+++ b/spec/models/concerns/ci/has_ref_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::HasRef do
+RSpec.describe Ci::HasRef do
describe '#branch?' do
let(:build) { create(:ci_build) }
diff --git a/spec/models/concerns/has_status_spec.rb b/spec/models/concerns/ci/has_status_spec.rb
index 68047f24ec3..fe46b63781d 100644
--- a/spec/models/concerns/has_status_spec.rb
+++ b/spec/models/concerns/ci/has_status_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe HasStatus do
+RSpec.describe Ci::HasStatus do
describe '.slow_composite_status' do
using RSpec::Parameterized::TableSyntax
diff --git a/spec/models/concerns/ci/has_variable_spec.rb b/spec/models/concerns/ci/has_variable_spec.rb
index c132fe47c3c..b5390281064 100644
--- a/spec/models/concerns/ci/has_variable_spec.rb
+++ b/spec/models/concerns/ci/has_variable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::HasVariable do
+RSpec.describe Ci::HasVariable do
subject { build(:ci_variable) }
it { is_expected.to validate_presence_of(:key) }
diff --git a/spec/models/concerns/ci/maskable_spec.rb b/spec/models/concerns/ci/maskable_spec.rb
index 01861b39165..840a08b6060 100644
--- a/spec/models/concerns/ci/maskable_spec.rb
+++ b/spec/models/concerns/ci/maskable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::Maskable do
+RSpec.describe Ci::Maskable do
let(:variable) { build(:ci_variable) }
describe 'masked value validations' do
diff --git a/spec/models/concerns/delete_with_limit_spec.rb b/spec/models/concerns/delete_with_limit_spec.rb
index 52085f970f3..0259a1ea4fb 100644
--- a/spec/models/concerns/delete_with_limit_spec.rb
+++ b/spec/models/concerns/delete_with_limit_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe DeleteWithLimit do
+RSpec.describe DeleteWithLimit do
describe '.delete_with_limit' do
it 'deletes a limited amount of rows' do
create_list(:web_hook_log, 4)
diff --git a/spec/models/concerns/deployment_platform_spec.rb b/spec/models/concerns/deployment_platform_spec.rb
index 9164c3a75c5..2bb6aa27e21 100644
--- a/spec/models/concerns/deployment_platform_spec.rb
+++ b/spec/models/concerns/deployment_platform_spec.rb
@@ -2,12 +2,247 @@
require 'spec_helper'
-describe DeploymentPlatform do
+RSpec.describe DeploymentPlatform do
let(:project) { create(:project) }
describe '#deployment_platform' do
subject { project.deployment_platform }
+ context 'multiple clusters' do
+ let(:group) { create(:group) }
+ let(:project) { create(:project, group: group) }
+
+ shared_examples 'matching environment scope' do
+ it 'returns environment specific cluster' do
+ is_expected.to eq(cluster.platform_kubernetes)
+ end
+ end
+
+ shared_examples 'not matching environment scope' do
+ it 'returns default cluster' do
+ is_expected.to eq(default_cluster.platform_kubernetes)
+ end
+ end
+
+ context 'multiple clusters use the same management project' do
+ let(:management_project) { create(:project, group: group) }
+
+ let!(:default_cluster) do
+ create(:cluster_for_group, groups: [group], environment_scope: '*', management_project: management_project)
+ end
+
+ let!(:cluster) do
+ create(:cluster_for_group, groups: [group], environment_scope: 'review/*', management_project: management_project)
+ end
+
+ let(:environment) { 'review/name' }
+
+ subject { management_project.deployment_platform(environment: environment) }
+
+ it_behaves_like 'matching environment scope'
+ end
+
+ context 'when project does not have a cluster but has group clusters' do
+ let!(:default_cluster) do
+ create(:cluster, :provided_by_user,
+ cluster_type: :group_type, groups: [group], environment_scope: '*')
+ end
+
+ let!(:cluster) do
+ create(:cluster, :provided_by_user,
+ cluster_type: :group_type, environment_scope: 'review/*', groups: [group])
+ end
+
+ let(:environment) { 'review/name' }
+
+ subject { project.deployment_platform(environment: environment) }
+
+ context 'when environment scope is exactly matched' do
+ before do
+ cluster.update!(environment_scope: 'review/name')
+ end
+
+ it_behaves_like 'matching environment scope'
+ end
+
+ context 'when environment scope is matched by wildcard' do
+ before do
+ cluster.update!(environment_scope: 'review/*')
+ end
+
+ it_behaves_like 'matching environment scope'
+ end
+
+ context 'when environment scope does not match' do
+ before do
+ cluster.update!(environment_scope: 'review/*/special')
+ end
+
+ it_behaves_like 'not matching environment scope'
+ end
+
+ context 'when group belongs to a parent group' do
+ let(:parent_group) { create(:group) }
+ let(:group) { create(:group, parent: parent_group) }
+
+ context 'when parent_group has a cluster with default scope' do
+ let!(:parent_group_cluster) do
+ create(:cluster, :provided_by_user,
+ cluster_type: :group_type, environment_scope: '*', groups: [parent_group])
+ end
+
+ it_behaves_like 'matching environment scope'
+ end
+
+ context 'when parent_group has a cluster that is an exact match' do
+ let!(:parent_group_cluster) do
+ create(:cluster, :provided_by_user,
+ cluster_type: :group_type, environment_scope: 'review/name', groups: [parent_group])
+ end
+
+ it_behaves_like 'matching environment scope'
+ end
+ end
+ end
+
+ context 'with instance clusters' do
+ let!(:default_cluster) do
+ create(:cluster, :provided_by_user, :instance, environment_scope: '*')
+ end
+
+ let!(:cluster) do
+ create(:cluster, :provided_by_user, :instance, environment_scope: 'review/*')
+ end
+
+ let(:environment) { 'review/name' }
+
+ subject { project.deployment_platform(environment: environment) }
+
+ context 'when environment scope is exactly matched' do
+ before do
+ cluster.update!(environment_scope: 'review/name')
+ end
+
+ it_behaves_like 'matching environment scope'
+ end
+
+ context 'when environment scope is matched by wildcard' do
+ before do
+ cluster.update!(environment_scope: 'review/*')
+ end
+
+ it_behaves_like 'matching environment scope'
+ end
+
+ context 'when environment scope does not match' do
+ before do
+ cluster.update!(environment_scope: 'review/*/special')
+ end
+
+ it_behaves_like 'not matching environment scope'
+ end
+ end
+
+ context 'when environment is specified' do
+ let!(:default_cluster) { create(:cluster, :provided_by_user, projects: [project], environment_scope: '*') }
+ let!(:cluster) { create(:cluster, :provided_by_user, environment_scope: 'review/*', projects: [project]) }
+
+ let!(:group_default_cluster) do
+ create(:cluster, :provided_by_user,
+ cluster_type: :group_type, groups: [group], environment_scope: '*')
+ end
+
+ let(:environment) { 'review/name' }
+
+ subject { project.deployment_platform(environment: environment) }
+
+ context 'when environment scope is exactly matched' do
+ before do
+ cluster.update!(environment_scope: 'review/name')
+ end
+
+ it_behaves_like 'matching environment scope'
+ end
+
+ context 'when environment scope is matched by wildcard' do
+ before do
+ cluster.update!(environment_scope: 'review/*')
+ end
+
+ it_behaves_like 'matching environment scope'
+ end
+
+ context 'when environment scope does not match' do
+ before do
+ cluster.update!(environment_scope: 'review/*/special')
+ end
+
+ it_behaves_like 'not matching environment scope'
+ end
+
+ context 'when environment scope has _' do
+ it 'does not treat it as wildcard' do
+ cluster.update!(environment_scope: 'foo_bar/*')
+
+ is_expected.to eq(default_cluster.platform_kubernetes)
+ end
+
+ context 'when environment name contains an underscore' do
+ let(:environment) { 'foo_bar/test' }
+
+ it 'matches literally for _' do
+ cluster.update!(environment_scope: 'foo_bar/*')
+
+ is_expected.to eq(cluster.platform_kubernetes)
+ end
+ end
+ end
+
+ # The environment name and scope cannot have % at the moment,
+ # but we're considering relaxing it and we should also make sure
+ # it doesn't break in case some data sneaked in somehow as we're
+ # not checking this integrity in database level.
+ context 'when environment scope has %' do
+ it 'does not treat it as wildcard' do
+ cluster.update_attribute(:environment_scope, '*%*')
+
+ is_expected.to eq(default_cluster.platform_kubernetes)
+ end
+
+ context 'when environment name contains a percent char' do
+ let(:environment) { 'foo%bar/test' }
+
+ it 'matches literally for %' do
+ cluster.update_attribute(:environment_scope, 'foo%bar/*')
+
+ is_expected.to eq(cluster.platform_kubernetes)
+ end
+ end
+ end
+
+ context 'when perfectly matched cluster exists' do
+ let!(:perfectly_matched_cluster) { create(:cluster, :provided_by_user, projects: [project], environment_scope: 'review/name') }
+
+ it 'returns perfectly matched cluster as highest precedence' do
+ is_expected.to eq(perfectly_matched_cluster.platform_kubernetes)
+ end
+ end
+ end
+
+ context 'with multiple clusters and multiple environments' do
+ let!(:cluster_1) { create(:cluster, :provided_by_user, projects: [project], environment_scope: 'staging/*') }
+ let!(:cluster_2) { create(:cluster, :provided_by_user, projects: [project], environment_scope: 'test/*') }
+
+ let(:environment_1) { 'staging/name' }
+ let(:environment_2) { 'test/name' }
+
+ it 'returns the appropriate cluster' do
+ expect(project.deployment_platform(environment: environment_1)).to eq(cluster_1.platform_kubernetes)
+ expect(project.deployment_platform(environment: environment_2)).to eq(cluster_2.platform_kubernetes)
+ end
+ end
+ end
+
context 'with no Kubernetes configuration on CI/CD, no Kubernetes Service' do
it { is_expected.to be_nil }
end
diff --git a/spec/models/concerns/deprecated_assignee_spec.rb b/spec/models/concerns/deprecated_assignee_spec.rb
index e394de0aa34..630d9ea601f 100644
--- a/spec/models/concerns/deprecated_assignee_spec.rb
+++ b/spec/models/concerns/deprecated_assignee_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe DeprecatedAssignee do
+RSpec.describe DeprecatedAssignee do
let(:user) { create(:user) }
describe '#assignee_id=' do
diff --git a/spec/models/concerns/discussion_on_diff_spec.rb b/spec/models/concerns/discussion_on_diff_spec.rb
index f091861bd41..dd5d422f12d 100644
--- a/spec/models/concerns/discussion_on_diff_spec.rb
+++ b/spec/models/concerns/discussion_on_diff_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe DiscussionOnDiff do
+RSpec.describe DiscussionOnDiff do
subject { create(:diff_note_on_merge_request, line_number: 18).to_discussion }
describe "#truncated_diff_lines" do
diff --git a/spec/models/concerns/each_batch_spec.rb b/spec/models/concerns/each_batch_spec.rb
index ee3d9aea505..3c93c8a7a79 100644
--- a/spec/models/concerns/each_batch_spec.rb
+++ b/spec/models/concerns/each_batch_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe EachBatch do
+RSpec.describe EachBatch do
describe '.each_batch' do
let(:model) do
Class.new(ActiveRecord::Base) do
diff --git a/spec/models/concerns/editable_spec.rb b/spec/models/concerns/editable_spec.rb
index 4a4a3ca5687..1d26629d0aa 100644
--- a/spec/models/concerns/editable_spec.rb
+++ b/spec/models/concerns/editable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Editable do
+RSpec.describe Editable do
describe '#edited?' do
let(:issue) { create(:issue, last_edited_at: nil) }
let(:edited_issue) { create(:issue, created_at: 3.days.ago, last_edited_at: 2.days.ago) }
diff --git a/spec/models/concerns/expirable_spec.rb b/spec/models/concerns/expirable_spec.rb
index f4f5eab5b86..b20d759fc3f 100644
--- a/spec/models/concerns/expirable_spec.rb
+++ b/spec/models/concerns/expirable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Expirable do
+RSpec.describe Expirable do
describe 'ProjectMember' do
let(:no_expire) { create(:project_member) }
let(:expire_later) { create(:project_member, expires_at: Time.current + 6.days) }
diff --git a/spec/models/concerns/faster_cache_keys_spec.rb b/spec/models/concerns/faster_cache_keys_spec.rb
index 7830acbae3d..ab6e809b3f7 100644
--- a/spec/models/concerns/faster_cache_keys_spec.rb
+++ b/spec/models/concerns/faster_cache_keys_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe FasterCacheKeys do
+RSpec.describe FasterCacheKeys do
describe '#cache_key' do
it 'returns a String' do
# We're using a fixed string here so it's easier to set an expectation for
diff --git a/spec/models/concerns/featurable_spec.rb b/spec/models/concerns/featurable_spec.rb
index 89720e3652c..cc01820cc97 100644
--- a/spec/models/concerns/featurable_spec.rb
+++ b/spec/models/concerns/featurable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Featurable do
+RSpec.describe Featurable do
let_it_be(:user) { create(:user) }
let(:project) { create(:project) }
let(:feature_class) { subject.class }
diff --git a/spec/models/concerns/feature_gate_spec.rb b/spec/models/concerns/feature_gate_spec.rb
index 276d3d9e1d5..6106708a32d 100644
--- a/spec/models/concerns/feature_gate_spec.rb
+++ b/spec/models/concerns/feature_gate_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe FeatureGate do
+RSpec.describe FeatureGate do
describe 'User' do
describe '#flipper_id' do
context 'when user is not persisted' do
diff --git a/spec/models/concerns/from_union_spec.rb b/spec/models/concerns/from_union_spec.rb
index 735e14b47ec..9819a6ec3de 100644
--- a/spec/models/concerns/from_union_spec.rb
+++ b/spec/models/concerns/from_union_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe FromUnion do
+RSpec.describe FromUnion do
describe '.from_union' do
let(:model) do
Class.new(ActiveRecord::Base) do
diff --git a/spec/models/concerns/group_descendant_spec.rb b/spec/models/concerns/group_descendant_spec.rb
index 47419770d0f..b29fa910ee6 100644
--- a/spec/models/concerns/group_descendant_spec.rb
+++ b/spec/models/concerns/group_descendant_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe GroupDescendant do
+RSpec.describe GroupDescendant do
let(:parent) { create(:group) }
let(:subgroup) { create(:group, parent: parent) }
let(:subsub_group) { create(:group, parent: subgroup) }
diff --git a/spec/models/concerns/has_environment_scope_spec.rb b/spec/models/concerns/has_environment_scope_spec.rb
index a6e1ba59263..0cc997709c9 100644
--- a/spec/models/concerns/has_environment_scope_spec.rb
+++ b/spec/models/concerns/has_environment_scope_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe HasEnvironmentScope do
+RSpec.describe HasEnvironmentScope do
subject { build(:ci_variable) }
it { is_expected.to allow_value('*').for(:environment_scope) }
diff --git a/spec/models/concerns/has_user_type_spec.rb b/spec/models/concerns/has_user_type_spec.rb
index f12eee414f9..9496bb57b8b 100644
--- a/spec/models/concerns/has_user_type_spec.rb
+++ b/spec/models/concerns/has_user_type_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe User do
+RSpec.describe User do
specify 'types consistency checks', :aggregate_failures do
expect(described_class::USER_TYPES.keys)
.to match_array(%w[human ghost alert_bot project_bot support_bot service_user visual_review_bot migration_bot])
diff --git a/spec/models/concerns/ignorable_columns_spec.rb b/spec/models/concerns/ignorable_columns_spec.rb
index 018b1296c62..a5eff154a0b 100644
--- a/spec/models/concerns/ignorable_columns_spec.rb
+++ b/spec/models/concerns/ignorable_columns_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe IgnorableColumns do
+RSpec.describe IgnorableColumns do
let(:record_class) do
Class.new(ApplicationRecord) do
include IgnorableColumns
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index 74ee7a87b7b..96d3e2b7b1b 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Issuable do
+RSpec.describe Issuable do
include ProjectForksHelper
let(:issuable_class) { Issue }
@@ -416,6 +416,27 @@ describe Issuable do
describe '#to_hook_data' do
let(:builder) { double }
+ context 'when old_associations is empty' do
+ let(:label) { create(:label) }
+
+ before do
+ issue.update!(labels: [label])
+ issue.assignees << user
+ issue.spend_time(duration: 2, user_id: user.id, spent_at: Time.current)
+ expect(Gitlab::HookData::IssuableBuilder)
+ .to receive(:new).with(issue).and_return(builder)
+ end
+
+ it 'delegates to Gitlab::HookData::IssuableBuilder#build and does not set labels, assignees, nor total_time_spent' do
+ expect(builder).to receive(:build).with(
+ user: user,
+ changes: {})
+
+ # In some cases, old_associations is empty, e.g. on a close event
+ issue.to_hook_data(user)
+ end
+ end
+
context 'labels are updated' do
let(:labels) { create_list(:label, 2) }
diff --git a/spec/models/concerns/limitable_spec.rb b/spec/models/concerns/limitable_spec.rb
index ca0a257be7a..753e2a8ee5e 100644
--- a/spec/models/concerns/limitable_spec.rb
+++ b/spec/models/concerns/limitable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Limitable do
+RSpec.describe Limitable do
let(:minimal_test_class) do
Class.new do
include ActiveModel::Model
diff --git a/spec/models/concerns/loaded_in_group_list_spec.rb b/spec/models/concerns/loaded_in_group_list_spec.rb
index 509811822e0..c37943022ba 100644
--- a/spec/models/concerns/loaded_in_group_list_spec.rb
+++ b/spec/models/concerns/loaded_in_group_list_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe LoadedInGroupList do
+RSpec.describe LoadedInGroupList do
let(:parent) { create(:group) }
subject(:found_group) { Group.with_selects_for_list.find_by(id: parent.id) }
diff --git a/spec/models/concerns/manual_inverse_association_spec.rb b/spec/models/concerns/manual_inverse_association_spec.rb
index ee32e3b165b..1349d2cc680 100644
--- a/spec/models/concerns/manual_inverse_association_spec.rb
+++ b/spec/models/concerns/manual_inverse_association_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ManualInverseAssociation do
+RSpec.describe ManualInverseAssociation do
let(:model) do
Class.new(MergeRequest) do
belongs_to :manual_association, class_name: 'MergeRequestDiff', foreign_key: :latest_merge_request_diff_id
diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb
index 03fd1c69654..758b5aa2ce4 100644
--- a/spec/models/concerns/mentionable_spec.rb
+++ b/spec/models/concerns/mentionable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Mentionable do
+RSpec.describe Mentionable do
before do
stub_const('Example', Class.new)
Example.class_eval do
@@ -67,7 +67,7 @@ describe Mentionable do
end
end
-describe Issue, "Mentionable" do
+RSpec.describe Issue, "Mentionable" do
describe '#mentioned_users' do
let!(:user) { create(:user, username: 'stranger') }
let!(:user2) { create(:user, username: 'john') }
@@ -222,7 +222,7 @@ describe Issue, "Mentionable" do
end
end
-describe Commit, 'Mentionable' do
+RSpec.describe Commit, 'Mentionable' do
let(:project) { create(:project, :public, :repository) }
let(:commit) { project.commit }
@@ -291,7 +291,7 @@ describe Commit, 'Mentionable' do
end
end
-describe MergeRequest, 'Mentionable' do
+RSpec.describe MergeRequest, 'Mentionable' do
describe '#store_mentions!' do
it_behaves_like 'mentions in description', :merge_request
it_behaves_like 'mentions in notes', :merge_request do
@@ -312,7 +312,7 @@ describe MergeRequest, 'Mentionable' do
end
end
-describe Snippet, 'Mentionable' do
+RSpec.describe Snippet, 'Mentionable' do
describe '#store_mentions!' do
it_behaves_like 'mentions in description', :project_snippet
it_behaves_like 'mentions in notes', :project_snippet do
@@ -329,7 +329,7 @@ describe Snippet, 'Mentionable' do
end
end
-describe PersonalSnippet, 'Mentionable' do
+RSpec.describe PersonalSnippet, 'Mentionable' do
describe '#store_mentions!' do
it_behaves_like 'mentions in description', :personal_snippet
it_behaves_like 'mentions in notes', :personal_snippet do
@@ -346,7 +346,7 @@ describe PersonalSnippet, 'Mentionable' do
end
end
-describe DesignManagement::Design do
+RSpec.describe DesignManagement::Design do
describe '#store_mentions!' do
it_behaves_like 'mentions in notes', :design do
let(:note) { create(:diff_note_on_design) }
diff --git a/spec/models/concerns/milestoneable_spec.rb b/spec/models/concerns/milestoneable_spec.rb
index 0b19c0542ee..15352a1453c 100644
--- a/spec/models/concerns/milestoneable_spec.rb
+++ b/spec/models/concerns/milestoneable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Milestoneable do
+RSpec.describe Milestoneable do
let(:user) { create(:user) }
let(:milestone) { create(:milestone, project: project) }
diff --git a/spec/models/concerns/milestoneish_spec.rb b/spec/models/concerns/milestoneish_spec.rb
index 8c43a12aa15..58cd054efd5 100644
--- a/spec/models/concerns/milestoneish_spec.rb
+++ b/spec/models/concerns/milestoneish_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Milestone, 'Milestoneish' do
+RSpec.describe Milestone, 'Milestoneish' do
let(:author) { create(:user) }
let(:assignee) { create(:user) }
let(:non_member) { create(:user) }
diff --git a/spec/models/concerns/noteable_spec.rb b/spec/models/concerns/noteable_spec.rb
index 5c8c5425ca7..bb7374bf46c 100644
--- a/spec/models/concerns/noteable_spec.rb
+++ b/spec/models/concerns/noteable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Noteable do
+RSpec.describe Noteable do
let!(:active_diff_note1) { create(:diff_note_on_merge_request) }
let(:project) { active_diff_note1.project }
subject { active_diff_note1.noteable }
@@ -262,4 +262,44 @@ describe Noteable do
end
end
end
+
+ describe "#has_any_diff_note_positions?" do
+ let(:source_branch) { "compare-with-merge-head-source" }
+ let(:target_branch) { "compare-with-merge-head-target" }
+ let(:merge_request) { create(:merge_request, source_branch: source_branch, target_branch: target_branch) }
+
+ let!(:note) do
+ path = "files/markdown/ruby-style-guide.md"
+
+ position = Gitlab::Diff::Position.new(
+ old_path: path,
+ new_path: path,
+ new_line: 508,
+ diff_refs: merge_request.diff_refs
+ )
+
+ create(:diff_note_on_merge_request, project: merge_request.project, position: position, noteable: merge_request)
+ end
+
+ before do
+ MergeRequests::MergeToRefService.new(merge_request.project, merge_request.author).execute(merge_request)
+ Discussions::CaptureDiffNotePositionsService.new(merge_request).execute
+ end
+
+ it "returns true when it has diff note positions" do
+ expect(merge_request.has_any_diff_note_positions?).to be(true)
+ end
+
+ it "returns false when it has notes but no diff note positions" do
+ DiffNotePosition.where(note: note).find_each(&:delete)
+
+ expect(merge_request.has_any_diff_note_positions?).to be(false)
+ end
+
+ it "returns false when it has no notes" do
+ merge_request.notes.find_each(&:destroy)
+
+ expect(merge_request.has_any_diff_note_positions?).to be(false)
+ end
+ end
end
diff --git a/spec/models/concerns/optionally_search_spec.rb b/spec/models/concerns/optionally_search_spec.rb
index e1eb4cf8cd2..c8e2e6da51f 100644
--- a/spec/models/concerns/optionally_search_spec.rb
+++ b/spec/models/concerns/optionally_search_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe OptionallySearch do
+RSpec.describe OptionallySearch do
describe '.search' do
let(:model) do
Class.new do
diff --git a/spec/models/concerns/participable_spec.rb b/spec/models/concerns/participable_spec.rb
index 3d5937c4fc6..3376e337dc9 100644
--- a/spec/models/concerns/participable_spec.rb
+++ b/spec/models/concerns/participable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Participable do
+RSpec.describe Participable do
let(:model) do
Class.new do
include Participable
diff --git a/spec/models/concerns/partitioned_table_spec.rb b/spec/models/concerns/partitioned_table_spec.rb
new file mode 100644
index 00000000000..3343b273ba2
--- /dev/null
+++ b/spec/models/concerns/partitioned_table_spec.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe PartitionedTable do
+ describe '.partitioned_by' do
+ subject { my_class.partitioned_by(key, strategy: :monthly) }
+
+ let(:key) { :foo }
+
+ let(:my_class) do
+ Class.new do
+ include PartitionedTable
+ end
+ end
+
+ it 'assigns the MonthlyStrategy as the partitioning strategy' do
+ subject
+
+ expect(my_class.partitioning_strategy).to be_a(Gitlab::Database::Partitioning::MonthlyStrategy)
+ end
+
+ it 'passes the partitioning key to the strategy instance' do
+ subject
+
+ expect(my_class.partitioning_strategy.partitioning_key).to eq(key)
+ end
+
+ it 'registers itself with the PartitionCreator' do
+ expect(Gitlab::Database::Partitioning::PartitionCreator).to receive(:register).with(my_class)
+
+ subject
+ end
+ end
+end
diff --git a/spec/models/concerns/presentable_spec.rb b/spec/models/concerns/presentable_spec.rb
index 9db868dd348..871e122e409 100644
--- a/spec/models/concerns/presentable_spec.rb
+++ b/spec/models/concerns/presentable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Presentable do
+RSpec.describe Presentable do
let(:build) { Ci::Build.new }
describe '#present' do
diff --git a/spec/models/concerns/project_api_compatibility_spec.rb b/spec/models/concerns/project_api_compatibility_spec.rb
index f5722f88aac..7a69406cb71 100644
--- a/spec/models/concerns/project_api_compatibility_spec.rb
+++ b/spec/models/concerns/project_api_compatibility_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ProjectAPICompatibility do
+RSpec.describe ProjectAPICompatibility do
let(:project) { create(:project) }
# git_strategy
diff --git a/spec/models/concerns/project_features_compatibility_spec.rb b/spec/models/concerns/project_features_compatibility_spec.rb
index 8346c4ad4cc..ba70ff563a8 100644
--- a/spec/models/concerns/project_features_compatibility_spec.rb
+++ b/spec/models/concerns/project_features_compatibility_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ProjectFeaturesCompatibility do
+RSpec.describe ProjectFeaturesCompatibility do
let(:project) { create(:project) }
let(:features_enabled) { %w(issues wiki builds merge_requests snippets) }
let(:features) { features_enabled + %w(repository pages) }
diff --git a/spec/models/concerns/prometheus_adapter_spec.rb b/spec/models/concerns/prometheus_adapter_spec.rb
index fdc98ba74b8..e795e2b06cb 100644
--- a/spec/models/concerns/prometheus_adapter_spec.rb
+++ b/spec/models/concerns/prometheus_adapter_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
+RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
include PrometheusHelpers
include ReactiveCachingHelpers
diff --git a/spec/models/concerns/protected_ref_access_spec.rb b/spec/models/concerns/protected_ref_access_spec.rb
index f63ad958ed3..750a5eba303 100644
--- a/spec/models/concerns/protected_ref_access_spec.rb
+++ b/spec/models/concerns/protected_ref_access_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ProtectedRefAccess do
+RSpec.describe ProtectedRefAccess do
include ExternalAuthorizationServiceHelpers
subject(:protected_ref_access) do
diff --git a/spec/models/concerns/reactive_caching_spec.rb b/spec/models/concerns/reactive_caching_spec.rb
index cfca383e0b0..b12ad82920f 100644
--- a/spec/models/concerns/reactive_caching_spec.rb
+++ b/spec/models/concerns/reactive_caching_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ReactiveCaching, :use_clean_rails_memory_store_caching do
+RSpec.describe ReactiveCaching, :use_clean_rails_memory_store_caching do
include ExclusiveLeaseHelpers
include ReactiveCachingHelpers
@@ -285,38 +285,30 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
go!
end
- context 'when calculated object size exceeds default reactive_cache_hard_limit' do
- let(:calculation) { -> { 'a' * 2 * 1.megabyte } }
+ context 'when reactive_cache_hard_limit is set' do
+ let(:test_class) { Class.new(cache_class_test) { self.reactive_cache_hard_limit = 1.megabyte } }
+ let(:instance) { test_class.new(666, &calculation) }
+
+ context 'when cache size is over the overridden limit' do
+ let(:calculation) { -> { 'a' * 2 * 1.megabyte } }
- shared_examples 'ExceededReactiveCacheLimit' do
it 'raises ExceededReactiveCacheLimit exception and does not cache new data' do
expect { go! }.to raise_exception(ReactiveCaching::ExceededReactiveCacheLimit)
expect(read_reactive_cache(instance)).not_to eq(calculation.call)
end
- end
- context 'when reactive_cache_hard_limit feature flag is enabled' do
- it_behaves_like 'ExceededReactiveCacheLimit'
-
- context 'when reactive_cache_hard_limit is overridden' do
- let(:test_class) { Class.new(cache_class_test) { self.reactive_cache_hard_limit = 3.megabytes } }
- let(:instance) { test_class.new(666, &calculation) }
+ context 'when reactive_cache_limit_enabled? is overridden to return false' do
+ before do
+ allow(instance).to receive(:reactive_cache_limit_enabled?).and_return(false)
+ end
it_behaves_like 'successful cache'
-
- context 'when cache size is over the overridden limit' do
- let(:calculation) { -> { 'a' * 4 * 1.megabyte } }
-
- it_behaves_like 'ExceededReactiveCacheLimit'
- end
end
end
- context 'when reactive_cache_limit feature flag is disabled' do
- before do
- stub_feature_flags(reactive_cache_limit: false)
- end
+ context 'when cache size is within the overridden limit' do
+ let(:calculation) { -> { 'Smaller than 1Mb reactive_cache_hard_limit' } }
it_behaves_like 'successful cache'
end
@@ -377,7 +369,7 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
it { expect(subject.reactive_cache_refresh_interval).to be_a(ActiveSupport::Duration) }
it { expect(subject.reactive_cache_lifetime).to be_a(ActiveSupport::Duration) }
it { expect(subject.reactive_cache_key).to respond_to(:call) }
- it { expect(subject.reactive_cache_hard_limit).to be_a(Integer) }
+ it { expect(subject.reactive_cache_hard_limit).to be_nil }
it { expect(subject.reactive_cache_worker_finder).to respond_to(:call) }
end
end
diff --git a/spec/models/concerns/redactable_spec.rb b/spec/models/concerns/redactable_spec.rb
index 3f6a2e2410c..bb59e04adf1 100644
--- a/spec/models/concerns/redactable_spec.rb
+++ b/spec/models/concerns/redactable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Redactable do
+RSpec.describe Redactable do
before do
stub_commonmark_sourcepos_disabled
end
diff --git a/spec/models/concerns/redis_cacheable_spec.rb b/spec/models/concerns/redis_cacheable_spec.rb
index 1cf6afcc167..c270f23defb 100644
--- a/spec/models/concerns/redis_cacheable_spec.rb
+++ b/spec/models/concerns/redis_cacheable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe RedisCacheable do
+RSpec.describe RedisCacheable do
let(:model) do
Struct.new(:id, :attributes) do
def read_attribute(attribute)
diff --git a/spec/models/concerns/resolvable_discussion_spec.rb b/spec/models/concerns/resolvable_discussion_spec.rb
index 95553fb13a6..c91ddfee944 100644
--- a/spec/models/concerns/resolvable_discussion_spec.rb
+++ b/spec/models/concerns/resolvable_discussion_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Discussion, ResolvableDiscussion do
+RSpec.describe Discussion, ResolvableDiscussion do
subject { described_class.new([first_note, second_note, third_note]) }
let(:first_note) { create(:discussion_note_on_merge_request) }
diff --git a/spec/models/concerns/resolvable_note_spec.rb b/spec/models/concerns/resolvable_note_spec.rb
index 12e50ac807e..69c58a5cfe5 100644
--- a/spec/models/concerns/resolvable_note_spec.rb
+++ b/spec/models/concerns/resolvable_note_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Note, ResolvableNote do
+RSpec.describe Note, ResolvableNote do
let(:project) { create(:project, :repository) }
let(:merge_request) { create(:merge_request, source_project: project) }
diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb
index c891fdcb6b5..15d754861b2 100644
--- a/spec/models/concerns/routable_spec.rb
+++ b/spec/models/concerns/routable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Group, 'Routable' do
+RSpec.describe Group, 'Routable' do
let!(:group) { create(:group, name: 'foo') }
describe 'Validations' do
@@ -164,7 +164,7 @@ describe Group, 'Routable' do
end
end
-describe Project, 'Routable' do
+RSpec.describe Project, 'Routable' do
describe '#full_path' do
let(:project) { build_stubbed(:project) }
diff --git a/spec/models/concerns/safe_url_spec.rb b/spec/models/concerns/safe_url_spec.rb
index e523e6a15e4..3d38c05bf11 100644
--- a/spec/models/concerns/safe_url_spec.rb
+++ b/spec/models/concerns/safe_url_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe SafeUrl do
+RSpec.describe SafeUrl do
describe '#safe_url' do
let(:safe_url_test_class) do
Class.new do
diff --git a/spec/models/concerns/schedulable_spec.rb b/spec/models/concerns/schedulable_spec.rb
index 38ae2112e01..875c2d80e55 100644
--- a/spec/models/concerns/schedulable_spec.rb
+++ b/spec/models/concerns/schedulable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Schedulable do
+RSpec.describe Schedulable do
shared_examples 'before_save callback' do
it 'updates next_run_at' do
expect { object.save! }.to change { object.next_run_at }
diff --git a/spec/models/concerns/sha256_attribute_spec.rb b/spec/models/concerns/sha256_attribute_spec.rb
index 213723c2dcb..c247865d77f 100644
--- a/spec/models/concerns/sha256_attribute_spec.rb
+++ b/spec/models/concerns/sha256_attribute_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Sha256Attribute do
+RSpec.describe Sha256Attribute do
let(:model) { Class.new { include Sha256Attribute } }
before do
diff --git a/spec/models/concerns/sha_attribute_spec.rb b/spec/models/concerns/sha_attribute_spec.rb
index 0d4dbfb215e..50748efcda4 100644
--- a/spec/models/concerns/sha_attribute_spec.rb
+++ b/spec/models/concerns/sha_attribute_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ShaAttribute do
+RSpec.describe ShaAttribute do
let(:model) { Class.new { include ShaAttribute } }
before do
diff --git a/spec/models/concerns/sortable_spec.rb b/spec/models/concerns/sortable_spec.rb
index a1fe5c0928d..bbfdaeec64c 100644
--- a/spec/models/concerns/sortable_spec.rb
+++ b/spec/models/concerns/sortable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Sortable do
+RSpec.describe Sortable do
describe '.order_by' do
let(:arel_table) { Group.arel_table }
let(:relation) { Group.all }
diff --git a/spec/models/concerns/spammable_spec.rb b/spec/models/concerns/spammable_spec.rb
index a8d27e174b7..d4fcb2e99eb 100644
--- a/spec/models/concerns/spammable_spec.rb
+++ b/spec/models/concerns/spammable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Spammable do
+RSpec.describe Spammable do
let(:issue) { create(:issue, description: 'Test Desc.') }
describe 'Associations' do
diff --git a/spec/models/concerns/stepable_spec.rb b/spec/models/concerns/stepable_spec.rb
index 51356c3eaf6..e442e4f0664 100644
--- a/spec/models/concerns/stepable_spec.rb
+++ b/spec/models/concerns/stepable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Stepable do
+RSpec.describe Stepable do
let(:described_class) do
Class.new do
include Stepable
diff --git a/spec/models/concerns/strip_attribute_spec.rb b/spec/models/concerns/strip_attribute_spec.rb
index 5c0d1042e06..812f0a015f7 100644
--- a/spec/models/concerns/strip_attribute_spec.rb
+++ b/spec/models/concerns/strip_attribute_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe StripAttribute do
+RSpec.describe StripAttribute do
let(:milestone) { create(:milestone) }
describe ".strip_attributes" do
diff --git a/spec/models/concerns/subscribable_spec.rb b/spec/models/concerns/subscribable_spec.rb
index f189cd7633c..2a43e748e58 100644
--- a/spec/models/concerns/subscribable_spec.rb
+++ b/spec/models/concerns/subscribable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Subscribable, 'Subscribable' do
+RSpec.describe Subscribable, 'Subscribable' do
let(:project) { create(:project) }
let(:resource) { create(:issue, project: project) }
let(:user_1) { create(:user) }
diff --git a/spec/models/concerns/token_authenticatable_spec.rb b/spec/models/concerns/token_authenticatable_spec.rb
index 36eb8fdaba4..e0e764fc63c 100644
--- a/spec/models/concerns/token_authenticatable_spec.rb
+++ b/spec/models/concerns/token_authenticatable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-shared_examples 'TokenAuthenticatable' do
+RSpec.shared_examples 'TokenAuthenticatable' do
describe 'dynamically defined methods' do
it { expect(described_class).to respond_to("find_by_#{token_field}") }
it { is_expected.to respond_to("ensure_#{token_field}") }
@@ -11,7 +11,7 @@ shared_examples 'TokenAuthenticatable' do
end
end
-describe User, 'TokenAuthenticatable' do
+RSpec.describe User, 'TokenAuthenticatable' do
let(:token_field) { :feed_token }
it_behaves_like 'TokenAuthenticatable'
@@ -23,7 +23,7 @@ describe User, 'TokenAuthenticatable' do
end
end
-describe ApplicationSetting, 'TokenAuthenticatable' do
+RSpec.describe ApplicationSetting, 'TokenAuthenticatable' do
let(:token_field) { :runners_registration_token }
let(:settings) { described_class.new }
@@ -100,7 +100,7 @@ describe ApplicationSetting, 'TokenAuthenticatable' do
end
end
-describe PersonalAccessToken, 'TokenAuthenticatable' do
+RSpec.describe PersonalAccessToken, 'TokenAuthenticatable' do
shared_examples 'changes personal access token' do
it 'sets new token' do
subject
@@ -205,7 +205,7 @@ describe PersonalAccessToken, 'TokenAuthenticatable' do
end
end
-describe Ci::Build, 'TokenAuthenticatable' do
+RSpec.describe Ci::Build, 'TokenAuthenticatable' do
let(:token_field) { :token }
let(:build) { FactoryBot.build(:ci_build) }
diff --git a/spec/models/concerns/token_authenticatable_strategies/base_spec.rb b/spec/models/concerns/token_authenticatable_strategies/base_spec.rb
index 7332da309d5..bccef9b9554 100644
--- a/spec/models/concerns/token_authenticatable_strategies/base_spec.rb
+++ b/spec/models/concerns/token_authenticatable_strategies/base_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe TokenAuthenticatableStrategies::Base do
+RSpec.describe TokenAuthenticatableStrategies::Base do
let(:instance) { double(:instance) }
let(:field) { double(:field) }
diff --git a/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb b/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
index 70f41981b3b..f6b8cf7def4 100644
--- a/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
+++ b/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe TokenAuthenticatableStrategies::Encrypted do
+RSpec.describe TokenAuthenticatableStrategies::Encrypted do
let(:model) { double(:model) }
let(:instance) { double(:instance) }
diff --git a/spec/models/concerns/uniquify_spec.rb b/spec/models/concerns/uniquify_spec.rb
index 9ba35702ba6..9b79e4d4154 100644
--- a/spec/models/concerns/uniquify_spec.rb
+++ b/spec/models/concerns/uniquify_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Uniquify do
+RSpec.describe Uniquify do
let(:uniquify) { described_class.new }
describe "#string" do
diff --git a/spec/models/concerns/usage_statistics_spec.rb b/spec/models/concerns/usage_statistics_spec.rb
index f99f0a13317..15ccd08eda9 100644
--- a/spec/models/concerns/usage_statistics_spec.rb
+++ b/spec/models/concerns/usage_statistics_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe UsageStatistics do
+RSpec.describe UsageStatistics do
describe '.distinct_count_by' do
let_it_be(:issue_1) { create(:issue) }
let_it_be(:issue_2) { create(:issue) }
diff --git a/spec/models/concerns/where_composite_spec.rb b/spec/models/concerns/where_composite_spec.rb
index 1c0951d90d0..fb23e6bfe1d 100644
--- a/spec/models/concerns/where_composite_spec.rb
+++ b/spec/models/concerns/where_composite_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe WhereComposite do
+RSpec.describe WhereComposite do
describe '.where_composite' do
let_it_be(:test_table_name) { "test_table_#{SecureRandom.hex(10)}" }
diff --git a/spec/models/concerns/x509_serial_number_attribute_spec.rb b/spec/models/concerns/x509_serial_number_attribute_spec.rb
index 18a1d85204c..88550823748 100644
--- a/spec/models/concerns/x509_serial_number_attribute_spec.rb
+++ b/spec/models/concerns/x509_serial_number_attribute_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe X509SerialNumberAttribute do
+RSpec.describe X509SerialNumberAttribute do
let(:model) { Class.new { include X509SerialNumberAttribute } }
before do