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: e0ca9443ae6c4495fe76be75142603808e37206f1a5f691692618fd650e49582
4
- data.tar.gz: d2baff7ccc9b188439d9545b4ebf69d7985e6db56b382c9d06c749a931f6ae7c
3
+ metadata.gz: 20626189e14765f0dcf1b88d4cd74b542f26cbe522b59b472fa2a13a6fa4c8ad
4
+ data.tar.gz: dfecf15184f5465eab585794303e83aff96860a77c44aceed03e8340d1e13485
5
5
  SHA512:
6
- metadata.gz: 6fbed7379cfa330b9dac84497ca76e9dada5d3400cb188541f28394548b99a717a84e42d8d5edf6d62fd139b8484a050824aec9ba0a1ec0f76e660075b82bfa5
7
- data.tar.gz: 6f37c4911fca2a124e9e57cdfefb027610bb4f4bd5286878db125d8588c49b22f5d0a67a218e3971bef51b111ca9eac7299dfc6eaa4fa642d800ac6226141eec
6
+ metadata.gz: c1a7b86997c59882918af9d8eabe61572b2b458a1b3ce33675cf3289ffcdaef5fa3589202c2341d699bfd6221608525b48f65edc314e649df1795cf5bf083251
7
+ data.tar.gz: 266e41e0fe810325b5c22757d8f01e66b40b6f7c66cf20bfd6c5f7599a5f3b97033f9ca03709dbe2b1a882b372330a1b609ea0289f2074e0b733fee757ad676f
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.1.1'
4
+ VERSION = '3.1.2'
5
5
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iknow_view_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - iKnow Team