ldap_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. require 'rails_helper'
  2. require 'lib/import/import_job_backend_examples'
  3. RSpec.describe Import::Ldap, sequencer: :caller do
  4. it_behaves_like 'ImportJob backend'
  5. describe '.queueable?' do
  6. it 'is queueable if LDAP integration is activated and configured' do
  7. allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
  8. allow(Setting).to receive(:get).with('ldap_config').and_return({ host: 'some' })
  9. expect(described_class.queueable?).to be true
  10. end
  11. it "isn't queueable if LDAP integration is deactivated" do
  12. allow(Setting).to receive(:get).with('ldap_integration').and_return(false)
  13. allow(Setting).to receive(:get).with('ldap_config').and_return({ host: 'some' })
  14. expect(described_class.queueable?).to be false
  15. end
  16. it "isn't queueable if LDAP configuration is missing" do
  17. allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
  18. allow(Setting).to receive(:get).with('ldap_config').and_return({})
  19. expect(described_class.queueable?).to be false
  20. end
  21. end
  22. describe '#start' do
  23. it 'starts LDAP import resource factories' do
  24. import_job = create(:import_job)
  25. instance = described_class.new(import_job)
  26. allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
  27. allow(Setting).to receive(:get).with('ldap_config').and_return(true)
  28. expect_sequence
  29. instance.start
  30. end
  31. context 'requirements' do
  32. it 'lets dry runs always start' do
  33. import_job = create(:import_job, dry_run: true)
  34. instance = described_class.new(import_job)
  35. expect_sequence
  36. instance.start
  37. end
  38. it 'informs about deactivated ldap_integration' do
  39. import_job = create(:import_job)
  40. instance = described_class.new(import_job)
  41. allow(Setting).to receive(:get).with('ldap_integration').and_return(false)
  42. expect_no_sequence
  43. expect do
  44. instance.start
  45. import_job.reload
  46. end.to change {
  47. import_job.result
  48. }
  49. expect(import_job.result.key?(:info)).to be true
  50. end
  51. it 'informs about blank ldap_config' do
  52. import_job = create(:import_job)
  53. instance = described_class.new(import_job)
  54. allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
  55. allow(Setting).to receive(:get).with('ldap_config').and_return({})
  56. expect_no_sequence
  57. expect do
  58. instance.start
  59. import_job.reload
  60. end.to change {
  61. import_job.result
  62. }
  63. expect(import_job.result.key?(:info)).to be true
  64. end
  65. end
  66. end
  67. describe '#reschedule?' do
  68. it 'initiates always a rescheduling' do
  69. import_job = create(:import_job)
  70. instance = described_class.new(import_job)
  71. delayed_job = double()
  72. expect(instance.reschedule?(delayed_job)).to be true
  73. end
  74. it 'updates the result with an info text' do
  75. import_job = create(:import_job)
  76. instance = described_class.new(import_job)
  77. delayed_job = double()
  78. expect do
  79. instance.reschedule?(delayed_job)
  80. end.to change {
  81. import_job.result
  82. }
  83. expect(import_job.result.key?(:info)).to be true
  84. end
  85. end
  86. end