Feature #42630 » Add-handling-reactions-with-missing-user-associations.patch
| app/models/reaction.rb | ||
|---|---|---|
|
m[reaction.reactable_id].then do |detail|
|
||
|
detail.reaction_count += 1
|
||
|
detail.visible_users << reaction.user if visible_user_ids.include?(reaction.user.id)
|
||
|
detail.visible_users << reaction.user if visible_user_ids.include?(reaction.user&.id)
|
||
|
detail.user_reaction = reaction if reaction.user == user
|
||
|
end
|
||
|
end
|
||
| test/unit/reaction_test.rb | ||
|---|---|---|
|
result[issue.id].visible_users.sort_by(&:id)
|
||
|
)
|
||
|
end
|
||
|
# When the user data associated with a reaction is missing for some reason (data inconsistency)
|
||
|
test 'build_detail_map_for avoids errors when reactions lack associated users' do
|
||
|
# Reaction (id=4) is associated with Journal (id=1)
|
||
|
reactions(:reaction_004).user.delete
|
||
|
result = Reaction.build_detail_map_for([journals(:journals_001)], users(:users_001))
|
||
|
assert_equal(
|
||
|
{
|
||
|
1 => Reaction::Detail.new(
|
||
|
reaction_count: 1,
|
||
|
visible_users: [],
|
||
|
user_reaction: nil
|
||
|
)
|
||
|
},
|
||
|
result
|
||
|
)
|
||
|
end
|
||
|
end
|
||