reform 2.3.0.rc2 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -1
- data/.travis.yml +5 -21
- data/Appraisals +8 -0
- data/CHANGES.md +5 -0
- data/Gemfile +1 -7
- data/LICENSE.txt +1 -1
- data/Rakefile +2 -2
- data/gemfiles/0.13.0.gemfile +8 -0
- data/gemfiles/1.5.0.gemfile +9 -0
- data/lib/reform/form/dry/new_api.rb +12 -24
- data/lib/reform/version.rb +1 -1
- data/reform.gemspec +1 -1
- data/test/test_helper.rb +1 -1
- data/test/validation/dry_validation_new_api.rb +22 -12
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f22b2268e248120b5738d5387d464d8563d661d6749a6c371ed1172d9c3fb18b
|
4
|
+
data.tar.gz: 534162094e74586a1c73634f1394f8ef8f37bb79b970c7003d37773c1f2109a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1f26ff2eb879a16cea3a230fb0fccf97525cf72321941b48312d47ed47e5a9759f67e44c9cd68057adf020ec0374706ae4991b9b29141b46ee963ef4e218d31
|
7
|
+
data.tar.gz: 77c4f8dc39bb7616e12b2b8c74f3f45e0b9285bd95dcc0a9a7206e35905c1b4ef956ab87eef49b20b87efc322578e047caa0f84cc30024ff236320af93764308
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -3,30 +3,14 @@ cache: bundler
|
|
3
3
|
bundler_args: --without benchmarks tools
|
4
4
|
rvm:
|
5
5
|
- ruby-head
|
6
|
+
- 2.7
|
7
|
+
- 2.6
|
6
8
|
- 2.5
|
7
9
|
- 2.4
|
8
|
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
- "DRY_VALIDATION='~> 1.1.0'"
|
12
|
-
- "DRY_VALIDATION='~> 1.0.0'"
|
13
|
-
- "DRY_VALIDATION='~> 0.13.0'"
|
14
|
-
- "DRY_VALIDATION='~> 0.12.0'"
|
10
|
+
gemfile:
|
11
|
+
- gemfiles/1.5.0.gemfile
|
12
|
+
- gemfiles/0.13.0.gemfile
|
15
13
|
matrix:
|
16
14
|
fast_finish: true
|
17
15
|
allow_failures:
|
18
16
|
- rvm: ruby-head
|
19
|
-
include:
|
20
|
-
- { rvm: 2.2, env: "DRY_VALIDATION='~> 0.11.0'" }
|
21
|
-
- { rvm: 2.3, env: "DRY_VALIDATION='~> 0.12.0'" }
|
22
|
-
- { rvm: 2.3, env: "DRY_VALIDATION='~> 0.13.0'" }
|
23
|
-
|
24
|
-
|
25
|
-
# maybe move this to slack in a private channel
|
26
|
-
# notifications:
|
27
|
-
# webhooks:
|
28
|
-
# urls:
|
29
|
-
# - https://webhooks.gitter.im/e/680e86d98056f2ae2fd7
|
30
|
-
# on_success: change # options: [always|never|change] default: always
|
31
|
-
# on_failure: always # options: [always|never|change] default: always
|
32
|
-
# on_start: never # options: [always|never|change] default: always
|
data/Appraisals
ADDED
data/CHANGES.md
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
[* Removed `Reform::Contract` ?]
|
4
4
|
[* Move Form#deserializer to Form::deserializer]
|
5
5
|
|
6
|
+
## 2.3.1
|
7
|
+
* With dry-validation 1.5 the form is always injected. Just add option :form to access it in the schema.
|
8
|
+
* Removed global monkey patching of Dry::Schema::DSL
|
9
|
+
* Tests in ruby 2.7
|
10
|
+
|
6
11
|
## 2.3.0
|
7
12
|
|
8
13
|
You can upgrade from 2.2.0 without worries.
|
data/Gemfile
CHANGED
@@ -2,10 +2,4 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
# just trying to add `dry-monads` correct version in base on dry-validation
|
8
|
-
dry_v_version = ENV.fetch('DRY_VALIDATION', '~> 0.13.0')
|
9
|
-
dry_m_version = "~> #{dry_v_version.gsub("~>", "").to_f}.0"
|
10
|
-
gem 'dry-monads', dry_m_version if dry_v_version.gsub("~>", "").to_f >= 1
|
11
|
-
gem 'dry-validation', ENV.fetch('DRY_VALIDATION', '~> 0.13.0')
|
5
|
+
gem "appraisal", "~> 2.2"
|
data/LICENSE.txt
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rake/testtask"
|
3
3
|
require "rubocop/rake_task"
|
4
|
+
require "dry/types/version"
|
4
5
|
|
5
6
|
task default: %i[test]
|
6
7
|
|
@@ -10,8 +11,7 @@ TEST_WITH_OLD_AND_NEW_API = %w[
|
|
10
11
|
].freeze
|
11
12
|
|
12
13
|
def dry_v_test_files
|
13
|
-
|
14
|
-
api = dry_v_version.gsub("~>", "").to_f >= 1.0 ? "new" : "old"
|
14
|
+
api = Gem::Version.new(Dry::Types::VERSION).to_s.split('.').first.to_i >= 1 ? "new" : "old"
|
15
15
|
TEST_WITH_OLD_AND_NEW_API.map { |file| "test/#{file}_#{api}_api.rb" }
|
16
16
|
end
|
17
17
|
|
@@ -1,6 +1,9 @@
|
|
1
|
+
::Dry::Validation.load_extensions(:hints)
|
2
|
+
|
1
3
|
module Reform::Form::Dry
|
2
4
|
module NewApi
|
3
|
-
|
5
|
+
|
6
|
+
class Contract < ::Dry::Validation::Contract
|
4
7
|
end
|
5
8
|
|
6
9
|
module Validations
|
@@ -18,39 +21,24 @@ module Reform::Form::Dry
|
|
18
21
|
include InputHash
|
19
22
|
|
20
23
|
def initialize(options = {})
|
21
|
-
options
|
22
|
-
@
|
23
|
-
|
24
|
-
@schema_inject_params = options[:with] || {}
|
24
|
+
@validator = options.fetch(:schema, Contract)
|
25
|
+
@schema_inject_params = options.fetch(:with, {})
|
25
26
|
end
|
26
27
|
|
27
28
|
def instance_exec(&block)
|
28
|
-
Dry::Validation.load_extensions(:hints)
|
29
29
|
@block = block
|
30
30
|
end
|
31
31
|
|
32
32
|
def call(form)
|
33
|
-
dynamic_options = {}
|
34
|
-
dynamic_options[:form] = form if @schema_inject_params[:form]
|
35
|
-
inject_options = @schema_inject_params.merge(dynamic_options)
|
36
|
-
|
37
|
-
Dry::Schema::DSL.class_eval do
|
38
|
-
inject_options.each do |key, value|
|
39
|
-
define_method(key) { value }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
33
|
# when passing options[:schema] the class instance is already created so we just need to call
|
44
34
|
# "call"
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
return dry_result
|
35
|
+
if @validator.is_a?(Class) && @validator <= ::Dry::Validation::Contract
|
36
|
+
dynamic_options = {form: form}
|
37
|
+
inject_options = @schema_inject_params.merge(dynamic_options)
|
38
|
+
@validator = @validator.build(inject_options, &@block)
|
39
|
+
end
|
52
40
|
|
53
|
-
|
41
|
+
@validator.call(input_hash(form))
|
54
42
|
end
|
55
43
|
end
|
56
44
|
end
|
data/lib/reform/version.rb
CHANGED
data/reform.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler"
|
25
25
|
spec.add_development_dependency "minitest"
|
26
26
|
spec.add_development_dependency "minitest-line"
|
27
|
-
spec.add_development_dependency "byebug"
|
27
|
+
spec.add_development_dependency "pry-byebug"
|
28
28
|
spec.add_development_dependency "multi_json"
|
29
29
|
spec.add_development_dependency "rake"
|
30
30
|
spec.add_development_dependency "rubocop"
|
data/test/test_helper.rb
CHANGED
@@ -73,21 +73,21 @@ class DryValidationErrorsAPITest < Minitest::Spec
|
|
73
73
|
form.to_result.hints.must_equal(title: ["size cannot be less than 2"])
|
74
74
|
form.artist.to_result.errors.must_equal(email: ["must be filled"])
|
75
75
|
form.artist.to_result.messages.must_equal(email: ["must be filled"])
|
76
|
-
form.artist.to_result.hints.must_equal(
|
76
|
+
form.artist.to_result.hints.must_equal({})
|
77
77
|
form.artist.label.to_result.errors.must_equal(location: ["must be filled"])
|
78
78
|
form.artist.label.to_result.messages.must_equal(location: ["must be filled"])
|
79
|
-
form.artist.label.to_result.hints.must_equal(
|
79
|
+
form.artist.label.to_result.hints.must_equal({})
|
80
80
|
form.songs[0].to_result.errors.must_equal({})
|
81
81
|
form.songs[0].to_result.messages.must_equal({})
|
82
82
|
form.songs[0].to_result.hints.must_equal({})
|
83
83
|
form.songs[1].to_result.errors.must_equal(title: ["must be filled"])
|
84
84
|
form.songs[1].to_result.messages.must_equal(title: ["must be filled"])
|
85
|
-
form.songs[1].to_result.hints.must_equal(
|
85
|
+
form.songs[1].to_result.hints.must_equal({})
|
86
86
|
form.songs[1].to_result.errors(locale: :de).must_equal(title: ["muss abgefüllt sein"])
|
87
87
|
# seems like dry-v when calling Dry::Schema::Result#messages locale option is ignored
|
88
88
|
# started a topic in their forum https://discourse.dry-rb.org/t/dry-result-messages-ignore-locale-option/910
|
89
89
|
# form.songs[1].to_result.messages(locale: :de).must_equal(title: ["muss abgefüllt sein"])
|
90
|
-
form.songs[1].to_result.hints(locale: :de).must_equal(
|
90
|
+
form.songs[1].to_result.hints(locale: :de).must_equal({})
|
91
91
|
end
|
92
92
|
|
93
93
|
it "only nested property is invalid." do
|
@@ -195,8 +195,14 @@ class DryValidationDefaultGroupTest < Minitest::Spec
|
|
195
195
|
params { required(:confirm_password).filled }
|
196
196
|
end
|
197
197
|
|
198
|
-
validation name: :dynamic_args
|
199
|
-
|
198
|
+
validation name: :dynamic_args do
|
199
|
+
option :form
|
200
|
+
params { optional(:color) }
|
201
|
+
rule(:color) do
|
202
|
+
if value
|
203
|
+
key.failure("must be one of: #{form.colors}") unless form.colors.include? value
|
204
|
+
end
|
205
|
+
end
|
200
206
|
end
|
201
207
|
|
202
208
|
def colors
|
@@ -208,15 +214,15 @@ class DryValidationDefaultGroupTest < Minitest::Spec
|
|
208
214
|
|
209
215
|
# valid.
|
210
216
|
it do
|
211
|
-
form.validate(
|
217
|
+
assert form.validate(
|
212
218
|
username: "Helloween",
|
213
219
|
email: "yep",
|
214
220
|
starts_at: "01/01/2000 - 11:00",
|
215
221
|
active: "true",
|
216
222
|
confirm_password: "pA55w0rd"
|
217
|
-
)
|
218
|
-
form.active
|
219
|
-
form.errors.messages.inspect
|
223
|
+
)
|
224
|
+
assert form.active
|
225
|
+
assert_equal "{}", form.errors.messages.inspect
|
220
226
|
end
|
221
227
|
|
222
228
|
it "invalid" do
|
@@ -309,8 +315,12 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
309
315
|
property :username
|
310
316
|
|
311
317
|
validation name: :default, with: {user: OpenStruct.new(name: "Nick")} do
|
318
|
+
option :user
|
312
319
|
params do
|
313
|
-
required(:username).filled
|
320
|
+
required(:username).filled
|
321
|
+
end
|
322
|
+
rule(:username) do
|
323
|
+
key.failure("must be equal to #{user.name}") unless user.name == value
|
314
324
|
end
|
315
325
|
end
|
316
326
|
end
|
@@ -471,7 +481,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
471
481
|
# TODO: use the same form structure as the top one and do the same test against messages, errors and hints.
|
472
482
|
form.producers[0].to_result.errors.must_equal(name: ["must be filled"])
|
473
483
|
form.producers[0].to_result.messages.must_equal(name: ["must be filled"])
|
474
|
-
form.producers[0].to_result.hints.must_equal(
|
484
|
+
form.producers[0].to_result.hints.must_equal({})
|
475
485
|
end
|
476
486
|
|
477
487
|
# FIXME: fix the "must be filled error"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: disposable
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
-
name: byebug
|
111
|
+
name: pry-byebug
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - ">="
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- ".rubocop.yml"
|
176
176
|
- ".rubocop_todo.yml"
|
177
177
|
- ".travis.yml"
|
178
|
+
- Appraisals
|
178
179
|
- CHANGES.md
|
179
180
|
- CONTRIBUTING.md
|
180
181
|
- Gemfile
|
@@ -183,6 +184,8 @@ files:
|
|
183
184
|
- README.md
|
184
185
|
- Rakefile
|
185
186
|
- TODO.md
|
187
|
+
- gemfiles/0.13.0.gemfile
|
188
|
+
- gemfiles/1.5.0.gemfile
|
186
189
|
- lib/reform.rb
|
187
190
|
- lib/reform/contract.rb
|
188
191
|
- lib/reform/contract/custom_error.rb
|
@@ -271,12 +274,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
271
274
|
version: '0'
|
272
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
273
276
|
requirements:
|
274
|
-
- - "
|
277
|
+
- - ">="
|
275
278
|
- !ruby/object:Gem::Version
|
276
|
-
version:
|
279
|
+
version: '0'
|
277
280
|
requirements: []
|
278
|
-
|
279
|
-
rubygems_version: 2.6.14.3
|
281
|
+
rubygems_version: 3.0.6
|
280
282
|
signing_key:
|
281
283
|
specification_version: 4
|
282
284
|
summary: Form object decoupled from models with validation, population and presentation.
|