granite-form 0.5.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -48
  3. data/.rubocop_todo.yml +304 -27
  4. data/CHANGELOG.md +14 -2
  5. data/granite-form.gemspec +2 -1
  6. data/lib/granite/form/active_record/associations.rb +4 -3
  7. data/lib/granite/form/config.rb +1 -1
  8. data/lib/granite/form/errors.rb +34 -32
  9. data/lib/granite/form/extensions.rb +2 -1
  10. data/lib/granite/form/model/associations/base.rb +6 -2
  11. data/lib/granite/form/model/associations/collection/embedded.rb +1 -1
  12. data/lib/granite/form/model/associations/collection/proxy.rb +3 -3
  13. data/lib/granite/form/model/associations/embeds_any.rb +1 -1
  14. data/lib/granite/form/model/associations/embeds_many.rb +15 -11
  15. data/lib/granite/form/model/associations/embeds_one.rb +9 -8
  16. data/lib/granite/form/model/associations/nested_attributes.rb +60 -32
  17. data/lib/granite/form/model/associations/persistence_adapters/active_record/referenced_proxy.rb +2 -1
  18. data/lib/granite/form/model/associations/persistence_adapters/active_record.rb +7 -6
  19. data/lib/granite/form/model/associations/persistence_adapters/base.rb +8 -4
  20. data/lib/granite/form/model/associations/references_any.rb +1 -1
  21. data/lib/granite/form/model/associations/references_many.rb +3 -2
  22. data/lib/granite/form/model/associations/references_one.rb +1 -1
  23. data/lib/granite/form/model/associations/reflections/base.rb +3 -2
  24. data/lib/granite/form/model/associations/reflections/embeds_any.rb +4 -4
  25. data/lib/granite/form/model/associations/reflections/embeds_many.rb +4 -1
  26. data/lib/granite/form/model/associations/reflections/embeds_one.rb +4 -1
  27. data/lib/granite/form/model/associations/reflections/references_any.rb +6 -6
  28. data/lib/granite/form/model/associations/reflections/references_many.rb +1 -1
  29. data/lib/granite/form/model/associations/reflections/references_one.rb +1 -1
  30. data/lib/granite/form/model/associations/validations.rb +6 -6
  31. data/lib/granite/form/model/associations.rb +6 -4
  32. data/lib/granite/form/model/attributes/attribute.rb +1 -0
  33. data/lib/granite/form/model/attributes/base.rb +9 -7
  34. data/lib/granite/form/model/attributes/reference_one.rb +1 -1
  35. data/lib/granite/form/model/attributes/reflections/base/build_type_definition.rb +2 -1
  36. data/lib/granite/form/model/attributes/reflections/represents/build_type_definition.rb +2 -2
  37. data/lib/granite/form/model/attributes/represents.rb +1 -1
  38. data/lib/granite/form/model/attributes.rb +31 -14
  39. data/lib/granite/form/model/conventions.rb +1 -1
  40. data/lib/granite/form/model/persistence.rb +1 -1
  41. data/lib/granite/form/model/primary.rb +1 -1
  42. data/lib/granite/form/model/representation.rb +4 -4
  43. data/lib/granite/form/model/scopes.rb +5 -5
  44. data/lib/granite/form/model/validations.rb +4 -3
  45. data/lib/granite/form/types/active_support/time_zone.rb +1 -1
  46. data/lib/granite/form/types/array.rb +1 -1
  47. data/lib/granite/form/types/big_decimal.rb +1 -1
  48. data/lib/granite/form/types/boolean.rb +1 -1
  49. data/lib/granite/form/types/date.rb +1 -1
  50. data/lib/granite/form/types/date_time.rb +1 -1
  51. data/lib/granite/form/types/dictionary.rb +1 -1
  52. data/lib/granite/form/types/float.rb +1 -1
  53. data/lib/granite/form/types/has_subtype.rb +1 -0
  54. data/lib/granite/form/types/hash_with_action_controller_parameters.rb +2 -2
  55. data/lib/granite/form/types/integer.rb +1 -1
  56. data/lib/granite/form/types/object.rb +2 -1
  57. data/lib/granite/form/types/string.rb +1 -1
  58. data/lib/granite/form/types/time.rb +1 -1
  59. data/lib/granite/form/types/uuid.rb +1 -1
  60. data/lib/granite/form/util.rb +1 -1
  61. data/lib/granite/form/version.rb +1 -1
  62. data/spec/granite/form/active_record/associations_spec.rb +35 -13
  63. data/spec/granite/form/config_spec.rb +8 -4
  64. data/spec/granite/form/model/associations/embeds_many_spec.rb +99 -51
  65. data/spec/granite/form/model/associations/embeds_one_spec.rb +48 -25
  66. data/spec/granite/form/model/associations/persistence_adapters/active_record_spec.rb +12 -7
  67. data/spec/granite/form/model/associations/references_many_spec.rb +51 -10
  68. data/spec/granite/form/model/associations/references_one_spec.rb +17 -6
  69. data/spec/granite/form/model/associations/reflections/embeds_many_spec.rb +51 -16
  70. data/spec/granite/form/model/associations/reflections/embeds_one_spec.rb +19 -9
  71. data/spec/granite/form/model/associations/reflections/references_many_spec.rb +67 -15
  72. data/spec/granite/form/model/associations/reflections/references_one_spec.rb +34 -11
  73. data/spec/granite/form/model/associations/validations_spec.rb +16 -5
  74. data/spec/granite/form/model/associations_spec.rb +28 -9
  75. data/spec/granite/form/model/attributes/attribute_spec.rb +33 -11
  76. data/spec/granite/form/model/attributes/base_spec.rb +9 -3
  77. data/spec/granite/form/model/attributes/reflections/attribute_spec.rb +1 -0
  78. data/spec/granite/form/model/attributes/reflections/base_spec.rb +1 -0
  79. data/spec/granite/form/model/attributes/reflections/represents/build_type_definition_spec.rb +3 -1
  80. data/spec/granite/form/model/attributes/reflections/represents_spec.rb +2 -2
  81. data/spec/granite/form/model/attributes/represents_spec.rb +2 -2
  82. data/spec/granite/form/model/attributes_spec.rb +97 -36
  83. data/spec/granite/form/model/dirty_spec.rb +3 -0
  84. data/spec/granite/form/model/persistence_spec.rb +15 -5
  85. data/spec/granite/form/model/primary_spec.rb +17 -2
  86. data/spec/granite/form/model/representation_spec.rb +13 -3
  87. data/spec/granite/form/model/scopes_spec.rb +8 -3
  88. data/spec/granite/form/model/validations/associated_spec.rb +20 -6
  89. data/spec/granite/form/model/validations/nested_spec.rb +30 -14
  90. data/spec/granite/form/model/validations_spec.rb +1 -1
  91. data/spec/granite/form/model_spec.rb +1 -0
  92. data/spec/granite/form/types/collection_spec.rb +2 -1
  93. data/spec/granite/form/types/date_spec.rb +1 -1
  94. data/spec/granite/form/types/date_time_spec.rb +0 -2
  95. data/spec/granite/form/types/dictionary_spec.rb +1 -0
  96. data/spec/granite/form/types/has_subtype_spec.rb +6 -1
  97. data/spec/granite/form/types/hash_with_action_controller_parameters_spec.rb +1 -1
  98. data/spec/granite/form/types/object_spec.rb +2 -0
  99. data/spec/granite/form/types/time_spec.rb +0 -2
  100. data/spec/granite/form/util_spec.rb +6 -3
  101. data/spec/support/active_record.rb +13 -0
  102. data/spec/support/shared/nested_attribute_examples.rb +110 -54
  103. metadata +19 -6
  104. data/.github/CODEOWNERS +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5519b4c103eaec0a823f7869c496af428a11d4bab6652822add9e826a64a86c0
