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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a58fb603731e3efd1d91be0295a9f9c6bb9ab563
4
- data.tar.gz: 914d82aa5c7e4c923e1f5d14552043bfab6f966b
3
+ metadata.gz: 5f49e721fd627858b268479539065b3f62ded837
4
+ data.tar.gz: 296511c0cf83bb00155e21cd78e6a5c05da93ec0
5
5
  SHA512:
6
- metadata.gz: 35cef4e720792c20f78a3e9db934fc7fc020de29d06c377641fc4a4484b0874822394c391f0bc1dfb7a39a2310054efe68d665171c7900d523bd21fe92276cf1
7
- data.tar.gz: c39c01e1d41bbceade9bf3eac3561766389e0763b308dd841e750e7e0440802809d1bcee273abc6d6b618e854aa8aa7f5377aab69b943ac4c6377d0783575591
6
+ metadata.gz: 6785712ac96112bf8e78cc551a6dc1b378968ee90d1e4fd4cd2d0294c0290d9b26b777deb50e45143801eb4567263628f5cc37676fb932dcc7e1231e8a7da2e1
7
+ data.tar.gz: 8fd0a91480de7a1a3a815c22db84cf2a783e2aefb68a8f47da958bf9e8d76c9d8399dfec093735f1494eec8212a0b6308899d46eab99b45be7b099849952dcc4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dynamini (2.6.5)
4
+ dynamini (2.6.6)
5
5
  activemodel (>= 3, < 5.0)
6
6
  aws-sdk (~> 2)
7
7
 
data/dynamini.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dynamini'
3
- s.version = '2.6.5'
3
+ s.version = '2.6.6'
4
4
  s.summary = 'DynamoDB interface'
5
5
  s.description = 'Lightweight DynamoDB interface gem designed as
6
6
  a drop-in replacement for ActiveRecord.
@@ -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
- key = item[hash_key_attr.to_s]
92
- get_table(table_name)[key] = item
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
- get_table(table_name).delete(id)
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
- let(:test_client) { Dynamini::TestClient.new(:id) }
370
+ context 'with only hash key' do
371
+ let(:test_client) { Dynamini::TestClient.new(:id) }
371
372
 
372
- it 'should store all items in the table correctly' do
373
- item1 = {'foo' => 'bar', 'id' => 1}
374
- item2 = {'foo' => 'bar', 'id' => 2}
375
- put_requests = [{put_request: {item: item1}},
376
- {put_request: {item: item2}}]
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
- request_options = {request_items: {table_name => put_requests}}
379
+ request_options = {request_items: {table_name => put_requests}}
379
380
 
380
- test_client.batch_write_item(request_options)
381
- expect(test_client.data[table_name][1]).to eq(item1)
382
- expect(test_client.data[table_name][2]).to eq(item2)
383
- end
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
- context 'batch deleting' do
386
- before do
387
- test_client.data[table_name] = {}
388
- test_client.data[table_name]['one'] = {name: 'item1'}
389
- test_client.data[table_name]['two'] = {name: 'item2'}
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
- it 'should remove all items from the table' do
410
+ context 'with hash key and range key' do
411
+ let(:test_client) { Dynamini::TestClient.new(:hash_key, :range_key) }
393
412
 
394
- delete_requests = [
395
- {delete_request: {key: {id: 'one'}}},
396
- {delete_request: {key: {id: 'two'}}}
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.5
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-04 00:00:00.000000000 Z
18
+ date: 2016-10-05 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activemodel