software_version_check_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.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. original = Rails.configuration.x.mastodon.software_update_url
  22. Rails.configuration.x.mastodon.software_update_url = ''
  23. example.run
  24. Rails.configuration.x.mastodon.software_update_url = original
  25. end
  26. it 'returns true' do
  27. expect(check.skip?).to be true
  28. end
  29. end
  30. end
  31. end
  32. describe 'pass?' do
  33. context 'when there is no known update' do
  34. it 'returns true' do
  35. expect(check.pass?).to be true
  36. end
  37. end
  38. context 'when there is a non-urgent major release' do
  39. before do
  40. Fabricate(:software_update, version: '99.99.99', type: 'major', urgent: false)
  41. end
  42. it 'returns false' do
  43. expect(check.pass?).to be false
  44. end
  45. end
  46. context 'when there is an urgent major release' do
  47. before do
  48. Fabricate(:software_update, version: '99.99.99', type: 'major', urgent: true)
  49. end
  50. it 'returns false' do
  51. expect(check.pass?).to be false
  52. end
  53. end
  54. context 'when there is an urgent minor release' do
  55. before do
  56. Fabricate(:software_update, version: '99.99.99', type: 'minor', urgent: true)
  57. end
  58. it 'returns false' do
  59. expect(check.pass?).to be false
  60. end
  61. end
  62. context 'when there is an urgent patch release' do
  63. before do
  64. Fabricate(:software_update, version: '99.99.99', type: 'patch', urgent: true)
  65. end
  66. it 'returns false' do
  67. expect(check.pass?).to be false
  68. end
  69. end
  70. context 'when there is a non-urgent patch release' do
  71. before do
  72. Fabricate(:software_update, version: '99.99.99', type: 'patch', urgent: false)
  73. end
  74. it 'returns false' do
  75. expect(check.pass?).to be false
  76. end
  77. end
  78. end
  79. describe 'message' do
  80. context 'when there is a non-urgent patch release pending' do
  81. before do
  82. Fabricate(:software_update, version: '99.99.99', type: 'patch', urgent: false)
  83. end
  84. it 'sends class name symbol to message instance' do
  85. allow(Admin::SystemCheck::Message).to receive(:new)
  86. .with(:software_version_patch_check, anything, anything)
  87. check.message
  88. expect(Admin::SystemCheck::Message).to have_received(:new)
  89. .with(:software_version_patch_check, nil, admin_software_updates_path)
  90. end
  91. end
  92. context 'when there is an urgent patch release pending' do
  93. before do
  94. Fabricate(:software_update, version: '99.99.99', type: 'patch', urgent: true)
  95. end
  96. it 'sends class name symbol to message instance' do
  97. allow(Admin::SystemCheck::Message).to receive(:new)
  98. .with(:software_version_critical_check, anything, anything, anything)
  99. check.message
  100. expect(Admin::SystemCheck::Message).to have_received(:new)
  101. .with(:software_version_critical_check, nil, admin_software_updates_path, true)
  102. end
  103. end
  104. end
  105. end