iknow_view_models 3.1.1 → 3.1.2
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20626189e14765f0dcf1b88d4cd74b542f26cbe522b59b472fa2a13a6fa4c8ad
|
4
|
+
data.tar.gz: dfecf15184f5465eab585794303e83aff96860a77c44aceed03e8340d1e13485
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a7b86997c59882918af9d8eabe61572b2b458a1b3ce33675cf3289ffcdaef5fa3589202c2341d699bfd6221608525b48f65edc314e649df1795cf5bf083251
|
7
|
+
data.tar.gz: 266e41e0fe810325b5c22757d8f01e66b40b6f7c66cf20bfd6c5f7599a5f3b97033f9ca03709dbe2b1a882b372330a1b609ea0289f2074e0b733fee757ad676f
|
@@ -40,7 +40,7 @@ class ViewModel::ActiveRecord::Cloner
|
|
40
40
|
reflection = association_data.direct_reflection
|
41
41
|
|
42
42
|
if ignored_associations.include?(name)
|
43
|
-
new_associated = nil
|
43
|
+
new_associated = association_data.collection? ? [] : nil
|
44
44
|
else
|
45
45
|
# Load the record associated with the old model
|
46
46
|
associated = node.model.public_send(reflection.name)
|
@@ -193,6 +193,12 @@ class ViewModel::ActiveRecord
|
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
|
+
class IgnoreChildrenAssociationCloner < Cloner
|
197
|
+
def visit_model_view(node, model)
|
198
|
+
ignore_association!(:children)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
196
202
|
describe "with has_many children" do
|
197
203
|
include ViewModelSpecHelpers::ParentAndHasManyChildren
|
198
204
|
def new_child_models
|
@@ -258,6 +264,16 @@ class ViewModel::ActiveRecord
|
|
258
264
|
assert_equal(1, clone_model.children.size)
|
259
265
|
assert_equal(model.children[1].name, clone_model.children[0].name)
|
260
266
|
end
|
267
|
+
|
268
|
+
it "can ignore the children association" do
|
269
|
+
clone_model = IgnoreChildrenAssociationCloner.new.clone(viewmodel)
|
270
|
+
|
271
|
+
assert(clone_model.new_record?)
|
272
|
+
assert_nil(clone_model.id)
|
273
|
+
assert_equal(model.name, clone_model.name)
|
274
|
+
|
275
|
+
assert(clone_model.children.blank?)
|
276
|
+
end
|
261
277
|
end
|
262
278
|
|
263
279
|
describe "with has_many_through shared children" do
|
@@ -308,6 +324,16 @@ class ViewModel::ActiveRecord
|
|
308
324
|
assert_equal(clone_model_child.child, model_child.child)
|
309
325
|
end
|
310
326
|
end
|
327
|
+
|
328
|
+
it "can ignore the children association" do
|
329
|
+
clone_model = IgnoreChildrenAssociationCloner.new.clone(viewmodel)
|
330
|
+
|
331
|
+
assert(clone_model.new_record?)
|
332
|
+
assert_nil(clone_model.id)
|
333
|
+
assert_equal(model.name, clone_model.name)
|
334
|
+
|
335
|
+
assert(clone_model.model_children.blank?)
|
336
|
+
end
|
311
337
|
end
|
312
338
|
end
|
313
339
|
end
|