Add coverage for malformed version cleanup in SoftwareUpdateCheckService, add helper query methods (#32876)
				
					
				
			This commit is contained in:
		@@ -22,6 +22,14 @@ class SoftwareUpdate < ApplicationRecord
 | 
			
		||||
    Gem::Version.new(version)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def outdated?
 | 
			
		||||
    runtime_version >= gem_version
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def pending?
 | 
			
		||||
    gem_version > runtime_version
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  class << self
 | 
			
		||||
    def check_enabled?
 | 
			
		||||
      Rails.configuration.x.mastodon.software_update_url.present?
 | 
			
		||||
@@ -30,11 +38,17 @@ class SoftwareUpdate < ApplicationRecord
 | 
			
		||||
    def pending_to_a
 | 
			
		||||
      return [] unless check_enabled?
 | 
			
		||||
 | 
			
		||||
      all.to_a.filter { |update| update.gem_version > Mastodon::Version.gem_version }
 | 
			
		||||
      all.to_a.filter(&:pending?)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def urgent_pending?
 | 
			
		||||
      pending_to_a.any?(&:urgent?)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def runtime_version
 | 
			
		||||
    Mastodon::Version.gem_version
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ class SoftwareUpdateCheckService < BaseService
 | 
			
		||||
 | 
			
		||||
  def clean_outdated_updates!
 | 
			
		||||
    SoftwareUpdate.find_each do |software_update|
 | 
			
		||||
      software_update.delete if Mastodon::Version.gem_version >= software_update.gem_version
 | 
			
		||||
      software_update.delete if software_update.outdated?
 | 
			
		||||
    rescue ArgumentError
 | 
			
		||||
      software_update.delete
 | 
			
		||||
    end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user