iknow_view_models 3.2.0 → 3.2.5

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +13 -0
  3. data/Appraisals +6 -6
  4. data/Rakefile +5 -5
  5. data/gemfiles/rails_5_2.gemfile +5 -5
  6. data/gemfiles/rails_6_0.gemfile +5 -5
  7. data/iknow_view_models.gemspec +40 -39
  8. data/lib/iknow_view_models.rb +9 -7
  9. data/lib/iknow_view_models/version.rb +1 -1
  10. data/lib/view_model.rb +17 -14
  11. data/lib/view_model/access_control.rb +5 -2
  12. data/lib/view_model/access_control/composed.rb +10 -9
  13. data/lib/view_model/access_control/open.rb +2 -0
  14. data/lib/view_model/access_control/read_only.rb +2 -0
  15. data/lib/view_model/access_control/tree.rb +11 -6
  16. data/lib/view_model/access_control_error.rb +4 -1
  17. data/lib/view_model/active_record.rb +17 -15
  18. data/lib/view_model/active_record/association_data.rb +2 -1
  19. data/lib/view_model/active_record/association_manipulation.rb +6 -4
  20. data/lib/view_model/active_record/cache.rb +4 -2
  21. data/lib/view_model/active_record/collection_nested_controller.rb +3 -3
  22. data/lib/view_model/active_record/controller.rb +20 -5
  23. data/lib/view_model/active_record/controller_base.rb +4 -1
  24. data/lib/view_model/active_record/nested_controller_base.rb +1 -0
  25. data/lib/view_model/active_record/update_context.rb +8 -6
  26. data/lib/view_model/active_record/update_data.rb +32 -30
  27. data/lib/view_model/active_record/update_operation.rb +17 -13
  28. data/lib/view_model/active_record/visitor.rb +0 -1
  29. data/lib/view_model/after_transaction_runner.rb +0 -1
  30. data/lib/view_model/callbacks.rb +3 -1
  31. data/lib/view_model/controller.rb +13 -3
  32. data/lib/view_model/deserialization_error.rb +15 -12
  33. data/lib/view_model/error.rb +12 -10
  34. data/lib/view_model/error_view.rb +3 -1
  35. data/lib/view_model/migration/no_path_error.rb +1 -0
  36. data/lib/view_model/migration/one_way_error.rb +1 -0
  37. data/lib/view_model/migration/unspecified_version_error.rb +1 -0
  38. data/lib/view_model/record.rb +11 -13
  39. data/lib/view_model/reference.rb +3 -1
  40. data/lib/view_model/references.rb +8 -5
  41. data/lib/view_model/registry.rb +14 -2
  42. data/lib/view_model/schemas.rb +9 -4
  43. data/lib/view_model/serialization_error.rb +4 -1
  44. data/lib/view_model/serialize_context.rb +4 -4
  45. data/lib/view_model/test_helpers.rb +8 -3
  46. data/lib/view_model/test_helpers/arvm_builder.rb +19 -14
  47. data/lib/view_model/traversal_context.rb +2 -1
  48. data/test/.rubocop.yml +14 -0
  49. data/test/helpers/arvm_test_models.rb +12 -9
  50. data/test/helpers/arvm_test_utilities.rb +5 -3
  51. data/test/helpers/controller_test_helpers.rb +42 -33
  52. data/test/helpers/match_enumerator.rb +1 -0
  53. data/test/helpers/query_logging.rb +2 -1
  54. data/test/helpers/test_access_control.rb +5 -3
  55. data/test/helpers/viewmodel_spec_helpers.rb +21 -20
  56. data/test/unit/view_model/access_control_test.rb +144 -144
  57. data/test/unit/view_model/active_record/alias_test.rb +15 -13
  58. data/test/unit/view_model/active_record/belongs_to_test.rb +40 -39
  59. data/test/unit/view_model/active_record/cache_test.rb +27 -26
  60. data/test/unit/view_model/active_record/cloner_test.rb +67 -63
  61. data/test/unit/view_model/active_record/controller_test.rb +81 -67
  62. data/test/unit/view_model/active_record/counter_test.rb +10 -9
  63. data/test/unit/view_model/active_record/customization_test.rb +59 -58
  64. data/test/unit/view_model/active_record/has_many_test.rb +112 -111
  65. data/test/unit/view_model/active_record/has_many_through_poly_test.rb +15 -14
  66. data/test/unit/view_model/active_record/has_many_through_test.rb +33 -38
  67. data/test/unit/view_model/active_record/has_one_test.rb +37 -36
  68. data/test/unit/view_model/active_record/migration_test.rb +13 -13
  69. data/test/unit/view_model/active_record/namespacing_test.rb +19 -17
  70. data/test/unit/view_model/active_record/poly_test.rb +44 -45
  71. data/test/unit/view_model/active_record/shared_test.rb +30 -28
  72. data/test/unit/view_model/active_record/version_test.rb +9 -7
  73. data/test/unit/view_model/active_record_test.rb +72 -72
  74. data/test/unit/view_model/callbacks_test.rb +19 -15
  75. data/test/unit/view_model/controller_test.rb +4 -2
  76. data/test/unit/view_model/record_test.rb +158 -145
  77. data/test/unit/view_model/registry_test.rb +38 -0
  78. data/test/unit/view_model/traversal_context_test.rb +4 -5
  79. data/test/unit/view_model_test.rb +18 -16
  80. metadata +10 -6