4
- data.tar.gz: ac3048e88443939c4bae29e5eac6d177ff58a782501f2ee03b57cc5c27697d9c
3
+ metadata.gz: 62a7935cb1b74f15d4599c3118e4b60728bcf8b27dac232a3893ef84d2b5f127
4
+ data.tar.gz: 2c6e8d0aeca6ca09aae7a364d2966a26c1ad1a4ab7f9986d348deeaab7688bdb
5
5
  SHA512:
6
- metadata.gz: a25adecefad4bd54870c96884c388ad4528ad03269b348422725a73bfe366204bfd530f58c8ac5ee92264891abcf34f824a4b4067620b9b118dba3e3e8da69d7
7
- data.tar.gz: b48f66dedbe424b642337f76468ddfc0809589e8d6e13c448ebe80b5cfe804e4bbf87e7107b14b24634af477f5cf9add77596f8c425757a75683867e2fe1320e
6
+ metadata.gz: 1545d76b21d34005b22708aa3670f7c893d322b388f217f70d21180d0dfa65621f694d87025e1b8c0fd243f97139b5f2e1a0c101a536c01750f3eba741ad0327
7
+ data.tar.gz: 0dbf480f6d6d8ebc4401ad698d3adfe8b894a2f07f6b32b9fdff0f3bc60605d7a97da1c305877db248f4a6005aebb836fa8000f22fb3c5096231e044d0491144
data/.rubocop.yml CHANGED
@@ -1,64 +1,42 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ require:
4
+ - rubocop-rspec
5
+
3
6
  AllCops:
