Use Rails 7.1 normalizes feature (#27521)

This commit is contained in:
Matt Jankowski 2023-10-24 06:06:10 -04:00 committed by GitHub
parent 50b7ea810e
commit 714e3ae5b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 25 deletions

View file

@ -23,10 +23,7 @@ class AccountAlias < ApplicationRecord
after_create :add_to_account after_create :add_to_account
after_destroy :remove_from_account after_destroy :remove_from_account
def acct=(val) normalizes :acct, with: ->(acct) { acct.strip.delete_prefix('@') }
val = val.to_s.strip
super(val.start_with?('@') ? val[1..] : val)
end
def pretty_acct def pretty_acct
username, domain = acct.split('@', 2) username, domain = acct.split('@', 2)

View file

@ -25,6 +25,8 @@ class AccountMigration < ApplicationRecord
before_validation :set_target_account before_validation :set_target_account
before_validation :set_followers_count before_validation :set_followers_count
normalizes :acct, with: ->(acct) { acct.strip.delete_prefix('@') }
validates :acct, presence: true, domain: { acct: true } validates :acct, presence: true, domain: { acct: true }
validate :validate_migration_cooldown validate :validate_migration_cooldown
validate :validate_target_account validate :validate_target_account
@ -51,10 +53,6 @@ class AccountMigration < ApplicationRecord
created_at + COOLDOWN_PERIOD created_at + COOLDOWN_PERIOD
end end
def acct=(val)
super(val.to_s.strip.gsub(/\A@/, ''))
end
private private
def set_target_account def set_target_account

View file

@ -27,7 +27,7 @@ class AccountWarning < ApplicationRecord
suspend: 4_000, suspend: 4_000,
}, _suffix: :action }, _suffix: :action
before_validation :before_validate normalizes :text, with: ->(text) { text.to_s }, apply_to_nil: true
belongs_to :account, inverse_of: :account_warnings belongs_to :account, inverse_of: :account_warnings
belongs_to :target_account, class_name: 'Account', inverse_of: :strikes belongs_to :target_account, class_name: 'Account', inverse_of: :strikes
@ -50,10 +50,4 @@ class AccountWarning < ApplicationRecord
def to_log_human_identifier def to_log_human_identifier
target_account.acct target_account.acct
end end
private
def before_validate
self.text = '' if text.blank?
end
end end

View file

@ -23,7 +23,7 @@ class FeaturedTag < ApplicationRecord
validate :validate_tag_uniqueness, on: :create validate :validate_tag_uniqueness, on: :create
validate :validate_featured_tags_limit, on: :create validate :validate_featured_tags_limit, on: :create
before_validation :strip_name normalizes :name, with: ->(name) { name.strip.delete_prefix('#') }
before_create :set_tag before_create :set_tag
before_create :reset_data before_create :reset_data
@ -50,10 +50,6 @@ class FeaturedTag < ApplicationRecord
private private
def strip_name
self.name = name&.strip&.delete_prefix('#')
end
def set_tag def set_tag
self.tag = Tag.find_or_create_by_names(name)&.first self.tag = Tag.find_or_create_by_names(name)&.first
end end

View file

@ -19,7 +19,8 @@ class Relay < ApplicationRecord
scope :enabled, -> { accepted } scope :enabled, -> { accepted }
before_validation :strip_url normalizes :inbox_url, with: ->(inbox_url) { inbox_url.strip }
before_destroy :ensure_disabled before_destroy :ensure_disabled
alias enabled? accepted? alias enabled? accepted?
@ -76,8 +77,4 @@ class Relay < ApplicationRecord
def ensure_disabled def ensure_disabled
disable! if enabled? disable! if enabled?
end end
def strip_url
inbox_url&.strip!
end
end end