Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete solution tags when resetting account #6678

Merged
merged 2 commits into from Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/commands/user/reset_account.rb
Expand Up @@ -65,6 +65,7 @@ def reset_associations!
user.scratchpad_pages.delete_all
user.solution_stars.delete_all
user.challenges.delete_all
user.solution_tags.update_all(user_id: User::GHOST_USER_ID)
end

def reset_badges!
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Expand Up @@ -103,6 +103,7 @@ class User < ApplicationRecord

has_many :solution_comments, dependent: :destroy, class_name: "Solution::Comment", inverse_of: :author
has_many :solution_stars, dependent: :destroy, class_name: "Solution::Star"
has_many :solution_tags, dependent: :destroy, class_name: "Solution::Tag"

has_many :track_mentorships, dependent: :destroy
has_many :mentored_tracks, through: :track_mentorships, source: :track
Expand Down
8 changes: 8 additions & 0 deletions test/commands/user/reset_account_test.rb
Expand Up @@ -180,6 +180,14 @@ class User::ResetAccountTest < ActiveSupport::TestCase
end
end

test "cleans up solution_tags" do
ghost_user = create :user, :ghost
user = create :user
solution_tag = create(:solution_tag, user:)
User::ResetAccount.(user)
assert_equal ghost_user, solution_tag.reload.user
end

test "cleans up problem reports" do
create :user, :ghost
user = create :user
Expand Down