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.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index fa2e4b63648..f9b819e22cd 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -76,6 +76,7 @@ RSpec.describe User do
it { is_expected.to have_many(:groups) }
it { is_expected.to have_many(:keys).dependent(:destroy) }
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) }
it { is_expected.to have_many(:issues).dependent(:destroy) }
it { is_expected.to have_many(:notes).dependent(:destroy) }
@@ -241,6 +242,22 @@ RSpec.describe User do
it { is_expected.to validate_length_of(:last_name).is_at_most(127) }
end
+ describe 'preferred_language' do
+ context 'when its value is nil in the database' do
+ let(:user) { build(:user, preferred_language: nil) }
+
+ it 'falls back to I18n.default_locale when empty in the database' do
+ expect(user.preferred_language).to eq I18n.default_locale.to_s
+ end
+
+ it 'falls back to english when I18n.default_locale is not an available language' do
+ I18n.default_locale = :kl
+
+ expect(user.preferred_language).to eq 'en'
+ end
+ end
+ end
+
describe 'username' do
it 'validates presence' do
expect(subject).to validate_presence_of(:username)
@@ -839,6 +856,24 @@ RSpec.describe User do
end
end
+ describe '.with_personal_access_tokens_expired_today' do
+ let_it_be(:user1) { create(:user) }
+ let_it_be(:expired_today) { create(:personal_access_token, user: user1, expires_at: Date.current) }
+
+ let_it_be(:user2) { create(:user) }
+ let_it_be(:revoked_token) { create(:personal_access_token, user: user2, expires_at: Date.current, revoked: true) }
+
+ let_it_be(:user3) { create(:user) }
+ let_it_be(:impersonated_token) { create(:personal_access_token, user: user3, expires_at: Date.current, impersonation: true) }
+
+ let_it_be(:user4) { create(:user) }
+ let_it_be(:already_notified) { create(:personal_access_token, user: user4, expires_at: Date.current, after_expiry_notification_delivered: true) }
+
+ it 'returns users whose token has expired today' do
+ expect(described_class.with_personal_access_tokens_expired_today).to contain_exactly(user1)
+ end
+ end
+
describe '.active_without_ghosts' do
let_it_be(:user1) { create(:user, :external) }
let_it_be(:user2) { create(:user, state: 'blocked') }