iknow_view_models 3.2.0 → 3.2.1

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 (78) 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 +12 -11
  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_base.rb +4 -1
  23. data/lib/view_model/active_record/nested_controller_base.rb +1 -0
  24. data/lib/view_model/active_record/update_context.rb +8 -6
  25. data/lib/view_model/active_record/update_data.rb +32 -30
  26. data/lib/view_model/active_record/update_operation.rb +17 -13
  27. data/lib/view_model/active_record/visitor.rb +0 -1
  28. data/lib/view_model/after_transaction_runner.rb +0 -1
  29. data/lib/view_model/callbacks.rb +3 -1
  30. data/lib/view_model/controller.rb +13 -3
  31. data/lib/view_model/deserialization_error.rb +15 -12
  32. data/lib/view_model/error.rb +12 -10
  33. data/lib/view_model/error_view.rb +3 -1
  34. data/lib/view_model/migration/no_path_error.rb +1 -0
  35. data/lib/view_model/migration/one_way_error.rb +1 -0
  36. data/lib/view_model/migration/unspecified_version_error.rb +1 -0
  37. data/lib/view_model/record.rb +11 -13
  38. data/lib/view_model/reference.rb +3 -1
  39. data/lib/view_model/references.rb +8 -5
  40. data/lib/view_model/registry.rb +1 -1
  41. data/lib/view_model/schemas.rb +9 -4
  42. data/lib/view_model/serialization_error.rb +4 -1
  43. data/lib/view_model/serialize_context.rb +4 -4
  44. data/lib/view_model/test_helpers.rb +8 -3
  45. data/lib/view_model/test_helpers/arvm_builder.rb +19 -14
  46. data/lib/view_model/traversal_context.rb +2 -1
  47. data/test/.rubocop.yml +14 -0
  48. data/test/helpers/arvm_test_models.rb +12 -9
  49. data/test/helpers/arvm_test_utilities.rb +5 -3
  50. data/test/helpers/controller_test_helpers.rb +31 -29
  51. data/test/helpers/match_enumerator.rb +1 -0
  52. data/test/helpers/query_logging.rb +2 -1
  53. data/test/helpers/test_access_control.rb +5 -3
  54. data/test/helpers/viewmodel_spec_helpers.rb +21 -20
  55. data/test/unit/view_model/access_control_test.rb +144 -144
  56. data/test/unit/view_model/active_record/alias_test.rb +15 -13
  57. data/test/unit/view_model/active_record/belongs_to_test.rb +40 -39
  58. data/test/unit/view_model/active_record/cache_test.rb +27 -26
  59. data/test/unit/view_model/active_record/cloner_test.rb +67 -63
  60. data/test/unit/view_model/active_record/controller_test.rb +37 -38
  61. data/test/unit/view_model/active_record/counter_test.rb +10 -9
  62. data/test/unit/view_model/active_record/customization_test.rb +59 -58
  63. data/test/unit/view_model/active_record/has_many_test.rb +112 -111
  64. data/test/unit/view_model/active_record/has_many_through_poly_test.rb +15 -14
  65. data/test/unit/view_model/active_record/has_many_through_test.rb +33 -38
  66. data/test/unit/view_model/active_record/has_one_test.rb +37 -36
  67. data/test/unit/view_model/active_record/migration_test.rb +13 -13
  68. data/test/unit/view_model/active_record/namespacing_test.rb +19 -17
  69. data/test/unit/view_model/active_record/poly_test.rb +44 -45
  70. data/test/unit/view_model/active_record/shared_test.rb +30 -28
  71. data/test/unit/view_model/active_record/version_test.rb +9 -7
  72. data/test/unit/view_model/active_record_test.rb +72 -72
  73. data/test/unit/view_model/callbacks_test.rb +19 -15
  74. data/test/unit/view_model/controller_test.rb +4 -2
  75. data/test/unit/view_model/record_test.rb +92 -97
  76. data/test/unit/view_model/traversal_context_test.rb +4 -5
  77. data/test/unit/view_model_test.rb +18 -16
  78. metadata +7 -5
@@ -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
 
