Skip to content

Commit

Permalink
Use Rails 7.1 normalizes feature (mastodon#27521)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski committed Oct 24, 2023
1 parent 50b7ea8 commit 714e3ae
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 25 deletions.
5 changes: 1 addition & 4 deletions app/models/account_alias.rb
Expand Up @@ -23,10 +23,7 @@ class AccountAlias < ApplicationRecord
after_create :add_to_account
after_destroy :remove_from_account

def acct=(val)
val = val.to_s.strip
super(val.start_with?('@') ? val[1..] : val)
end
normalizes :acct, with: ->(acct) { acct.strip.delete_prefix('@') }

def pretty_acct
username, domain = acct.split('@', 2)
Expand Down
6 changes: 2 additions & 4 deletions app/models/account_migration.rb
Expand Up @@ -25,6 +25,8 @@ class AccountMigration < ApplicationRecord
before_validation :set_target_account
before_validation :set_followers_count

normalizes :acct, with: ->(acct) { acct.strip.delete_prefix('@') }

validates :acct, presence: true, domain: { acct: true }
validate :validate_migration_cooldown
validate :validate_target_account
Expand All @@ -51,10 +53,6 @@ def cooldown_at
created_at + COOLDOWN_PERIOD
end

def acct=(val)
super(val.to_s.strip.gsub(/\A@/, ''))
end

private

def set_target_account
Expand Down
8 changes: 1 addition & 7 deletions app/models/account_warning.rb
Expand Up @@ -27,7 +27,7 @@ class AccountWarning < ApplicationRecord
suspend: 4_000,
}, _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 :target_account, class_name: 'Account', inverse_of: :strikes
Expand All @@ -50,10 +50,4 @@ def overruled?
def to_log_human_identifier
target_account.acct
end

private

def before_validate
self.text = '' if text.blank?
end
end
6 changes: 1 addition & 5 deletions app/models/featured_tag.rb
Expand Up @@ -23,7 +23,7 @@ class FeaturedTag < ApplicationRecord
validate :validate_tag_uniqueness, 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 :reset_data
Expand All @@ -50,10 +50,6 @@ def decrement(deleted_status_id)

private

def strip_name
self.name = name&.strip&.delete_prefix('#')
end

def set_tag
self.tag = Tag.find_or_create_by_names(name)&.first
end
Expand Down
7 changes: 2 additions & 5 deletions app/models/relay.rb
Expand Up @@ -19,7 +19,8 @@ class Relay < ApplicationRecord

scope :enabled, -> { accepted }

before_validation :strip_url
normalizes :inbox_url, with: ->(inbox_url) { inbox_url.strip }

before_destroy :ensure_disabled

alias enabled? accepted?
Expand Down Expand Up @@ -76,8 +77,4 @@ def some_local_account
def ensure_disabled
disable! if enabled?
end

def strip_url
inbox_url&.strip!
end
end

0 comments on commit 714e3ae

Please sign in to comment.