software_version_check_spec.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::SystemCheck::SoftwareVersionCheck do
  4. include RoutingHelper
  5. subject(:check) { described_class.new(user) }
  6. let(:user) { Fabricate(:user) }
  7. describe 'skip?' do
  8. context 'when user cannot view devops' do
  9. before { allow(user).to receive(:can?).with(:view_devops).and_return(false) }
  10. it 'returns true' do
  11. expect(check.skip?).to be true
  12. end
  13. end
  14. context 'when user can view devops' do
  15. before { allow(user).to receive(:can?).with(:view_devops).and_return(true) }
  16. it 'returns false' do
  17. expect(check.skip?).to be false
  18. end
  19. context 'when checks are disabled' do
  20. around do |example|
  21. ClimateControl.modify UPDATE_CHECK_URL: '' do
  22. example.run
  23. end
  24. end
  25. it 'returns true' do
  26. expect(check.skip?).to be true
  27. end
  28. end
  29. end
  30. end
  31. describe 'pass?' do
  32. context 'when there is no known update' do
  33. it 'returns true' do
  34. expect(check.pass?).to be true
  35. end
  36. end
  37. context 'when there is a non-urgent major release' do
  38. before do
  39. Fabricate(:software_update, version: '99.99.99', type: 'major', urgent: false)
  40. end
  41. it 'returns true' do
  42. expect(check.pass?).to be true
  43. end
  44. end
  45. context 'when there is an urgent major release' do
  46. before do
  47. Fabricate(:software_update, version: '99.99.99', type: 'major', urgent: true)
  48. end
  49. it 'returns false' do
  50. expect(check.pass?).to be false
  51. end
  52. end
  53. context 'when there is an urgent minor release' do
  54. before do
  55. Fabricate(:software_update, version: '99.99.99', type: 'minor', urgent: true)
  56. end
  57. it 'returns false' do
  58. expect(check.pass?).to be false
  59. end
  60. end
  61. context 'when there is an urgent patch release' do
  62. before do
  63. Fabricate(:software_update, version: '99.99.99', type: 'patch', urgent: true)
  64. end
  65. it 'returns false' do
  66. expect(check.pass?).to be false
  67. end
  68. end
  69. context 'when there is a non-urgent patch release' do
  70. before do
  71. Fabricate(:software_update, version: '99.99.99', type: 'patch', urgent: false)
  72. end
  73. it 'returns false' do
  74. expect(check.pass?).to be false
  75. end
  76. end
  77. end
  78. describe 'message' do
  79. context 'when there is a non-urgent patch release pending' do
  80. before do
  81. Fabricate(:software_update, version: '99.99.99', type: 'patch', urgent: false)
  82. end
  83. it 'sends class name symbol to message instance' do
  84. allow(Admin::SystemCheck::Message).to receive(:new)
  85. .with(:software_version_patch_check, anything, anything)
  86. check.message
  87. expect(Admin::SystemCheck::Message).to have_received(:new)
  88. .with(:software_version_patch_check, nil, admin_software_updates_path)
  89. end
  90. end
  91. context 'when there is an urgent patch release pending' do
  92. before do
  93. Fabricate(:software_update, version: '99.99.99', type: 'patch', urgent: true)
  94. end
  95. it 'sends class name symbol to message instance' do
  96. allow(Admin::SystemCheck::Message).to receive(:new)
  97. .with(:software_version_critical_check, anything, anything, anything)
  98. check.message
  99. expect(Admin::SystemCheck::Message).to have_received(:new)
  100. .with(:software_version_critical_check, nil, admin_software_updates_path, true)
  101. end
  102. end
  103. end
  104. end