dynamini 2.6.5 → 2.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/dynamini.gemspec +1 -1
- data/lib/dynamini/test_client.rb +14 -5
- data/spec/dynamini/test_client_spec.rb +68 -27
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f49e721fd627858b268479539065b3f62ded837
|
4
|
+
data.tar.gz: 296511c0cf83bb00155e21cd78e6a5c05da93ec0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6785712ac96112bf8e78cc551a6dc1b378968ee90d1e4fd4cd2d0294c0290d9b26b777deb50e45143801eb4567263628f5cc37676fb932dcc7e1231e8a7da2e1
|
7
|
+
data.tar.gz: 8fd0a91480de7a1a3a815c22db84cf2a783e2aefb68a8f47da958bf9e8d76c9d8399dfec093735f1494eec8212a0b6308899d46eab99b45be7b099849952dcc4
|
data/Gemfile.lock
CHANGED
data/dynamini.gemspec
CHANGED
data/lib/dynamini/test_client.rb
CHANGED
@@ -82,23 +82,32 @@ module Dynamini
|
|
82
82
|
OpenStruct.new(responses: responses)
|
83
83
|
end
|
84
84
|
|
85
|
-
# TODO add range key support
|
85
|
+
# TODO add range key support for delete, not currently implemented batch_operations.batch_delete
|
86
86
|
def batch_write_item(request_options)
|
87
87
|
request_options[:request_items].each do |table_name, requests|
|
88
|
+
table = get_table(table_name)
|
89
|
+
|
88
90
|
requests.each do |request_hash|
|
89
91
|
if request_hash[:put_request]
|
90
|
-
item = request_hash[:put_request][:item]
|
91
|
-
|
92
|
-
|
92
|
+
item = request_hash[:put_request][:item].symbolize_keys
|
93
|
+
hash_key_value = item[hash_key_attr]
|
94
|
+
if range_key_attr.present?
|
95
|
+
range_key_value = item[range_key_attr]
|
96
|
+
table[hash_key_value] = {} if table[hash_key_value].nil?
|
97
|
+
table[hash_key_value][range_key_value] = item
|
98
|
+
else
|
99
|
+
table[hash_key_value] = item
|
100
|
+
end
|
93
101
|
else
|
94
102
|
item = request_hash[:delete_request][:key]
|
95
103
|
id = item[hash_key_attr]
|
96
|
-
|
104
|
+
table.delete(id)
|
97
105
|
end
|
98
106
|
end
|
99
107
|
end
|
100
108
|
end
|
101
109
|
|
110
|
+
|
102
111
|
def delete_item(args = {})
|
103
112
|
get_table(args[:table_name]).delete(args[:key][hash_key_attr])
|
104
113
|
end
|
@@ -367,41 +367,82 @@ describe Dynamini::TestClient do
|
|
367
367
|
end
|
368
368
|
|
369
369
|
describe '#batch_write_item' do
|
370
|
-
|
370
|
+
context 'with only hash key' do
|
371
|
+
let(:test_client) { Dynamini::TestClient.new(:id) }
|
371
372
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
373
|
+
it 'should store all items in the table correctly' do
|
374
|
+
item1 = {'foo' => 'bar', 'id' => 1}
|
375
|
+
item2 = {'foo' => 'bar', 'id' => 2}
|
376
|
+
put_requests = [{put_request: {item: item1}},
|
377
|
+
{put_request: {item: item2}}]
|
377
378
|
|
378
|
-
|
379
|
+
request_options = {request_items: {table_name => put_requests}}
|
379
380
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
381
|
+
test_client.batch_write_item(request_options)
|
382
|
+
expect(test_client.data[table_name][1]).to eq({foo: 'bar', id: 1})
|
383
|
+
expect(test_client.data[table_name][2]).to eq({foo: 'bar', id: 2})
|
384
|
+
end
|
384
385
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
386
|
+
context 'batch deleting' do
|
387
|
+
before do
|
388
|
+
test_client.data[table_name] = {}
|
389
|
+
test_client.data[table_name]['one'] = {name: 'item1'}
|
390
|
+
test_client.data[table_name]['two'] = {name: 'item2'}
|
391
|
+
end
|
392
|
+
|
393
|
+
it 'should remove all items from the table' do
|
394
|
+
|
395
|
+
delete_requests = [
|
396
|
+
{delete_request: {key: {id: 'one'}}},
|
397
|
+
{delete_request: {key: {id: 'two'}}}
|
398
|
+
]
|
399
|
+
|
400
|
+
request_options = {request_items: {table_name => delete_requests}}
|
401
|
+
expect(test_client.data[table_name]['one']).to eq({name: 'item1'})
|
402
|
+
expect(test_client.data[table_name]['two']).to eq({name: 'item2'})
|
403
|
+
test_client.batch_write_item(request_options)
|
404
|
+
expect(test_client.data[table_name]['one']).to be_nil
|
405
|
+
expect(test_client.data[table_name]['two']).to be_nil
|
406
|
+
end
|
390
407
|
end
|
408
|
+
end
|
391
409
|
|
392
|
-
|
410
|
+
context 'with hash key and range key' do
|
411
|
+
let(:test_client) { Dynamini::TestClient.new(:hash_key, :range_key) }
|
393
412
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
413
|
+
context 'executing put requests' do
|
414
|
+
it 'should store all items in the table correctly' do
|
415
|
+
item1 = {'foo' => 'bar', 'hash_key' => 1, 'range_key' => 'a'}
|
416
|
+
item2 = {'foo' => 'bar', 'hash_key' => 2, 'range_key' => 'b'}
|
417
|
+
put_requests = [{put_request: {item: item1}},
|
418
|
+
{put_request: {item: item2}}]
|
419
|
+
|
420
|
+
request_options = {request_items: {table_name => put_requests}}
|
421
|
+
|
422
|
+
test_client.batch_write_item(request_options)
|
423
|
+
expect(test_client.data[table_name][1]['a']).to eq({foo: 'bar', hash_key: 1, range_key: 'a'})
|
424
|
+
expect(test_client.data[table_name][2]['b']).to eq({foo: 'bar', hash_key: 2, range_key: 'b'})
|
425
|
+
end
|
426
|
+
|
427
|
+
it 'should add a new record to the hash key if it is a new range key' do
|
428
|
+
item1 = {'foo' => 'bar', 'hash_key' => 1, 'range_key' => 'a'}
|
429
|
+
item2 = {'foo' => 'bar', 'hash_key' => 1, 'range_key' => 'b'}
|
430
|
+
|
431
|
+
put_requests1 = [{put_request: {item: item1}}]
|
432
|
+
request_options1 = {request_items: {table_name => put_requests1}}
|
433
|
+
|
434
|
+
put_requests2 = [{put_request: {item: item2}}]
|
435
|
+
request_options2 = {request_items: {table_name => put_requests2}}
|
436
|
+
|
437
|
+
test_client.batch_write_item(request_options1)
|
438
|
+
test_client.batch_write_item(request_options2)
|
439
|
+
expect(test_client.data[table_name][1]['a']).to eq({foo: 'bar', hash_key: 1, range_key: 'a'})
|
440
|
+
expect(test_client.data[table_name][1]['b']).to eq({foo: 'bar', hash_key: 1, range_key: 'b'})
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
context 'executing delete requests' do
|
398
445
|
|
399
|
-
request_options = {request_items: {table_name => delete_requests}}
|
400
|
-
expect(test_client.data[table_name]['one']).to eq({name: 'item1'})
|
401
|
-
expect(test_client.data[table_name]['two']).to eq({name: 'item2'})
|
402
|
-
test_client.batch_write_item(request_options)
|
403
|
-
expect(test_client.data[table_name]['one']).to be_nil
|
404
|
-
expect(test_client.data[table_name]['two']).to be_nil
|
405
446
|
end
|
406
447
|
end
|
407
448
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Ward
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2016-10-
|
18
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activemodel
|