granite-form 0.6.0 → 0.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/granite/form/model/attributes.rb +11 -2
- data/lib/granite/form/version.rb +1 -1
- data/spec/granite/form/model/attributes_spec.rb +21 -0
- metadata +7 -8
- data/.github/CODEOWNERS +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62a7935cb1b74f15d4599c3118e4b60728bcf8b27dac232a3893ef84d2b5f127
|
4
|
+
data.tar.gz: 2c6e8d0aeca6ca09aae7a364d2966a26c1ad1a4ab7f9986d348deeaab7688bdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1545d76b21d34005b22708aa3670f7c893d322b388f217f70d21180d0dfa65621f694d87025e1b8c0fd243f97139b5f2e1a0c101a536c01750f3eba741ad0327
|
7
|
+
data.tar.gz: 0dbf480f6d6d8ebc4401ad698d3adfe8b894a2f07f6b32b9fdff0f3bc60605d7a97da1c305877db248f4a6005aebb836fa8000f22fb3c5096231e044d0491144
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## Next
|
4
4
|
|
5
|
+
## v0.6.1
|
6
|
+
|
7
|
+
* Introduces `mass_assignment_strict_mode` configuration option to control the behavior of mass assignment.
|
8
|
+
* The setting is per class and configures strict handling of unknown attributes by raising an exception.
|
9
|
+
* By default it is disabled, and you need to opt-in.
|
10
|
+
* https://github.com/toptal/granite-form/pull/32
|
11
|
+
|
5
12
|
## v0.6.0
|
6
13
|
|
7
14
|
* Fix crash when mapping PostgreSQL enum to ruby variable in https://github.com/toptal/granite-form/pull/28
|
@@ -16,10 +16,13 @@ module Granite
|
|
16
16
|
extend ActiveSupport::Concern
|
17
17
|
|
18
18
|
included do
|
19
|
-
class_attribute :_attributes, :_attribute_aliases, :_sanitize,
|
19
|
+
class_attribute :_attributes, :_attribute_aliases, :_sanitize,
|
20
|
+
:mass_assignment_strict_mode,
|
21
|
+
instance_reader: false, instance_writer: false
|
20
22
|
self._attributes = {}
|
21
23
|
self._attribute_aliases = {}
|
22
24
|
self._sanitize = true
|
25
|
+
self.mass_assignment_strict_mode = false
|
23
26
|
|
24
27
|
delegate :attribute_names, :has_attribute?, to: 'self.class'
|
25
28
|
|
@@ -180,7 +183,7 @@ module Granite
|
|
180
183
|
public_send("#{name}=", value)
|
181
184
|
else
|
182
185
|
attribute_type = sanitize_value ? 'primary' : 'undefined'
|
183
|
-
|
186
|
+
report_unknown_attribute(attribute_type, name)
|
184
187
|
end
|
185
188
|
end
|
186
189
|
end
|
@@ -208,6 +211,12 @@ module Granite
|
|
208
211
|
|
209
212
|
private
|
210
213
|
|
214
|
+
def report_unknown_attribute(attribute_type, name)
|
215
|
+
raise ActiveModel::UnknownAttributeError.new(self, name.to_s) if self.class.mass_assignment_strict_mode
|
216
|
+
|
217
|
+
logger.debug("Ignoring #{attribute_type} `#{name}` attribute value for #{self} during mass-assignment")
|
218
|
+
end
|
219
|
+
|
211
220
|
def attributes_for_inspect
|
212
221
|
attribute_names(false).map do |name|
|
213
222
|
prefix = self.class.primary_name == name ? '*' : ''
|
data/lib/granite/form/version.rb
CHANGED
@@ -206,6 +206,27 @@ describe Granite::Form::Model::Attributes do
|
|
206
206
|
end
|
207
207
|
end
|
208
208
|
end
|
209
|
+
|
210
|
+
context 'with mass_assignment_strict_mode' do
|
211
|
+
let(:model) do
|
212
|
+
stub_model do
|
213
|
+
self.mass_assignment_strict_mode = true
|
214
|
+
attribute :full_name, String
|
215
|
+
alias_attribute :name, :full_name
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
specify do
|
220
|
+
expect do
|
221
|
+
subject.assign_attributes(name: 'name', unexisting: 'value')
|
222
|
+
end.to raise_error(ActiveModel::UnknownAttributeError, /unknown attribute 'unexisting' for/)
|
223
|
+
end
|
224
|
+
|
225
|
+
specify do
|
226
|
+
subject.assign_attributes(name: 'name', full_name: 'full_name')
|
227
|
+
expect(subject.name).to eq('full_name')
|
228
|
+
end
|
229
|
+
end
|
209
230
|
end
|
210
231
|
|
211
232
|
describe '#sync_attributes' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: granite-form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toptal Engineering
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05
|
11
|
+
date: 2024-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -221,13 +221,12 @@ dependencies:
|
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
223
|
description: Making object from any hash or hash array
|
224
|
-
email:
|
224
|
+
email:
|
225
225
|
executables: []
|
226
226
|
extensions: []
|
227
227
|
extra_rdoc_files: []
|
228
228
|
files:
|
229
229
|
- ".codeclimate.yml"
|
230
|
-
- ".github/CODEOWNERS"
|
231
230
|
- ".github/workflows/ruby.yml"
|
232
231
|
- ".gitignore"
|
233
232
|
- ".rspec"
|
@@ -392,7 +391,7 @@ files:
|
|
392
391
|
homepage: https://github.com/toptal/granite-form
|
393
392
|
licenses: []
|
394
393
|
metadata: {}
|
395
|
-
post_install_message:
|
394
|
+
post_install_message:
|
396
395
|
rdoc_options: []
|
397
396
|
require_paths:
|
398
397
|
- lib
|
@@ -407,8 +406,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
407
406
|
- !ruby/object:Gem::Version
|
408
407
|
version: '0'
|
409
408
|
requirements: []
|
410
|
-
rubygems_version: 3.
|
411
|
-
signing_key:
|
409
|
+
rubygems_version: 3.4.19
|
410
|
+
signing_key:
|
412
411
|
specification_version: 4
|
413
412
|
summary: Working with hashes in AR style
|
414
413
|
test_files:
|
data/.github/CODEOWNERS
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
* @toptal/devx
|