7
+ Include:
8
+ - '**/*.rb'
9
+ - '**/Gemfile'
10
+ - '**/Rakefile'
11
+ Exclude:
12
+ - 'vendor/bundle/**/*'
13
+ - 'log/**/*'
14
+ - 'spec/fixtures/**/*'
15
+ - 'lib/granite/form/model/dirty.rb'
4
16
  DisplayCopNames: true
5
- TargetRubyVersion: 2.4.0
17
+ TargetRubyVersion: 2.6
18
+ NewCops: enable
6
19
 
7
- Lint/AmbiguousBlockAssociation:
20
+ RSpec/MultipleExpectations:
8
21
  Enabled: false
9
22
 
10
- Lint/EndAlignment:
11
- EnforcedStyleAlignWith: variable
12
-
13
- Layout/AccessModifierIndentation:
14
- EnforcedStyle: outdent
15
-
16
- Layout/AlignHash:
17
- EnforcedLastArgumentHashStyle: always_ignore
18
-
19
- Layout/AlignParameters:
20
- EnforcedStyle: with_fixed_indentation
21
-
22
- Layout/CaseIndentation:
23
- EnforcedStyle: end
24
-
25
- Layout/IndentArray:
26
- EnforcedStyle: consistent
27
-
28
- Layout/IndentHash:
29
- EnforcedStyle: consistent
30
-
31
- Layout/IndentHeredoc:
23
+ RSpec/NestedGroups:
32
24
  Enabled: false
33
25
 
34
- Layout/MultilineMethodCallIndentation:
35
- EnforcedStyle: indented
36
-
37
- Layout/MultilineOperationIndentation:
38
- EnforcedStyle: indented
39
-
40
- Layout/SpaceInsideHashLiteralBraces:
41
- EnforcedStyle: no_space
42
-
43
- Metrics/BlockLength:
44
- Exclude:
45
- - '**/*_spec.rb'
46
- - '**/*_examples.rb'
47
- - '**/*.rake'
26
+ RSpec/MessageSpies:
27
+ Enabled: false
48
28
 
49
- Metrics/ModuleLength:
50
- Exclude:
51
- - '**/*_spec.rb'
52
- - 'lib/granite/form.rb'
29
+ Gemspec/DevelopmentDependencies:
30
+ Enabled: false
53
31
 
54
- Style/Alias:
55
- EnforcedStyle: prefer_alias_method
32
+ Style/FrozenStringLiteralComment:
33
+ Enabled: false
56
34
 
57
- Style/AndOr:
58
- EnforcedStyle: conditionals
35
+ RSpec/DescribedClass:
36
+ Enabled: false
59
37
 
60
- Style/DoubleNegation:
38
+ Style/OptionalBooleanParameter:
61
39
  Enabled: false
62
40
 
63
- Style/FrozenStringLiteralComment:
41
+ Style/MissingRespondToMissing:
64
42
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,48 +1,325 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-10-14 10:15:31 +0700 using RuboCop version 0.44.1.
3
+ # on 2024-05-13 08:55:48 UTC using RuboCop version 1.63.5.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 19
9
+ # Offense count: 10
10
+ # Configuration parameters: AllowComments, AllowEmptyLambdas.
11
+ Lint/EmptyBlock:
12
+ Exclude:
13
+ - 'spec/granite/form/config_spec.rb'
14
+ - 'spec/granite/form/model/associations/reflections/embeds_any_spec.rb'
15
+ - 'spec/granite/form/model/attributes/reflections/attribute_spec.rb'
16
+ - 'spec/granite/form/model/attributes_spec.rb'
17
+ - 'spec/granite/form/model/dirty_spec.rb'
18
+ - 'spec/granite/form/model/validations_spec.rb'
19
+
20
+ # Offense count: 1
21
+ # Configuration parameters: AllowComments.
22
+ Lint/EmptyClass:
23
+ Exclude:
24
+ - 'lib/granite/form/extensions.rb'
25
+
26
+ # Offense count: 1
27
+ # Configuration parameters: AllowedParentClasses.
28
+ Lint/MissingSuper:
29
+ Exclude:
30
+ - 'lib/granite/form/model/associations/reflections/references_any.rb'
31
+
32
+ # Offense count: 1
33
+ # This cop supports unsafe autocorrection (--autocorrect-all).
34
+ Lint/NonDeterministicRequireOrder:
35
+ Exclude:
36
+ - 'lib/granite/form/model/validations.rb'
37
+
38
+ # Offense count: 8
39
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
10
40
  Metrics/AbcSize:
