Skip to content

Commit c2f3468

Browse files
authored
Merge pull request #653 from larskanis/marshal-compat-array
Serialize CompositeCoder#dimensions only when set
2 parents 3a9938b + 887ebee commit c2f3468

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/pg/coder.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ def inspect_short
7272

7373
class CompositeCoder < Coder
7474
def to_h
75-
{ **super,
75+
h = { **super,
7676
elements_type: elements_type,
7777
needs_quotation: needs_quotation?,
7878
delimiter: delimiter,
79-
dimensions: dimensions,
8079
}
80+
h[:dimensions] = dimensions if dimensions # Write only when set, for Marshal compat with pg<1.6
81+
h
8182
end
8283

8384
def inspect

spec/pg/type_spec.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,8 +1184,15 @@ def expect_deprecated_coder_init
11841184
it "should respond to to_h" do
11851185
expect( textenc_int_array.to_h ).to eq( {
11861186
name: nil, oid: 0, format: 0, flags: 0,
1187-
elements_type: textenc_int, needs_quotation: false, delimiter: ',',
1188-
dimensions: nil
1187+
elements_type: textenc_int, needs_quotation: false, delimiter: ','
1188+
} )
1189+
end
1190+
1191+
it "should respond to to_h with dimensions set" do
1192+
enc_array = PG::BinaryEncoder::Array.new dimensions: 1
1193+
expect( enc_array.to_h ).to eq( {
1194+
name: nil, oid: 0, format: 1, flags: 0, dimensions: 1,
1195+
elements_type: nil, needs_quotation: true, delimiter: ','
11891196
} )
11901197
end
11911198

0 commit comments

Comments
 (0)