Add has_many associations to User model (#19625)

This commit is contained in:
Mac Siri 2023-06-23 14:58:55 -04:00 committed by GitHub
parent 90780fd97a
commit d5ad2ac5e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 0 deletions

View file

@ -97,6 +97,8 @@ class User < ApplicationRecord
has_many :poll_skips, dependent: :delete_all
has_many :poll_votes, dependent: :delete_all
has_many :profile_pins, as: :profile, inverse_of: :profile, dependent: :delete_all
has_many :segmented_users, dependent: :destroy
has_many :audience_segments, through: :segmented_users
# we keep rating votes as they belong to the article, not to the user who viewed it
has_many :rating_votes, dependent: :nullify

View file

@ -0,0 +1,6 @@
FactoryBot.define do
factory :segmented_user do
user
audience_segment
end
end

View file

@ -106,6 +106,8 @@ RSpec.describe User do
it { is_expected.to have_many(:reactions).dependent(:destroy) }
it { is_expected.to have_many(:response_templates).dependent(:delete_all) }
it { is_expected.to have_many(:source_authored_user_subscriptions).dependent(:destroy) }
it { is_expected.to have_many(:segmented_users).dependent(:destroy) }
it { is_expected.to have_many(:audience_segments).through(:segmented_users) }
it { is_expected.to have_many(:subscribed_to_user_subscriptions).dependent(:destroy) }
it { is_expected.to have_many(:subscribers).dependent(:destroy) }
it { is_expected.to have_many(:tweets).dependent(:nullify) }

View file

@ -136,6 +136,7 @@ RSpec.describe Users::Delete, type: :service do
end
it "keeps the kept associations" do
# NB: each association must have a factory defined!
expect(kept_associations).not_to be_empty
user.reload
described_class.call(user)