11
- Max: 59
41
+ Max: 60
42
+
43
+ # Offense count: 5
44
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
45
+ Metrics/CyclomaticComplexity:
46
+ Max: 17
47
+
48
+ # Offense count: 14
49
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
50
+ Metrics/MethodLength:
51
+ Max: 46
52
+
53
+ # Offense count: 5
54
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
55
+ Metrics/PerceivedComplexity:
56
+ Max: 20
12
57
 
13
58
  # Offense count: 2
14
- # Configuration parameters: CountComments.
15
- Metrics/ClassLength:
16
- Max: 128
59
+ # This cop supports unsafe autocorrection (--autocorrect-all).
60
+ # Configuration parameters: EnforcedStyleForLeadingUnderscores.
61
+ # SupportedStylesForLeadingUnderscores: disallowed, required, optional
62
+ Naming/MemoizedInstanceVariableName:
63
+ Exclude:
64
+ - 'lib/granite/form/model/associations/embeds_many.rb'
65
+ - 'lib/granite/form/model/associations/references_many.rb'
17
66
 
18
- # Offense count: 4
19
- Metrics/CyclomaticComplexity:
20
- Max: 15
67
+ # Offense count: 2
68
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
69
+ # AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
70
+ Naming/MethodParameterName:
71
+ Exclude:
72
+ - 'spec/granite/form/model/attributes_spec.rb'
21
73
 
22
- # Offense count: 904
23
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
24
- # URISchemes: http, https
25
- Metrics/LineLength:
26
- Max: 187
74
+ # Offense count: 2
75
+ RSpec/AnyInstance:
76
+ Exclude:
77
+ - 'spec/granite/form/model/attributes/attribute_spec.rb'
27
78
 