@@ -128,7 +128,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
128
128
  end
129
129
 
130
130
  def test_index
131
- p2 = Parent.create(name: "p2")
131
+ p2 = Parent.create(name: 'p2')
132
132
  p2_view = ParentView.new(p2)
133
133
 
134
134
  parentcontroller = ParentController.new
@@ -137,7 +137,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
137
137
  assert_equal(200, parentcontroller.status)
138
138
 
139
139
  assert_equal(parentcontroller.hash_response,
140
- { "data" => [@parent_view.to_hash, p2_view.to_hash] })
140
+ { 'data' => [@parent_view.to_hash, p2_view.to_hash] })
141
141
 
142
142
  assert_all_hooks_nested_inside_parent_hook(parentcontroller.hook_trace)
143
143
  end
@@ -149,7 +149,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
149
149
  'label' => { '_type' => 'Label', 'text' => 'l' },
150
150
  'target' => { '_type' => 'Target', 'text' => 't' },
151
151
  'children' => [{ '_type' => 'Child', 'name' => 'c1' },
152
- { '_type' => 'Child', 'name' => 'c2' }]
152
+ { '_type' => 'Child', 'name' => 'c2' },],
153
153
  }
154
154
 
155
155
  parentcontroller = ParentController.new(data: data)
@@ -240,10 +240,10 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
240
240
  'status' => 404,
241
241
  'detail' => "Couldn't find Parent(s) with id(s)=[9999]",
242
242
  'title' => nil,
243
- 'code' => "DeserializationError.NotFound",
244
- 'meta' => { 'nodes' => [{ '_type' => "Parent", 'id' => 9999 }]},
243
+ 'code' => 'DeserializationError.NotFound',
244
+ 'meta' => { 'nodes' => [{ '_type' => 'Parent', 'id' => 9999 }] },
245
245
  'exception' => nil,
246
- 'causes' => nil }},
246
+ 'causes' => nil } },
247
247
  parentcontroller.hash_response)
248
248
  end
249
249
 
@@ -261,13 +261,13 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
261
261
  'status' => 400,
262
262
  'detail' => 'Validation failed: \'age\' must be less than 42',
263
263
  'title' => nil,
264
- 'code' => "DeserializationError.Validation",
265
- 'meta' => { 'nodes' => [{ '_type' => "Child", 'id' => nil }],
264
+ 'code' => 'DeserializationError.Validation',
265
+ 'meta' => { 'nodes' => [{ '_type' => 'Child', 'id' => nil }],
266
266
  'attribute' => 'age',
267
267
  'message' => 'must be less than 42',
268
- 'details' => { 'error' => 'less_than', 'value' => 42, 'count' => 42 }},
268
+ 'details' => { 'error' => 'less_than', 'value' => 42, 'count' => 42 } },
269
269
  'exception' => nil,
270
- 'causes' => nil }},
270
+ 'causes' => nil } },
271
271
  parentcontroller.hash_response)
272
272
  end
273
273
 
@@ -279,9 +279,9 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
279
279
  parentcontroller.invoke(:create)
280
280
 
281
281
  assert_equal(400, parentcontroller.status)
282
- assert_match(%r{check constraint}i,
283
- parentcontroller.hash_response["error"]["detail"],
284
- "Database error propagated")
282
+ assert_match(/check constraint/i,
283
+ parentcontroller.hash_response['error']['detail'],
284
+ 'Database error propagated')
285
285
  end
286
286
 
287
287
  def test_destroy_missing
@@ -294,8 +294,8 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
294
294
  'status' => 404,
295
295
  'detail' => "Couldn't find Parent(s) with id(s)=[9999]",
296
296
  'title' => nil,
297
- 'code' => "DeserializationError.NotFound",
298
- 'meta' => { "nodes" => [{"_type" => "Parent", "id" => 9999 }] },
297
+ 'code' => 'DeserializationError.NotFound',
298
+ 'meta' => { 'nodes' => [{ '_type' => 'Parent', 'id' => 9999 }] },
299
299
  'exception' => nil,
300
300
  'causes' => nil } },
301
301
  parentcontroller.hash_response)
