software_update_spec.rb 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe SoftwareUpdate do
  4. describe '#pending?' do
  5. subject { described_class.new(version: update_version) }
  6. before { allow(Mastodon::Version).to receive(:gem_version).and_return(Gem::Version.new(mastodon_version)) }
  7. context 'when the runtime version is older than the update' do
  8. let(:mastodon_version) { '4.0.0' }
  9. let(:update_version) { '5.0.0' }
  10. it { is_expected.to be_pending }
  11. end
  12. context 'when the runtime version is newer than the update' do
  13. let(:mastodon_version) { '6.0.0' }
  14. let(:update_version) { '5.0.0' }
  15. it { is_expected.to_not be_pending }
  16. end
  17. context 'when the runtime version is same as the update' do
  18. let(:mastodon_version) { '4.0.0' }
  19. let(:update_version) { '4.0.0' }
  20. it { is_expected.to_not be_pending }
  21. end
  22. end
  23. describe '#outdated?' do
  24. subject { described_class.new(version: update_version) }
  25. before { allow(Mastodon::Version).to receive(:gem_version).and_return(Gem::Version.new(mastodon_version)) }
  26. context 'when the runtime version is older than the update' do
  27. let(:mastodon_version) { '4.0.0' }
  28. let(:update_version) { '5.0.0' }
  29. it { is_expected.to_not be_outdated }
  30. end
  31. context 'when the runtime version is newer than the update' do
  32. let(:mastodon_version) { '6.0.0' }
  33. let(:update_version) { '5.0.0' }
  34. it { is_expected.to be_outdated }
  35. end
  36. context 'when the runtime version is same as the update' do
  37. let(:mastodon_version) { '4.0.0' }
  38. let(:update_version) { '4.0.0' }
  39. it { is_expected.to be_outdated }
  40. end
  41. end
  42. describe '.pending_to_a' do
  43. before do
  44. allow(Mastodon::Version).to receive(:gem_version).and_return(Gem::Version.new(mastodon_version))
  45. Fabricate(:software_update, version: '3.4.42', type: 'patch', urgent: true)
  46. Fabricate(:software_update, version: '3.5.0', type: 'minor', urgent: false)
  47. Fabricate(:software_update, version: '4.2.0', type: 'major', urgent: false)
  48. end
  49. context 'when the Mastodon version is an outdated release' do
  50. let(:mastodon_version) { '3.4.0' }
  51. it 'returns the expected versions' do
  52. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('3.4.42', '3.5.0', '4.2.0')
  53. end
  54. end
  55. context 'when the Mastodon version is more recent than anything last returned by the server' do
  56. let(:mastodon_version) { '5.0.0' }
  57. it 'returns the expected versions' do
  58. expect(described_class.pending_to_a.pluck(:version)).to eq []
  59. end
  60. end
  61. context 'when the Mastodon version is an outdated nightly' do
  62. let(:mastodon_version) { '4.3.0-nightly.2023-09-10' }
  63. before do
  64. Fabricate(:software_update, version: '4.3.0-nightly.2023-09-12', type: 'major', urgent: true)
  65. end
  66. it 'returns the expected versions' do
  67. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-nightly.2023-09-12')
  68. end
  69. end
  70. context 'when the Mastodon version is a very outdated nightly' do
  71. let(:mastodon_version) { '4.2.0-nightly.2023-07-10' }
  72. it 'returns the expected versions' do
  73. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.2.0')
  74. end
  75. end
  76. context 'when the Mastodon version is an outdated dev version' do
  77. let(:mastodon_version) { '4.3.0-0.dev.0' }
  78. before do
  79. Fabricate(:software_update, version: '4.3.0-0.dev.2', type: 'major', urgent: true)
  80. end
  81. it 'returns the expected versions' do
  82. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-0.dev.2')
  83. end
  84. end
  85. context 'when the Mastodon version is an outdated beta version' do
  86. let(:mastodon_version) { '4.3.0-beta1' }
  87. before do
  88. Fabricate(:software_update, version: '4.3.0-beta2', type: 'major', urgent: true)
  89. end
  90. it 'returns the expected versions' do
  91. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-beta2')
  92. end
  93. end
  94. context 'when the Mastodon version is an outdated beta version and there is a rc' do
  95. let(:mastodon_version) { '4.3.0-beta1' }
  96. before do
  97. Fabricate(:software_update, version: '4.3.0-rc1', type: 'major', urgent: true)
  98. end
  99. it 'returns the expected versions' do
  100. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-rc1')
  101. end
  102. end
  103. end
  104. end