@@ -1,14 +1,14 @@
1
- # -*- coding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require "minitest/autorun"
3
+ require 'minitest/autorun'
4
4
  require 'minitest/unit'
5
5
  require 'minitest/hooks'
6
6
 
7
- require "view_model"
8
- require "view_model/active_record"
7
+ require 'view_model'
8
+ require 'view_model/active_record'
9
9
 
10
- require_relative "../../../helpers/controller_test_helpers.rb"
11
- require_relative "../../../helpers/callback_tracer.rb"
10
+ require_relative '../../../helpers/controller_test_helpers'
11
+ require_relative '../../../helpers/callback_tracer'
12
12
 
13
13
  class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
14
14
  include ARVMTestUtilities
@@ -88,7 +88,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
88
88
  super
89
89
  @parent = Parent.create(name: 'p',
90
90
  children: [Child.new(name: 'c1', position: 1.0),
91
- Child.new(name: 'c2', position: 2.0)],
91
+ Child.new(name: 'c2', position: 2.0),],
92
92
  label: Label.new,
93
93
  target: Target.new)
94
94
 
@@ -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(id: @parent.id, versions: { ParentView.view_name => 1 })
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,8 +130,20 @@ 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
- p2 = Parent.create(name: "p2")
146
+ p2 = Parent.create(name: 'p2')
132
147
  p2_view = ParentView.new(p2)
133
148
 
134
149
  parentcontroller = ParentController.new
@@ -137,7 +152,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
137
152
  assert_equal(200, parentcontroller.status)
138
153
 
139
154
  assert_equal(parentcontroller.hash_response,
140
- { "data" => [@parent_view.to_hash, p2_view.to_hash] })
155
+ { 'data' => [@parent_view.to_hash, p2_view.to_hash] })
141
156
 
142
157
  assert_all_hooks_nested_inside_parent_hook(parentcontroller.hook_trace)
143
158
  end
@@ -149,10 +164,10 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
149
164
  'label' => { '_type' => 'Label', 'text' => 'l' },
150
165
  'target' => { '_type' => 'Target', 'text' => 't' },
151
166
  'children' => [{ '_type' => 'Child', 'name' => 'c1' },
152
- { '_type' => 'Child', 'name' => 'c2' }]
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)
@@ -240,10 +255,10 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
240
255
  'status' => 404,
241
256
  'detail' => "Couldn't find Parent(s) with id(s)=[9999]",
242
257
  'title' => nil,
243
- 'code' => "DeserializationError.NotFound",
244
- 'meta' => { 'nodes' => [{ '_type' => "Parent", 'id' => 9999 }]},
258
+ 'code' => 'DeserializationError.NotFound',
259
+ 'meta' => { 'nodes' => [{ '_type' => 'Parent', 'id' => 9999 }] },
245
260
  'exception' => nil,
246
- 'causes' => nil }},
261
+ 'causes' => nil } },
247
262
  parentcontroller.hash_response)
248
263
  end
249
264
 
@@ -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' => {
@@ -261,13 +276,13 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
261
276
  'status' => 400,
262
277
  'detail' => 'Validation failed: \'age\' must be less than 42',
263
278
  'title' => nil,
264
- 'code' => "DeserializationError.Validation",
265
- 'meta' => { 'nodes' => [{ '_type' => "Child", 'id' => nil }],
279
+ 'code' => 'DeserializationError.Validation',
280
+ 'meta' => { 'nodes' => [{ '_type' => 'Child', 'id' => nil }],
266
281
  'attribute' => 'age',
267
282
  'message' => 'must be less than 42',
268
- 'details' => { 'error' => 'less_than', 'value' => 42, 'count' => 42 }},
283
+ 'details' => { 'error' => 'less_than', 'value' => 42, 'count' => 42 } },
269
284
  'exception' => nil,
270
- 'causes' => nil }},
285
+ 'causes' => nil } },
271
286
  parentcontroller.hash_response)
272
287
  end
273
288
 
@@ -275,17 +290,17 @@ 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)
282
- assert_match(%r{check constraint}i,
283
- parentcontroller.hash_response["error"]["detail"],
284
- "Database error propagated")
297
+ assert_match(/check constraint/i,
298
+ parentcontroller.hash_response['error']['detail'],
299
+ 'Database error propagated')
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' => {
@@ -294,8 +309,8 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
294
309
  'status' => 404,
295
310
  'detail' => "Couldn't find Parent(s) with id(s)=[9999]",
296
311
  'title' => nil,
297
- 'code' => "DeserializationError.NotFound",
298
- 'meta' => { "nodes" => [{"_type" => "Parent", "id" => 9999 }] },
312
+ 'code' => 'DeserializationError.NotFound',
313
+ 'meta' => { 'nodes' => [{ '_type' => 'Parent', 'id' => 9999 }] },
299
314
  'exception' => nil,
300
315
  'causes' => nil } },
301
316
  parentcontroller.hash_response)
@@ -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
 
@@ -342,7 +357,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
342
357
 
343
358
  @parent.reload
344
359
 
345
- assert_equal(%w{c1 c2 c3}, @parent.children.order(:position).pluck(:name))
360
+ assert_equal(%w[c1 c2 c3], @parent.children.order(:position).pluck(:name))
346
361
  assert_equal({ 'data' => ChildView.new(@parent.children.last).to_hash },
347
362
  childcontroller.hash_response)
348
363
 
@@ -351,17 +366,17 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
351
366
 
352
367
  def test_nested_collection_append_many
353
368
  data = [{ '_type' => 'Child', 'name' => 'c3' },
354
- { '_type' => 'Child', 'name' => 'c4' }]
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)
360
375
 
361
376
  @parent.reload
362
377
 
363
- assert_equal(%w{c1 c2 c3 c4}, @parent.children.order(:position).pluck(:name))
364
- new_children_hashes = @parent.children.last(2).map{ |c| ChildView.new(c).to_hash }
378
+ assert_equal(%w[c1 c2 c3 c4], @parent.children.order(:position).pluck(:name))
379
+ new_children_hashes = @parent.children.last(2).map { |c| ChildView.new(c).to_hash }
365
380
  assert_equal({ 'data' => new_children_hashes },
366
381
  childcontroller.hash_response)
367
382
 
@@ -373,25 +388,25 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
373
388
  # Parent.children
374
389
  old_children = @parent.children
375
390
 
376
- data = [{'_type' => 'Child', 'name' => 'newc1'},
377
- {'_type' => 'Child', 'name' => 'newc2'}]
391
+ data = [{ '_type' => 'Child', 'name' => 'newc1' },
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)
383
398
 
384
399
  @parent.reload