@@ -342,7 +342,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
342
342
 
343
343
  @parent.reload
344
344
 
345
- assert_equal(%w{c1 c2 c3}, @parent.children.order(:position).pluck(:name))
345
+ assert_equal(%w[c1 c2 c3], @parent.children.order(:position).pluck(:name))
346
346
  assert_equal({ 'data' => ChildView.new(@parent.children.last).to_hash },
347
347
  childcontroller.hash_response)
348
348
 
@@ -351,7 +351,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
351
351
 
352
352
  def test_nested_collection_append_many
353
353
  data = [{ '_type' => 'Child', 'name' => 'c3' },
354
- { '_type' => 'Child', 'name' => 'c4' }]
354
+ { '_type' => 'Child', 'name' => 'c4' },]
355
355
 
356
356
  childcontroller = ChildController.new(parent_id: @parent.id, data: data)
357
357
  childcontroller.invoke(:append)
@@ -360,8 +360,8 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
360
360
 
361
361
  @parent.reload
362
362
 
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 }
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 }
365
365
  assert_equal({ 'data' => new_children_hashes },
366
366
  childcontroller.hash_response)
367
367
 
@@ -373,8 +373,8 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
373
373
  # Parent.children
374
374
  old_children = @parent.children
375
375
 
376
- data = [{'_type' => 'Child', 'name' => 'newc1'},
377
- {'_type' => 'Child', 'name' => 'newc2'}]
376
+ data = [{ '_type' => 'Child', 'name' => 'newc1' },
377
+ { '_type' => 'Child', 'name' => 'newc2' },]
378
378
 
379
379
  childcontroller = ChildController.new(parent_id: @parent.id, data: data)
380
380
  childcontroller.invoke(:replace)
@@ -383,14 +383,14 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
383
383
 
384
384
  @parent.reload
385
385
 
386
- assert_equal(%w{newc1 newc2}, @parent.children.order(:position).pluck(:name))
386
+ assert_equal(%w[newc1 newc2], @parent.children.order(:position).pluck(:name))
387
387
  assert_predicate(Child.where(id: old_children.map(&:id)), :empty?)
388
388
 
389
389
  assert_all_hooks_nested_inside_parent_hook(childcontroller.hook_trace)
390
390
  end
391
391
 
392
392
  def test_nested_collection_replace_bad_data
393
- data = [{ "name" => "nc" }]
393
+ data = [{ 'name' => 'nc' }]
394
394
  childcontroller = ChildController.new(parent_id: @parent.id, data: data)
395
395
 
396
396
  childcontroller.invoke(:replace)
@@ -409,7 +409,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
409
409
 
410
410
  @parent.reload
411
411
 
412
- assert_equal(%w{c2}, @parent.children.order(:position).pluck(:name))
412
+ assert_equal(%w[c2], @parent.children.order(:position).pluck(:name))
413
413
  assert_predicate(Child.where(id: old_child.id), :empty?)
414
414
 
415
415
  assert_all_hooks_nested_inside_parent_hook(childcontroller.hook_trace)
@@ -441,7 +441,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
441
441
 
442
442
  @parent.reload
443
443
 
444
- assert_equal(%w{c2}, @parent.children.order(:position).pluck(:name))
444
+ assert_equal(%w[c2], @parent.children.order(:position).pluck(:name))
445
445
  assert_predicate(Child.where(id: old_child.id), :empty?)
446
446
  end
447
447
 
@@ -464,7 +464,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
464
464
  childcontroller.hash_response)
465
465
  end
466
466
 
467
- def test_nested_collection_show
467
+ def test_nested_collection_show
468
468
  old_child = @parent.children.first
469
469
 
470
470
  childcontroller = ChildController.new(id: old_child.id)
@@ -474,15 +474,14 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
474
474
  childcontroller.hash_response)
475
475
 
476
476
  assert_equal(200, childcontroller.status)
477
- end
478
-
477
+ end
479
478
 
480
479
  ## Single association
481
480
 
482
481
  def test_nested_singular_replace_from_parent
483
482
  old_label = @parent.label
484
483
 
