dynamini 2.2.5 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc2cb03535d576707c7d063479495420f147402c
4
- data.tar.gz: 9a13209c5dd606f18be36a0a6b8178cee4a95309
3
+ metadata.gz: 42a0405b70513e4b385e3e5817bd165f3965a9da
4
+ data.tar.gz: c248a81d97633dd595b6dfb3ff3f5881dee6c264
5
5
  SHA512:
6
- metadata.gz: ed8549da709ccd8347fa152729a07ad9889ae33afbdfaa7e8d0162d791a869bbe660c78185eb332eb70ec3c784deda8d0a2d4559848ba24e742b7bb53dbfdabb
7
- data.tar.gz: 054b7037256a8e9c8af8c7e8fbe12de5b6f99df929ace57361c731ec07c622bfe49bded36cf43db93b629bd18896455a7ab520bf7711841fe1def54c1cdef51d
6
+ metadata.gz: ba66289642c867b5cbadbf3078a80d0d809e1210170c7b7ab41046dd6ced32a8d753596dcc919b4f7a602a9c552de0661a39d184593a9c7bc4422b16776d84c6
7
+ data.tar.gz: 56d3a8b2f619e62de98763b88fec4fec50c2681a53b5086dae33865d979f7f2ac00e9d16af773d61047f6c8fb3c7c564d8625de48c2bb6394a24923ee9c38ce8
data/README.md CHANGED
@@ -187,6 +187,8 @@ Vehicle.find('H3LLO').stuff
187
187
  > ['wheel', 'brakes', BigDecimal(5)]
