auth_spec.rb 1.5 KB

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