demarches-normaliennes/spec/models/administrateur_spec.rb

65 lines
1.9 KiB
Ruby
Raw Normal View History

2015-11-04 17:27:01 +01:00
require 'spec_helper'
2015-11-04 17:27:01 +01:00
describe Administrateur, type: :model do
let(:administration) { create(:administration) }
describe 'assocations' do
it { is_expected.to have_and_belong_to_many(:instructeurs) }
it { is_expected.to have_many(:procedures) }
end
describe "#renew_api_token" do
let!(:administrateur) { create(:administrateur) }
let!(:token) { administrateur.renew_api_token }
it { expect(BCrypt::Password.new(administrateur.encrypted_token)).to eq(token) }
context 'when it s called twice' do
let!(:new_token) { administrateur.renew_api_token }
it { expect(new_token).not_to eq(token) }
end
end
describe '#feature_enabled?' do
let(:administrateur) { create(:administrateur) }
before do
2018-12-10 19:47:52 +01:00
administrateur.enable_feature(:test_a)
end
2018-12-10 19:47:52 +01:00
it { expect(administrateur.feature_enabled?(:test_b)).to be_falsey }
it { expect(administrateur.feature_enabled?(:test_a)).to be_truthy }
end
# describe '#password_complexity' do
# let(:email) { 'mail@beta.gouv.fr' }
# let(:passwords) { ['pass', '12pass23', 'démarches ', 'démarches-simple', 'démarches-simplifiées-pwd'] }
# let(:administrateur) { build(:administrateur, email: email, password: password) }
# let(:min_complexity) { PASSWORD_COMPLEXITY_FOR_ADMIN }
# subject do
# administrateur.save
# administrateur.errors.full_messages
# end
# context 'when password is too short' do
# let(:password) { 's' * (PASSWORD_MIN_LENGTH - 1) }
# it { expect(subject).to eq(["Le mot de passe est trop court"]) }
# end
# context 'when password is too simple' do
# let(:password) { passwords[min_complexity - 1] }
# it { expect(subject).to eq(["Le mot de passe n'est pas assez complexe"]) }
# end
# context 'when password is acceptable' do
# let(:password) { passwords[min_complexity] }
# it { expect(subject).to eq([]) }
# end
# end
end