auth_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. require 'rails_helper'
  2. RSpec.describe Auth do
  3. context '.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. end
  29. context '.valid?' do
  30. it 'responds to valid?' do
  31. expect(described_class).to respond_to(:valid?)
  32. end
  33. it 'authenticates users' do
  34. user = create(:user)
  35. result = described_class.valid?(user, 'zammad')
  36. expect(result).to be true
  37. end
  38. end
  39. context '.backends' do
  40. it 'responds to backends' do
  41. expect(described_class).to respond_to(:backends)
  42. end
  43. it 'returns a list of Hashes' do
  44. result = described_class.backends
  45. expect(result).to be_an(Array)
  46. expect(result.first).to be_a(Hash)
  47. end
  48. end
  49. end