summaryrefslogtreecommitdiff
path: root/spec/models/user_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r--spec/models/user_spec.rb69
1 files changed, 25 insertions, 44 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index cb34917f073..f1c30a646f5 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -22,6 +22,8 @@ RSpec.describe User do
describe 'constants' do
it { expect(described_class::COUNT_CACHE_VALIDITY_PERIOD).to be_a(Integer) }
+ it { expect(described_class::MAX_USERNAME_LENGTH).to be_a(Integer) }
+ it { expect(described_class::MIN_USERNAME_LENGTH).to be_a(Integer) }
end
describe 'delegations' do
@@ -72,6 +74,9 @@ RSpec.describe User do
it { is_expected.to delegate_method(:job_title).to(:user_detail).allow_nil }
it { is_expected.to delegate_method(:job_title=).to(:user_detail).with_arguments(:args).allow_nil }
+ it { is_expected.to delegate_method(:pronouns).to(:user_detail).allow_nil }
+ it { is_expected.to delegate_method(:pronouns=).to(:user_detail).with_arguments(:args).allow_nil }
+
it { is_expected.to delegate_method(:bio).to(:user_detail).allow_nil }
it { is_expected.to delegate_method(:bio=).to(:user_detail).with_arguments(:args).allow_nil }
it { is_expected.to delegate_method(:bio_html).to(:user_detail).allow_nil }
@@ -90,7 +95,7 @@ RSpec.describe User do
it { is_expected.to have_many(:group_members) }
it { is_expected.to have_many(:groups) }
it { is_expected.to have_many(:keys).dependent(:destroy) }
- it { is_expected.to have_many(:expired_today_and_unnotified_keys) }
+ it { is_expected.to have_many(:expired_and_unnotified_keys) }
it { is_expected.to have_many(:deploy_keys).dependent(:nullify) }
it { is_expected.to have_many(:group_deploy_keys) }
it { is_expected.to have_many(:events).dependent(:delete_all) }
@@ -134,6 +139,12 @@ RSpec.describe User do
expect(user.bio).to eq(user.user_detail.bio)
end
+ it 'delegates `pronouns` to `user_detail`' do
+ user = create(:user, pronouns: 'they/them')
+
+ expect(user.pronouns).to eq(user.user_detail.pronouns)
+ end
+
it 'creates `user_detail` when `bio` is first updated' do
user = create(:user)
@@ -1025,12 +1036,6 @@ RSpec.describe User do
let_it_be(:expiring_soon_not_notified) { create(:key, expires_at: 2.days.from_now, user: user2) }
let_it_be(:expiring_soon_notified) { create(:key, expires_at: 2.days.from_now, user: user1, before_expiry_notification_delivered_at: Time.current) }
- describe '.with_ssh_key_expired_today' do
- it 'returns users whose key has expired today' do
- expect(described_class.with_ssh_key_expired_today).to contain_exactly(user1)
- end
- end
-
describe '.with_ssh_key_expiring_soon' do
it 'returns users whose keys will expire soon' do
expect(described_class.with_ssh_key_expiring_soon).to contain_exactly(user2)
@@ -4258,45 +4263,16 @@ RSpec.describe User do
end
describe '#invalidate_issue_cache_counts' do
- let_it_be(:user) { create(:user) }
-
- subject do
- user.invalidate_issue_cache_counts
- user.save!
- end
-
- shared_examples 'invalidates the cached value' do
- it 'invalidates cache for issue counter' do
- expect(Rails.cache).to receive(:delete).with(['users', user.id, 'assigned_open_issues_count'])
-
- subject
- end
- end
-
- it_behaves_like 'invalidates the cached value'
-
- context 'if feature flag assigned_open_issues_cache is enabled' do
- it 'calls the recalculate worker' do
- expect(Users::UpdateOpenIssueCountWorker).to receive(:perform_async).with(user.id)
-
- subject
- end
-
- it_behaves_like 'invalidates the cached value'
- end
+ let(:user) { build_stubbed(:user) }
- context 'if feature flag assigned_open_issues_cache is disabled' do
- before do
- stub_feature_flags(assigned_open_issues_cache: false)
- end
+ it 'invalidates cache for issue counter' do
+ cache_mock = double
- it 'does not call the recalculate worker' do
- expect(Users::UpdateOpenIssueCountWorker).not_to receive(:perform_async).with(user.id)
+ expect(cache_mock).to receive(:delete).with(['users', user.id, 'assigned_open_issues_count'])
- subject
- end
+ allow(Rails).to receive(:cache).and_return(cache_mock)
- it_behaves_like 'invalidates the cached value'
+ user.invalidate_issue_cache_counts
end
end
@@ -5272,9 +5248,10 @@ RSpec.describe User do
let_it_be(:user3) { create(:user, :ghost) }
let_it_be(:user4) { create(:user, user_type: :support_bot) }
let_it_be(:user5) { create(:user, state: 'blocked', user_type: :support_bot) }
+ let_it_be(:user6) { create(:user, user_type: :automation_bot) }
it 'returns all active users including active bots but ghost users' do
- expect(described_class.active_without_ghosts).to match_array([user1, user4])
+ expect(described_class.active_without_ghosts).to match_array([user1, user4, user6])
end
end
@@ -5409,7 +5386,8 @@ RSpec.describe User do
{ user_type: :ghost },
{ user_type: :alert_bot },
{ user_type: :support_bot },
- { user_type: :security_bot }
+ { user_type: :security_bot },
+ { user_type: :automation_bot }
]
end
@@ -5465,6 +5443,7 @@ RSpec.describe User do
'alert_bot' | false
'support_bot' | false
'security_bot' | false
+ 'automation_bot' | false
end
with_them do
@@ -5612,10 +5591,12 @@ RSpec.describe User do
it_behaves_like 'bot users', :migration_bot
it_behaves_like 'bot users', :security_bot
it_behaves_like 'bot users', :ghost
+ it_behaves_like 'bot users', :automation_bot
it_behaves_like 'bot user avatars', :alert_bot, 'alert-bot.png'
it_behaves_like 'bot user avatars', :support_bot, 'support-bot.png'
it_behaves_like 'bot user avatars', :security_bot, 'security-bot.png'
+ it_behaves_like 'bot user avatars', :automation_bot, 'support-bot.png'
context 'when bot is the support_bot' do
subject { described_class.support_bot }