Add urgent
scope and by_version
method to SoftwareUpdate
(#33470)
This commit is contained in:
parent
4cf031ee13
commit
ef39398b82
4 changed files with 32 additions and 3 deletions
|
@ -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
|
||||||
|
|
|
@ -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.where(urgent: true).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)
|
||||||
|
|
|
@ -18,6 +18,8 @@ class SoftwareUpdate < ApplicationRecord
|
||||||
|
|
||||||
enum :type, { patch: 0, minor: 1, major: 2 }, suffix: :type
|
enum :type, { patch: 0, minor: 1, major: 2 }, suffix: :type
|
||||||
|
|
||||||
|
scope :urgent, -> { where(urgent: true) }
|
||||||
|
|
||||||
def gem_version
|
def gem_version
|
||||||
Gem::Version.new(version)
|
Gem::Version.new(version)
|
||||||
end
|
end
|
||||||
|
@ -35,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?
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,29 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe SoftwareUpdate do
|
RSpec.describe SoftwareUpdate do
|
||||||
|
describe 'Scopes' do
|
||||||
|
describe '.urgent' do
|
||||||
|
let!(:urgent_update) { Fabricate :software_update, urgent: true }
|
||||||
|
let!(:non_urgent_update) { Fabricate :software_update, urgent: false }
|
||||||
|
|
||||||
|
it 'returns records that are urgent' do
|
||||||
|
expect(described_class.urgent)
|
||||||
|
.to include(urgent_update)
|
||||||
|
.and not_include(non_urgent_update)
|
||||||
|
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) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue