Add has_many associations to User model (#19625)
This commit is contained in:
parent
90780fd97a
commit
d5ad2ac5e6
4 changed files with 11 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
6
spec/factories/segmented_user.rb
Normal file
6
spec/factories/segmented_user.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
FactoryBot.define do
|
||||
factory :segmented_user do
|
||||
user
|
||||
audience_segment
|
||||
end
|
||||
end
|
||||
|
|
@ -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) }
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue