iknow_view_models 3.4.4 → 3.5.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.
@@ -187,7 +187,21 @@ class ViewModel::TraversalContextTest < ActiveSupport::TestCase
187
187
  it 'traverses as expected in replace_associated' do
188
188
  ctx = vm_deserialize_context(viewmodel_class)
189
189
  replacement = subject_association.collection? ? [new_child_hash] : new_child_hash
190
- vm.replace_associated(subject_association_name, replacement, deserialize_context: ctx)
190
+ references = {}
191
+
192
+ # Referenced collections need to be presented as is, _except_ for when they're owned, as
193
+ # this is special cased in NestedControllerBase#write_association (+_bulk) for
194
+ # convenience.
195
+ if subject_association.referenced? && !subject_association.owned?
196
+ replacement = ViewModel::Utils.wrap_one_or_many(replacement) do |replacements|
197
+ replacements.map!.with_index do |update, index|
198
+ references["ref#{index}"] = update
199
+ { ViewModel::REFERENCE_ATTRIBUTE => "ref#{index}" }
200
+ end
201
+ end
202
+ end
203
+
204
+ vm.replace_associated(subject_association_name, replacement, references: references, deserialize_context: ctx)
191
205
 
192
206
  expected = expected_parent_details
193
207
  expected = expected.merge(expected_children_details) unless subject_association.referenced?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iknow_view_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.4
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iKnow Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-24 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -453,6 +453,7 @@ files:
453
453
  - test/unit/view_model/active_record/belongs_to_test.rb
454
454
  - test/unit/view_model/active_record/cache_test.rb
455
455
  - test/unit/view_model/active_record/cloner_test.rb
456
+ - test/unit/view_model/active_record/controller_nested_test.rb
456
457
  - test/unit/view_model/active_record/controller_test.rb
457
458
  - test/unit/view_model/active_record/counter_test.rb
458
459
  - test/unit/view_model/active_record/customization_test.rb
@@ -514,6 +515,7 @@ test_files:
514
515
  - test/unit/view_model/active_record/belongs_to_test.rb
515
516
  - test/unit/view_model/active_record/cache_test.rb
516
517
  - test/unit/view_model/active_record/cloner_test.rb
518
+ - test/unit/view_model/active_record/controller_nested_test.rb
517
519
  - test/unit/view_model/active_record/controller_test.rb
518
520
  - test/unit/view_model/active_record/counter_test.rb
519
521
  - test/unit/view_model/active_record/customization_test.rb