Permalink
Browse files

Don't Read IO Objects in Attribute Value Marshal

Resolves Issue #831

Running the following code exercised the problem, and now works with
this change:

```
dynamodb.put_item(
  table_name: "foo",
  item: {
    id: 1,
    contents: StringIO.new("bar")
  }
)
```

The issue appeared to be that #read was called twice on the StringIO or
IO object, and the second call would fail as String#read does not
exist.
  • Loading branch information...
awood45 committed Jun 2, 2015
1 parent be9b131 commit b59e760b15969671ea9c8cfcbd119fe626aa389e
@@ -34,7 +34,7 @@ def format(obj)
end
when String then { s: obj }
when Numeric then { n: obj.to_s }
when StringIO, IO then { b: obj.read }
when StringIO, IO then { b: obj }
when Set then format_set(obj)
when true, false then { bool: obj }
when nil then { null: true }
@@ -26,6 +26,12 @@ module DynamoDB
])
end
it 'converts IO objects to :b (blob)' do
io = StringIO.new('bar')
formatted = value.marshal(foo: io)
expect(formatted[:m]["foo"][:b].read).to eq('bar')
end
it 'converts string sets to :ss (string set)' do
formatted = value.marshal(Set.new(%w(abc mno)))
expect(formatted).to eq(ss: %w(abc mno))

0 comments on commit b59e760

Please sign in to comment.