Add coverage for FollowRecommendationMute model (#35376)

This commit is contained in:
Matt Jankowski 2025-07-15 02:27:36 -04:00 committed by GitHub
parent 7273f6c03c
commit dec1fb71f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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