You don't need to group, since you are iterating a hash (no duplicate keys), the output hash won't have multiple elements by key. Simply use map
+ Hash
(or mash for Facets connoisseurs):
defects = Hash[test_phases.map do |test_phase, found_in_values|
[test_phase, Defect.where(found_in: found_in_values)]
end]