485
- data = {'_type' => 'Label', 'text' => 'new label'}
484
+ data = { '_type' => 'Label', 'text' => 'new label' }
486
485
  labelcontroller = LabelController.new(parent_id: @parent.id, data: data)
487
486
  labelcontroller.invoke(:create_associated)
488
487
 
@@ -536,7 +535,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
536
535
  def test_nested_singular_update_from_parent
537
536
  old_label = @parent.label
538
537
 
539
- data = {'_type' => 'Label', 'id' => old_label.id, 'text' => 'new label'}
538
+ data = { '_type' => 'Label', 'id' => old_label.id, 'text' => 'new label' }
540
539
  labelcontroller = LabelController.new(parent_id: @parent.id, data: data)
541
540
  labelcontroller.invoke(:create_associated)
542
541
 
@@ -583,7 +582,7 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
583
582
  def test_nested_singular_update
584
583
  old_label = @parent.label
585
584
 
586
- data = {'_type' => 'Label', 'id' => old_label.id, 'text' => 'new label'}
585
+ data = { '_type' => 'Label', 'id' => old_label.id, 'text' => 'new label' }
587
586
  labelcontroller = LabelController.new(data: data)
588
587
  labelcontroller.invoke(:create)
589
588
 
@@ -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)
@@ -1,11 +1,11 @@
1
- # coding: utf-8
2
- require_relative "../../../helpers/arvm_test_utilities.rb"
3
- require_relative "../../../helpers/arvm_test_models.rb"
1
+ # frozen_string_literal: true
4
2
 
5
- require "minitest/autorun"
3
+ require_relative '../../../helpers/arvm_test_utilities'
4
+ require_relative '../../../helpers/arvm_test_models'
6
5
 
7
- require "view_model/active_record"
6
+ require 'minitest/autorun'
8
7
 
8
+ require 'view_model/active_record'
9
9
 
10
10
  require 'renum'
11
11
 
@@ -28,15 +28,16 @@ class ViewModel::ActiveRecord::SpecializeAssociationTest < ActiveSupport::TestCa
28
28
  attributes :text
29
29
  association :translations
30
30
 
31
- def self.pre_parse_translations(viewmodel_reference, metadata, hash, translations)
32
- raise "type check" unless translations.is_a?(Hash) && translations.all? { |k, v| k.is_a?(String) && v.is_a?(String) }
33
- hash["translations"] = translations.map { |lang, text| { "_type" => "Translation", "language" => lang, "translation" => text } }
31
+ def self.pre_parse_translations(_viewmodel_reference, _metadata, hash, translations)
32
+ raise 'type check' unless translations.is_a?(Hash) && translations.all? { |k, v| k.is_a?(String) && v.is_a?(String) }
33
+
34
+ hash['translations'] = translations.map { |lang, text| { '_type' => 'Translation', 'language' => lang, 'translation' => text } }
34
35
  end
35
36
 
36
37
  def resolve_translations(update_datas, previous_translation_views)
37
38
  existing = previous_translation_views.index_by { |x| [x.model.language, x.model.translation] }
38
39
  update_datas.map do |update_data|
39
- existing.fetch([update_data["language"], update_data["translation"]]) { TranslationView.for_new_model }
40
+ existing.fetch([update_data['language'], update_data['translation']]) { TranslationView.for_new_model }
40
41
  end
41
42
  end
42
43
 
@@ -71,19 +72,19 @@ class ViewModel::ActiveRecord::SpecializeAssociationTest < ActiveSupport::TestCa
71
72
  def setup
72
73
  super
73
74
 
74
- @text1 = Text.create(text: "dog",
75
- translations: [Translation.new(language: "ja", translation: ""),
76
- Translation.new(language: "fr", translation: "chien")])
75
+ @text1 = Text.create(text: 'dog',
76
+ translations: [Translation.new(language: 'ja', translation: ''),
77
+ Translation.new(language: 'fr', translation: 'chien'),])
77
78
 