28
- # Offense count: 21
29
- # Configuration parameters: CountComments.
30
- Metrics/MethodLength:
31
- Max: 43
79
+ # Offense count: 77
80
+ # This cop supports unsafe autocorrection (--autocorrect-all).
81
+ RSpec/BeEq:
82
+ Exclude:
83
+ - 'spec/granite/form/active_record/associations_spec.rb'
84
+ - 'spec/granite/form/config_spec.rb'
85
+ - 'spec/granite/form/model/associations/embeds_many_spec.rb'
86
+ - 'spec/granite/form/model/associations/embeds_one_spec.rb'
87
+ - 'spec/granite/form/model/associations/references_many_spec.rb'
88
+ - 'spec/granite/form/model/associations/references_one_spec.rb'
89
+ - 'spec/granite/form/model/associations/validations_spec.rb'
90
+ - 'spec/granite/form/model/attributes/attribute_spec.rb'
91
+ - 'spec/granite/form/model/attributes/base_spec.rb'
92
+ - 'spec/granite/form/model/attributes_spec.rb'
93
+ - 'spec/granite/form/model/primary_spec.rb'
94
+ - 'spec/granite/form/model/representation_spec.rb'
95
+ - 'spec/granite/form/model/validations_spec.rb'
96
+ - 'spec/granite/form/types/boolean_spec.rb'
97
+ - 'spec/granite/form/types/object_spec.rb'
98
+
99
+ # Offense count: 1
100
+ RSpec/BeforeAfterAll:
101
+ Exclude:
102
+ - '**/spec/spec_helper.rb'
103
+ - '**/spec/rails_helper.rb'
104
+ - '**/spec/support/**/*.rb'
105
+ - 'spec/granite/form/types/hash_with_action_controller_parameters_spec.rb'
106
+
107
+ # Offense count: 74
108
+ # Configuration parameters: Prefixes, AllowedPatterns.
109
+ # Prefixes: when, with, without
110
+ RSpec/ContextWording:
111
+ Enabled: false
112
+
113
+ # Offense count: 42
114
+ # Configuration parameters: CountAsOne.
115
+ RSpec/ExampleLength:
116
+ Max: 10
117
+
118
+ # Offense count: 220
119
+ # This cop supports unsafe autocorrection (--autocorrect-all).
120
+ # Configuration parameters: EnforcedStyle.
121
+ # SupportedStyles: method_call, block
122
+ RSpec/ExpectChange:
123
+ Exclude:
124
+ - 'spec/granite/form/active_record/associations_spec.rb'
125
+ - 'spec/granite/form/config_spec.rb'
126
+ - 'spec/granite/form/model/associations/embeds_many_spec.rb'
127
+ - 'spec/granite/form/model/associations/embeds_one_spec.rb'
128
+ - 'spec/granite/form/model/associations/references_many_spec.rb'
129
+ - 'spec/granite/form/model/associations/references_one_spec.rb'
130
+ - 'spec/granite/form/model/associations/reflections/embeds_many_spec.rb'
131
+ - 'spec/granite/form/model/associations/reflections/embeds_one_spec.rb'
132
+ - 'spec/granite/form/model/associations/reflections/references_many_spec.rb'
133
+ - 'spec/granite/form/model/associations/reflections/references_one_spec.rb'
134
+ - 'spec/granite/form/model/attributes_spec.rb'
135
+ - 'spec/granite/form/model/representation_spec.rb'
136
+ - 'spec/support/shared/nested_attribute_examples.rb'
137
+
138
+ # Offense count: 3
139
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
140
+ # Include: **/*_spec*rb*, **/spec/**/*
141
+ RSpec/FilePath:
142
+ Exclude:
143
+ - 'spec/granite/form/extensions_spec.rb'
144
+ - 'spec/granite/form/model/validations/associated_spec.rb'
145
+ - 'spec/granite/form/model/validations/nested_spec.rb'
146
+
147
+ # Offense count: 6
148
+ RSpec/IdenticalEqualityAssertion:
149
+ Exclude:
150
+ - 'spec/granite/form/model/associations_spec.rb'
151
+ - 'spec/granite/form/model/primary_spec.rb'
152
+
153
+ # Offense count: 23
154
+ # Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
155
+ RSpec/IndexedLet:
156
+ Exclude:
157
+ - 'spec/granite/form/model/associations/embeds_many_spec.rb'
158
+ - 'spec/granite/form/model/associations/embeds_one_spec.rb'
159
+ - 'spec/granite/form/model/associations/references_many_spec.rb'
160
+ - 'spec/granite/form/model/associations/reflections/embeds_many_spec.rb'
161
+ - 'spec/granite/form/model/associations/reflections/references_many_spec.rb'
162
+ - 'spec/granite/form/model/associations/reflections/references_one_spec.rb'
163
+ - 'spec/granite/form/model/attributes_spec.rb'
164
+ - 'spec/granite/form/model/scopes_spec.rb'
165
+
166
+ # Offense count: 8
167
+ # Configuration parameters: AssignmentOnly.
168
+ RSpec/InstanceVariable:
169
+ Exclude:
170
+ - 'spec/granite/form/model/attributes/reflections/base/build_type_definition_spec.rb'
171
+ - 'spec/granite/form/model/attributes/reflections/collection/build_type_definition_spec.rb'
172
+ - 'spec/granite/form/model/attributes/reflections/dictionary/build_type_definition_spec.rb'
173
+ - 'spec/granite/form/model/attributes/reflections/represents/build_type_definition_spec.rb'
174
+
175
+ # Offense count: 81
176
+ RSpec/MissingExampleGroupArgument:
177
+ Enabled: false
178
+
179
+ # Offense count: 39
180
+ # Configuration parameters: AllowSubject.
181
+ RSpec/MultipleMemoizedHelpers:
182
+ Max: 9
183
+
184
+ # Offense count: 95
185
+ # Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
186
+ # SupportedStyles: always, named_only
187
+ RSpec/NamedSubject:
188
+ Exclude:
189
+ - 'spec/granite/form/config_spec.rb'
190
+ - 'spec/granite/form/model/attributes/base_spec.rb'
191
+ - 'spec/granite/form/model/attributes_spec.rb'
192
+ - 'spec/granite/form/model/persistence_spec.rb'
193
+ - 'spec/granite/form/model/validations/nested_spec.rb'
194
+ - 'spec/granite/form/types/collection_spec.rb'
195
+ - 'spec/granite/form/types/dictionary_spec.rb'
196
+ - 'spec/granite/form/types/has_subtype_spec.rb'
197
+ - 'spec/granite/form/util_spec.rb'
198
+ - 'spec/granite/form_spec.rb'
199
+
200
+ # Offense count: 14
201
+ # Configuration parameters: AllowedPatterns.
202
+ # AllowedPatterns: ^expect_, ^assert_
203
+ RSpec/NoExpectationExample:
204
+ Exclude:
205
+ - 'spec/granite/form/model/attributes_spec.rb'
206
+
207
+ # Offense count: 1
208
+ RSpec/PendingWithoutReason:
209
+ Exclude:
210
+ - 'spec/granite/form/model/associations/reflections/references_many_spec.rb'
211
+
212
+ # Offense count: 10
213
+ RSpec/RepeatedExample:
214
+ Exclude:
215
+ - 'spec/support/shared/nested_attribute_examples.rb'
216
+
217
+ # Offense count: 2
218
+ RSpec/RepeatedExampleGroupDescription:
219
+ Exclude:
220
+ - 'spec/granite/form/model/primary_spec.rb'
221
+
222
+ # Offense count: 3
223
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
224
+ # Include: **/*_spec.rb
225
+ RSpec/SpecFilePathFormat:
226
+ Exclude:
227
+ - '**/spec/routing/**/*'
228
+ - 'spec/granite/form/extensions_spec.rb'
229
+ - 'spec/granite/form/model/validations/associated_spec.rb'
230
+ - 'spec/granite/form/model/validations/nested_spec.rb'
231
+
232
+ # Offense count: 1
233
+ # This cop supports unsafe autocorrection (--autocorrect-all).
234
+ # Configuration parameters: EnforcedStyle.
235
+ # SupportedStyles: constant, string
236
+ RSpec/VerifiedDoubleReference:
237
+ Exclude:
238
+ - 'spec/granite/form/model/representation_spec.rb'
239
+
240
+ # Offense count: 3
241
+ # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
242
+ RSpec/VerifiedDoubles:
243
+ Exclude:
244
+ - 'spec/granite/form/types/has_subtype_spec.rb'
245
+ - 'spec/granite/form/types/object_spec.rb'
32
246
 
