reform 2.3.3 → 2.5.0
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/.gitignore +1 -1
- data/.travis.yml +0 -3
- data/CHANGES.md +9 -0
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +5 -5
- data/Rakefile +1 -12
- data/lib/reform/contract/validate.rb +1 -1
- data/lib/reform/form/dry.rb +47 -9
- data/lib/reform/validation/groups.rb +0 -1
- data/lib/reform/version.rb +1 -1
- data/test/call_test.rb +23 -0
- data/test/changed_test.rb +6 -6
- data/test/coercion_test.rb +17 -17
- data/test/{composition_new_api.rb → composition_test.rb} +27 -28
- data/test/{contract_new_api.rb → contract_test.rb} +8 -8
- data/test/default_test.rb +2 -2
- data/test/deserialize_test.rb +8 -8
- data/test/docs/validation_test.rb +134 -0
- data/test/{errors_new_api.rb → errors_test.rb} +41 -41
- data/test/feature_test.rb +2 -2
- data/test/fixtures/dry_error_messages.yml +64 -54
- data/test/{form_option_new_api.rb → form_option_test.rb} +1 -1
- data/test/{form_new_api.rb → form_test.rb} +3 -3
- data/test/from_test.rb +10 -10
- data/test/{inherit_new_api.rb → inherit_test.rb} +17 -17
- data/test/{module_new_api.rb → module_test.rb} +10 -10
- data/test/parse_option_test.rb +7 -7
- data/test/parse_pipeline_test.rb +1 -1
- data/test/{populate_new_api.rb → populate_test.rb} +112 -53
- data/test/populator_skip_test.rb +2 -2
- data/test/prepopulator_test.rb +15 -15
- data/test/read_only_test.rb +2 -2
- data/test/readable_test.rb +3 -3
- data/test/{reform_new_api.rb → reform_test.rb} +19 -19
- data/test/{save_new_api.rb → save_test.rb} +4 -4
- data/test/setup_test.rb +9 -9
- data/test/{skip_if_new_api.rb → skip_if_test.rb} +12 -12
- data/test/skip_setter_and_getter_test.rb +6 -6
- data/test/test_helper.rb +5 -6
- data/test/{validate_new_api.rb → validate_test.rb} +65 -78
- data/test/validation/{dry_validation_new_api.rb → dry_validation_test.rb} +124 -123
- data/test/validation/result_test.rb +14 -14
- data/test/virtual_test.rb +7 -7
- data/test/writeable_test.rb +8 -8
- metadata +35 -68
- data/Appraisals +0 -8
- data/gemfiles/0.13.0.gemfile +0 -8
- data/gemfiles/1.5.0.gemfile +0 -9
- data/lib/reform/form/dry/new_api.rb +0 -45
- data/lib/reform/form/dry/old_api.rb +0 -61
- data/test/call_new_api.rb +0 -23
- data/test/call_old_api.rb +0 -23
- data/test/composition_old_api.rb +0 -184
- data/test/contract_old_api.rb +0 -77
- data/test/errors_old_api.rb +0 -230
- data/test/fixtures/dry_new_api_error_messages.yml +0 -104
- data/test/form_old_api.rb +0 -57
- data/test/form_option_old_api.rb +0 -24
- data/test/inherit_old_api.rb +0 -105
- data/test/module_old_api.rb +0 -146
- data/test/populate_old_api.rb +0 -304
- data/test/reform_old_api.rb +0 -202
- data/test/save_old_api.rb +0 -101
- data/test/skip_if_old_api.rb +0 -92
- data/test/validate_old_api.rb +0 -410
- data/test/validation/dry_validation_old_api.rb +0 -772
@@ -11,10 +11,10 @@ class ErrorsResultTest < Minitest::Spec
|
|
11
11
|
let(:failed) { MyResult.new(false) }
|
12
12
|
let(:succeeded) { MyResult.new(true) }
|
13
13
|
|
14
|
-
it {
|
15
|
-
it {
|
16
|
-
it {
|
17
|
-
it {
|
14
|
+
it { assert_equal Reform::Contract::Result.new([failed, failed]).success?, false }
|
15
|
+
it { assert_equal Reform::Contract::Result.new([succeeded, failed]).success?, false }
|
16
|
+
it { assert_equal Reform::Contract::Result.new([failed, succeeded]).success?, false }
|
17
|
+
it { assert Reform::Contract::Result.new([succeeded, succeeded]).success? }
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "Contract::Result#errors" do
|
@@ -27,7 +27,7 @@ class ErrorsResultTest < Minitest::Spec
|
|
27
27
|
]
|
28
28
|
end
|
29
29
|
|
30
|
-
it {
|
30
|
+
it { assert_equal Reform::Contract::Result.new(results).errors, {title: ["must be filled", "something more"], length: ["no Int"]} }
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "Result::Pointer" do
|
@@ -44,24 +44,24 @@ class ErrorsResultTest < Minitest::Spec
|
|
44
44
|
end
|
45
45
|
|
46
46
|
let(:top) { Reform::Contract::Result::Pointer.new(MyResult.new(false, errors), []) }
|
47
|
-
it {
|
48
|
-
it {
|
47
|
+
it { assert_equal top.success?, false }
|
48
|
+
it { assert_equal top.errors, errors }
|
49
49
|
|
50
50
|
let(:artist) { Reform::Contract::Result::Pointer.new(MyResult.new(false, errors), [:artist]) }
|
51
|
-
it {
|
52
|
-
it {
|
51
|
+
it { assert_equal artist.success?, false }
|
52
|
+
it { assert_equal artist.errors,({age: ["too old"], bands: {0 => {name: "too new school"}, 1 => {name: "too boring"}}}) }
|
53
53
|
|
54
54
|
let(:band) { Reform::Contract::Result::Pointer.new(MyResult.new(false, errors), [:artist, :bands, 1]) }
|
55
|
-
it {
|
56
|
-
it {
|
55
|
+
it { assert_equal band.success?, false }
|
56
|
+
it { assert_equal band.errors,({name: "too boring"}) }
|
57
57
|
|
58
58
|
describe "advance" do
|
59
59
|
let(:advanced) { artist.advance(:bands, 1) }
|
60
60
|
|
61
|
-
it {
|
62
|
-
it {
|
61
|
+
it { assert_equal advanced.success?, false }
|
62
|
+
it { assert_equal advanced.errors,({name: "too boring"}) }
|
63
63
|
|
64
|
-
it {
|
64
|
+
it { assert_nil artist.advance(%i[absolute nonsense]) }
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
data/test/virtual_test.rb
CHANGED
@@ -13,8 +13,8 @@ class VirtualTest < MiniTest::Spec
|
|
13
13
|
it {
|
14
14
|
form.validate(credit_card_number: "123", transactions: [id: 1])
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
assert_equal form.credit_card_number, "123" # this is still readable in the UI.
|
17
|
+
assert_equal form.transactions.first.id, 1 # this is still readable in the UI.
|
18
18
|
|
19
19
|
form.sync
|
20
20
|
|
@@ -23,7 +23,7 @@ class VirtualTest < MiniTest::Spec
|
|
23
23
|
hash = nested
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
assert_equal hash, "credit_card_number" => "123", "transactions" => ["id" => 1]
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
@@ -49,16 +49,16 @@ class VirtualAndDefaultTest < MiniTest::Spec
|
|
49
49
|
form = CreditCardForm.new(Object.new)
|
50
50
|
form.validate({})
|
51
51
|
|
52
|
-
|
52
|
+
assert_equal hash(form), "credit_card_number" => "123", "transactions" => ["id" => 2]
|
53
53
|
|
54
54
|
form = CreditCardForm.new(Object.new)
|
55
55
|
form.validate(credit_card_number: "123", transactions: [id: 1])
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
assert_equal form.credit_card_number, "123" # this is still readable in the UI.
|
58
|
+
assert_equal form.transactions.first.id, 1 # this is still readable in the UI.
|
59
59
|
|
60
60
|
form.sync
|
61
61
|
|
62
|
-
|
62
|
+
assert_equal hash(form), "credit_card_number" => "123", "transactions" => ["id" => 1]
|
63
63
|
}
|
64
64
|
end
|
data/test/writeable_test.rb
CHANGED
@@ -11,20 +11,20 @@ class WriteableTest < MiniTest::Spec
|
|
11
11
|
let(:form) { LocationForm.new(loc) }
|
12
12
|
|
13
13
|
it do
|
14
|
-
|
14
|
+
assert_equal form.country, "Australia"
|
15
15
|
|
16
16
|
form.validate("country" => "Germany") # this usually won't change when submitting.
|
17
|
-
|
17
|
+
assert_equal form.country, "Germany"
|
18
18
|
|
19
19
|
form.sync
|
20
|
-
|
20
|
+
assert_equal loc.country, "Australia" # the writer wasn't called.
|
21
21
|
|
22
22
|
hash = {}
|
23
23
|
form.save do |nested|
|
24
24
|
hash = nested
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
assert_equal hash, "country" => "Germany"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -40,19 +40,19 @@ class WritableTest < MiniTest::Spec
|
|
40
40
|
let(:form) { LocationForm.new(loc) }
|
41
41
|
|
42
42
|
it do
|
43
|
-
|
43
|
+
assert_equal form.country, "Australia"
|
44
44
|
|
45
45
|
form.validate("country" => "Germany") # this usually won't change when submitting.
|
46
|
-
|
46
|
+
assert_equal form.country, "Germany"
|
47
47
|
|
48
48
|
form.sync
|
49
|
-
|
49
|
+
assert_equal loc.country, "Australia" # the writer wasn't called.
|
50
50
|
|
51
51
|
hash = {}
|
52
52
|
form.save do |nested|
|
53
53
|
hash = nested
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
assert_equal hash, "country" => "Germany"
|
57
57
|
end
|
58
58
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
- Fran Worley
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: disposable
|
@@ -159,7 +159,6 @@ extra_rdoc_files: []
|
|
159
159
|
files:
|
160
160
|
- ".gitignore"
|
161
161
|
- ".travis.yml"
|
162
|
-
- Appraisals
|
163
162
|
- CHANGES.md
|
164
163
|
- CONTRIBUTING.md
|
165
164
|
- Gemfile
|
@@ -168,8 +167,6 @@ files:
|
|
168
167
|
- README.md
|
169
168
|
- Rakefile
|
170
169
|
- TODO.md
|
171
|
-
- gemfiles/0.13.0.gemfile
|
172
|
-
- gemfiles/1.5.0.gemfile
|
173
170
|
- lib/reform.rb
|
174
171
|
- lib/reform/contract.rb
|
175
172
|
- lib/reform/contract/custom_error.rb
|
@@ -181,8 +178,6 @@ files:
|
|
181
178
|
- lib/reform/form/composition.rb
|
182
179
|
- lib/reform/form/dry.rb
|
183
180
|
- lib/reform/form/dry/input_hash.rb
|
184
|
-
- lib/reform/form/dry/new_api.rb
|
185
|
-
- lib/reform/form/dry/old_api.rb
|
186
181
|
- lib/reform/form/module.rb
|
187
182
|
- lib/reform/form/populator.rb
|
188
183
|
- lib/reform/form/prepopulate.rb
|
@@ -193,52 +188,38 @@ files:
|
|
193
188
|
- lib/reform/version.rb
|
194
189
|
- reform.gemspec
|
195
190
|
- test/benchmarking.rb
|
196
|
-
- test/
|
197
|
-
- test/call_old_api.rb
|
191
|
+
- test/call_test.rb
|
198
192
|
- test/changed_test.rb
|
199
193
|
- test/coercion_test.rb
|
200
|
-
- test/
|
201
|
-
- test/composition_old_api.rb
|
194
|
+
- test/composition_test.rb
|
202
195
|
- test/contract/custom_error_test.rb
|
203
|
-
- test/
|
204
|
-
- test/contract_old_api.rb
|
196
|
+
- test/contract_test.rb
|
205
197
|
- test/default_test.rb
|
206
198
|
- test/deserialize_test.rb
|
207
|
-
- test/
|
208
|
-
- test/
|
199
|
+
- test/docs/validation_test.rb
|
200
|
+
- test/errors_test.rb
|
209
201
|
- test/feature_test.rb
|
210
202
|
- test/fixtures/dry_error_messages.yml
|
211
|
-
- test/
|
212
|
-
- test/
|
213
|
-
- test/form_old_api.rb
|
214
|
-
- test/form_option_new_api.rb
|
215
|
-
- test/form_option_old_api.rb
|
203
|
+
- test/form_option_test.rb
|
204
|
+
- test/form_test.rb
|
216
205
|
- test/from_test.rb
|
217
|
-
- test/
|
218
|
-
- test/
|
219
|
-
- test/module_new_api.rb
|
220
|
-
- test/module_old_api.rb
|
206
|
+
- test/inherit_test.rb
|
207
|
+
- test/module_test.rb
|
221
208
|
- test/parse_option_test.rb
|
222
209
|
- test/parse_pipeline_test.rb
|
223
|
-
- test/
|
224
|
-
- test/populate_old_api.rb
|
210
|
+
- test/populate_test.rb
|
225
211
|
- test/populator_skip_test.rb
|
226
212
|
- test/prepopulator_test.rb
|
227
213
|
- test/read_only_test.rb
|
228
214
|
- test/readable_test.rb
|
229
|
-
- test/
|
230
|
-
- test/
|
231
|
-
- test/save_new_api.rb
|
232
|
-
- test/save_old_api.rb
|
215
|
+
- test/reform_test.rb
|
216
|
+
- test/save_test.rb
|
233
217
|
- test/setup_test.rb
|
234
|
-
- test/
|
235
|
-
- test/skip_if_old_api.rb
|
218
|
+
- test/skip_if_test.rb
|
236
219
|
- test/skip_setter_and_getter_test.rb
|
237
220
|
- test/test_helper.rb
|
238
|
-
- test/
|
239
|
-
- test/
|
240
|
-
- test/validation/dry_validation_new_api.rb
|
241
|
-
- test/validation/dry_validation_old_api.rb
|
221
|
+
- test/validate_test.rb
|
222
|
+
- test/validation/dry_validation_test.rb
|
242
223
|
- test/validation/result_test.rb
|
243
224
|
- test/validation_library_provided_test.rb
|
244
225
|
- test/virtual_test.rb
|
@@ -247,7 +228,7 @@ homepage: https://github.com/trailblazer/reform
|
|
247
228
|
licenses:
|
248
229
|
- MIT
|
249
230
|
metadata: {}
|
250
|
-
post_install_message:
|
231
|
+
post_install_message:
|
251
232
|
rdoc_options: []
|
252
233
|
require_paths:
|
253
234
|
- lib
|
@@ -263,57 +244,43 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
263
244
|
version: '0'
|
264
245
|
requirements: []
|
265
246
|
rubygems_version: 3.0.3
|
266
|
-
signing_key:
|
247
|
+
signing_key:
|
267
248
|
specification_version: 4
|
268
249
|
summary: Form object decoupled from models with validation, population and presentation.
|
269
250
|
test_files:
|
270
251
|
- test/benchmarking.rb
|
271
|
-
- test/
|
272
|
-
- test/call_old_api.rb
|
252
|
+
- test/call_test.rb
|
273
253
|
- test/changed_test.rb
|
274
254
|
- test/coercion_test.rb
|
275
|
-
- test/
|
276
|
-
- test/composition_old_api.rb
|
255
|
+
- test/composition_test.rb
|
277
256
|
- test/contract/custom_error_test.rb
|
278
|
-
- test/
|
279
|
-
- test/contract_old_api.rb
|
257
|
+
- test/contract_test.rb
|
280
258
|
- test/default_test.rb
|
281
259
|
- test/deserialize_test.rb
|
282
|
-
- test/
|
283
|
-
- test/
|
260
|
+
- test/docs/validation_test.rb
|
261
|
+
- test/errors_test.rb
|
284
262
|
- test/feature_test.rb
|
285
263
|
- test/fixtures/dry_error_messages.yml
|
286
|
-
- test/
|
287
|
-
- test/
|
288
|
-
- test/form_old_api.rb
|
289
|
-
- test/form_option_new_api.rb
|
290
|
-
- test/form_option_old_api.rb
|
264
|
+
- test/form_option_test.rb
|
265
|
+
- test/form_test.rb
|
291
266
|
- test/from_test.rb
|
292
|
-
- test/
|
293
|
-
- test/
|
294
|
-
- test/module_new_api.rb
|
295
|
-
- test/module_old_api.rb
|
267
|
+
- test/inherit_test.rb
|
268
|
+
- test/module_test.rb
|
296
269
|
- test/parse_option_test.rb
|
297
270
|
- test/parse_pipeline_test.rb
|
298
|
-
- test/
|
299
|
-
- test/populate_old_api.rb
|
271
|
+
- test/populate_test.rb
|
300
272
|
- test/populator_skip_test.rb
|
301
273
|
- test/prepopulator_test.rb
|
302
274
|
- test/read_only_test.rb
|
303
275
|
- test/readable_test.rb
|
304
|
-
- test/
|
305
|
-
- test/
|
306
|
-
- test/save_new_api.rb
|
307
|
-
- test/save_old_api.rb
|
276
|
+
- test/reform_test.rb
|
277
|
+
- test/save_test.rb
|
308
278
|
- test/setup_test.rb
|
309
|
-
- test/
|
310
|
-
- test/skip_if_old_api.rb
|
279
|
+
- test/skip_if_test.rb
|
311
280
|
- test/skip_setter_and_getter_test.rb
|
312
281
|
- test/test_helper.rb
|
313
|
-
- test/
|
314
|
-
- test/
|
315
|
-
- test/validation/dry_validation_new_api.rb
|
316
|
-
- test/validation/dry_validation_old_api.rb
|
282
|
+
- test/validate_test.rb
|
283
|
+
- test/validation/dry_validation_test.rb
|
317
284
|
- test/validation/result_test.rb
|
318
285
|
- test/validation_library_provided_test.rb
|
319
286
|
- test/virtual_test.rb
|
data/Appraisals
DELETED
data/gemfiles/0.13.0.gemfile
DELETED
data/gemfiles/1.5.0.gemfile
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
::Dry::Validation.load_extensions(:hints)
|
2
|
-
|
3
|
-
module Reform::Form::Dry
|
4
|
-
module NewApi
|
5
|
-
|
6
|
-
class Contract < ::Dry::Validation::Contract
|
7
|
-
end
|
8
|
-
|
9
|
-
module Validations
|
10
|
-
module ClassMethods
|
11
|
-
def validation_group_class
|
12
|
-
Group
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.included(includer)
|
17
|
-
includer.extend(ClassMethods)
|
18
|
-
end
|
19
|
-
|
20
|
-
class Group
|
21
|
-
include InputHash
|
22
|
-
|
23
|
-
def initialize(**options)
|
24
|
-
@validator = options.fetch(:contract, Contract)
|
25
|
-
@schema_inject_params = options.fetch(:with, {})
|
26
|
-
end
|
27
|
-
|
28
|
-
attr_reader :validator, :schema_inject_params, :block
|
29
|
-
|
30
|
-
def instance_exec(&block)
|
31
|
-
@block = block
|
32
|
-
end
|
33
|
-
|
34
|
-
def call(form)
|
35
|
-
return validator.call(input_hash(form)) unless validator.is_a?(Class) && @validator <= ::Dry::Validation::Contract
|
36
|
-
|
37
|
-
dynamic_options = { form: form }
|
38
|
-
inject_options = schema_inject_params.merge(dynamic_options)
|
39
|
-
|
40
|
-
validator.build(inject_options, &block).call(input_hash(form))
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
module Reform::Form::Dry
|
2
|
-
module OldApi
|
3
|
-
class Schema < Dry::Validation::Schema
|
4
|
-
end
|
5
|
-
|
6
|
-
module Validations
|
7
|
-
module ClassMethods
|
8
|
-
def validation_group_class
|
9
|
-
Group
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.included(includer)
|
14
|
-
includer.extend(ClassMethods)
|
15
|
-
end
|
16
|
-
|
17
|
-
class Group
|
18
|
-
include InputHash
|
19
|
-
|
20
|
-
def initialize(options = {})
|
21
|
-
options ||= {}
|
22
|
-
schema_class = options[:schema] || Reform::Form::Dry::OldApi::Schema
|
23
|
-
@validator = Dry::Validation.Schema(schema_class, build: false)
|
24
|
-
|
25
|
-
@schema_inject_params = options[:with] || {}
|
26
|
-
end
|
27
|
-
|
28
|
-
def instance_exec(&block)
|
29
|
-
@validator = Dry::Validation.Schema(@validator, build: false, &block)
|
30
|
-
# inject the keys into the configure block automatically
|
31
|
-
keys = @schema_inject_params.keys
|
32
|
-
@validator.class_eval do
|
33
|
-
configure do
|
34
|
-
keys.each { |k| option k }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def call(form)
|
40
|
-
dynamic_options = {}
|
41
|
-
dynamic_options[:form] = form if @schema_inject_params[:form]
|
42
|
-
inject_options = @schema_inject_params.merge(dynamic_options)
|
43
|
-
|
44
|
-
# TODO: only pass submitted values to Schema#call?
|
45
|
-
dry_result = call_schema(inject_options, input_hash(form))
|
46
|
-
# dry_messages = dry_result.messages
|
47
|
-
|
48
|
-
return dry_result
|
49
|
-
|
50
|
-
_reform_errors = Reform::Contract::Errors.new(dry_result) # TODO: dry should be merged here.
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def call_schema(inject_options, input)
|
56
|
-
@validator.new(@validator.rules, inject_options).(input)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|