software_update_spec.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe SoftwareUpdate do
  4. describe '.pending_to_a' do
  5. before do
  6. allow(Mastodon::Version).to receive(:gem_version).and_return(Gem::Version.new(mastodon_version))
  7. Fabricate(:software_update, version: '3.4.42', type: 'patch', urgent: true)
  8. Fabricate(:software_update, version: '3.5.0', type: 'minor', urgent: false)
  9. Fabricate(:software_update, version: '4.2.0', type: 'major', urgent: false)
  10. end
  11. context 'when the Mastodon version is an outdated release' do
  12. let(:mastodon_version) { '3.4.0' }
  13. it 'returns the expected versions' do
  14. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('3.4.42', '3.5.0', '4.2.0')
  15. end
  16. end
  17. context 'when the Mastodon version is more recent than anything last returned by the server' do
  18. let(:mastodon_version) { '5.0.0' }
  19. it 'returns the expected versions' do
  20. expect(described_class.pending_to_a.pluck(:version)).to eq []
  21. end
  22. end
  23. context 'when the Mastodon version is an outdated nightly' do
  24. let(:mastodon_version) { '4.3.0-nightly.2023-09-10' }
  25. before do
  26. Fabricate(:software_update, version: '4.3.0-nightly.2023-09-12', type: 'major', urgent: true)
  27. end
  28. it 'returns the expected versions' do
  29. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-nightly.2023-09-12')
  30. end
  31. end
  32. context 'when the Mastodon version is a very outdated nightly' do
  33. let(:mastodon_version) { '4.2.0-nightly.2023-07-10' }
  34. it 'returns the expected versions' do
  35. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.2.0')
  36. end
  37. end
  38. context 'when the Mastodon version is an outdated dev version' do
  39. let(:mastodon_version) { '4.3.0-0.dev.0' }
  40. before do
  41. Fabricate(:software_update, version: '4.3.0-0.dev.2', type: 'major', urgent: true)
  42. end
  43. it 'returns the expected versions' do
  44. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-0.dev.2')
  45. end
  46. end
  47. context 'when the Mastodon version is an outdated beta version' do
  48. let(:mastodon_version) { '4.3.0-beta1' }
  49. before do
  50. Fabricate(:software_update, version: '4.3.0-beta2', type: 'major', urgent: true)
  51. end
  52. it 'returns the expected versions' do
  53. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-beta2')
  54. end
  55. end
  56. context 'when the Mastodon version is an outdated beta version and there is a rc' do
  57. let(:mastodon_version) { '4.3.0-beta1' }
  58. before do
  59. Fabricate(:software_update, version: '4.3.0-rc1', type: 'major', urgent: true)
  60. end
  61. it 'returns the expected versions' do
  62. expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-rc1')
  63. end
  64. end
  65. end
  66. end