soulless 0.4.1 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/soulless/model.rb +11 -1
- data/lib/soulless/version.rb +1 -1
- data/spec/soulless_spec.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb87770d995077463f68f4e6b80da470b5897368
|
4
|
+
data.tar.gz: 8c5b6ff12f1f3cd329fc1ecaa12af79f567a53e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 432822f228e7c4c5111e21c4c3fd6d89de3cd134f598c055054d0198d0856553a85bec2febd324a19715756dad5b7710facdd7694ddb4bd6be2cc71efbd7a821
|
7
|
+
data.tar.gz: 747fd977b5017cf8761fe866b6178d558fa297bb56ef36056d6c04b89c6fea81af3fa5e54d7ddca80274a147fe2b207804c122f6df88fd0e56cc6682884be5d2
|
data/lib/soulless/model.rb
CHANGED
@@ -35,7 +35,7 @@ module Soulless
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def update_attributes(attributes)
|
38
|
-
self
|
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
|
data/lib/soulless/version.rb
CHANGED
data/spec/soulless_spec.rb
CHANGED
@@ -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
|