33
247
  # Offense count: 2
34
- # Configuration parameters: CountComments.
35
- Metrics/ModuleLength:
36
- Max: 114
248
+ RSpec/VoidExpect:
249
+ Exclude:
250
+ - 'spec/granite/form/model/attributes_spec.rb'
251
+
252
+ # Offense count: 1
253
+ # This cop supports unsafe autocorrection (--autocorrect-all).
254
+ # Configuration parameters: EnforcedStyle.
255
+ # SupportedStyles: not_to, be_invalid
256
+ RSpecRails/NegationBeValid:
257
+ Exclude:
258
+ - 'spec/granite/form/model/validations_spec.rb'
259
+
260
+ # Offense count: 1
261
+ # This cop supports unsafe autocorrection (--autocorrect-all).
262
+ # Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols.
263
+ # SupportedStyles: inline, group
264
+ Style/AccessModifierDeclarations:
265
+ Exclude:
266
+ - 'lib/granite/form/model/associations/reflections/embeds_any.rb'
37
267
 
38
268
  # Offense count: 2
39
- Metrics/BlockLength:
40
- Max: 27
269
+ # This cop supports unsafe autocorrection (--autocorrect-all).
270
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
271
+ # AllowedMethods: ==, equal?, eql?
272
+ Style/ClassEqualityComparison:
273
+ Exclude:
274
+ - 'lib/granite/form/model/attributes.rb'
41
275
 
42
- # Offense count: 4
43
- Metrics/PerceivedComplexity:
44
- Max: 18
276
+ # Offense count: 7
277
+ # This cop supports unsafe autocorrection (--autocorrect-all).
278
+ Style/ConcatArrayLiterals:
279
+ Exclude:
280
+ - 'spec/granite/form/model/associations/embeds_many_spec.rb'
281
+ - 'spec/granite/form/model/associations/references_many_spec.rb'
282
+
283
+ # Offense count: 8
284
+ Style/DocumentDynamicEvalDefinition:
285
+ Exclude:
286
+ - 'lib/granite/form/active_record/associations.rb'
287
+ - 'lib/granite/form/model/associations/nested_attributes.rb'
288
+ - 'lib/granite/form/model/associations/reflections/base.rb'
289
+ - 'lib/granite/form/model/associations/reflections/embeds_one.rb'
290
+ - 'lib/granite/form/model/attributes/reflections/attribute.rb'
291
+ - 'lib/granite/form/model/attributes/reflections/reference_one.rb'
292
+ - 'lib/granite/form/model/dirty.rb'
45
293
 
46
- # Offense count: 75
294
+ # Offense count: 96
295
+ # Configuration parameters: AllowedConstants.
47
296
  Style/Documentation:
48
297
  Enabled: false
