0
0
Fork 0

Add coverage for title/limit validations in List model (#31869)

This commit is contained in:
Matt Jankowski 2024-09-12 09:25:23 -04:00 committed by GitHub
parent a496aeabcb
commit 17c57c46e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 4 deletions

View file

@ -20,21 +20,23 @@ class List < ApplicationRecord
enum :replies_policy, { list: 0, followed: 1, none: 2 }, prefix: :show
belongs_to :account, optional: true
belongs_to :account
has_many :list_accounts, inverse_of: :list, dependent: :destroy
has_many :accounts, through: :list_accounts
validates :title, presence: true
validates_each :account_id, on: :create do |record, _attr, value|
record.errors.add(:base, I18n.t('lists.errors.limit')) if List.where(account_id: value).count >= PER_ACCOUNT_LIMIT
end
validate :validate_account_lists_limit, on: :create
before_destroy :clean_feed_manager
private
def validate_account_lists_limit
errors.add(:base, I18n.t('lists.errors.limit')) if account.lists.count >= PER_ACCOUNT_LIMIT
end
def clean_feed_manager
FeedManager.instance.clean_feeds!(:list, [id])
end