78
79
  @text1_view = {
79
- "id" => @text1.id,
80
- "_type" => "Text",
81
- "_version" => 1,
82
- "text" => "dog",
83
- "translations" => {
84
- "ja" => "",
85
- "fr" => "chien"
86
- }
80
+ 'id' => @text1.id,
81
+ '_type' => 'Text',
82
+ '_version' => 1,
83
+ 'text' => 'dog',
84
+ 'translations' => {
85
+ 'ja' => '',
86
+ 'fr' => 'chien',
87
+ },
87
88
  }
88
89
 
89
90
  enable_logging!
@@ -94,7 +95,7 @@ class ViewModel::ActiveRecord::SpecializeAssociationTest < ActiveSupport::TestCa
94
95
  end
95
96
 
96
97
  def test_create
97
- create_view = @text1_view.dup.tap {|v| v.delete('id')}
98
+ create_view = @text1_view.dup.tap { |v| v.delete('id') }
98
99
  new_text_view = TextView.deserialize_from_view(create_view)
99
100
  new_text_model = new_text_view.model
100
101
 
@@ -103,8 +104,8 @@ class ViewModel::ActiveRecord::SpecializeAssociationTest < ActiveSupport::TestCa
103
104
  new_translations = new_text_model.translations.map do |x|
104
105
  [x['language'], x['translation']]
105
106
  end
