Introduce ApiUser.min_password_length

#248
This commit is contained in:
Artur Beljajev 2017-01-08 21:28:21 +02:00
parent 1784980e6c
commit fd58024226
2 changed files with 13 additions and 3 deletions

View file

@ -11,12 +11,16 @@ class ApiUser < User
}
end
def self.min_password_length # Must precede .validates
6
end
# TODO: should have max request limit per day?
belongs_to :registrar
has_many :certificates
validates :username, :password, :registrar, :roles, presence: true
validates :password, length: { minimum: 6 }
validates :password, length: { minimum: min_password_length }
validates :username, uniqueness: true
# TODO: probably cache, because it's requested on every EPP

View file

@ -1,6 +1,6 @@
require 'rails_helper'
describe ApiUser do
RSpec.describe ApiUser do
context 'class methods' do
before do
Fabricate(:api_user, identity_code: '')
@ -26,7 +26,7 @@ describe ApiUser do
@api_user.valid?
@api_user.errors.full_messages.should match_array([
"Password Password is missing",
"Password is too short (minimum is 6 characters)",
"Password is too short (minimum is #{ApiUser.min_password_length} characters)",
"Registrar Registrar is missing",
"Username Username is missing",
"Roles is missing"
@ -68,4 +68,10 @@ describe ApiUser do
end
end
end
describe '::min_password_length', db: false do
it 'returns minimum password length' do
expect(described_class.min_password_length).to eq(6)
end
end
end