385
400
 
386
- assert_equal(%w{newc1 newc2}, @parent.children.order(:position).pluck(:name))
401
+ assert_equal(%w[newc1 newc2], @parent.children.order(:position).pluck(:name))
387
402
  assert_predicate(Child.where(id: old_children.map(&:id)), :empty?)
388
403
 
389
404
  assert_all_hooks_nested_inside_parent_hook(childcontroller.hook_trace)
390
405
  end
391
406
 
392
407
  def test_nested_collection_replace_bad_data
393
- data = [{ "name" => "nc" }]
394
- childcontroller = ChildController.new(parent_id: @parent.id, data: data)
408
+ data = [{ 'name' => 'nc' }]
409
+ childcontroller = ChildController.new(params: { parent_id: @parent.id, data: data })
395
410
 
396
411
  childcontroller.invoke(:replace)
397
412
 
@@ -402,14 +417,14 @@ 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)
409
424
 
410
425
  @parent.reload
411
426
 
412
- assert_equal(%w{c2}, @parent.children.order(:position).pluck(:name))
427
+ assert_equal(%w[c2], @parent.children.order(:position).pluck(:name))
413
428
  assert_predicate(Child.where(id: old_child.id), :empty?)
414
429
 
415
430
  assert_all_hooks_nested_inside_parent_hook(childcontroller.hook_trace)
@@ -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,14 +449,14 @@ 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)
441
456
 
442
457
  @parent.reload
443
458
 
444
- assert_equal(%w{c2}, @parent.children.order(:position).pluck(:name))
459
+ assert_equal(%w[c2], @parent.children.order(:position).pluck(:name))
445
460
  assert_predicate(Child.where(id: old_child.id), :empty?)
446
461
  end
447
462
 
@@ -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)
@@ -464,26 +479,25 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
464
479
  childcontroller.hash_response)
465
480
  end
466
481
 
467
- def test_nested_collection_show
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 },
474
489
  childcontroller.hash_response)
475
490
 
476
491
  assert_equal(200, childcontroller.status)
477
- end
478
-
492
+ end
479
493
 
480
494
  ## Single association
481
495
 
482
496
  def test_nested_singular_replace_from_parent
483
497
  old_label = @parent.label
484
498
 
485
- data = {'_type' => 'Label', 'text' => 'new label'}
486
- labelcontroller = LabelController.new(parent_id: @parent.id, data: data)
499
+ data = { '_type' => 'Label', 'text' => 'new label' }
500
+ labelcontroller = LabelController.new(params: { parent_id: @parent.id, data: data })
487
501
  labelcontroller.invoke(:create_associated)
488
502
 
489
503
  assert_equal(200, labelcontroller.status, labelcontroller.hash_response)
@@ -505,7 +519,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
505
519
  def test_nested_singular_show_from_parent
506
520
  old_label = @parent.label
507
521
 
508
- labelcontroller = LabelController.new(parent_id: @parent.id)
522
+ labelcontroller = LabelController.new(params: { parent_id: @parent.id })
509
523
  labelcontroller.invoke(:show_associated)
510
524
 
511
525
  assert_equal(200, labelcontroller.status, labelcontroller.hash_response)
@@ -519,7 +533,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
519
533
  def test_nested_singular_destroy_from_parent
520
534
  old_label = @parent.label
521
535
 
522
- labelcontroller = LabelController.new(parent_id: @parent.id)
536
+ labelcontroller = LabelController.new(params: { parent_id: @parent.id })
523
537
  labelcontroller.invoke(:destroy_associated)
524
538
 
525
539
  @parent.reload
@@ -536,8 +550,8 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
536
550
  def test_nested_singular_update_from_parent
537
551
  old_label = @parent.label
538
552
 
539
- data = {'_type' => 'Label', 'id' => old_label.id, 'text' => 'new label'}
540
- labelcontroller = LabelController.new(parent_id: @parent.id, data: data)
553
+ data = { '_type' => 'Label', 'id' => old_label.id, 'text' => 'new label' }
554
+ labelcontroller = LabelController.new(params: { parent_id: @parent.id, data: data })
541
555
  labelcontroller.invoke(:create_associated)
