max_length_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'lib/password_policy/error_examples'
  4. RSpec.describe PasswordPolicy::MaxLength do
  5. let(:long_string) { Faker::Lorem.characters(number: 1_111) }
  6. it_behaves_like 'declaring an error'
  7. describe '.applicable?' do
  8. it 'returns true' do
  9. expect(described_class).to be_applicable
  10. end
  11. end
  12. describe '#valid?' do
  13. it 'long string is invalid' do
  14. instance = described_class.new long_string
  15. expect(instance).not_to be_valid
  16. end
  17. it 'short string is valid' do
  18. instance = described_class.new Faker::Lorem.sentence
  19. expect(instance).to be_valid
  20. end
  21. end
  22. describe '#error' do
  23. it 'includes value of MAX_LENGTH' do
  24. instance = described_class.new(long_string)
  25. expect(instance.error.last).to eq described_class::MAX_LENGTH
  26. end
  27. end
  28. describe '.valid?' do
  29. it 'long string is invalid' do
  30. expect(described_class).not_to be_valid(long_string)
  31. end
  32. it 'short string is valid' do
  33. expect(described_class).to be_valid(Faker::Lorem.sentence)
  34. end
  35. end
  36. end