Fix antenna fabricator tests and move duplicate check to db
This commit is contained in:
parent
e656ab15a1
commit
df0b1a4632
8 changed files with 34 additions and 19 deletions
|
@ -15,14 +15,11 @@ class AntennaAccount < ApplicationRecord
|
|||
belongs_to :antenna
|
||||
belongs_to :account
|
||||
|
||||
validate :duplicate_account
|
||||
validate :limit_per_antenna
|
||||
|
||||
private
|
||||
validates :account_id, uniqueness: { scope: :antenna_id }
|
||||
|
||||
def duplicate_account
|
||||
raise Mastodon::ValidationError, I18n.t('antennas.errors.duplicate_account') if AntennaAccount.exists?(antenna_id: antenna_id, account_id: account_id, exclude: exclude)
|
||||
end
|
||||
private
|
||||
|
||||
def limit_per_antenna
|
||||
raise Mastodon::ValidationError, I18n.t('antennas.errors.limit.accounts') if AntennaAccount.where(antenna_id: antenna_id).count >= Antenna::ACCOUNTS_PER_ANTENNA_LIMIT
|
||||
|
|
|
@ -14,14 +14,11 @@
|
|||
class AntennaDomain < ApplicationRecord
|
||||
belongs_to :antenna
|
||||
|
||||
validate :duplicate_domain
|
||||
validate :limit_per_antenna
|
||||
|
||||
private
|
||||
validates :name, uniqueness: { scope: :antenna_id }
|
||||
|
||||
def duplicate_domain
|
||||
raise Mastodon::ValidationError, I18n.t('antennas.errors.duplicate_domain') if AntennaDomain.exists?(antenna_id: antenna_id, name: name, exclude: exclude)
|
||||
end
|
||||
private
|
||||
|
||||
def limit_per_antenna
|
||||
raise Mastodon::ValidationError, I18n.t('antennas.errors.limit.domains') if AntennaDomain.where(antenna_id: antenna_id).count >= Antenna::DOMAINS_PER_ANTENNA_LIMIT
|
||||
|
|
|
@ -15,14 +15,11 @@ class AntennaTag < ApplicationRecord
|
|||
belongs_to :antenna
|
||||
belongs_to :tag
|
||||
|
||||
validate :duplicate_tag
|
||||
validate :limit_per_antenna
|
||||
|
||||
private
|
||||
validates :tag_id, uniqueness: { scope: :antenna_id }
|
||||
|
||||
def duplicate_tag
|
||||
raise Mastodon::ValidationError, I18n.t('antennas.errors.duplicate_tag') if AntennaTag.exists?(antenna_id: antenna_id, tag_id: tag_id, exclude: exclude)
|
||||
end
|
||||
private
|
||||
|
||||
def limit_per_antenna
|
||||
raise Mastodon::ValidationError, I18n.t('antennas.errors.limit.tags') if AntennaTag.where(antenna_id: antenna_id).count >= Antenna::TAGS_PER_ANTENNA_LIMIT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue