reform 2.1.0.rc1 → 2.1.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/CHANGES.md +13 -4
- data/Gemfile +1 -2
- data/database.sqlite3 +0 -0
- data/lib/reform/contract.rb +2 -0
- data/lib/reform/contract/errors.rb +43 -0
- data/lib/reform/form/active_model/validations.rb +5 -2
- data/lib/reform/form/dry.rb +5 -6
- data/lib/reform/version.rb +1 -1
- data/reform.gemspec +2 -2
- data/test/fixtures/dry_error_messages.yml +2 -1
- data/test/reform_test.rb +1 -1
- data/test/validation/dry_validation_test.rb +8 -8
- metadata +9 -9
- data/lib/reform/form/active_model/errors.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22e0b3849f8a705c51f5e805dfaca960279b8d3d
|
4
|
+
data.tar.gz: 1fa928b3309dcca60a1c5801a58acca34d7996ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5daaf2a361ee1a200b7d300f926ff6e4acf7503d73b5b3dcde106201d9b6bcf8a015ba4472ba5496a67af48af7be7bd4879d6afa6ed2cee649ec776ec437afea
|
7
|
+
data.tar.gz: 1adf91b4dfd4de9e14871b7f56953cd83ce765d6d1576858314ba4416f9c15c0d9eaad57b26b450345c8d4420ffd3ff524b67df210665d9f4268f4484a9b8894
|
data/CHANGES.md
CHANGED
@@ -1,15 +1,24 @@
|
|
1
|
-
## 2.1
|
1
|
+
## 2.1.0
|
2
|
+
|
3
|
+
You should be able to upgrade from 2.0 without any code changes.
|
2
4
|
|
3
5
|
### Awesomeness
|
4
6
|
|
5
7
|
* You can now have `:populator` for scalar properties, too. This allows "parsing code" per property which is super helpful to structure your deserialization.
|
6
8
|
* `:populator` can be a method name, as in `populator: :populate_authors!`.
|
7
|
-
* Populators can now skip deserialization of a nested fragment using `skip!`. [Learn more here](http://trailblazer.to/gems/reform/populator.html).
|
8
|
-
* Added
|
9
|
+
* Populators can now skip deserialization of a nested fragment using `skip!`. [Learn more here](http://trailblazer.to/gems/reform/populator.html#skip).
|
10
|
+
* Added support for dry-validation as a future replacement for ActiveModel::Validation. Note that this is still experimental, but works great.
|
11
|
+
* Added validation groups.
|
12
|
+
|
13
|
+
### Changes
|
9
14
|
|
10
|
-
* :populator ->(options) or
|
15
|
+
* All lambda APIs change (with deprecation): `populator: ->(options)` or `->(fragment:, model:, **o)` where we only receive one hash instead of a varying number or arguments. This is pretty cool and should be listed under _Awesomeness_.
|
11
16
|
* `ActiveModel::Validator` prevents Rails from adding methods to it. This makes `acceptance` and `confirmation` validations work properly.
|
12
17
|
|
18
|
+
### Notes
|
19
|
+
|
20
|
+
* Please be warned that we will drop support for `ActiveModel::Validations` from 2.2 onwards. Don't worry, it will still work, but we don't want to work with it anymore.
|
21
|
+
|
13
22
|
## 2.0.5
|
14
23
|
|
15
24
|
* `ActiveModel::Validator` now delegates all methods properly to the form. It used to crashed with properties called `format` or other private `Object` methods.
|
data/Gemfile
CHANGED
data/database.sqlite3
CHANGED
Binary file
|
data/lib/reform/contract.rb
CHANGED
@@ -33,6 +33,7 @@ module Reform
|
|
33
33
|
args.each { |name| property(name, options.dup) }
|
34
34
|
end
|
35
35
|
|
36
|
+
require "reform/contract/errors"
|
36
37
|
require 'reform/contract/validate'
|
37
38
|
include Reform::Contract::Validate
|
38
39
|
|
@@ -40,6 +41,7 @@ module Reform
|
|
40
41
|
include Reform::Validation # ::validates and #valid?
|
41
42
|
|
42
43
|
|
44
|
+
|
43
45
|
# module ValidatesWarning
|
44
46
|
# def validates(*)
|
45
47
|
# raise "[Reform] Please include either Reform::Form::ActiveModel::Validations or Reform::Form::Lotus in your form class."
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Reform::Contract::Errors
|
2
|
+
def initialize(*)
|
3
|
+
@errors = {}
|
4
|
+
end
|
5
|
+
|
6
|
+
module Merge
|
7
|
+
def merge!(errors, prefix)
|
8
|
+
errors.messages.each do |field, msgs|
|
9
|
+
unless field.to_sym == :base
|
10
|
+
field = (prefix+[field]).join(".").to_sym # TODO: why is that a symbol in Rails?
|
11
|
+
end
|
12
|
+
|
13
|
+
msgs.each do |msg|
|
14
|
+
next if messages[field] and messages[field].include?(msg)
|
15
|
+
add(field, msg)
|
16
|
+
end # Forms now contains a plain errors hash. the errors for each item are still available in item.errors.
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
messages.inspect
|
22
|
+
end
|
23
|
+
end
|
24
|
+
include Merge
|
25
|
+
|
26
|
+
def add(field, message)
|
27
|
+
@errors[field] ||= []
|
28
|
+
@errors[field] << message
|
29
|
+
end
|
30
|
+
|
31
|
+
def messages
|
32
|
+
@errors
|
33
|
+
end
|
34
|
+
|
35
|
+
def empty?
|
36
|
+
@errors.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
# needed by Rails form builder.
|
40
|
+
def [](name)
|
41
|
+
@errors[name] || []
|
42
|
+
end
|
43
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require "active_model"
|
2
|
-
require "reform/form/active_model/errors"
|
3
2
|
require "uber/delegates"
|
4
3
|
|
5
4
|
module Reform::Form::ActiveModel
|
@@ -35,7 +34,7 @@ module Reform::Form::ActiveModel
|
|
35
34
|
end
|
36
35
|
|
37
36
|
def build_errors
|
38
|
-
|
37
|
+
Errors.new(self)
|
39
38
|
end
|
40
39
|
|
41
40
|
# The concept of "composition" has still not arrived in Rails core and they rely on 400 methods being
|
@@ -101,4 +100,8 @@ module Reform::Form::ActiveModel
|
|
101
100
|
end
|
102
101
|
end
|
103
102
|
end
|
103
|
+
|
104
|
+
class Errors < ActiveModel::Errors
|
105
|
+
include Reform::Form::Errors::Merge
|
106
|
+
end
|
104
107
|
end
|
data/lib/reform/form/dry.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "dry-validation"
|
2
|
-
require "reform/validation"
|
3
2
|
require "dry/validation/schema/form"
|
3
|
+
require "reform/validation"
|
4
4
|
|
5
5
|
module Reform::Form::Dry
|
6
6
|
module Validations
|
@@ -31,11 +31,10 @@ module Reform::Form::Dry
|
|
31
31
|
def call(fields, reform_errors, form)
|
32
32
|
validator = @validator.new(form)
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
reform_errors.add(dry_error[0], attr_error[0])
|
34
|
+
# a message item looks like: {:confirm_password=>[["confirm_password size cannot be less than 2"], "9"]}
|
35
|
+
validator.call(fields).messages.each do |field, dry_error|
|
36
|
+
dry_error[0].each do |attr_error|
|
37
|
+
reform_errors.add(field, attr_error)
|
39
38
|
end
|
40
39
|
end
|
41
40
|
end
|
data/lib/reform/version.rb
CHANGED
data/reform.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "disposable", ">= 0.2.
|
20
|
+
spec.add_dependency "disposable", ">= 0.2.2", "< 0.3.0"
|
21
21
|
spec.add_dependency "uber", "~> 0.0.11"
|
22
22
|
spec.add_dependency "representable", ">= 2.4.0", "< 3.1.0"
|
23
23
|
|
@@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency "multi_json"
|
33
33
|
|
34
34
|
spec.add_development_dependency "lotus-validations"
|
35
|
-
spec.add_development_dependency "dry-validation"
|
35
|
+
spec.add_development_dependency "dry-validation", ">= 0.4.0"
|
36
36
|
spec.add_development_dependency "actionpack"
|
37
37
|
end
|
data/test/reform_test.rb
CHANGED
@@ -89,7 +89,7 @@ class ReformTest < ReformSpec
|
|
89
89
|
describe "#errors" do
|
90
90
|
before { form.validate({})}
|
91
91
|
|
92
|
-
it { form.errors.must_be_kind_of Reform::Form::Errors }
|
92
|
+
it { form.errors.must_be_kind_of Reform::Form::ActiveModel::Errors }
|
93
93
|
|
94
94
|
it { form.errors.messages.must_equal({}) }
|
95
95
|
|
@@ -59,18 +59,18 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
59
59
|
# 2nd group fails.
|
60
60
|
it do
|
61
61
|
form.validate(username: "Helloween", email: "yo", confirm_password:"9").must_equal false
|
62
|
-
form.errors.messages.inspect.must_equal "{:email=>[\"email size cannot be less than 3\"], :confirm_password=>[\"confirm_password size cannot be less than 2\"], :password=>[\"password must be filled\"]}"
|
62
|
+
form.errors.messages.inspect.must_equal "{:email=>[\"email size cannot be less than 3\"], :confirm_password=>[\"confirm_password size cannot be less than 2\"], :password=>[\"password must be filled\", \"password size cannot be less than 2\"]}"
|
63
63
|
end
|
64
64
|
# 3rd group fails.
|
65
65
|
it do
|
66
66
|
form.validate(username: "Helloween", email: "yo!", confirm_password:"9").must_equal false
|
67
67
|
form.errors.messages.inspect
|
68
|
-
.must_equal "{:confirm_password=>[\"confirm_password size cannot be less than 2\"], :password=>[\"password must be filled\"]}"
|
68
|
+
.must_equal "{:confirm_password=>[\"confirm_password size cannot be less than 2\"], :password=>[\"password must be filled\", \"password size cannot be less than 2\"]}"
|
69
69
|
end
|
70
70
|
# 4th group with after: fails.
|
71
71
|
it do
|
72
72
|
form.validate(username: "Helloween", email: "yo!", password: "", confirm_password: "9").must_equal false
|
73
|
-
form.errors.messages.inspect.must_equal "{:confirm_password=>[\"confirm_password size cannot be less than 2\"], :password=>[\"password must be filled\"]}"
|
73
|
+
form.errors.messages.inspect.must_equal "{:confirm_password=>[\"confirm_password size cannot be less than 2\"], :password=>[\"password must be filled\", \"password size cannot be less than 2\"]}"
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -104,7 +104,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
104
104
|
|
105
105
|
validation :default do
|
106
106
|
configure { |config|
|
107
|
-
config.messages_file = 'test/fixtures/dry_error_messages.yml'
|
107
|
+
# config.messages_file = 'test/fixtures/dry_error_messages.yml'
|
108
108
|
}
|
109
109
|
|
110
110
|
key(:title) do |title|
|
@@ -167,7 +167,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
167
167
|
validates(:email, &:filled?)
|
168
168
|
end
|
169
169
|
end
|
170
|
-
end.must_raise
|
170
|
+
end.must_raise(NoMethodError)
|
171
171
|
# e.message.must_equal 'validates() is not supported by Dry Validation backend.'
|
172
172
|
|
173
173
|
e = proc do
|
@@ -193,8 +193,8 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
193
193
|
validates_with(:email, &:filled?)
|
194
194
|
end
|
195
195
|
end
|
196
|
-
end.must_raise
|
197
|
-
# e.message.must_equal 'validates_with() is not supported by Dry Validation backend.'
|
196
|
+
end.must_raise(NoMethodError)
|
197
|
+
# e.message.must_equal (NoMethodError)'validates_with() is not supported by Dry Validation backend.'
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
@@ -327,4 +327,4 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
327
327
|
# form.errors.messages.inspect.must_equal "{:username=>[\"username must be filled\", \"username is not proper size\"]}"
|
328
328
|
# end
|
329
329
|
# end
|
330
|
-
end
|
330
|
+
end
|
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.1.0
|
4
|
+
version: 2.1.0
|
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: 2015-12-
|
12
|
+
date: 2015-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: disposable
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.2.
|
20
|
+
version: 0.2.2
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 0.3.0
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: 0.2.
|
30
|
+
version: 0.2.2
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.3.0
|
@@ -211,14 +211,14 @@ dependencies:
|
|
211
211
|
requirements:
|
212
212
|
- - ">="
|
213
213
|
- !ruby/object:Gem::Version
|
214
|
-
version:
|
214
|
+
version: 0.4.0
|
215
215
|
type: :development
|
216
216
|
prerelease: false
|
217
217
|
version_requirements: !ruby/object:Gem::Requirement
|
218
218
|
requirements:
|
219
219
|
- - ">="
|
220
220
|
- !ruby/object:Gem::Version
|
221
|
-
version:
|
221
|
+
version: 0.4.0
|
222
222
|
- !ruby/object:Gem::Dependency
|
223
223
|
name: actionpack
|
224
224
|
requirement: !ruby/object:Gem::Requirement
|
@@ -258,10 +258,10 @@ files:
|
|
258
258
|
- lib/reform.rb
|
259
259
|
- lib/reform/active_record.rb
|
260
260
|
- lib/reform/contract.rb
|
261
|
+
- lib/reform/contract/errors.rb
|
261
262
|
- lib/reform/contract/validate.rb
|
262
263
|
- lib/reform/form.rb
|
263
264
|
- lib/reform/form/active_model.rb
|
264
|
-
- lib/reform/form/active_model/errors.rb
|
265
265
|
- lib/reform/form/active_model/form_builder_methods.rb
|
266
266
|
- lib/reform/form/active_model/model_reflections.rb
|
267
267
|
- lib/reform/form/active_model/model_validations.rb
|
@@ -373,9 +373,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
373
373
|
version: '0'
|
374
374
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
375
375
|
requirements:
|
376
|
-
- - "
|
376
|
+
- - ">="
|
377
377
|
- !ruby/object:Gem::Version
|
378
|
-
version:
|
378
|
+
version: '0'
|
379
379
|
requirements: []
|
380
380
|
rubyforge_project:
|
381
381
|
rubygems_version: 2.4.8
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# The Errors class is planned to replace AM::Errors. It provides proper nested error messages.
|
2
|
-
class Reform::Contract::Errors < ActiveModel::Errors
|
3
|
-
def merge!(errors, prefix)
|
4
|
-
errors.messages.each do |field, msgs|
|
5
|
-
unless field.to_sym == :base
|
6
|
-
field = (prefix+[field]).join(".").to_sym # TODO: why is that a symbol in Rails?
|
7
|
-
end
|
8
|
-
|
9
|
-
msgs.each do |msg|
|
10
|
-
next if messages[field] and messages[field].include?(msg)
|
11
|
-
add(field, msg)
|
12
|
-
end # Forms now contains a plain errors hash. the errors for each item are still available in item.errors.
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def valid? # TODO: test me in unit test.
|
17
|
-
empty?
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_s
|
21
|
-
messages.inspect
|
22
|
-
end
|
23
|
-
end # Errors
|