mastodon/spec/models/software_update_spec.rb
Matt Jankowski 766358e52b
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Add coverage for malformed version cleanup in SoftwareUpdateCheckService, add helper query methods (#32876)
2024-11-14 14:03:57 +00:00

142 lines
4.5 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe SoftwareUpdate do
describe '#pending?' do
subject { described_class.new(version: update_version) }
before { allow(Mastodon::Version).to receive(:gem_version).and_return(Gem::Version.new(mastodon_version)) }
context 'when the runtime version is older than the update' do
let(:mastodon_version) { '4.0.0' }
let(:update_version) { '5.0.0' }
it { is_expected.to be_pending }
end
context 'when the runtime version is newer than the update' do
let(:mastodon_version) { '6.0.0' }
let(:update_version) { '5.0.0' }
it { is_expected.to_not be_pending }
end
context 'when the runtime version is same as the update' do
let(:mastodon_version) { '4.0.0' }
let(:update_version) { '4.0.0' }
it { is_expected.to_not be_pending }
end
end
describe '#outdated?' do
subject { described_class.new(version: update_version) }
before { allow(Mastodon::Version).to receive(:gem_version).and_return(Gem::Version.new(mastodon_version)) }
context 'when the runtime version is older than the update' do
let(:mastodon_version) { '4.0.0' }
let(:update_version) { '5.0.0' }
it { is_expected.to_not be_outdated }
end
context 'when the runtime version is newer than the update' do
let(:mastodon_version) { '6.0.0' }
let(:update_version) { '5.0.0' }
it { is_expected.to be_outdated }
end
context 'when the runtime version is same as the update' do
let(:mastodon_version) { '4.0.0' }
let(:update_version) { '4.0.0' }
it { is_expected.to be_outdated }
end
end
describe '.pending_to_a' do
before do
allow(Mastodon::Version).to receive(:gem_version).and_return(Gem::Version.new(mastodon_version))
Fabricate(:software_update, version: '3.4.42', type: 'patch', urgent: true)
Fabricate(:software_update, version: '3.5.0', type: 'minor', urgent: false)
Fabricate(:software_update, version: '4.2.0', type: 'major', urgent: false)
end
context 'when the Mastodon version is an outdated release' do
let(:mastodon_version) { '3.4.0' }
it 'returns the expected versions' do
expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('3.4.42', '3.5.0', '4.2.0')
end
end
context 'when the Mastodon version is more recent than anything last returned by the server' do
let(:mastodon_version) { '5.0.0' }
it 'returns the expected versions' do
expect(described_class.pending_to_a.pluck(:version)).to eq []
end
end
context 'when the Mastodon version is an outdated nightly' do
let(:mastodon_version) { '4.3.0-nightly.2023-09-10' }
before do
Fabricate(:software_update, version: '4.3.0-nightly.2023-09-12', type: 'major', urgent: true)
end
it 'returns the expected versions' do
expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-nightly.2023-09-12')
end
end
context 'when the Mastodon version is a very outdated nightly' do
let(:mastodon_version) { '4.2.0-nightly.2023-07-10' }
it 'returns the expected versions' do
expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.2.0')
end
end
context 'when the Mastodon version is an outdated dev version' do
let(:mastodon_version) { '4.3.0-0.dev.0' }
before do
Fabricate(:software_update, version: '4.3.0-0.dev.2', type: 'major', urgent: true)
end
it 'returns the expected versions' do
expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-0.dev.2')
end
end
context 'when the Mastodon version is an outdated beta version' do
let(:mastodon_version) { '4.3.0-beta1' }
before do
Fabricate(:software_update, version: '4.3.0-beta2', type: 'major', urgent: true)
end
it 'returns the expected versions' do
expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-beta2')
end
end
context 'when the Mastodon version is an outdated beta version and there is a rc' do
let(:mastodon_version) { '4.3.0-beta1' }
before do
Fabricate(:software_update, version: '4.3.0-rc1', type: 'major', urgent: true)
end
it 'returns the expected versions' do
expect(described_class.pending_to_a.pluck(:version)).to contain_exactly('4.3.0-rc1')
end
end
end
end