soulless 0.4.1 → 0.4.3

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: 21360afcf39cf68b66a39e14171298cd628cc3f2
4
- data.tar.gz: 887ea03598950007d8968069a439e1eebb10e609
3
+ metadata.gz: bb87770d995077463f68f4e6b80da470b5897368
4
+ data.tar.gz: 8c5b6ff12f1f3cd329fc1ecaa12af79f567a53e3
5
5
  SHA512:
6
- metadata.gz: c9c3c7b0fc26fb0dbc7ecc6fb06f5efe37f678460169b78b6336cd358051910754edc379e6cbd3ff560630bcf60c16f5b058f30efbe32df6ffc6295007f32088
7
- data.tar.gz: 881ea4291ce2f79553b78c8e2499d1a1242a1f9f280487b76d35b06753cabecbc41b12c4b256611359f9d52066172fcd0da37d6a7178c3de88a53b4ba3d9a0c3
6
+ metadata.gz: 432822f228e7c4c5111e21c4c3fd6d89de3cd134f598c055054d0198d0856553a85bec2febd324a19715756dad5b7710facdd7694ddb4bd6be2cc71efbd7a821
7
+ data.tar.gz: 747fd977b5017cf8761fe866b6178d558fa297bb56ef36056d6c04b89c6fea81af3fa5e54d7ddca80274a147fe2b207804c122f6df88fd0e56cc6682884be5d2
@@ -35,7 +35,7 @@ module Soulless
35
35
  end
36
36
 
37
37
  def update_attributes(attributes)
38
- self.attributes = attributes
38
+ deep_update(self, attributes)
39
39
  save
40
40
  end
41
41
 
@@ -43,6 +43,16 @@ module Soulless
43
43
  def persist!
44
44
  raise 'Method persist! not defined...'
45
45
  end
46
+
47
+ def deep_update(object, attributes)
48
+ attributes.each do |key, value|
49
+ if value.kind_of?(Hash)
50
+ deep_update(object.send(key), value)
51
+ else
52
+ object.send("#{key}=", value)
53
+ end
54
+ end
55
+ end
46
56
  end
47
57
  end
48
58
  end
@@ -1,3 +1,3 @@
1
1
  module Soulless
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -34,6 +34,19 @@ describe Soulless do
34
34
  @dummy_class.saved?.should be_true
35
35
  end
36
36
 
37
+ it '#update_attributes should merge new values' do
38
+ @dummy_class.email = 'yokoono@thebeatles.com'
39
+ @dummy_class.update_attributes(name: 'Yaw')
40
+ @dummy_class.name.should == 'Yaw'
41
+ @dummy_class.email.should == 'yokoono@thebeatles.com'
42
+ end
43
+
44
+ it '#update_attributes should deep merge new values' do
45
+ @dummy_class = DummyAssociation.new(spouse: { name: 'Megan' })
46
+ @dummy_class.update_attributes(spouse: { name: 'Mary Jane Watson' })
47
+ @dummy_class.spouse.name.should == 'Mary Jane Watson'
48
+ end
49
+
37
50
  it '#persisted? should be false' do
38
51
  @dummy_class.persisted?.should be_false
39
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soulless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Smith