embedded_associations 4.0.0 → 4.1.0
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 +4 -4
- data/lib/embedded_associations/version.rb +1 -1
- data/lib/embedded_associations.rb +8 -3
- data/spec/embedded_associations_spec.rb +40 -11
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76c8b0e4ae9164c343480eb95de82cd07a83c8fe
|
4
|
+
data.tar.gz: 04934eb299a9eb501f8f77a8c803bc7715d4925c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fad90037a4e1e2528772398f851f55230a4f8559eb02d621566ac092c6c9a87509581e71d40756deef82dbc3183146c77095208622d7a75f26e49e630653eeb
|
7
|
+
data.tar.gz: 074f845b30f457745ae7976bf8fccadea23e231d0006e8d325daa19418fece68ecdaa033e10e07f4ab875d2ee32438eff88e22849c700c08e6cae12a07f52413
|
@@ -87,8 +87,13 @@ module EmbeddedAssociations
|
|
87
87
|
end
|
88
88
|
|
89
89
|
definition.each do |name, child_definition|
|
90
|
+
if !parent_params || !parent_params.has_key?(name.to_s)
|
91
|
+
next
|
92
|
+
end
|
93
|
+
|
90
94
|
reflection = parent.class.reflect_on_association(name)
|
91
|
-
|
95
|
+
|
96
|
+
attrs = parent_params.delete(name.to_s)
|
92
97
|
|
93
98
|
if reflection.collection?
|
94
99
|
attrs ||= []
|
@@ -131,7 +136,7 @@ module EmbeddedAssociations
|
|
131
136
|
current_assoc = parent.send(name)
|
132
137
|
|
133
138
|
if r = current_assoc
|
134
|
-
if attrs
|
139
|
+
if attrs && attrs != ''
|
135
140
|
attrs = controller.send(:filter_attributes, r.class.name, attrs, :update)
|
136
141
|
handle_resource(child_definition, r, attrs) if child_definition
|
137
142
|
r.assign_attributes(attrs)
|
@@ -141,7 +146,7 @@ module EmbeddedAssociations
|
|
141
146
|
run_before_destroy_callbacks(r)
|
142
147
|
r.mark_for_destruction
|
143
148
|
end
|
144
|
-
elsif attrs
|
149
|
+
elsif attrs && attrs != ''
|
145
150
|
r = parent.send("build_#{name}")
|
146
151
|
attrs = controller.send(:filter_attributes, r.class.name, attrs, :create)
|
147
152
|
handle_resource(child_definition, r, attrs) if child_definition
|
@@ -46,6 +46,16 @@ describe PostsController, type: :controller do
|
|
46
46
|
|
47
47
|
Tag.all.each{ |t| expect(t.post).to_not be_nil }
|
48
48
|
end
|
49
|
+
|
50
|
+
it "should not destory if entire field missing" do
|
51
|
+
hash.delete(:tags)
|
52
|
+
json = post :update, :id => resource.id, post: hash
|
53
|
+
|
54
|
+
expect(Post.count).to eq(1)
|
55
|
+
expect(Tag.count).to eq(2)
|
56
|
+
|
57
|
+
Tag.all.each{ |t| expect(t.post).to_not be_nil }
|
58
|
+
end
|
49
59
|
|
50
60
|
it "should update modified child records" do
|
51
61
|
hash[:tags].first[:name] = 'modified'
|
@@ -104,8 +114,8 @@ describe PostsController, type: :controller do
|
|
104
114
|
|
105
115
|
let(:resource) { Post.create(category: Category.create(name: 'ember')) }
|
106
116
|
|
107
|
-
it "should destroy
|
108
|
-
hash[:category] =
|
117
|
+
it "should destroy blank child record" do
|
118
|
+
hash[:category] = ''
|
109
119
|
json = post :update, :id => resource.id, post: hash
|
110
120
|
|
111
121
|
expect(Post.count).to eq(1)
|
@@ -115,6 +125,14 @@ describe PostsController, type: :controller do
|
|
115
125
|
|
116
126
|
expect(resource.category).to be_nil
|
117
127
|
end
|
128
|
+
|
129
|
+
it "should not destroy missing child field" do
|
130
|
+
hash.delete(:category)
|
131
|
+
json = post :update, :id => resource.id, post: hash
|
132
|
+
|
133
|
+
expect(Post.count).to eq(1)
|
134
|
+
expect(Category.count).to eq(1)
|
135
|
+
end
|
118
136
|
|
119
137
|
it "should update modified child records" do
|
120
138
|
hash[:category][:name] = 'ember-data'
|
@@ -174,8 +192,8 @@ describe PostsController, type: :controller do
|
|
174
192
|
|
175
193
|
let(:resource) { Post.create({user: User.create({name: 'G$', account: Account.create})}) }
|
176
194
|
|
177
|
-
it "should destroy
|
178
|
-
hash[:user] =
|
195
|
+
it "should destroy blank child hierarchy" do
|
196
|
+
hash[:user] = ''
|
179
197
|
json = post :update, :id => resource.id, post: hash
|
180
198
|
|
181
199
|
expect(Post.count).to eq(1)
|
@@ -187,8 +205,8 @@ describe PostsController, type: :controller do
|
|
187
205
|
expect(resource.user).to be_nil
|
188
206
|
end
|
189
207
|
|
190
|
-
it "should destroy
|
191
|
-
hash[:user] = {name: 'G$'}
|
208
|
+
it "should destroy blank grand-child" do
|
209
|
+
hash[:user] = {name: 'G$', account: ''}
|
192
210
|
json = post :update, :id => resource.id, post: hash
|
193
211
|
|
194
212
|
expect(Post.count).to eq(1)
|
@@ -199,6 +217,16 @@ describe PostsController, type: :controller do
|
|
199
217
|
|
200
218
|
expect(resource.user.account).to be_nil
|
201
219
|
end
|
220
|
+
|
221
|
+
it "should not destroy missing grand-child" do
|
222
|
+
hash[:user] = {name: 'G$'}
|
223
|
+
json = post :update, :id => resource.id, post: hash
|
224
|
+
|
225
|
+
expect(Post.count).to eq(1)
|
226
|
+
expect(User.count).to eq(1)
|
227
|
+
expect(Account.count).to eq(1)
|
228
|
+
end
|
229
|
+
|
202
230
|
|
203
231
|
it "should update modified child records" do
|
204
232
|
hash[:user][:name] = 'wes'
|
@@ -230,7 +258,7 @@ describe PostsController, type: :controller do
|
|
230
258
|
|
231
259
|
context "creating" do
|
232
260
|
|
233
|
-
it "should create hierarchy"
|
261
|
+
it "should create hierarchy" do
|
234
262
|
json = post :create, post: {
|
235
263
|
title: 'ma post',
|
236
264
|
comments: [{user: {name: 'G$', account: {}}}]
|
@@ -280,8 +308,9 @@ describe PostsController, type: :controller do
|
|
280
308
|
p
|
281
309
|
}
|
282
310
|
|
283
|
-
it "should destroy
|
284
|
-
hash[:comments] =
|
311
|
+
it "should destroy blank child hierarchy" do
|
312
|
+
hash[:comments] = []
|
313
|
+
hash[:user] = ''
|
285
314
|
json = post :update, :id => resource.id, post: hash
|
286
315
|
|
287
316
|
expect(Post.count).to eq(1)
|
@@ -294,8 +323,8 @@ describe PostsController, type: :controller do
|
|
294
323
|
expect(resource.comments).to be_empty
|
295
324
|
end
|
296
325
|
|
297
|
-
it "should destroy
|
298
|
-
hash[:comments].first[:user] =
|
326
|
+
it "should destroy blank grand-child hierarchy" do
|
327
|
+
hash[:comments].first[:user] = ''
|
299
328
|
json = post :update, :id => resource.id, post: hash
|
300
329
|
|
301
330
|
expect(Post.count).to eq(1)
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embedded_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gordon L. Hempton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.0.0
|
27
27
|
description: ActiveRecord controller-level support for embedded associations
|
@@ -31,8 +31,8 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
- .gitignore
|
35
|
-
- .travis.yml
|
34
|
+
- ".gitignore"
|
35
|
+
- ".travis.yml"
|
36
36
|
- Gemfile
|
37
37
|
- LICENSE.txt
|
38
38
|
- README.md
|
@@ -97,17 +97,17 @@ require_paths:
|
|
97
97
|
- lib
|
98
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- -
|
100
|
+
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
|
-
- -
|
105
|
+
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.2.2
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: ActiveRecord controller-level support for embedded associations
|