diff options
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/bulk_insert_safe_spec.rb | 24 | ||||
-rw-r--r-- | spec/models/concerns/bulk_insertable_associations_spec.rb | 32 | ||||
-rw-r--r-- | spec/models/concerns/cascading_namespace_setting_attribute_spec.rb | 15 | ||||
-rw-r--r-- | spec/models/concerns/clusters/agents/authorization_config_scopes_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/concerns/database_reflection_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/concerns/has_integrations_spec.rb | 25 | ||||
-rw-r--r-- | spec/models/concerns/legacy_bulk_insert_spec.rb | 103 | ||||
-rw-r--r-- | spec/models/concerns/loaded_in_group_list_spec.rb | 58 | ||||
-rw-r--r-- | spec/models/concerns/loose_foreign_key_spec.rb | 29 | ||||
-rw-r--r-- | spec/models/concerns/noteable_spec.rb | 64 | ||||
-rw-r--r-- | spec/models/concerns/prometheus_adapter_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/concerns/reactive_caching_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/concerns/sha256_attribute_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/concerns/sha_attribute_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/concerns/where_composite_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/concerns/x509_serial_number_attribute_spec.rb | 2 |
16 files changed, 310 insertions, 97 deletions
diff --git a/spec/models/concerns/bulk_insert_safe_spec.rb b/spec/models/concerns/bulk_insert_safe_spec.rb index 172986c142c..e6b197f34ca 100644 --- a/spec/models/concerns/bulk_insert_safe_spec.rb +++ b/spec/models/concerns/bulk_insert_safe_spec.rb @@ -5,42 +5,42 @@ require 'spec_helper' RSpec.describe BulkInsertSafe do before(:all) do ActiveRecord::Schema.define do - create_table :bulk_insert_parent_items, force: true do |t| + create_table :_test_bulk_insert_parent_items, force: true do |t| t.string :name, null: false end - create_table :bulk_insert_items, force: true do |t| + create_table :_test_bulk_insert_items, force: true do |t| t.string :name, null: true t.integer :enum_value, null: false t.text :encrypted_secret_value, null: false t.string :encrypted_secret_value_iv, null: false t.binary :sha_value, null: false, limit: 20 t.jsonb :jsonb_value, null: false - t.belongs_to :bulk_insert_parent_item, foreign_key: true, null: true + t.belongs_to :bulk_insert_parent_item, foreign_key: { to_table: :_test_bulk_insert_parent_items }, null: true t.timestamps null: true t.index :name, unique: true end - create_table :bulk_insert_items_with_composite_pk, id: false, force: true do |t| + create_table :_test_bulk_insert_items_with_composite_pk, id: false, force: true do |t| t.integer :id, null: true t.string :name, null: true end - execute("ALTER TABLE bulk_insert_items_with_composite_pk ADD PRIMARY KEY (id,name);") + execute("ALTER TABLE _test_bulk_insert_items_with_composite_pk ADD PRIMARY KEY (id,name);") end end after(:all) do ActiveRecord::Schema.define do - drop_table :bulk_insert_items, force: true - drop_table :bulk_insert_parent_items, force: true - drop_table :bulk_insert_items_with_composite_pk, force: true + drop_table :_test_bulk_insert_items, force: true + drop_table :_test_bulk_insert_parent_items, force: true + drop_table :_test_bulk_insert_items_with_composite_pk, force: true end end BulkInsertParentItem = Class.new(ActiveRecord::Base) do - self.table_name = :bulk_insert_parent_items + self.table_name = :_test_bulk_insert_parent_items self.inheritance_column = :_type_disabled def self.name @@ -54,7 +54,7 @@ RSpec.describe BulkInsertSafe do let_it_be(:bulk_insert_item_class) do Class.new(ActiveRecord::Base) do - self.table_name = 'bulk_insert_items' + self.table_name = '_test_bulk_insert_items' include BulkInsertSafe include ShaAttribute @@ -182,7 +182,7 @@ RSpec.describe BulkInsertSafe do context 'with returns option set' do let(:items) { bulk_insert_item_class.valid_list(1) } - subject(:bulk_insert) { bulk_insert_item_class.bulk_insert!(items, returns: returns) } + subject(:legacy_bulk_insert) { bulk_insert_item_class.bulk_insert!(items, returns: returns) } context 'when is set to :ids' do let(:returns) { :ids } @@ -247,7 +247,7 @@ RSpec.describe BulkInsertSafe do context 'when a model with composite primary key is inserted' do let_it_be(:bulk_insert_items_with_composite_pk_class) do Class.new(ActiveRecord::Base) do - self.table_name = 'bulk_insert_items_with_composite_pk' + self.table_name = '_test_bulk_insert_items_with_composite_pk' include BulkInsertSafe end diff --git a/spec/models/concerns/bulk_insertable_associations_spec.rb b/spec/models/concerns/bulk_insertable_associations_spec.rb index 25b13c8233d..9713f1ce9a4 100644 --- a/spec/models/concerns/bulk_insertable_associations_spec.rb +++ b/spec/models/concerns/bulk_insertable_associations_spec.rb @@ -6,42 +6,50 @@ RSpec.describe BulkInsertableAssociations do class BulkFoo < ApplicationRecord include BulkInsertSafe + self.table_name = '_test_bulk_foos' + validates :name, presence: true end class BulkBar < ApplicationRecord include BulkInsertSafe + + self.table_name = '_test_bulk_bars' end - SimpleBar = Class.new(ApplicationRecord) + SimpleBar = Class.new(ApplicationRecord) do + self.table_name = '_test_simple_bars' + end class BulkParent < ApplicationRecord include BulkInsertableAssociations - has_many :bulk_foos + self.table_name = '_test_bulk_parents' + + has_many :bulk_foos, class_name: 'BulkFoo' has_many :bulk_hunks, class_name: 'BulkFoo' - has_many :bulk_bars - has_many :simple_bars # not `BulkInsertSafe` + has_many :bulk_bars, class_name: 'BulkBar' + has_many :simple_bars, class_name: 'SimpleBar' # not `BulkInsertSafe` has_one :bulk_foo # not supported end before(:all) do ActiveRecord::Schema.define do - create_table :bulk_parents, force: true do |t| + create_table :_test_bulk_parents, force: true do |t| t.string :name, null: true end - create_table :bulk_foos, force: true do |t| + create_table :_test_bulk_foos, force: true do |t| t.string :name, null: true t.belongs_to :bulk_parent, null: false end - create_table :bulk_bars, force: true do |t| + create_table :_test_bulk_bars, force: true do |t| t.string :name, null: true t.belongs_to :bulk_parent, null: false end - create_table :simple_bars, force: true do |t| + create_table :_test_simple_bars, force: true do |t| t.string :name, null: true t.belongs_to :bulk_parent, null: false end @@ -50,10 +58,10 @@ RSpec.describe BulkInsertableAssociations do after(:all) do ActiveRecord::Schema.define do - drop_table :bulk_foos, force: true - drop_table :bulk_bars, force: true - drop_table :simple_bars, force: true - drop_table :bulk_parents, force: true + drop_table :_test_bulk_foos, force: true + drop_table :_test_bulk_bars, force: true + drop_table :_test_simple_bars, force: true + drop_table :_test_bulk_parents, force: true end end diff --git a/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb b/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb index e8f2b18e662..6be6e3f048f 100644 --- a/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb +++ b/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb @@ -136,6 +136,21 @@ RSpec.describe NamespaceSetting, 'CascadingNamespaceSettingAttribute' do .to raise_error(ActiveRecord::RecordInvalid, /Delayed project removal cannot be changed because it is locked by an ancestor/) end end + + context 'when parent locked the attribute then the application settings locks it' do + before do + subgroup_settings.update!(delayed_project_removal: true) + group_settings.update!(lock_delayed_project_removal: true, delayed_project_removal: false) + stub_application_setting(lock_delayed_project_removal: true, delayed_project_removal: true) + + subgroup_settings.clear_memoization(:delayed_project_removal) + subgroup_settings.clear_memoization(:delayed_project_removal_locked_ancestor) + end + + it 'returns the application setting value' do + expect(delayed_project_removal).to eq(true) + end + end end describe '#delayed_project_removal?' do diff --git a/spec/models/concerns/clusters/agents/authorization_config_scopes_spec.rb b/spec/models/concerns/clusters/agents/authorization_config_scopes_spec.rb new file mode 100644 index 00000000000..a4d1a33b3d5 --- /dev/null +++ b/spec/models/concerns/clusters/agents/authorization_config_scopes_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Clusters::Agents::AuthorizationConfigScopes do + describe '.with_available_ci_access_fields' do + let(:project) { create(:project) } + + let!(:agent_authorization_0) { create(:agent_project_authorization, project: project) } + let!(:agent_authorization_1) { create(:agent_project_authorization, project: project, config: { access_as: {} }) } + let!(:agent_authorization_2) { create(:agent_project_authorization, project: project, config: { access_as: { agent: {} } }) } + let!(:impersonate_authorization) { create(:agent_project_authorization, project: project, config: { access_as: { impersonate: {} } }) } + let!(:ci_user_authorization) { create(:agent_project_authorization, project: project, config: { access_as: { ci_user: {} } }) } + let!(:ci_job_authorization) { create(:agent_project_authorization, project: project, config: { access_as: { ci_job: {} } }) } + let!(:unexpected_authorization) { create(:agent_project_authorization, project: project, config: { access_as: { unexpected: {} } }) } + + subject { Clusters::Agents::ProjectAuthorization.with_available_ci_access_fields(project) } + + it { is_expected.to contain_exactly(agent_authorization_0, agent_authorization_1, agent_authorization_2) } + end +end diff --git a/spec/models/concerns/database_reflection_spec.rb b/spec/models/concerns/database_reflection_spec.rb new file mode 100644 index 00000000000..4111f29ea8d --- /dev/null +++ b/spec/models/concerns/database_reflection_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe DatabaseReflection do + describe '.reflect' do + it 'returns a Reflection instance' do + expect(User.database).to be_an_instance_of(Gitlab::Database::Reflection) + end + + it 'memoizes the result' do + instance1 = User.database + instance2 = User.database + + expect(instance1).to equal(instance2) + end + end +end diff --git a/spec/models/concerns/has_integrations_spec.rb b/spec/models/concerns/has_integrations_spec.rb deleted file mode 100644 index ea6b0e69209..00000000000 --- a/spec/models/concerns/has_integrations_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe HasIntegrations do - let_it_be(:project_1) { create(:project) } - let_it_be(:project_2) { create(:project) } - let_it_be(:project_3) { create(:project) } - let_it_be(:project_4) { create(:project) } - let_it_be(:instance_integration) { create(:jira_integration, :instance) } - - before do - create(:jira_integration, project: project_1, inherit_from_id: instance_integration.id) - create(:jira_integration, project: project_2, inherit_from_id: nil) - create(:jira_integration, group: create(:group), project: nil, inherit_from_id: nil) - create(:jira_integration, project: project_3, inherit_from_id: nil) - create(:integrations_slack, project: project_4, inherit_from_id: nil) - end - - describe '.without_integration' do - it 'returns projects without integration' do - expect(Project.without_integration(instance_integration)).to contain_exactly(project_4) - end - end -end diff --git a/spec/models/concerns/legacy_bulk_insert_spec.rb b/spec/models/concerns/legacy_bulk_insert_spec.rb new file mode 100644 index 00000000000..0c6f84f391b --- /dev/null +++ b/spec/models/concerns/legacy_bulk_insert_spec.rb @@ -0,0 +1,103 @@ +# frozen_string_literal: true + +require 'spec_helper' + +# rubocop: disable Gitlab/BulkInsert +RSpec.describe LegacyBulkInsert do + let(:model) { ApplicationRecord } + + describe '#bulk_insert' do + before do + allow(model).to receive(:connection).and_return(dummy_connection) + allow(dummy_connection).to receive(:quote_column_name, &:itself) + allow(dummy_connection).to receive(:quote, &:itself) + allow(dummy_connection).to receive(:execute) + end + + let(:dummy_connection) { double(:connection) } + + let(:rows) do + [ + { a: 1, b: 2, c: 3 }, + { c: 6, a: 4, b: 5 } + ] + end + + it 'does nothing with empty rows' do + expect(dummy_connection).not_to receive(:execute) + + model.legacy_bulk_insert('test', []) + end + + it 'uses the ordering from the first row' do + expect(dummy_connection).to receive(:execute) do |sql| + expect(sql).to include('(1, 2, 3)') + expect(sql).to include('(4, 5, 6)') + end + + model.legacy_bulk_insert('test', rows) + end + + it 'quotes column names' do + expect(dummy_connection).to receive(:quote_column_name).with(:a) + expect(dummy_connection).to receive(:quote_column_name).with(:b) + expect(dummy_connection).to receive(:quote_column_name).with(:c) + + model.legacy_bulk_insert('test', rows) + end + + it 'quotes values' do + 1.upto(6) do |i| + expect(dummy_connection).to receive(:quote).with(i) + end + + model.legacy_bulk_insert('test', rows) + end + + it 'does not quote values of a column in the disable_quote option' do + [1, 2, 4, 5].each do |i| + expect(dummy_connection).to receive(:quote).with(i) + end + + model.legacy_bulk_insert('test', rows, disable_quote: :c) + end + + it 'does not quote values of columns in the disable_quote option' do + [2, 5].each do |i| + expect(dummy_connection).to receive(:quote).with(i) + end + + model.legacy_bulk_insert('test', rows, disable_quote: [:a, :c]) + end + + it 'handles non-UTF-8 data' do + expect { model.legacy_bulk_insert('test', [{ a: "\255" }]) }.not_to raise_error + end + + context 'when using PostgreSQL' do + it 'allows the returning of the IDs of the inserted rows' do + result = double(:result, values: [['10']]) + + expect(dummy_connection) + .to receive(:execute) + .with(/RETURNING id/) + .and_return(result) + + ids = model + .legacy_bulk_insert('test', [{ number: 10 }], return_ids: true) + + expect(ids).to eq([10]) + end + + it 'allows setting the upsert to do nothing' do + expect(dummy_connection) + .to receive(:execute) + .with(/ON CONFLICT DO NOTHING/) + + model + .legacy_bulk_insert('test', [{ number: 10 }], on_conflict: :do_nothing) + end + end + end +end +# rubocop: enable Gitlab/BulkInsert diff --git a/spec/models/concerns/loaded_in_group_list_spec.rb b/spec/models/concerns/loaded_in_group_list_spec.rb index c37943022ba..d38e842c666 100644 --- a/spec/models/concerns/loaded_in_group_list_spec.rb +++ b/spec/models/concerns/loaded_in_group_list_spec.rb @@ -3,49 +3,67 @@ require 'spec_helper' RSpec.describe LoadedInGroupList do - let(:parent) { create(:group) } + let_it_be(:parent) { create(:group) } + let_it_be(:group) { create(:group, parent: parent) } + let_it_be(:project) { create(:project, namespace: parent) } - subject(:found_group) { Group.with_selects_for_list.find_by(id: parent.id) } + let(:archived_parameter) { nil } - describe '.with_selects_for_list' do - it 'includes the preloaded counts for groups' do - create(:group, parent: parent) - create(:project, namespace: parent) - parent.add_developer(create(:user)) + before do + parent.add_developer(create(:user)) + end - found_group = Group.with_selects_for_list.find_by(id: parent.id) + subject(:found_group) { Group.with_selects_for_list(archived: archived_parameter).find_by(id: parent.id) } + describe '.with_selects_for_list' do + it 'includes the preloaded counts for groups' do expect(found_group.preloaded_project_count).to eq(1) expect(found_group.preloaded_subgroup_count).to eq(1) expect(found_group.preloaded_member_count).to eq(1) end + context 'with project namespaces' do + let_it_be(:group1) { create(:group, parent: parent) } + let_it_be(:group2) { create(:group, parent: parent) } + let_it_be(:project_namespace) { project.project_namespace } + + it 'does not include project_namespaces in the count of subgroups' do + expect(found_group.preloaded_subgroup_count).to eq(3) + expect(parent.subgroup_count).to eq(3) + end + end + context 'with archived projects' do - it 'counts including archived projects when `true` is passed' do - create(:project, namespace: parent, archived: true) - create(:project, namespace: parent) + let_it_be(:archived_project) { create(:project, namespace: parent, archived: true) } - found_group = Group.with_selects_for_list(archived: 'true').find_by(id: parent.id) + let(:archived_parameter) { true } + it 'counts including archived projects when `true` is passed' do expect(found_group.preloaded_project_count).to eq(2) end - it 'counts only archived projects when `only` is passed' do - create_list(:project, 2, namespace: parent, archived: true) - create(:project, namespace: parent) + context 'when not counting archived projects' do + let(:archived_parameter) { false } + + it 'counts projects without archived ones' do + expect(found_group.preloaded_project_count).to eq(1) + end + end + + context 'with archived only' do + let_it_be(:archived_project2) { create(:project, namespace: parent, archived: true) } - found_group = Group.with_selects_for_list(archived: 'only').find_by(id: parent.id) + let(:archived_parameter) { 'only' } - expect(found_group.preloaded_project_count).to eq(2) + it 'counts only archived projects when `only` is passed' do + expect(found_group.preloaded_project_count).to eq(2) + end end end end describe '#children_count' do it 'counts groups and projects' do - create(:group, parent: parent) - create(:project, namespace: parent) - expect(found_group.children_count).to eq(2) end end diff --git a/spec/models/concerns/loose_foreign_key_spec.rb b/spec/models/concerns/loose_foreign_key_spec.rb index ce5e33261a9..42da69eb75e 100644 --- a/spec/models/concerns/loose_foreign_key_spec.rb +++ b/spec/models/concerns/loose_foreign_key_spec.rb @@ -9,8 +9,8 @@ RSpec.describe LooseForeignKey do self.table_name = 'projects' - loose_foreign_key :issues, :project_id, on_delete: :async_delete, gitlab_schema: :gitlab_main - loose_foreign_key 'merge_requests', 'project_id', 'on_delete' => 'async_nullify', 'gitlab_schema' => :gitlab_main + loose_foreign_key :issues, :project_id, on_delete: :async_delete + loose_foreign_key 'merge_requests', 'project_id', 'on_delete' => 'async_nullify' end end @@ -28,7 +28,6 @@ RSpec.describe LooseForeignKey do expect(definition.to_table).to eq('merge_requests') expect(definition.column).to eq('project_id') expect(definition.on_delete).to eq(:async_nullify) - expect(definition.options[:gitlab_schema]).to eq(:gitlab_main) end context 'validation' do @@ -39,9 +38,9 @@ RSpec.describe LooseForeignKey do self.table_name = 'projects' - loose_foreign_key :issues, :project_id, on_delete: :async_delete, gitlab_schema: :gitlab_main - loose_foreign_key :merge_requests, :project_id, on_delete: :async_nullify, gitlab_schema: :gitlab_main - loose_foreign_key :merge_requests, :project_id, on_delete: :destroy, gitlab_schema: :gitlab_main + loose_foreign_key :issues, :project_id, on_delete: :async_delete + loose_foreign_key :merge_requests, :project_id, on_delete: :async_nullify + loose_foreign_key :merge_requests, :project_id, on_delete: :destroy end end @@ -50,28 +49,12 @@ RSpec.describe LooseForeignKey do end end - context 'gitlab_schema validation' do - let(:invalid_class) do - Class.new(ApplicationRecord) do - include LooseForeignKey - - self.table_name = 'projects' - - loose_foreign_key :merge_requests, :project_id, on_delete: :async_nullify, gitlab_schema: :unknown - end - end - - it 'raises error when invalid `gitlab_schema` option was given' do - expect { invalid_class }.to raise_error /Invalid gitlab_schema option given: unknown/ - end - end - context 'inheritance validation' do let(:inherited_project_class) do Class.new(Project) do include LooseForeignKey - loose_foreign_key :issues, :project_id, on_delete: :async_delete, gitlab_schema: :gitlab_main + loose_foreign_key :issues, :project_id, on_delete: :async_delete end end diff --git a/spec/models/concerns/noteable_spec.rb b/spec/models/concerns/noteable_spec.rb index 38766d8decd..81ae30b7116 100644 --- a/spec/models/concerns/noteable_spec.rb +++ b/spec/models/concerns/noteable_spec.rb @@ -77,6 +77,70 @@ RSpec.describe Noteable do end end + describe '#discussion_root_note_ids' do + let!(:label_event) { create(:resource_label_event, merge_request: subject) } + let!(:system_note) { create(:system_note, project: project, noteable: subject) } + let!(:milestone_event) { create(:resource_milestone_event, merge_request: subject) } + let!(:state_event) { create(:resource_state_event, merge_request: subject) } + + it 'returns ordered discussion_ids and synthetic note ids' do + discussions = subject.discussion_root_note_ids(notes_filter: UserPreference::NOTES_FILTERS[:all_notes]).map do |n| + { table_name: n.table_name, discussion_id: n.discussion_id, id: n.id } + end + + expect(discussions).to match([ + a_hash_including(table_name: 'notes', discussion_id: active_diff_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: active_diff_note3.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: outdated_diff_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: discussion_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: commit_diff_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: commit_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: commit_note2.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: commit_discussion_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: commit_discussion_note3.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: note2.discussion_id), + a_hash_including(table_name: 'resource_label_events', id: label_event.id), + a_hash_including(table_name: 'notes', discussion_id: system_note.discussion_id), + a_hash_including(table_name: 'resource_milestone_events', id: milestone_event.id), + a_hash_including(table_name: 'resource_state_events', id: state_event.id) + ]) + end + + it 'filters by comments only' do + discussions = subject.discussion_root_note_ids(notes_filter: UserPreference::NOTES_FILTERS[:only_comments]).map do |n| + { table_name: n.table_name, discussion_id: n.discussion_id, id: n.id } + end + + expect(discussions).to match([ + a_hash_including(table_name: 'notes', discussion_id: active_diff_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: active_diff_note3.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: outdated_diff_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: discussion_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: commit_diff_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: commit_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: commit_note2.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: commit_discussion_note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: commit_discussion_note3.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: note1.discussion_id), + a_hash_including(table_name: 'notes', discussion_id: note2.discussion_id) + ]) + end + + it 'filters by system notes only' do + discussions = subject.discussion_root_note_ids(notes_filter: UserPreference::NOTES_FILTERS[:only_activity]).map do |n| + { table_name: n.table_name, discussion_id: n.discussion_id, id: n.id } + end + + expect(discussions).to match([ + a_hash_including(table_name: 'resource_label_events', id: label_event.id), + a_hash_including(table_name: 'notes', discussion_id: system_note.discussion_id), + a_hash_including(table_name: 'resource_milestone_events', id: milestone_event.id), + a_hash_including(table_name: 'resource_state_events', id: state_event.id) + ]) + end + end + describe '#grouped_diff_discussions' do let(:grouped_diff_discussions) { subject.grouped_diff_discussions } diff --git a/spec/models/concerns/prometheus_adapter_spec.rb b/spec/models/concerns/prometheus_adapter_spec.rb index 01c987a1d92..4158e8a0a4c 100644 --- a/spec/models/concerns/prometheus_adapter_spec.rb +++ b/spec/models/concerns/prometheus_adapter_spec.rb @@ -165,6 +165,14 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do it { is_expected.to eq(success: false, result: %(#{status} - "QUERY FAILED!")) } end end + + context "when client raises Gitlab::PrometheusClient::ConnectionError" do + before do + stub_any_prometheus_request.to_raise(Gitlab::PrometheusClient::ConnectionError) + end + + it { is_expected.to include(success: false, result: kind_of(String)) } + end end describe '#build_query_args' do diff --git a/spec/models/concerns/reactive_caching_spec.rb b/spec/models/concerns/reactive_caching_spec.rb index 7e031bdd263..4f3b95e43cd 100644 --- a/spec/models/concerns/reactive_caching_spec.rb +++ b/spec/models/concerns/reactive_caching_spec.rb @@ -375,7 +375,7 @@ RSpec.describe ReactiveCaching, :use_clean_rails_memory_store_caching do end describe 'classes including this concern' do - it 'sets reactive_cache_work_type' do + it 'sets reactive_cache_work_type', :eager_load do classes = ObjectSpace.each_object(Class).select do |klass| klass < described_class && klass.name end diff --git a/spec/models/concerns/sha256_attribute_spec.rb b/spec/models/concerns/sha256_attribute_spec.rb index c247865d77f..02947325bf4 100644 --- a/spec/models/concerns/sha256_attribute_spec.rb +++ b/spec/models/concerns/sha256_attribute_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Sha256Attribute do - let(:model) { Class.new { include Sha256Attribute } } + let(:model) { Class.new(ApplicationRecord) { include Sha256Attribute } } before do columns = [ diff --git a/spec/models/concerns/sha_attribute_spec.rb b/spec/models/concerns/sha_attribute_spec.rb index 3846dd9c231..220eadfab92 100644 --- a/spec/models/concerns/sha_attribute_spec.rb +++ b/spec/models/concerns/sha_attribute_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe ShaAttribute do - let(:model) { Class.new { include ShaAttribute } } + let(:model) { Class.new(ApplicationRecord) { include ShaAttribute } } before do columns = [ diff --git a/spec/models/concerns/where_composite_spec.rb b/spec/models/concerns/where_composite_spec.rb index 5e67f2f5b65..6abdd12aac5 100644 --- a/spec/models/concerns/where_composite_spec.rb +++ b/spec/models/concerns/where_composite_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe WhereComposite do describe '.where_composite' do - let_it_be(:test_table_name) { "test_table_#{SecureRandom.hex(10)}" } + let_it_be(:test_table_name) { "_test_table_#{SecureRandom.hex(10)}" } let(:model) do tbl_name = test_table_name diff --git a/spec/models/concerns/x509_serial_number_attribute_spec.rb b/spec/models/concerns/x509_serial_number_attribute_spec.rb index 88550823748..723e2ad07b6 100644 --- a/spec/models/concerns/x509_serial_number_attribute_spec.rb +++ b/spec/models/concerns/x509_serial_number_attribute_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe X509SerialNumberAttribute do - let(:model) { Class.new { include X509SerialNumberAttribute } } + let(:model) { Class.new(ApplicationRecord) { include X509SerialNumberAttribute } } before do columns = [ |