From dec1fb71f4958771e8bb80d5415956fd3428e429 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 15 Jul 2025 02:27:36 -0400 Subject: [PATCH] Add coverage for `FollowRecommendationMute` model (#35376) --- app/models/follow_recommendation_mute.rb | 2 +- .../models/follow_recommendation_mute_spec.rb | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 spec/models/follow_recommendation_mute_spec.rb diff --git a/app/models/follow_recommendation_mute.rb b/app/models/follow_recommendation_mute.rb index d166d0a62..ef931988e 100644 --- a/app/models/follow_recommendation_mute.rb +++ b/app/models/follow_recommendation_mute.rb @@ -14,7 +14,7 @@ class FollowRecommendationMute < ApplicationRecord belongs_to :account belongs_to :target_account, class_name: 'Account' - validates :target_account, uniqueness: { scope: :account_id } + validates :target_account_id, uniqueness: { scope: :account_id } after_commit :invalidate_follow_recommendations_cache diff --git a/spec/models/follow_recommendation_mute_spec.rb b/spec/models/follow_recommendation_mute_spec.rb new file mode 100644 index 000000000..0141d9042 --- /dev/null +++ b/spec/models/follow_recommendation_mute_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe FollowRecommendationMute do + describe 'Associations' do + it { is_expected.to belong_to(:account) } + it { is_expected.to belong_to(:target_account).class_name('Account') } + end + + describe 'Validations' do + subject { Fabricate.build :follow_recommendation_mute } + + it { is_expected.to validate_uniqueness_of(:target_account_id).scoped_to(:account_id) } + end + + describe 'Callbacks' do + describe 'Maintaining the recommendation cache' do + let(:account) { Fabricate :account } + let(:cache_key) { "follow_recommendations/#{account.id}" } + + before { Rails.cache.write(cache_key, 123) } + + it 'purges on save' do + expect { Fabricate :follow_recommendation_mute, account: account } + .to(change { Rails.cache.exist?(cache_key) }.from(true).to(false)) + end + end + end +end