diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 4272f225d..38cfeb0c9 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -22,7 +22,11 @@ FactoryBot.define do role_ids { Role.signup_role_ids.sort } end - factory :user_login_failed, parent: :user do - login_failed { (Setting.get('password_max_login_failed').to_i || 10) + 1 } + factory :agent_user, parent: :user do + roles { Role.where(name: 'Agent') } + end + + factory :admin_user, parent: :user do + roles { Role.where(name: %w[Admin Agent]) } end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 6e814ec6a..79aa14f33 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -5,8 +5,8 @@ require 'models/concerns/has_groups_permissions_examples' RSpec.describe User do - let(:group_access_instance) { create(:user, roles: [Role.find_by(name: 'Agent')]) } - let(:new_group_access_instance) { build(:user, roles: [Role.find_by(name: 'Agent')]) } + let(:group_access_instance) { create(:agent_user) } + let(:new_group_access_instance) { build(:agent_user) } let(:group_access_no_permission_instance) { build(:user) } include_examples 'HasGroups' @@ -18,7 +18,10 @@ RSpec.describe User do context 'password' do it 'resets login_failed on password change' do - user = create(:user_login_failed) + + failed_logins = (Setting.get('password_max_login_failed').to_i || 10) + 1 + user = create(:user, login_failed: failed_logins) + expect do user.password = new_password user.save