auth_spec.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. require 'rails_helper'
  2. RSpec.describe Auth do
  3. describe '.can_login?' do
  4. it 'responds to can_login?' do
  5. expect(described_class).to respond_to(:can_login?)
  6. end
  7. it 'checks if users can login' do
  8. user = create(:user)
  9. result = described_class.can_login?(user)
  10. expect(result).to be true
  11. end
  12. context 'not loginable' do
  13. it 'fails if user has too many failed logins' do
  14. user = create(:user, login_failed: 999)
  15. result = described_class.can_login?(user)
  16. expect(result).to be false
  17. end
  18. it "fails if user isn't active" do
  19. user = create(:user, active: false)
  20. result = described_class.can_login?(user)
  21. expect(result).to be false
  22. end
  23. it 'fails if parameter is no User instance' do
  24. result = described_class.can_login?('user')
  25. expect(result).to be false
  26. end
  27. end
  28. context 'given default password_max_login_failed' do
  29. it 'passes with 5 attempts' do
  30. user = create(:user, login_failed: 5)
  31. result = described_class.can_login?(user)
  32. expect(result).to be true
  33. end
  34. it 'fails with 6 attempts' do
  35. user = create(:user, login_failed: 6)
  36. result = described_class.can_login?(user)
  37. expect(result).to be false
  38. end
  39. end
  40. end
  41. describe '.valid?' do
  42. it 'responds to valid?' do
  43. expect(described_class).to respond_to(:valid?)
  44. end
  45. it 'authenticates users' do
  46. password = 'zammad'
  47. user = create(:user, password: password)
  48. result = described_class.valid?(user, password)
  49. expect(result).to be true
  50. end
  51. end
  52. describe '.backends' do
  53. it 'responds to backends' do
  54. expect(described_class).to respond_to(:backends)
  55. end
  56. it 'returns a list of Hashes' do
  57. result = described_class.backends
  58. expect(result).to be_an(Array)
  59. expect(result.first).to be_a(Hash)
  60. end
  61. end
  62. end