188
188
  ```
189
189
 
190
+ Please note that changing arrays in place using mutator methods like << or map! will not record a change to the object. If you want to make changes like this, either use the assignment operator (e.g. model.array = model.array << 'foo') or call model.mark(:attribute) after mutation and before saving to force Dynamini to write the change.
191
+
190
192
  ## Testing
191
193
  We've included an optional in-memory test client, so you don't necessarily have to connect to a real Dynamo instance when running tests. You could also use this in your development environment if you don't have a real Dynamo instance yet, but the data saved to it won't persist through a server restart.
192
194
 
data/dynamini.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dynamini'
3
- s.version = '2.2.5'
3
+ s.version = '2.2.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.
@@ -14,6 +14,13 @@ module Dynamini
14
14
  @new_record
15
15
  end
16
16
 
17
+ def mark(attr)
18
+ if @changes[attr] == [nil, nil]
19
+ val = @attributes[attr]
20
+ @changes[attr] = [val, val]
21
+ end
22
+ end
23
+
17
24
  private
18
25
 
19
26
  def record_change(attribute, new_value, old_value)
@@ -35,4 +42,4 @@ module Dynamini
35
42
  @changes[attr_name].compact.present? ? @changes[attr_name][0] : read_attribute(attr_name)
36
43
  end
37
44
  end
38
- end
45
+ end
@@ -1,6 +1,7 @@
1
- module Dynamini
2
- require 'ostruct'
1
+ require 'ostruct'
2
+ require 'active_support/core_ext/object/deep_dup'
3
3
 
4
+ module Dynamini
4
5
  # In-memory database client for test purposes.
5
6
  class TestClient
6
7
 
@@ -30,7 +31,6 @@ module Dynamini
30
31
  )
31
32
 
32
33
  primary_index_insertion(hash_key_value, range_key_value, updates, table) if hash_key_value
33
-
34
34
  end
35
35
 
36
36
  def primary_index_insertion(hash_key_value, range_key_value, updates, table)
@@ -66,7 +66,7 @@ module Dynamini
66
66
  attributes_hash = table[hash_key_value]
67
67
  attributes_hash = attributes_hash[range_key_value] if attributes_hash && range_key_value
68
68
 
69
- OpenStruct.new(item: attributes_hash)
69
+ OpenStruct.new(item: (attributes_hash ? attributes_hash.deep_dup : nil))
70
70
  end
71
71
 
72
72
  # No range key support - use query instead.
@@ -90,7 +90,7 @@ module Dynamini
90
90
  put_requests.each do |request_hash|
91
91
  item = request_hash[:put_request][:item]
92
92
  key = item[hash_key_attr.to_s]
93
- get_table(table_name)[key] = item
93
+ get_table(table_name)[key] = item # not merging since real client does not support batch update
94
94
  end
95
95
  end
96
96
  end
@@ -3,13 +3,14 @@ require 'spec_helper'
3
3
  describe Dynamini::Dirty do
4
4
 
5
5
  let(:model_attributes) {
6
- {
7
- name: 'Widget',
8
- price: 9.99,
9
- id: 'abcd1234',
10
- hash_key: '009'
11
- }
6
+ {
7
+ name: 'Widget',
8
+ price: 9.99,
9
+ id: 'abcd1234',
10
+ hash_key: '009'
11
+ }
12
12
  }
13
+
13
14
  let(:dirty_model) { Dynamini::Base.new(model_attributes) }
14
15
  let(:model) { Dynamini::Base.new(model_attributes, false) }
15
16
 
@@ -22,7 +23,31 @@ describe Dynamini::Dirty do
22
23
  end
23
24
 
24
25
  it 'should not include the primary key in the changes' do
25
- expect(dirty_model.changes[:id]).to be_nil
26
+ expect(dirty_model.changes['id']).to be_nil
27
+ end
28
+ end
29
+
30
+ describe '#mark' do
31
+ context 'when marking an unchanged attribute' do
32
+ it 'should add the marked attribute to @changed' do
33
+ model.mark(:price)
34
+ expect(model.changed).to eq(['price'])
35
+ end
36
+ end
37
+ context 'when marking an already changed attribute' do
38
+ it 'should do nothing' do
39
+ dirty_model.mark(:price)
40
+ expect(dirty_model.changes['price']).to eq([nil, model_attributes[:price]])
41
+ end
42
+ end
43
+ context 'when using it to mark a changed array' do
44
+ it 'should write the mutated array value when saving' do
45
+ model_with_array = Dynamini::Base.new({elements: ['a','b','c'], id: 'foo'}, false)
46
+ model_with_array.elements << 'd'
47
+ model_with_array.mark(:elements)
48
+ model_with_array.save
49
+ expect(Dynamini::Base.find('foo').elements).to eq(['a','b','c','d'])
50
+ end
26
51
  end
27
52
  end
28
53
 
@@ -141,4 +166,4 @@ describe Dynamini::Dirty do
141
166
  expect(model.changed).to eq(['price', 'name'])
142
167
  end
143
168
  end
144
- end
169
+ end
@@ -19,7 +19,6 @@ describe Dynamini::TestClient do
19
19
  test_client.update_item(table_name: table_name, key: {hash_key_name: 'hash_key_value'}, attribute_updates: {abc: {value: 'def', action: 'PUT'}})
20
20
  expect(test_client.data[table_name]['hash_key_value']).to eq(abc: 'def', :hash_key_name => "hash_key_value")
21
21
  end
22
-
23
22
  end
24
23
 
25
24
  context 'with Hash key and range key' do
@@ -76,6 +75,13 @@ describe Dynamini::TestClient do
76
75
 
77
76
  expect(test_client.get_item(table_name: table_name, key: {test_client.hash_key_attr => "abc", :extra_key => "extra"}).item[:test_attr]).to eq('test')
78
77
  end
78
+
79
+ it 'should return new (cloned) arrays if arrays are present in the model attributes' do
80
+ test_client.update_item(table_name: table_name, key: {test_client.hash_key_attr => "abc"}, attribute_updates: {ary: {value: ['a','b','c'], action: 'PUT'}})
81
+ retrieved = test_client.get_item(table_name: table_name, key: {test_client.hash_key_attr => "abc", :extra_key => "extra"}).item
82
+ retrieved[:ary] = ['a','b','c','d']
83
+ expect(test_client.get_item(table_name: table_name, key: {test_client.hash_key_attr => "abc", :extra_key => "extra"}).item[:ary]).to eq(['a','b','c'])
84
+ end
79
85
  end
80
86
 
81
87
  context 'table with hash and range key' do
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.2.5
4
+ version: 2.2.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-03-23 00:00:00.000000000 Z
18
+ date: 2016-06-23 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activemodel