From e76aff7de563f1c7afdfdd83e35728ba412d02b8 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 10 Dec 2024 10:45:13 -0500 Subject: [PATCH] Standardize uniqueness validation declaration on `Mention` (#33247) --- app/models/mention.rb | 2 +- spec/models/mention_spec.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/mention.rb b/app/models/mention.rb index a508ed630e..e921d41de3 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -18,7 +18,7 @@ class Mention < ApplicationRecord has_one :notification, as: :activity, dependent: :destroy - validates :account, uniqueness: { scope: :status } + validates :account_id, uniqueness: { scope: :status_id } scope :active, -> { where(silent: false) } scope :silent, -> { where(silent: true) } diff --git a/spec/models/mention_spec.rb b/spec/models/mention_spec.rb index 3a9b9fddf2..67c22b5d1f 100644 --- a/spec/models/mention_spec.rb +++ b/spec/models/mention_spec.rb @@ -3,8 +3,14 @@ require 'rails_helper' RSpec.describe Mention do - describe 'validations' do + describe 'Associations' do it { is_expected.to belong_to(:account).required } it { is_expected.to belong_to(:status).required } end + + describe 'Validations' do + subject { Fabricate.build :mention } + + it { is_expected.to validate_uniqueness_of(:account_id).scoped_to(:status_id) } + end end