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 :notifications, dependent: :destroy
|
||||
has_many :topic_users, dependent: :destroy
|
||||
has_many :category_users, dependent: :destroy
|
||||
has_many :topics
|
||||
has_many :user_open_ids, dependent: :destroy
|
||||
has_many :user_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 :email_logs, dependent: :delete_all
|
||||
has_many :post_timings
|
||||
|
|
|
@ -80,6 +80,19 @@ describe CategoryUser do
|
|||
expect(TopicUser.get(post.topic, user)).to be_blank
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue