iknow_view_models 3.5.0 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b538a2d547114ecfbb76bfc790daea11b2185abdbad54d5da82723bb7fa1bef
|
4
|
+
data.tar.gz: 97b7e6d1d66cae14d56fe53931d06a4079e5c9b4b61e60bf56027d539fd41224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f70185a7ba12a222eee6a1549f724c08754f7213a1c1594d5b2ea0060baac04fce839cb480615e02741adcc82cd2d910e8d82e519127da15efd6e14dbdf3b0b
|
7
|
+
data.tar.gz: 82a343d49bf61a6e351653c8a3e3855344b5dd017acc7722cc526e41af8915d6aedb028995f859354df23de82f55b2c342b2fa1a572af76b1690345fb120ae02
|
data/lib/view_model/migrator.rb
CHANGED
@@ -75,6 +75,32 @@ class ViewModel
|
|
75
75
|
class UpMigrator < Migrator
|
76
76
|
private
|
77
77
|
|
78
|
+
def migrate_tree!(node, references:)
|
79
|
+
if node.is_a?(Hash) && node[ViewModel::TYPE_ATTRIBUTE] == ViewModel::ActiveRecord::FUNCTIONAL_UPDATE_TYPE
|
80
|
+
migrate_functional_update!(node, references: references)
|
81
|
+
else
|
82
|
+
super
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
NESTED_FUPDATE_TYPES = ['append', 'update'].freeze
|
87
|
+
|
88
|
+
# The functional update structure uses `_type` internally with a
|
89
|
+
# context-dependent meaning. Retrospectively this was a poor choice, but we
|
90
|
+
# need to account for it here.
|
91
|
+
def migrate_functional_update!(node, references:)
|
92
|
+
actions = node[ViewModel::ActiveRecord::ACTIONS_ATTRIBUTE]
|
93
|
+
actions&.each do |action|
|
94
|
+
action_type = action[ViewModel::TYPE_ATTRIBUTE]
|
95
|
+
next unless NESTED_FUPDATE_TYPES.include?(action_type)
|
96
|
+
|
97
|
+
values = action[ViewModel::ActiveRecord::VALUES_ATTRIBUTE]
|
98
|
+
values&.each do |value|
|
99
|
+
migrate_tree!(value, references: references)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
78
104
|
def migrate_viewmodel!(view_name, source_version, view_hash, references)
|
79
105
|
path = @paths[view_name]
|
80
106
|
return false unless path
|
@@ -178,6 +178,35 @@ class ViewModel::ActiveRecord::Migration < ActiveSupport::TestCase
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|
181
|
+
|
182
|
+
describe 'with a functional update' do
|
183
|
+
# note that this wouldn't actually be deserializable as child is not a collection
|
184
|
+
def subject_data
|
185
|
+
data = super()
|
186
|
+
data['child'] = wrap_with_fupdate(data['child'])
|
187
|
+
data
|
188
|
+
end
|
189
|
+
|
190
|
+
def expected_result
|
191
|
+
data = super()
|
192
|
+
data['data']['child'] = wrap_with_fupdate(data['data']['child'])
|
193
|
+
data
|
194
|
+
end
|
195
|
+
|
196
|
+
def wrap_with_fupdate(child)
|
197
|
+
# The 'after' and remove shouldn't get changed in migration, even though it has _type: Child
|
198
|
+
build_fupdate do
|
199
|
+
append([child], after: { '_type' => 'Child', 'id' => 9999 })
|
200
|
+
update([child.deep_merge('id' => 8888)])
|
201
|
+
remove([{ '_type' => 'Child', 'id' => 7777 }])
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'migrates' do
|
206
|
+
migrate!
|
207
|
+
assert_equal(expected_result, subject)
|
208
|
+
end
|
209
|
+
end
|
181
210
|
end
|
182
211
|
end
|
183
212
|
|
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.5.
|
4
|
+
version: 3.5.1
|
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-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|