From 2e23d3508a1d8af9b4bc08691cb7232a1b272d52 Mon Sep 17 00:00:00 2001 From: Alex Wood Date: Wed, 3 Jun 2015 14:10:24 -0700 Subject: [PATCH] Fix IO Handling in DynamoDB Sets The hash and array logic used the format method changed in the previous diff, so those worked correctly from the outset. Sets, however, had special logic which required a second change. --- aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb | 2 +- aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb b/aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb index de4d4e248e9..161ff881724 100644 --- a/aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb +++ b/aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb @@ -51,7 +51,7 @@ def format_set(set) case set.first when String then { ss: set.map(&:to_s) } when Numeric then { ns: set.map(&:to_s) } - when StringIO, IO then { bs: set.map(&:read) } + when StringIO, IO then { bs: set.to_a } else msg = "set types only support String, Numeric, or IO objects" raise ArgumentError, msg diff --git a/aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb b/aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb index 65a3e70561e..cb9384b0794 100644 --- a/aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb +++ b/aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb @@ -26,7 +26,7 @@ module DynamoDB ]) end - it 'converts IO objects to :b (blob)' do + it 'converts IO objects to :b (binary)' do io = StringIO.new('bar') formatted = value.marshal(foo: io) expect(formatted[:m]["foo"][:b].read).to eq('bar') @@ -43,8 +43,9 @@ module DynamoDB end it 'converts binary sets to :bs (binary set)' do - formatted = value.marshal(Set.new([StringIO.new('data')])) - expect(formatted).to eq(bs: ['data']) + io_obj = StringIO.new('data') + formatted = value.marshal(Set.new([io_obj])) + expect(formatted).to eq(bs: [io_obj]) end it 'converts numerics to :n (number)' do