A small session exporter builds hashes for a report from incoming records. After a recent change, part of the rows started being assembled incorrectly: for some records labels disappear, and in others the order and contents of the list change after reading the result again.
3.3 and the standard library.SessionExport.build(rows, locale: nil).rows is an enumerable object that yields records as hashes.:id — a string;:labels — a new array of strings;:locale — a string if the locale argument is passed, otherwise nil.rows = [
{ id: "a1", meta: { labels: ["new", "urgent"] } },
{ id: "b2", meta: { labels: [] } },
{ id: "skip", meta: {} },
]
result = SessionExport.build(rows, locale: "ru-RU")
result[0][:labels] << "vip"
puts rows[0][:meta][:labels].inspect
puts result.map { |r| [r[:id], r[:labels], r[:locale]] }.inspect
rows[0][:meta][:labels] must not change.result.:labels array.locale must be set identically for all exported rows when the argument is explicitly passed.ruby session_export.rbUse line comments to explain the problem, its impact, the fix and how to test it.