Refactored FactoryBot User factory.
This commit is contained in:
parent
d00f82b63a
commit
68881113e4
2 changed files with 12 additions and 5 deletions
|
@ -22,7 +22,11 @@ FactoryBot.define do
|
||||||
role_ids { Role.signup_role_ids.sort }
|
role_ids { Role.signup_role_ids.sort }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :user_login_failed, parent: :user do
|
factory :agent_user, parent: :user do
|
||||||
login_failed { (Setting.get('password_max_login_failed').to_i || 10) + 1 }
|
roles { Role.where(name: 'Agent') }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :admin_user, parent: :user do
|
||||||
|
roles { Role.where(name: %w[Admin Agent]) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,8 @@ require 'models/concerns/has_groups_permissions_examples'
|
||||||
|
|
||||||
RSpec.describe User do
|
RSpec.describe User do
|
||||||
|
|
||||||
let(:group_access_instance) { create(:user, roles: [Role.find_by(name: 'Agent')]) }
|
let(:group_access_instance) { create(:agent_user) }
|
||||||
let(:new_group_access_instance) { build(:user, roles: [Role.find_by(name: 'Agent')]) }
|
let(:new_group_access_instance) { build(:agent_user) }
|
||||||
let(:group_access_no_permission_instance) { build(:user) }
|
let(:group_access_no_permission_instance) { build(:user) }
|
||||||
|
|
||||||
include_examples 'HasGroups'
|
include_examples 'HasGroups'
|
||||||
|
@ -18,7 +18,10 @@ RSpec.describe User do
|
||||||
context 'password' do
|
context 'password' do
|
||||||
|
|
||||||
it 'resets login_failed on password change' 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
|
expect do
|
||||||
user.password = new_password
|
user.password = new_password
|
||||||
user.save
|
user.save
|
||||||
|
|
Loading…
Reference in a new issue