iknow_view_models 3.4.4 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iknow_view_models/version.rb +1 -1
- data/lib/view_model.rb +12 -0
- data/lib/view_model/active_record.rb +46 -5
- data/lib/view_model/active_record/association_manipulation.rb +181 -44
- data/lib/view_model/active_record/collection_nested_controller.rb +5 -2
- data/lib/view_model/active_record/controller_base.rb +45 -6
- data/lib/view_model/active_record/nested_controller_base.rb +125 -13
- data/lib/view_model/active_record/singular_nested_controller.rb +5 -2
- data/lib/view_model/callbacks.rb +1 -1
- data/lib/view_model/controller.rb +17 -0
- data/lib/view_model/record.rb +1 -1
- data/lib/view_model/schemas.rb +44 -0
- data/test/helpers/arvm_test_utilities.rb +65 -0
- data/test/helpers/controller_test_helpers.rb +65 -34
- data/test/unit/view_model/active_record/controller_nested_test.rb +599 -0
- data/test/unit/view_model/active_record/controller_test.rb +6 -362
- data/test/unit/view_model/active_record/has_many_test.rb +10 -5
- data/test/unit/view_model/active_record/has_many_through_test.rb +28 -12
- data/test/unit/view_model/traversal_context_test.rb +15 -1
- metadata +4 -2
@@ -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
|
-
|
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
|
+
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-
|
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
|