298
+
299
+ # Offense count: 1
300
+ # This cop supports unsafe autocorrection (--autocorrect-all).
301
+ Style/GlobalStdStream:
302
+ Exclude:
303
+ - 'lib/granite/form/config.rb'
304
+
305
+ # Offense count: 1
306
+ # This cop supports safe autocorrection (--autocorrect).
307
+ # Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
308
+ Style/GuardClause:
309
+ Exclude:
310
+ - 'lib/granite/form/config.rb'
311
+
312
+ # Offense count: 3
313
+ # This cop supports unsafe autocorrection (--autocorrect-all).
314
+ # Configuration parameters: AllowSplatArgument.
315
+ Style/HashConversion:
316
+ Exclude:
317
+ - 'lib/granite/form/model/attributes.rb'
318
+ - 'lib/granite/form/types/dictionary.rb'
319
+
320
+ # Offense count: 2
321
+ # This cop supports safe autocorrection (--autocorrect).
322
+ Style/IfUnlessModifier:
323
+ Exclude:
324
+ - 'lib/granite/form/model/associations/nested_attributes.rb'
325
+ - 'spec/granite/form/model/representation_spec.rb'
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
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
+
12
+ ## v0.6.0
13
+
14
+ * Fix crash when mapping PostgreSQL enum to ruby variable in https://github.com/toptal/granite-form/pull/28
15
+ * Lower severity of the log message during mass assignment https://github.com/toptal/granite-form/pull/26
16
+
5
17
  ## v0.5.0
6
18
 
7
19
  * Support for ruby 3.2 by @konalegi in https://github.com/toptal/granite-form/pull/22
@@ -15,7 +27,7 @@
15
27
  * Add support for evaluating `Symbol` for readonly/enum/normalize. If symbol is passed in one of those options, method with that name will be called when evaluating the value.
16
28
  * [BREAKING] Remove `localized` attribute type.
17
29
  * [BREAKING] Change the behavior of `default` and `normalize` for `collection` & `dictionary`. Instead of acting per element they will now act on the attribute as a whole.
18
- * E.g. `collection :numbers, default: [1, 2, 3]` will not set the default for the whole collection of `numbers` rather than each element in `numbers`.
30
+ * E.g. `collection :numbers, default: [1, 2, 3]` will not set the default for the whole collection of `numbers` rather than each element in `numbers`.
19
31
 
20
32
  ## v0.3.0
21
33
 
@@ -32,7 +44,7 @@
32
44
 
33
45
  ## v0.1.1
34
46
 
35
- - Fixed represented error message copying when represented model uses symbols for `message`.
47
+ - Fixed represented error message copying when represented model uses symbols for `message`.
36
48
 
37
49
  ## v0.1.0
38
50
 
data/granite-form.gemspec CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency 'rake'
24
24
  gem.add_development_dependency 'rspec', '~> 3.7.0'
25
25
  gem.add_development_dependency 'rspec-its'
26
- gem.add_development_dependency 'rubocop', '0.52.1'
26
+ gem.add_development_dependency 'rubocop', '1.63.5'
27
+ gem.add_development_dependency 'rubocop-rspec', '2.29.2'
27
28
  gem.add_development_dependency 'uuidtools'
28
29
 
29
30
  gem.add_runtime_dependency 'activemodel', '>= 6.0'
@@ -30,11 +30,12 @@ module Granite
30
30
  extend ActiveSupport::Concern
31
31
 
32
32
  included do
33
- {embeds_many: Reflections::EmbedsMany, embeds_one: Reflections::EmbedsOne}.each do |(method, reflection_class)|
33
+ { embeds_many: Reflections::EmbedsMany,
34
+ embeds_one: Reflections::EmbedsOne }.each do |(method, reflection_class)|
34
35
  define_singleton_method method do |name, options = {}, &block|
35
36
  reflection = reflection_class.build(self, self, name,
36
- options.reverse_merge(read: READER, write: WRITER),
37
- &block)
37
+ options.reverse_merge(read: READER, write: WRITER),
38
+ &block)
38
39
  if ::ActiveRecord::Reflection.respond_to? :add_reflection
39
40
  ::ActiveRecord::Reflection.add_reflection self, reflection.name, reflection
40
41
  else
@@ -4,7 +4,7 @@ module Granite
4
4
  include Singleton
5
5
 
6
6
  attr_accessor :include_root_in_json, :i18n_scope, :logger, :primary_attribute, :base_class, :base_concern,
7
- :_normalizers, :types
7
+ :_normalizers, :types
8
8
 
9
9
  def self.delegated
10
10
  public_instance_methods - superclass.public_instance_methods - Singleton.public_instance_methods
@@ -13,53 +13,55 @@ module Granite
13
13
  def initialize(model)
14
14
  @model = model
15
15
  errors = @model.errors.full_messages.join(', ')
16
- super(I18n.t(:"#{@model.class.i18n_scope}.errors.messages.model_invalid", errors: errors, default: :'errors.messages.model_invalid'))
16
+ super(I18n.t(:"#{@model.class.i18n_scope}.errors.messages.model_invalid",
17
+ errors: errors, default: :'errors.messages.model_invalid'))
17
18
  end
