Feature #42630 » Add-handling-reactions-with-missing-user-associations.patch
app/models/reaction.rb | ||
---|---|---|
57 | 57 | |
58 | 58 |
m[reaction.reactable_id].then do |detail| |
59 | 59 |
detail.reaction_count += 1 |
60 |
detail.visible_users << reaction.user if visible_user_ids.include?(reaction.user.id) |
|
60 |
detail.visible_users << reaction.user if visible_user_ids.include?(reaction.user&.id)
|
|
61 | 61 |
detail.user_reaction = reaction if reaction.user == user |
62 | 62 |
end |
63 | 63 |
end |
test/unit/reaction_test.rb | ||
---|---|---|
117 | 117 |
result[issue.id].visible_users.sort_by(&:id) |
118 | 118 |
) |
119 | 119 |
end |
120 | ||
121 |
# When the user data associated with a reaction is missing for some reason (data inconsistency) |
|
122 |
test 'build_detail_map_for avoids errors when reactions lack associated users' do |
|
123 |
# Reaction (id=4) is associated with Journal (id=1) |
|
124 |
reactions(:reaction_004).user.delete |
|
125 | ||
126 |
result = Reaction.build_detail_map_for([journals(:journals_001)], users(:users_001)) |
|
127 | ||
128 |
assert_equal( |
|
129 |
{ |
|
130 |
1 => Reaction::Detail.new( |
|
131 |
reaction_count: 1, |
|
132 |
visible_users: [], |
|
133 |
user_reaction: nil |
|
134 |
) |
|
135 |
}, |
|
136 |
result |
|
137 |
) |
|
138 |
end |
|
120 | 139 |
end |