Add by_version method to SoftwareUpdate model

This commit is contained in:
Matt Jankowski 2024-11-14 10:57:25 -05:00
parent c24cbc60e3
commit 2bfa58aa1a
4 changed files with 17 additions and 3 deletions

View file

@ -6,7 +6,7 @@ module Admin
def index def index
authorize :software_update, :index? authorize :software_update, :index?
@software_updates = SoftwareUpdate.all.sort_by(&:gem_version) @software_updates = SoftwareUpdate.by_version
end end
private private

View file

@ -48,7 +48,7 @@ class AdminMailer < ApplicationMailer
end end
def new_software_updates def new_software_updates
@software_updates = SoftwareUpdate.all.to_a.sort_by(&:gem_version) @software_updates = SoftwareUpdate.by_version
locale_for_account(@me) do locale_for_account(@me) do
mail subject: default_i18n_subject(instance: @instance) mail subject: default_i18n_subject(instance: @instance)
@ -56,7 +56,7 @@ class AdminMailer < ApplicationMailer
end end
def new_critical_software_updates def new_critical_software_updates
@software_updates = SoftwareUpdate.urgent.to_a.sort_by(&:gem_version) @software_updates = SoftwareUpdate.urgent.by_version
locale_for_account(@me) do locale_for_account(@me) do
mail subject: default_i18n_subject(instance: @instance) mail subject: default_i18n_subject(instance: @instance)

View file

@ -37,6 +37,10 @@ class SoftwareUpdate < ApplicationRecord
Rails.configuration.x.mastodon.software_update_url.present? Rails.configuration.x.mastodon.software_update_url.present?
end end
def by_version
all.sort_by(&:gem_version)
end
def pending_to_a def pending_to_a
return [] unless check_enabled? return [] unless check_enabled?

View file

@ -16,6 +16,16 @@ RSpec.describe SoftwareUpdate do
end end
end end
describe '.by_version' do
let!(:latest_update) { Fabricate :software_update, version: '4.0.0' }
let!(:older_update) { Fabricate :software_update, version: '3.0.0' }
it 'returns record in gem version order' do
expect(described_class.by_version)
.to eq([older_update, latest_update])
end
end
describe '#pending?' do describe '#pending?' do
subject { described_class.new(version: update_version) } subject { described_class.new(version: update_version) }