mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 13:18:24 +08:00
FIX: ensure we remove 'category_users' records when a user is deleted
This commit is contained in:
parent
e624b7198d
commit
5984b62347
@ -17,11 +17,12 @@ class User < ActiveRecord::Base
|
|||||||
has_many :posts
|
has_many :posts
|
||||||
has_many :notifications, dependent: :destroy
|
has_many :notifications, dependent: :destroy
|
||||||
has_many :topic_users, dependent: :destroy
|
has_many :topic_users, dependent: :destroy
|
||||||
|
has_many :category_users, dependent: :destroy
|
||||||
has_many :topics
|
has_many :topics
|
||||||
has_many :user_open_ids, dependent: :destroy
|
has_many :user_open_ids, dependent: :destroy
|
||||||
has_many :user_actions, dependent: :destroy
|
has_many :user_actions, dependent: :destroy
|
||||||
has_many :post_actions, dependent: :destroy
|
has_many :post_actions, dependent: :destroy
|
||||||
has_many :user_badges, -> {where('user_badges.badge_id IN (SELECT id FROM badges where enabled)')}, dependent: :destroy
|
has_many :user_badges, -> { where('user_badges.badge_id IN (SELECT id FROM badges WHERE enabled)') }, dependent: :destroy
|
||||||
has_many :badges, through: :user_badges
|
has_many :badges, through: :user_badges
|
||||||
has_many :email_logs, dependent: :delete_all
|
has_many :email_logs, dependent: :delete_all
|
||||||
has_many :post_timings
|
has_many :post_timings
|
||||||
|
@ -80,6 +80,19 @@ describe CategoryUser do
|
|||||||
expect(TopicUser.get(post.topic, user)).to be_blank
|
expect(TopicUser.get(post.topic, user)).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "is destroyed when a user is deleted" do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
category = Fabricate(:category)
|
||||||
|
|
||||||
|
CategoryUser.create!(user: user, category: category, notification_level: CategoryUser.notification_levels[:watching])
|
||||||
|
|
||||||
|
expect(CategoryUser.where(user_id: user.id).count).to eq(1)
|
||||||
|
|
||||||
|
user.destroy!
|
||||||
|
|
||||||
|
expect(CategoryUser.where(user_id: user.id).count).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user