18
19
  end
19
20
 
20
21
  class AssociationTypeMismatch < Error
21
22
  def initialize(expected, got)
22
- super "Expected `#{expected}` (##{expected.object_id}), but got `#{got}` (##{got.object_id})"
23
+ super("Expected `#{expected}` (##{expected.object_id}), but got `#{got}` (##{got.object_id})")
23
24
  end
24
25
  end
25
26
 
26
27
  class ObjectNotFound < Error
27
28
  def initialize(object, association_name, record_id)
29
+ primary_name = object.respond_to?(:_primary_name) ? object._primary_name : 'id'
28
30
  message = "Couldn't find #{object.class.reflect_on_association(association_name).klass.name}" \
29
- "with #{object.respond_to?(:_primary_name) ? object._primary_name : 'id'} = #{record_id} for #{object.inspect}"
30
- super message
31
+ "with #{primary_name} = #{record_id} for #{object.inspect}"
32
+ super(message)
31
33
  end
32
34
  end
33
35
 
34
36
  class TooManyObjects < Error
35
37
  def initialize(limit, actual_size)
36
- super "Maximum #{limit} objects are allowed. Got #{actual_size} objects instead."
38
+ super("Maximum #{limit} objects are allowed. Got #{actual_size} objects instead.")
37
39
  end
38
40
  end
39
41
 
40
42
  class UndefinedPrimaryAttribute < Error
41
43
  def initialize(klass, association_name)
42
- super <<-MESSAGE
43
- Undefined primary attribute for `#{association_name}` in #{klass}.
44
- It is required for embeds_many nested attributes proper operation.
45
- You can define this association as:
44
+ super(<<~MESSAGE)
45
+ Undefined primary attribute for `#{association_name}` in #{klass}.
46
+ It is required for embeds_many nested attributes proper operation.
47
+ You can define this association as:
46
48
 
47
- embeds_many :#{association_name} do
48
- primary :attribute_name
49
- end
49
+ embeds_many :#{association_name} do
50
+ primary :attribute_name
51
+ end
50
52
  MESSAGE
51
53
  end
52
54
  end
53
55
 
54
56
  class NormalizerMissing < NoMethodError
55
57
  def initialize(name)
56
- super <<-MESSAGE
57
- Could not find normalizer `:#{name}`
58
- You can define it with:
58
+ super(<<~MESSAGE)
59
+ Could not find normalizer `:#{name}`
60
+ You can define it with:
59
61
 
60
- Granite::Form.normalizer(:#{name}) do |value, options|
61
- # do some staff with value and options
62
- end
62
+ Granite::Form.normalizer(:#{name}) do |value, options|
63
+ # do some staff with value and options
64
+ end
63
65
  MESSAGE
64
66
  end
65
67
  end
@@ -67,28 +69,28 @@ You can define it with:
67
69
  class TypecasterMissing < NoMethodError
68
70
  def initialize(*classes)
69
71
  classes = classes.flatten
70
- super <<-MESSAGE
71
- Could not find typecaster for #{classes}
72
- You can define it with:
72
+ super(<<~MESSAGE)
73
+ Could not find typecaster for #{classes}
74
+ You can define it with:
73
75
 
74
- Granite::Form.typecaster('#{classes.first}') do |value|
75
- # do some staff with value and options
76
- end
76
+ Granite::Form.typecaster('#{classes.first}') do |value|
77
+ # do some staff with value and options
78
+ end
77
79
  MESSAGE
78
80
  end
79
81
  end
80
82
 
81
83
  class PersistenceAdapterMissing < NoMethodError
82
84
  def initialize(data_source)
83
- super <<-MESSAGE
84
- Could not find persistence adapter for #{data_source}
85
- You can define it with:
85
+ super(<<~MESSAGE)
86
+ Could not find persistence adapter for #{data_source}
87
+ You can define it with:
86
88
 
87
- class #{data_source}
88
- def self.granite_persistence_adapter
89
- #{data_source}GraniteFormPersistenceAdapter
90
- end
91
- end
89
+ class #{data_source}
90
+ def self.granite_persistence_adapter
91
+ #{data_source}GraniteFormPersistenceAdapter
92
+ end
93
+ end
92
94
  MESSAGE
93
95
  end
94
96
  end
@@ -17,7 +17,8 @@ else
17
17
  end
18
18
 
19
19
  def self.parse_string(value)
20
- return nil if value.length.zero?
20
+ return nil if value.empty?
21
+
21
22
  if value.length == 36
22
23
  parse value
23
24
  elsif value.length == 32