Skip to content

Commit 77b42c2

Browse files
nbudinclaude
andcommitted
Fix FK violation when merging users with signup_ranked_choices (#11215)
Add SignupRankedChoice to both RECORD_KEEPING_FIELDS (updated_by_id) and USER_CON_PROFILE_REFERENCES (user_con_profile_id) so ranked choices are reassigned to the winning user/profile rather than causing a FK violation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2499c34 commit 77b42c2

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

app/services/merge_users_service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Result < CivilService::Result
1212
{ model: Order, field: :user_con_profile_id },
1313
{ model: Signup, field: :user_con_profile_id },
1414
{ model: SignupChange, field: :user_con_profile_id },
15+
{ model: SignupRankedChoice, field: :user_con_profile_id },
1516
{ model: SignupRequest, field: :user_con_profile_id },
1617
{ model: TeamMember, field: :user_con_profile_id },
1718
{ model: Ticket, field: :user_con_profile_id }
@@ -25,6 +26,7 @@ class Result < CivilService::Result
2526
{ model: Run, field: :updated_by_id },
2627
{ model: Signup, field: :updated_by_id },
2728
{ model: SignupChange, field: :updated_by_id },
29+
{ model: SignupRankedChoice, field: :updated_by_id },
2830
{ model: SignupRequest, field: :updated_by_id },
2931
{ model: UserActivityAlert, field: :user_id }
3032
].freeze

test/services/merge_users_service_test.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
require 'test_helper'
1+
require "test_helper"
22

33
class MergeUsersServiceTest < ActiveSupport::TestCase
4-
it 'merges two users' do
4+
it "merges two users" do
55
profile1, profile2 = create_list(:user_con_profile, 2)
66
user_id1, user_id2 = [profile1, profile2].map(&:user_id)
77

88
MergeUsersService.new(
99
user_ids: [user_id1, user_id2],
1010
winning_user_id: user_id1,
11-
winning_user_con_profile_ids_by_convention_id: {}
11+
winning_user_con_profile_ids_by_convention_id: {
12+
}
1213
).call!
1314

1415
assert UserConProfile.find_by(id: profile1.id)
@@ -18,7 +19,25 @@ class MergeUsersServiceTest < ActiveSupport::TestCase
1819
assert_nil User.find_by(id: user_id2)
1920
end
2021

21-
it 'merges two profiles from the same convention' do
22+
it "reassigns signup_ranked_choices updated_by to winning user" do
23+
profile1, profile2 = create_list(:user_con_profile, 2)
24+
user1 = profile1.user
25+
user2 = profile2.user
26+
run = create(:run, event: create(:event, convention: profile2.convention))
27+
choice = create(:signup_ranked_choice, user_con_profile: profile2, target_run: run, updated_by: user2)
28+
29+
MergeUsersService.new(
30+
user_ids: [user1.id, user2.id],
31+
winning_user_id: user1.id,
32+
winning_user_con_profile_ids_by_convention_id: {
33+
}
34+
).call!
35+
36+
assert_equal user1.id, choice.reload.updated_by_id
37+
assert_nil User.find_by(id: user2.id)
38+
end
39+
40+
it "merges two profiles from the same convention" do
2241
profile1, profile2 = create_list(:user_con_profile, 2)
2342
user_id1, user_id2 = [profile1, profile2].map(&:user_id)
2443
profile3 = create(:user_con_profile, convention: profile1.convention, user: profile2.user)

0 commit comments

Comments
 (0)