iknow_view_models 3.10.1 → 3.11.0

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: 417eb3615156fa48cf438ead03e2ea33e323c5baa7d411b1e0fafcea5050acb1
4
- data.tar.gz: cdede3ad865389a0d006725819595aec6da1ea417e9d061452ef3198a39af3d8
3
+ metadata.gz: 40eb8cc78ae998113eac37ef9cd944ecefc1c4b0a71a492944ac88ff2bfa4077
4
+ data.tar.gz: cb7d430a809687598e365e54a0312e97fc6ee1938cfdd1c4f9f1bd924e8364a5
5
5
  SHA512:
6
- metadata.gz: ada26778b54ffb60a825d408fe40f05c8a4aa93cbac7b5519b2338b5afb4cadfda0d1eb7b359b65584f88fbb9cadea4a35a7d2ba0aad9fb8e4d8ec9d5f894e03
7
- data.tar.gz: b70d2b42d4a599c3d284dbb96c4506c8ff7b6104108ebcb7126c554fcd671eb0bad04dc4df5a1006f76af272a71c5ca46f54736bf4961821dd7f22160d46fada
6
+ metadata.gz: dd1c4215f6e9bafaf68c618d4ba59541089016d4dcea45ab90892489cc6ada0183f95a6d07ae88899fc54d5a9bf37a3619e70bc62c54ed9c5b9de57eeec5f37f
7
+ data.tar.gz: e1cd93bf28d4ad96ac347effeb96d9bbbd6a1ec9a09944091d8127555b1c22ca2e97bfa7f5ce670f86cf42647b06d3e1da13a842935eb0bd39e44c303af666ab
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.10.1'
4
+ VERSION = '3.11.0'
5
5
  end
@@ -56,9 +56,14 @@ module ViewModel::ActiveRecord::Controller
56
56
  end
57
57
 
58
58
  def destroy(serialize_context: new_serialize_context, deserialize_context: new_deserialize_context)
59
+ viewmodel_ids = parse_param(
60
+ :id, with: IknowParams::Serializer::ArrayOf.new(ViewmodelIdSerializer, allow_singleton: true))
61
+
59
62
  viewmodel_class.transaction do
60
- view = viewmodel_class.find(viewmodel_id, eager_include: false)
61
- view.destroy!(deserialize_context: deserialize_context)
63
+ views = viewmodel_class.find(viewmodel_ids, eager_include: false)
64
+ views.each do |view|
65
+ view.destroy!(deserialize_context: deserialize_context)
66
+ end
62
67
  end
63
68
  render_viewmodel(nil)
64
69
  end
@@ -91,8 +96,28 @@ module ViewModel::ActiveRecord::Controller
91
96
 
92
97
  private
93
98
 
99
+ # Viewmodel ids are permitted to be either integers or strings
100
+ class ViewmodelIdSerializer < IknowParams::Serializer
101
+ def initialize
102
+ super(::Object)
103
+ end
104
+
105
+ def load(val)
106
+ case val
107
+ when ::Integer, ::String
108
+ val
109
+ else
110
+ raise IknowParams::Serializer::LoadError.new(
111
+ "Incorrect type for #{self.class.name}: #{val.inspect}:#{val.class.name}")
112
+ end
113
+ end
114
+
115
+ set_singleton!
116
+ json_value!
117
+ end
118
+
94
119
  def viewmodel_id
95
- parse_param(:id)
120
+ parse_param(:id, with: ViewmodelIdSerializer)
96
121
  end
97
122
 
98
123
  def migrated_deep_schema_version
@@ -156,11 +156,13 @@ module ActionDispatch
156
156
  name_route = { as: '' } # Only one route may take the name
157
157
  post('', action: :create, **name_route.extract!(:as)) unless except.include?(:create) || !add_shallow_routes
158
158
  get('', action: :index, **name_route.extract!(:as)) unless except.include?(:index) || !add_shallow_routes
159
+ delete('', action: :destroy, as: :bulk_delete) unless except.include?(:destroy) || !add_shallow_routes
159
160
  end
160
161
  end
161
162
  else
162
163
  collection do
163
164
  get('', action: :index, as: '') unless except.include?(:index)
165
+ delete('', action: :destroy, as: :bulk_delete) unless except.include?(:destroy)
164
166
  end
165
167
  end
166
168
  end
@@ -167,6 +167,22 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
167
167
  end
168
168
 
169
169
  def test_destroy
170
+ other_parent = make_parent
171
+ parentcontroller = ParentController.new(params: { id: [@parent.id, other_parent.id] })
172
+ parentcontroller.invoke(:destroy)
173
+
174
+ assert_equal(200, parentcontroller.status)
175
+
176
+ assert(Parent.where(id: @parent.id).blank?, "record doesn't exist after delete")
177
+ assert(Parent.where(id: other_parent.id).blank?, "record doesn't exist after delete")
178
+
179
+ assert_equal({ 'data' => nil },
180
+ parentcontroller.hash_response)
181
+
182
+ assert_all_hooks_nested_inside_parent_hook(parentcontroller.hook_trace)
183
+ end
184
+
185
+ def test_batch_destroy
170
186
  parentcontroller = ParentController.new(params: { id: @parent.id })
171
187
  parentcontroller.invoke(:destroy)
172
188
 
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.10.1
4
+ version: 3.11.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: 2024-05-24 00:00:00.000000000 Z
11
+ date: 2024-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack