Extract constant for attribution domains limit

This commit is contained in:
Matt Jankowski 2025-07-09 11:03:45 -04:00
parent 853a0c466e
commit aa72701f8d
2 changed files with 5 additions and 3 deletions

View File

@ -3,10 +3,12 @@
module Account::AttributionDomains
extend ActiveSupport::Concern
ATTRIBUTION_DOMAINS_LIMIT = 100
included do
normalizes :attribution_domains, with: ->(arr) { arr.filter_map { |str| str.to_s.strip.delete_prefix('http://').delete_prefix('https://').delete_prefix('*.').presence }.uniq }
validates :attribution_domains, domain: true, length: { maximum: 100 }, if: -> { local? && will_save_change_to_attribution_domains? }
validates :attribution_domains, domain: true, length: { maximum: ATTRIBUTION_DOMAINS_LIMIT }, if: -> { local? && will_save_change_to_attribution_domains? }
end
def can_be_attributed_from?(domain)

View File

@ -547,8 +547,8 @@ RSpec.describe Account do
it { is_expected.to validate_absence_of(:shared_inbox_url).on(:create) }
it { is_expected.to validate_absence_of(:uri).on(:create) }
it { is_expected.to allow_values([], ['example.com'], (1..100).to_a).for(:attribution_domains) }
it { is_expected.to_not allow_values(['example com'], ['@'], (1..101).to_a).for(:attribution_domains) }
it { is_expected.to allow_values([], ['example.com'], Array.new(described_class::ATTRIBUTION_DOMAINS_LIMIT, &:to_s)).for(:attribution_domains) }
it { is_expected.to_not allow_values(['example com'], ['@'], Array.new(described_class::ATTRIBUTION_DOMAINS_LIMIT * 2, &:to_s)).for(:attribution_domains) }
end
context 'when account is remote' do