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
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/users')
-rw-r--r--spec/services/users/assigned_issues_count_service_spec.rb57
-rw-r--r--spec/services/users/keys_count_service_spec.rb6
-rw-r--r--spec/services/users/migrate_records_to_ghost_user_service_spec.rb14
-rw-r--r--spec/services/users/registrations_build_service_spec.rb4
4 files changed, 73 insertions, 8 deletions
diff --git a/spec/services/users/assigned_issues_count_service_spec.rb b/spec/services/users/assigned_issues_count_service_spec.rb
new file mode 100644
index 00000000000..afa6a0af3dd
--- /dev/null
+++ b/spec/services/users/assigned_issues_count_service_spec.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Users::AssignedIssuesCountService, :use_clean_rails_memory_store_caching,
+ feature_category: :project_management do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:max_limit) { 10 }
+
+ let(:current_user) { user }
+
+ subject { described_class.new(current_user: current_user, max_limit: max_limit) }
+
+ it_behaves_like 'a counter caching service'
+
+ context 'when user has assigned open issues from archived and closed projects' do
+ before do
+ project = create(:project, :public)
+ archived_project = create(:project, :public, :archived)
+
+ create(:issue, project: project, author: user, assignees: [user])
+ create(:issue, :closed, project: project, author: user, assignees: [user])
+ create(:issue, project: archived_project, author: user, assignees: [user])
+ end
+
+ it 'count all assigned open issues excluding those from closed or archived projects' do
+ expect(subject.count).to eq(1)
+ end
+ end
+
+ context 'when the number of assigned open issues exceeds max_limit' do
+ let_it_be(:banned_user) { create(:user, :banned) }
+ let_it_be(:project) { create(:project).tap { |p| p.add_developer(user) } }
+
+ context 'when user is admin', :enable_admin_mode do
+ let_it_be(:admin) { create(:admin) }
+ let_it_be(:issues) { create_list(:issue, max_limit + 1, project: project, assignees: [admin]) }
+ let_it_be(:banned_issue) { create(:issue, project: project, assignees: [admin], author: banned_user) }
+
+ let(:current_user) { admin }
+
+ it 'returns the max_limit count' do
+ expect(subject.count).to eq max_limit
+ end
+ end
+
+ context 'when user is non-admin' do
+ let_it_be(:issues) { create_list(:issue, max_limit + 1, project: project, assignees: [user]) }
+ let_it_be(:closed_issue) { create(:issue, :closed, project: project, assignees: [user]) }
+ let_it_be(:banned_issue) { create(:issue, project: project, assignees: [user], author: banned_user) }
+
+ it 'returns the max_limit count' do
+ expect(subject.count).to eq max_limit
+ end
+ end
+ end
+end
diff --git a/spec/services/users/keys_count_service_spec.rb b/spec/services/users/keys_count_service_spec.rb
index aff267cce5e..607d2946b2c 100644
--- a/spec/services/users/keys_count_service_spec.rb
+++ b/spec/services/users/keys_count_service_spec.rb
@@ -17,6 +17,12 @@ RSpec.describe Users::KeysCountService, :use_clean_rails_memory_store_caching do
it 'returns the number of SSH keys as an Integer' do
expect(subject.count).to eq(1)
end
+
+ it 'does not count signing keys' do
+ create(:key, usage_type: :signing, user: user)
+
+ expect(subject.count).to eq(1)
+ end
end
describe '#uncached_count' do
diff --git a/spec/services/users/migrate_records_to_ghost_user_service_spec.rb b/spec/services/users/migrate_records_to_ghost_user_service_spec.rb
index 6082c7bd10e..827d6f652a4 100644
--- a/spec/services/users/migrate_records_to_ghost_user_service_spec.rb
+++ b/spec/services/users/migrate_records_to_ghost_user_service_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Users::MigrateRecordsToGhostUserService do
+ include BatchDestroyDependentAssociationsHelper
+
let!(:user) { create(:user) }
let(:service) { described_class.new(user, admin, execution_tracker) }
let(:execution_tracker) { instance_double(::Gitlab::Utils::ExecutionTracker, over_limit?: false) }
@@ -125,6 +127,12 @@ RSpec.describe Users::MigrateRecordsToGhostUserService do
let(:created_record) { create(:review, author: user) }
end
end
+
+ context 'for releases' do
+ include_examples 'migrating records to the ghost user', Release, [:author] do
+ let(:created_record) { create(:release, author: user) }
+ end
+ end
end
context 'on post-migrate cleanups' do
@@ -150,12 +158,6 @@ RSpec.describe Users::MigrateRecordsToGhostUserService do
def nullify_in_batches_regexp(table, column, user, batch_size: 100)
%r{^UPDATE "#{table}" SET "#{column}" = NULL WHERE "#{table}"."id" IN \(SELECT "#{table}"."id" FROM "#{table}" WHERE "#{table}"."#{column}" = #{user.id} LIMIT #{batch_size}\)}
end
-
- def delete_in_batches_regexps(table, column, user, items, batch_size: 1000)
- select_query = %r{^SELECT "#{table}".* FROM "#{table}" WHERE "#{table}"."#{column}" = #{user.id}.*ORDER BY "#{table}"."id" ASC LIMIT #{batch_size}}
-
- [select_query] + items.map { |item| %r{^DELETE FROM "#{table}" WHERE "#{table}"."id" = #{item.id}} }
- end
# rubocop:enable Layout/LineLength
it 'nullifies related associations in batches' do
diff --git a/spec/services/users/registrations_build_service_spec.rb b/spec/services/users/registrations_build_service_spec.rb
index bc3718dbdb2..fa53a4cc604 100644
--- a/spec/services/users/registrations_build_service_spec.rb
+++ b/spec/services/users/registrations_build_service_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe Users::RegistrationsBuildService do
context 'when automatic user confirmation is not enabled' do
before do
- stub_application_setting(send_user_confirmation_email: true)
+ stub_application_setting_enum('email_confirmation_setting', 'hard')
end
context 'when skip_confirmation is true' do
@@ -44,7 +44,7 @@ RSpec.describe Users::RegistrationsBuildService do
context 'when automatic user confirmation is enabled' do
before do
- stub_application_setting(send_user_confirmation_email: false)
+ stub_application_setting_enum('email_confirmation_setting', 'off')
end
context 'when skip_confirmation is true' do