Zip plucked values with tstruct keys in the same order for pluck_to_tstruct - #563
Conversation
| pluck(*pluck_keys).map do |row| | ||
| row = [row] if keys_one | ||
| value = Hash[map_nil_values_to_default(tstruct_props, tstruct_keys.zip(row))] | ||
| value = Hash[map_nil_values_to_default(tstruct_props, tstruct_keys_in_pluck_order.zip(row))] |
There was a problem hiding this comment.
When we zip the tstruct keys with the plucked values, we want to make sure the corresponding key and value match up correctly.
This requires that our tstruct keys are in the same order as the pluck_keys, which is why we want to subtract the associations_keys and then append them to the end of tstruct_keys on line 34. This matches the operations and order changes we performed for the pluck_keys on line 33.
| const :name, String | ||
| const :house, String | ||
| const :wand_wood_type, String | ||
| const :house, String |
There was a problem hiding this comment.
With this change in the order of the tstruct props, the spec on line 138 fails without the new changes to pluck_to_tstruct.rb.
sorbet-rails/spec/pluck_to_tstruct_spec.rb
Lines 138 to 147 in 447ecbe
Rather than the expected array, the actual array would look like:
[
WizardWithWandT.new(name: "Harry Potter", house: "Holly", wand_wood_type: "Gryffindor"),
WizardWithWandT.new(name: "Hermione Granger", house: "Vine", wand_wood_type: "Gryffindor"),
]
Codecov Report
@@ Coverage Diff @@
## master #563 +/- ##
==========================================
- Coverage 97.48% 97.44% -0.04%
==========================================
Files 115 115
Lines 2978 2979 +1
==========================================
Hits 2903 2903
- Misses 75 76 +1
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Fixes #562