digit_spec.rb 1001 B

1234567891011121314151617181920212223242526272829303132333435
  1. require 'rails_helper'
  2. require 'lib/password_policy/error_examples'
  3. RSpec.describe PasswordPolicy::Digit do
  4. it_behaves_like 'declaring an error'
  5. describe '.applicable?' do
  6. it "returns false when Setting 'password_need_digit' is disabled" do
  7. Setting.set('password_need_digit', 0)
  8. expect(described_class).not_to be_applicable
  9. end
  10. it "returns true when Setting 'password_need_digit' is enabled" do
  11. Setting.set('password_need_digit', 1)
  12. expect(described_class).to be_applicable
  13. end
  14. end
  15. describe '#valid?' do
  16. it 'valid when digit is included' do
  17. instance = described_class.new('goodPW!!1111')
  18. expect(instance).to be_valid
  19. end
  20. it 'not valid when only letters' do
  21. instance = described_class.new('notsogoodpw')
  22. expect(instance).not_to be_valid
  23. end
  24. it 'not valid when includes special characters' do
  25. instance = described_class.new('notsogoodpw@#!')
  26. expect(instance).not_to be_valid
  27. end
  28. end
  29. end