106
- assert_equal([%w(fr chien),
107
- %w(ja 犬)],
107
+ assert_equal([%w[fr chien],
108
+ %w[ja 犬],],
108
109
  new_translations.sort)
109
110
  end
110
111
 
@@ -163,10 +164,11 @@ class ViewModel::ActiveRecord::FlattenAssociationTest < ActiveSupport::TestCase
163
164
  def construct_hash(members)
164
165
  case self
165
166
  when SectionType::Simple
166
- raise "nopes" if members.present?
167
+ raise 'nopes' if members.present?
168
+
167
169
  nil
168
170
  else
169
- members.merge("_type" => viewmodel.view_name)
171
+ members.merge('_type' => viewmodel.view_name)
170
172
  end
171
173
  end
172
174
 
@@ -219,7 +221,7 @@ class ViewModel::ActiveRecord::FlattenAssociationTest < ActiveSupport::TestCase
219
221
  section_type = SectionType.with_name(section_type_name)
220
222
  raise "Invalid section type: #{section_type_name.inspect}" unless section_type
221
223
 
222
- user_data["section_data"] = section_type.construct_hash(user_data.slice!(*self._members.keys))
224
+ user_data['section_data'] = section_type.construct_hash(user_data.slice!(*self._members.keys))
223
225
  end
224
226
 
225
227
  def resolve_section_data(update_data, previous_translation_view)
@@ -242,39 +244,38 @@ class ViewModel::ActiveRecord::FlattenAssociationTest < ActiveSupport::TestCase
242
244
  end
243
245
  end
244
246
  end
245
-
246
247
  end
247
248
 
248
249
  def setup
249
250
  super
250
251
 
251
- @simplesection = Section.create(name: "simple1")
252
+ @simplesection = Section.create(name: 'simple1')
252
253
  @simplesection_view = {
253
- "id" => @simplesection.id,
254
- "_type" => "Section",
255
- "_version" => 1,
256
- "section_type" => "Simple",
257
- "name" => "simple1"
254
+ 'id' => @simplesection.id,
255
+ '_type' => 'Section',
256
+ '_version' => 1,
257
+ 'section_type' => 'Simple',
258
+ 'name' => 'simple1',
258
259
  }
259
260
 
260
- @quizsection = Section.create(name: "quiz1", section_data: QuizSection.new(quiz_name: "qq"))
261
+ @quizsection = Section.create(name: 'quiz1', section_data: QuizSection.new(quiz_name: 'qq'))
261
262
  @quizsection_view = {
262
- "id" => @quizsection.id,
263
- "_type" => "Section",
264
- "_version" => 1,
265
- "section_type" => "Quiz",
266
- "name" => "quiz1",
267
- "quiz_name" => "qq"
263
+ 'id' => @quizsection.id,
264
+ '_type' => 'Section',
265
+ '_version' => 1,
266
+ 'section_type' => 'Quiz',
267
+ 'name' => 'quiz1',
268
+ 'quiz_name' => 'qq',
268
269
  }
269
270
 
270
- @vocabsection = Section.create(name: "vocab1", section_data: VocabSection.new(vocab_word: "dog"))
271
+ @vocabsection = Section.create(name: 'vocab1', section_data: VocabSection.new(vocab_word: 'dog'))
271
272
  @vocabsection_view = {
272
- "id" => @vocabsection.id,
273
- "_type" => "Section",
274
- "_version" => 1,
275
- "section_type" => "Vocab",
276
- "name" => "vocab1",
277
- "vocab_word" => "dog"
273
+ 'id' => @vocabsection.id,
274
+ '_type' => 'Section',
275
+ '_version' => 1,
276
+ 'section_type' => 'Vocab',
277
+ 'name' => 'vocab1',
278
+ 'vocab_word' => 'dog',
278
279
  }
279
280
 
280
281
  enable_logging!
@@ -296,7 +297,7 @@ class ViewModel::ActiveRecord::FlattenAssociationTest < ActiveSupport::TestCase
296
297
  end
297
298
 
298
299
  def test_create
299
- assert_section = ->(model, name, &check_section){
300
+ assert_section = ->(model, name, &check_section) {
300
301
  assert(!model.changed?)
301
302
  assert(!model.new_record?)
302
303
  assert_equal(name, model.name)
@@ -313,18 +314,18 @@ class ViewModel::ActiveRecord::FlattenAssociationTest < ActiveSupport::TestCase
313
314
  }
314
315
 
315
316
  v = SectionView.deserialize_from_view(new_view_like(@simplesection_view))
316
- assert_section.call(v.model, "simple1")
317
+ assert_section.call(v.model, 'simple1')
317
318
 
318
319
  v = SectionView.deserialize_from_view(new_view_like(@quizsection_view))
319
- assert_section.call(v.model, "quiz1") do |m|
320
+ assert_section.call(v.model, 'quiz1') do |m|
320
321
  assert(m.is_a?(QuizSection))
321
- assert_equal("qq", m.quiz_name)
322
+ assert_equal('qq', m.quiz_name)
322
323
  end
323
324
 
324
325
  v = SectionView.deserialize_from_view(new_view_like(@vocabsection_view))
325
- assert_section.call(v.model, "vocab1") do |m|
326
+ assert_section.call(v.model, 'vocab1') do |m|
326
327
  assert(m.is_a?(VocabSection))
327
- assert_equal("dog", m.vocab_word)
328
+ assert_equal('dog', m.vocab_word)
328
329
  end
329
330
  end
330
331
 
@@ -363,15 +364,15 @@ class ViewModel::ActiveRecord::FlattenAssociationTest < ActiveSupport::TestCase
363
364
  def setup
364
365
  super
365
366
  sections = [
366
- Section.new(name: "simple1"),
367
- Section.new(name: "quiz1", section_data: QuizSection.new(quiz_name: "qq")),
368
- Section.new(name: "vocab1", section_data: VocabSection.new(vocab_word: "dog")),
367
+ Section.new(name: 'simple1'),
368
+ Section.new(name: 'quiz1', section_data: QuizSection.new(quiz_name: 'qq')),
369
+ Section.new(name: 'vocab1', section_data: VocabSection.new(vocab_word: 'dog')),
369
370
  ]
370
371
  @exercise1 = Exercise.create(sections: sections)
371
372
  end
372
373
 
373
374
  def test_functional_update
374
- alter_by_view!(ExerciseView, @exercise1) do |view, refs|
375
+ alter_by_view!(ExerciseView, @exercise1) do |view, _refs|
375
376
  view['sections'] = {
376
377
  '_type' => '_update',
377
378
  'actions' => [{ '_type' => 'append',
@@ -380,7 +381,7 @@ class ViewModel::ActiveRecord::FlattenAssociationTest < ActiveSupport::TestCase
380
381
  'name' => 'vocab_new',
381
382
  'vocab_word' => 'cat',
382
383
  }],
383
- }]
384
+ }],
384
385
  }
385
386
  end
386
387
  end