Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/database/dictionary_spec.rb51
-rw-r--r--spec/lib/gitlab/database/no_new_tables_with_gitlab_main_schema_spec.rb10
-rw-r--r--spec/lib/gitlab/database/sharding_key_spec.rb6
-rw-r--r--spec/lib/gitlab/import_export/all_models.yml2
-rw-r--r--spec/models/members/members/member_approval_spec.rb17
-rw-r--r--spec/services/merge_requests/request_review_service_spec.rb23
6 files changed, 97 insertions, 12 deletions
diff --git a/spec/lib/gitlab/database/dictionary_spec.rb b/spec/lib/gitlab/database/dictionary_spec.rb
index 59145842b24..2a7535ffb23 100644
--- a/spec/lib/gitlab/database/dictionary_spec.rb
+++ b/spec/lib/gitlab/database/dictionary_spec.rb
@@ -3,10 +3,12 @@
require 'spec_helper'
RSpec.describe Gitlab::Database::Dictionary, feature_category: :database do
+ subject(:dictionary) { described_class.entries('') }
+
describe '.entries' do
it 'all tables and views are unique' do
- table_and_view_names = described_class.entries('')
- table_and_view_names += described_class.entries('views')
+ table_and_view_names = dictionary.to_a
+ table_and_view_names += described_class.entries('views').to_a
# ignore gitlab_internal due to `ar_internal_metadata`, `schema_migrations`
table_and_view_names = table_and_view_names
@@ -22,6 +24,51 @@ RSpec.describe Gitlab::Database::Dictionary, feature_category: :database do
"Any duplicated table must be removed from db/docs/ or ee/db/docs/. " \
"More info: https://docs.gitlab.com/ee/development/database/database_dictionary.html"
end
+
+ it 'builds a Dictionary with validated Entry records' do
+ expect { dictionary }.not_to raise_error
+
+ expect(dictionary).to be_instance_of(described_class)
+ expect(dictionary).to all(be_instance_of(Gitlab::Database::Dictionary::Entry))
+ end
+ end
+
+ describe '#to_name_and_schema_mapping' do
+ it 'returns a hash of name and schema mappings' do
+ expect(dictionary.to_name_and_schema_mapping).to include(
+ {
+ 'application_settings' => :gitlab_main_clusterwide,
+ 'members' => :gitlab_main_cell
+ }
+ )
+ end
+ end
+
+ describe '#find_by_table_name' do
+ it 'finds an entry by table name' do
+ entry = dictionary.find_by_table_name('application_settings')
+ expect(entry).to be_instance_of(Gitlab::Database::Dictionary::Entry)
+ expect(entry.key_name).to eq('application_settings')
+ expect(entry.gitlab_schema).to eq('gitlab_main_clusterwide')
+ end
+
+ it 'returns nil if the entry is not found' do
+ entry = dictionary.find_by_table_name('non_existent_table')
+ expect(entry).to be_nil
+ end
+ end
+
+ describe '#find_all_by_schema' do
+ it 'returns an array of entries with a given schema' do
+ entries = dictionary.find_all_by_schema('gitlab_main_cell')
+ expect(entries).to all(be_instance_of(Gitlab::Database::Dictionary::Entry))
+ expect(entries).to all(have_attributes(gitlab_schema: 'gitlab_main_cell'))
+ end
+
+ it 'returns an empty array if no entries match the schema' do
+ entries = dictionary.find_all_by_schema('non_existent_schema')
+ expect(entries).to be_empty
+ end
end
describe '.any_entry' do
diff --git a/spec/lib/gitlab/database/no_new_tables_with_gitlab_main_schema_spec.rb b/spec/lib/gitlab/database/no_new_tables_with_gitlab_main_schema_spec.rb
index 4fc62c6cc74..09cf7808042 100644
--- a/spec/lib/gitlab/database/no_new_tables_with_gitlab_main_schema_spec.rb
+++ b/spec/lib/gitlab/database/no_new_tables_with_gitlab_main_schema_spec.rb
@@ -51,16 +51,12 @@ RSpec.describe 'new tables with gitlab_main schema', feature_category: :cell do
end
def tables_having_gitlab_main_schema(starting_from_milestone:)
- selected_data = gitlab_main_schema_tables.select do |entry|
- entry.milestone.to_f >= starting_from_milestone
+ gitlab_main_schema_tables.filter_map do |entry|
+ entry.table_name if entry.milestone.to_f >= starting_from_milestone
end
-
- selected_data.map(&:table_name)
end
def gitlab_main_schema_tables
- ::Gitlab::Database::Dictionary.entries.select do |entry|
- entry.schema?('gitlab_main')
- end
+ ::Gitlab::Database::Dictionary.entries.find_all_by_schema('gitlab_main')
end
end
diff --git a/spec/lib/gitlab/database/sharding_key_spec.rb b/spec/lib/gitlab/database/sharding_key_spec.rb
index 67c1422af3c..dfd78bfacba 100644
--- a/spec/lib/gitlab/database/sharding_key_spec.rb
+++ b/spec/lib/gitlab/database/sharding_key_spec.rb
@@ -108,11 +108,11 @@ RSpec.describe 'new tables missing sharding_key', feature_category: :cell do
end
def tables_missing_sharding_key(starting_from_milestone:)
- ::Gitlab::Database::Dictionary.entries.select do |entry|
- entry.sharding_key.blank? &&
+ ::Gitlab::Database::Dictionary.entries.filter_map do |entry|
+ entry.table_name if entry.sharding_key.blank? &&
entry.milestone.to_f >= starting_from_milestone &&
::Gitlab::Database::GitlabSchema.cell_local?(entry.gitlab_schema)
- end.map(&:table_name)
+ end
end
def all_tables_to_sharding_key
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml
index 8da05ed7b7e..6d5c17176dc 100644
--- a/spec/lib/gitlab/import_export/all_models.yml
+++ b/spec/lib/gitlab/import_export/all_models.yml
@@ -176,6 +176,7 @@ project_members:
- project
- member_namespace
- member_role
+- member_approvals
member_roles:
- members
- namespace
@@ -838,6 +839,7 @@ project:
- organization
- dora_performance_scores
- xray_reports
+- member_approvals
award_emoji:
- awardable
- user
diff --git a/spec/models/members/members/member_approval_spec.rb b/spec/models/members/members/member_approval_spec.rb
new file mode 100644
index 00000000000..ed012a5a7c0
--- /dev/null
+++ b/spec/models/members/members/member_approval_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Members::MemberApproval, feature_category: :groups_and_projects do
+ describe 'associations' do
+ it { is_expected.to belong_to(:member) }
+ it { is_expected.to belong_to(:member_namespace) }
+ it { is_expected.to belong_to(:reviewed_by) }
+ it { is_expected.to belong_to(:requested_by) }
+ end
+
+ describe 'validations' do
+ it { is_expected.to validate_presence_of(:new_access_level) }
+ it { is_expected.to validate_presence_of(:old_access_level) }
+ end
+end
diff --git a/spec/services/merge_requests/request_review_service_spec.rb b/spec/services/merge_requests/request_review_service_spec.rb
index a5f0d5b5c5a..7e2931288de 100644
--- a/spec/services/merge_requests/request_review_service_spec.rb
+++ b/spec/services/merge_requests/request_review_service_spec.rb
@@ -82,6 +82,29 @@ RSpec.describe MergeRequests::RequestReviewService, feature_category: :code_revi
it_behaves_like 'triggers GraphQL subscription mergeRequestReviewersUpdated' do
let(:action) { result }
end
+
+ it 'calls MergeRequests::RemoveApprovalService' do
+ expect_next_instance_of(
+ MergeRequests::RemoveApprovalService,
+ project: project, current_user: current_user
+ ) do |service|
+ expect(service).to receive(:execute).with(merge_request).and_return({ success: true })
+ end
+
+ service.execute(merge_request, user)
+ end
+
+ describe 'mr_request_changes feature flag is disabled' do
+ before do
+ stub_feature_flags(mr_request_changes: false)
+ end
+
+ it 'does not call MergeRequests::RemoveApprovalService' do
+ expect(MergeRequests::RemoveApprovalService).not_to receive(:new)
+
+ service.execute(merge_request, user)
+ end
+ end
end
end
end