542
556
 
543
557
  assert_equal(200, labelcontroller.status, labelcontroller.hash_response)
@@ -554,7 +568,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
554
568
  def test_nested_singular_show_from_id
555
569
  old_label = @parent.label
556
570
 
557
- labelcontroller = LabelController.new(id: old_label.id)
571
+ labelcontroller = LabelController.new(params: { id: old_label.id })
558
572
  labelcontroller.invoke(:show)
559
573
 
560
574
  assert_equal(200, labelcontroller.status, labelcontroller.hash_response)
@@ -568,7 +582,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
568
582
  # foreign key violation. Destroy target instead.
569
583
  old_target = @parent.target
570
584
 
571
- targetcontroller = TargetController.new(id: old_target.id)
585
+ targetcontroller = TargetController.new(params: { id: old_target.id })
572
586
  targetcontroller.invoke(:destroy)
573
587
 
574
588
  @parent.reload
@@ -583,8 +597,8 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
583
597
  def test_nested_singular_update
584
598
  old_label = @parent.label
585
599
 
586
- data = {'_type' => 'Label', 'id' => old_label.id, 'text' => 'new label'}
587
- labelcontroller = LabelController.new(data: data)
600
+ data = { '_type' => 'Label', 'id' => old_label.id, 'text' => 'new label' }
601
+ labelcontroller = LabelController.new(params: { data: data })
588
602
  labelcontroller.invoke(:create)
589
603
 
590
604
  assert_equal(200, labelcontroller.status, labelcontroller.hash_response)
@@ -1,9 +1,11 @@
1
- require_relative "../../../helpers/arvm_test_utilities.rb"
2
- require_relative "../../../helpers/arvm_test_models.rb"
1
+ # frozen_string_literal: true
3
2
 
4
- require "minitest/autorun"
3
+ require_relative '../../../helpers/arvm_test_utilities'
4
+ require_relative '../../../helpers/arvm_test_models'
5
5
 
6
- require "view_model/active_record"
6
+ require 'minitest/autorun'
7
+
8
+ require 'view_model/active_record'
7
9
 
8
10
  class ViewModel::ActiveRecord::CounterTest < ActiveSupport::TestCase
9
11
  include ARVMTestUtilities
@@ -40,7 +42,6 @@ class ViewModel::ActiveRecord::CounterTest < ActiveSupport::TestCase
40
42
  attribute :name
41
43
  end
42
44
  end
43
-
44
45
  end
45
46
 
46
47
  def setup
@@ -50,15 +51,15 @@ class ViewModel::ActiveRecord::CounterTest < ActiveSupport::TestCase
50
51
  end
51
52
 
52
53
  def test_counter_cache_create
53
- alter_by_view!(CategoryView, @category1) do |view, refs|
54
- view['products'] << {'_type' => 'Product'}
54
+ alter_by_view!(CategoryView, @category1) do |view, _refs|
55
+ view['products'] << { '_type' => 'Product' }
55
56
  end
56
57
  assert_equal(2, @category1.products_count)
57
58
  end
58
59
 
59
60
  def test_counter_cache_move
60
61
  @category2 = Category.create(name: 'c2')
61
- alter_by_view!(CategoryView, [@category1, @category2]) do |(c1view, c2view), refs|
62
+ alter_by_view!(CategoryView, [@category1, @category2]) do |(c1view, c2view), _refs|
62
63
  c2view['products'] = c1view['products']
63
64
  c1view['products'] = []
64
65
  end
@@ -67,7 +68,7 @@ class ViewModel::ActiveRecord::CounterTest < ActiveSupport::TestCase
67
68
  end
68
69
 
69
70
  def test_counter_cache_delete
70
- alter_by_view!(CategoryView, @category1) do |view, refs|
71
+ alter_by_view!(CategoryView, @category1) do |view, _refs|
71
72
  view['products'] = []
72
73
  end
73
74
  assert_equal(0, @category1.products_count)