iknow_view_models 3.2.1 → 3.2.2
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: a86b2b9fdc89ee421bcb155ae29e3ac4f2c809be4d40e483a405337f8729a7f9
|
4
|
+
data.tar.gz: 8fd1c498264a0eefe30d9c3c6a35c4f005a94aaf71b03d37044a23212cb90eb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2a2fd321cf605709eb398771cd6cc475869e80c59d5a4934a2cf5429cfa3e1a6a5e3e74f358227793ff2cc7ce10a1eff46fe3c4db20e859d49d54be306b4afb
|
7
|
+
data.tar.gz: cfb7009b02acbebce85d3ad41205549430370710633d51176ac8596acf6a83fb98f0e76132bf850baf37da36acfe402afc21d00c8996f66ca2a98f62a9380dc1
|
@@ -17,6 +17,8 @@ module ViewModel::ActiveRecord::Controller
|
|
17
17
|
include ViewModel::ActiveRecord::CollectionNestedController
|
18
18
|
include ViewModel::ActiveRecord::SingularNestedController
|
19
19
|
|
20
|
+
MIGRATION_VERSION_HEADER = 'X-ViewModel-Versions'
|
21
|
+
|
20
22
|
def show(scope: nil, viewmodel_class: self.viewmodel_class, serialize_context: new_serialize_context(viewmodel_class: viewmodel_class))
|
21
23
|
view = nil
|
22
24
|
pre_rendered = viewmodel_class.transaction do
|
@@ -96,11 +98,24 @@ module ViewModel::ActiveRecord::Controller
|
|
96
98
|
def migration_versions
|
97
99
|
@migration_versions ||=
|
98
100
|
begin
|
99
|
-
|
100
|
-
:versions
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
version_spec =
|
102
|
+
if params.include?(:versions)
|
103
|
+
params[:versions]
|
104
|
+
elsif request.headers.include?(MIGRATION_VERSION_HEADER)
|
105
|
+
begin
|
106
|
+
JSON.parse(request.headers[MIGRATION_VERSION_HEADER])
|
107
|
+
rescue JSON::ParserError
|
108
|
+
raise ViewModel::Error.new(status: 400, detail: "Invalid JSON in #{MIGRATION_VERSION_HEADER}")
|
109
|
+
end
|
110
|
+
else
|
111
|
+
{}
|
112
|
+
end
|
113
|
+
|
114
|
+
versions =
|
115
|
+
IknowParams::Parser.parse_value(
|
116
|
+
version_spec,
|
117
|
+
with: IknowParams::Serializer::HashOf.new(
|
118
|
+
IknowParams::Serializer::String, IknowParams::Serializer::Integer))
|
104
119
|
|
105
120
|
migration_versions = {}
|
106
121
|
|
@@ -7,6 +7,8 @@ require 'view_model/active_record/controller'
|
|
7
7
|
require_relative '../helpers/arvm_test_utilities'
|
8
8
|
require_relative '../helpers/arvm_test_models'
|
9
9
|
|
10
|
+
require 'action_controller'
|
11
|
+
|
10
12
|
require 'acts_as_manual_list'
|
11
13
|
|
12
14
|
# models for ARVM controller test
|
@@ -145,11 +147,11 @@ end
|
|
145
147
|
|
146
148
|
## Dummy Rails Controllers
|
147
149
|
class DummyController
|
148
|
-
attr_reader :params, :status
|
150
|
+
attr_reader :params, :headers, :status
|
149
151
|
|
150
|
-
def initialize(
|
151
|
-
|
152
|
-
@
|
152
|
+
def initialize(headers: {}, params: {})
|
153
|
+
@params = ActionController::Parameters.new(params)
|
154
|
+
@headers = ActionDispatch::Http::Headers.from_hash({}).merge!(headers)
|
153
155
|
@status = 200
|
154
156
|
end
|
155
157
|
|
@@ -192,6 +194,11 @@ class DummyController
|
|
192
194
|
JSON.parse(json_response)
|
193
195
|
end
|
194
196
|
|
197
|
+
# for request.params and request.headers
|
198
|
+
def request
|
199
|
+
self
|
200
|
+
end
|
201
|
+
|
195
202
|
class << self
|
196
203
|
def inherited(subclass)
|
197
204
|
subclass.initialize_rescue_blocks
|
@@ -98,7 +98,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def test_show
|
101
|
-
parentcontroller = ParentController.new(id: @parent.id)
|
101
|
+
parentcontroller = ParentController.new(params: { id: @parent.id })
|
102
102
|
parentcontroller.invoke(:show)
|
103
103
|
|
104
104
|
assert_equal({ 'data' => @parent_view.to_hash },
|
@@ -110,7 +110,10 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def test_migrated_show
|
113
|
-
parentcontroller = ParentController.new(
|
113
|
+
parentcontroller = ParentController.new(
|
114
|
+
params: { id: @parent.id },
|
115
|
+
headers: { 'X-ViewModel-Versions' => { ParentView.view_name => 1 }.to_json })
|
116
|
+
|
114
117
|
parentcontroller.invoke(:show)
|
115
118
|
|
116
119
|
expected_view = @parent_view.to_hash
|
@@ -127,6 +130,18 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
127
130
|
assert_all_hooks_nested_inside_parent_hook(parentcontroller.hook_trace)
|
128
131
|
end
|
129
132
|
|
133
|
+
def test_invalid_migration_header
|
134
|
+
parentcontroller = ParentController.new(
|
135
|
+
params: { id: @parent.id },
|
136
|
+
headers: { 'X-ViewModel-Versions' => 'not a json' })
|
137
|
+
|
138
|
+
parentcontroller.invoke(:show)
|
139
|
+
assert_equal(400, parentcontroller.status)
|
140
|
+
assert_match(/Invalid JSON/i,
|
141
|
+
parentcontroller.hash_response['error']['detail'],
|
142
|
+
'json error propagated')
|
143
|
+
end
|
144
|
+
|
130
145
|
def test_index
|
131
146
|
p2 = Parent.create(name: 'p2')
|
132
147
|
p2_view = ParentView.new(p2)
|
@@ -152,7 +167,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
152
167
|
{ '_type' => 'Child', 'name' => 'c2' },],
|
153
168
|
}
|
154
169
|
|
155
|
-
parentcontroller = ParentController.new(data: data)
|
170
|
+
parentcontroller = ParentController.new(params: { data: data })
|
156
171
|
parentcontroller.invoke(:create)
|
157
172
|
|
158
173
|
assert_equal(200, parentcontroller.status)
|
@@ -173,7 +188,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
173
188
|
'old_name' => 'p2',
|
174
189
|
}
|
175
190
|
|
176
|
-
parentcontroller = ParentController.new(data: data, versions: { ParentView.view_name => 1 })
|
191
|
+
parentcontroller = ParentController.new(params: { data: data, versions: { ParentView.view_name => 1 } })
|
177
192
|
parentcontroller.invoke(:create)
|
178
193
|
|
179
194
|
assert_equal(200, parentcontroller.status)
|
@@ -183,14 +198,14 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
183
198
|
end
|
184
199
|
|
185
200
|
def test_create_empty
|
186
|
-
parentcontroller = ParentController.new(data: [])
|
201
|
+
parentcontroller = ParentController.new(params: { data: [] })
|
187
202
|
parentcontroller.invoke(:create)
|
188
203
|
|
189
204
|
assert_equal(400, parentcontroller.status)
|
190
205
|
end
|
191
206
|
|
192
207
|
def test_create_invalid
|
193
|
-
parentcontroller = ParentController.new(data: 42)
|
208
|
+
parentcontroller = ParentController.new(params: { data: 42 })
|
194
209
|
parentcontroller.invoke(:create)
|
195
210
|
|
196
211
|
assert_equal(400, parentcontroller.status)
|
@@ -201,7 +216,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
201
216
|
'_type' => 'Parent',
|
202
217
|
'name' => 'new' }
|
203
218
|
|
204
|
-
parentcontroller = ParentController.new(id: @parent.id, data: data)
|
219
|
+
parentcontroller = ParentController.new(params: { id: @parent.id, data: data })
|
205
220
|
parentcontroller.invoke(:create)
|
206
221
|
|
207
222
|
assert_equal(200, parentcontroller.status)
|
@@ -216,7 +231,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
216
231
|
end
|
217
232
|
|
218
233
|
def test_destroy
|
219
|
-
parentcontroller = ParentController.new(id: @parent.id)
|
234
|
+
parentcontroller = ParentController.new(params: { id: @parent.id })
|
220
235
|
parentcontroller.invoke(:destroy)
|
221
236
|
|
222
237
|
assert_equal(200, parentcontroller.status)
|
@@ -230,7 +245,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
230
245
|
end
|
231
246
|
|
232
247
|
def test_show_missing
|
233
|
-
parentcontroller = ParentController.new(id: 9999)
|
248
|
+
parentcontroller = ParentController.new(params: { id: 9999 })
|
234
249
|
parentcontroller.invoke(:show)
|
235
250
|
|
236
251
|
assert_equal(404, parentcontroller.status)
|
@@ -252,7 +267,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
252
267
|
'children' => [{ '_type' => 'Child',
|
253
268
|
'age' => 42 }] }
|
254
269
|
|
255
|
-
parentcontroller = ParentController.new(data: data)
|
270
|
+
parentcontroller = ParentController.new(params: { data: data })
|
256
271
|
parentcontroller.invoke(:create)
|
257
272
|
|
258
273
|
assert_equal({ 'error' => {
|
@@ -275,7 +290,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
275
290
|
data = { '_type' => 'Parent',
|
276
291
|
'children' => [{ '_type' => 'Child',
|
277
292
|
'age' => 1 }] }
|
278
|
-
parentcontroller = ParentController.new(data: data)
|
293
|
+
parentcontroller = ParentController.new(params: { data: data })
|
279
294
|
parentcontroller.invoke(:create)
|
280
295
|
|
281
296
|
assert_equal(400, parentcontroller.status)
|
@@ -285,7 +300,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
285
300
|
end
|
286
301
|
|
287
302
|
def test_destroy_missing
|
288
|
-
parentcontroller = ParentController.new(id: 9999)
|
303
|
+
parentcontroller = ParentController.new(params: { id: 9999 })
|
289
304
|
parentcontroller.invoke(:destroy)
|
290
305
|
|
291
306
|
assert_equal({ 'error' => {
|
@@ -307,7 +322,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
307
322
|
def test_nested_collection_index_associated
|
308
323
|
_distractor = Parent.create(name: 'p2', children: [Child.new(name: 'c3', position: 1)])
|
309
324
|
|
310
|
-
childcontroller = ChildController.new(parent_id: @parent.id)
|
325
|
+
childcontroller = ChildController.new(params: { parent_id: @parent.id })
|
311
326
|
childcontroller.invoke(:index_associated)
|
312
327
|
|
313
328
|
assert_equal(200, childcontroller.status)
|
@@ -334,7 +349,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
334
349
|
|
335
350
|
def test_nested_collection_append_one
|
336
351
|
data = { '_type' => 'Child', 'name' => 'c3' }
|
337
|
-
childcontroller = ChildController.new(parent_id: @parent.id, data: data)
|
352
|
+
childcontroller = ChildController.new(params: { parent_id: @parent.id, data: data })
|
338
353
|
|
339
354
|
childcontroller.invoke(:append)
|
340
355
|
|
@@ -353,7 +368,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
353
368
|
data = [{ '_type' => 'Child', 'name' => 'c3' },
|
354
369
|
{ '_type' => 'Child', 'name' => 'c4' },]
|
355
370
|
|
356
|
-
childcontroller = ChildController.new(parent_id: @parent.id, data: data)
|
371
|
+
childcontroller = ChildController.new(params: { parent_id: @parent.id, data: data })
|
357
372
|
childcontroller.invoke(:append)
|
358
373
|
|
359
374
|
assert_equal(200, childcontroller.status, childcontroller.hash_response)
|
@@ -376,7 +391,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
376
391
|
data = [{ '_type' => 'Child', 'name' => 'newc1' },
|
377
392
|
{ '_type' => 'Child', 'name' => 'newc2' },]
|
378
393
|
|
379
|
-
childcontroller = ChildController.new(parent_id: @parent.id, data: data)
|
394
|
+
childcontroller = ChildController.new(params: { parent_id: @parent.id, data: data })
|
380
395
|
childcontroller.invoke(:replace)
|
381
396
|
|
382
397
|
assert_equal(200, childcontroller.status, childcontroller.hash_response)
|
@@ -391,7 +406,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
391
406
|
|
392
407
|
def test_nested_collection_replace_bad_data
|
393
408
|
data = [{ 'name' => 'nc' }]
|
394
|
-
childcontroller = ChildController.new(parent_id: @parent.id, data: data)
|
409
|
+
childcontroller = ChildController.new(params: { parent_id: @parent.id, data: data })
|
395
410
|
|
396
411
|
childcontroller.invoke(:replace)
|
397
412
|
|
@@ -402,7 +417,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
402
417
|
|
403
418
|
def test_nested_collection_disassociate_one
|
404
419
|
old_child = @parent.children.first
|
405
|
-
childcontroller = ChildController.new(parent_id: @parent.id, id: old_child.id)
|
420
|
+
childcontroller = ChildController.new(params: { parent_id: @parent.id, id: old_child.id })
|
406
421
|
childcontroller.invoke(:disassociate)
|
407
422
|
|
408
423
|
assert_equal(200, childcontroller.status, childcontroller.hash_response)
|
@@ -418,7 +433,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
418
433
|
def test_nested_collection_disassociate_many
|
419
434
|
old_children = @parent.children
|
420
435
|
|
421
|
-
childcontroller = ChildController.new(parent_id: @parent.id)
|
436
|
+
childcontroller = ChildController.new(params: { parent_id: @parent.id })
|
422
437
|
childcontroller.invoke(:disassociate_all)
|
423
438
|
|
424
439
|
assert_equal(200, childcontroller.status, childcontroller.hash_response)
|
@@ -434,7 +449,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
434
449
|
# direct methods on nested controller
|
435
450
|
def test_nested_collection_destroy
|
436
451
|
old_child = @parent.children.first
|
437
|
-
childcontroller = ChildController.new(id: old_child.id)
|
452
|
+
childcontroller = ChildController.new(params: { id: old_child.id })
|
438
453
|
childcontroller.invoke(:destroy)
|
439
454
|
|
440
455
|
assert_equal(200, childcontroller.status, childcontroller.hash_response)
|
@@ -452,7 +467,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
452
467
|
'_type' => 'Child',
|
453
468
|
'name' => 'new_name' }
|
454
469
|
|
455
|
-
childcontroller = ChildController.new(data: data)
|
470
|
+
childcontroller = ChildController.new(params: { data: data })
|
456
471
|
childcontroller.invoke(:create)
|
457
472
|
|
458
473
|
assert_equal(200, childcontroller.status, childcontroller.hash_response)
|
@@ -467,7 +482,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
467
482
|
def test_nested_collection_show
|
468
483
|
old_child = @parent.children.first
|
469
484
|
|
470
|
-
childcontroller = ChildController.new(id: old_child.id)
|
485
|
+
childcontroller = ChildController.new(params: { id: old_child.id })
|
471
486
|
childcontroller.invoke(:show)
|
472
487
|
|
473
488
|
assert_equal({ 'data' => ChildView.new(old_child).to_hash },
|
@@ -482,7 +497,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
482
497
|
old_label = @parent.label
|
483
498
|
|
484
499
|
data = { '_type' => 'Label', 'text' => 'new label' }
|
485
|
-
labelcontroller = LabelController.new(parent_id: @parent.id, data: data)
|
500
|
+
labelcontroller = LabelController.new(params: { parent_id: @parent.id, data: data })
|
486
501
|
labelcontroller.invoke(:create_associated)
|
487
502
|
|
488
503
|
assert_equal(200, labelcontroller.status, labelcontroller.hash_response)
|
@@ -504,7 +519,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
504
519
|
def test_nested_singular_show_from_parent
|
505
520
|
old_label = @parent.label
|
506
521
|
|
507
|
-
labelcontroller = LabelController.new(parent_id: @parent.id)
|
522
|
+
labelcontroller = LabelController.new(params: { parent_id: @parent.id })
|
508
523
|
labelcontroller.invoke(:show_associated)
|
509
524
|
|
510
525
|
assert_equal(200, labelcontroller.status, labelcontroller.hash_response)
|
@@ -518,7 +533,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
518
533
|
def test_nested_singular_destroy_from_parent
|
519
534
|
old_label = @parent.label
|
520
535
|
|
521
|
-
labelcontroller = LabelController.new(parent_id: @parent.id)
|
536
|
+
labelcontroller = LabelController.new(params: { parent_id: @parent.id })
|
522
537
|
labelcontroller.invoke(:destroy_associated)
|
523
538
|
|
524
539
|
@parent.reload
|
@@ -536,7 +551,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
536
551
|
old_label = @parent.label
|
537
552
|
|
538
553
|
data = { '_type' => 'Label', 'id' => old_label.id, 'text' => 'new label' }
|
539
|
-
labelcontroller = LabelController.new(parent_id: @parent.id, data: data)
|
554
|
+
labelcontroller = LabelController.new(params: { parent_id: @parent.id, data: data })
|
540
555
|
labelcontroller.invoke(:create_associated)
|
541
556
|
|
542
557
|
assert_equal(200, labelcontroller.status, labelcontroller.hash_response)
|
@@ -553,7 +568,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
553
568
|
def test_nested_singular_show_from_id
|
554
569
|
old_label = @parent.label
|
555
570
|
|
556
|
-
labelcontroller = LabelController.new(id: old_label.id)
|
571
|
+
labelcontroller = LabelController.new(params: { id: old_label.id })
|
557
572
|
labelcontroller.invoke(:show)
|
558
573
|
|
559
574
|
assert_equal(200, labelcontroller.status, labelcontroller.hash_response)
|
@@ -567,7 +582,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
567
582
|
# foreign key violation. Destroy target instead.
|
568
583
|
old_target = @parent.target
|
569
584
|
|
570
|
-
targetcontroller = TargetController.new(id: old_target.id)
|
585
|
+
targetcontroller = TargetController.new(params: { id: old_target.id })
|
571
586
|
targetcontroller.invoke(:destroy)
|
572
587
|
|
573
588
|
@parent.reload
|
@@ -583,7 +598,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
|
|
583
598
|
old_label = @parent.label
|
584
599
|
|
585
600
|
data = { '_type' => 'Label', 'id' => old_label.id, 'text' => 'new label' }
|
586
|
-
labelcontroller = LabelController.new(data: data)
|
601
|
+
labelcontroller = LabelController.new(params: { data: data })
|
587
602
|
labelcontroller.invoke(:create)
|
588
603
|
|
589
604
|
assert_equal(200, labelcontroller.status, labelcontroller.hash_response)
|
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.2.
|
4
|
+
version: 3.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iKnow Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|