reform 2.3.0.rc1 → 2.3.0.rc2
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 +2 -0
- data/.rubocop.yml +30 -0
- data/.rubocop_todo.yml +460 -0
- data/.travis.yml +26 -11
- data/CHANGES.md +25 -2
- data/Gemfile +6 -3
- data/ISSUE_TEMPLATE.md +1 -1
- data/README.md +2 -4
- data/Rakefile +18 -9
- data/lib/reform/contract.rb +7 -7
- data/lib/reform/contract/custom_error.rb +41 -0
- data/lib/reform/contract/validate.rb +9 -5
- data/lib/reform/errors.rb +27 -15
- data/lib/reform/form.rb +22 -11
- data/lib/reform/form/call.rb +1 -1
- data/lib/reform/form/composition.rb +2 -2
- data/lib/reform/form/dry.rb +10 -86
- data/lib/reform/form/dry/input_hash.rb +37 -0
- data/lib/reform/form/dry/new_api.rb +58 -0
- data/lib/reform/form/dry/old_api.rb +61 -0
- data/lib/reform/form/populator.rb +9 -11
- data/lib/reform/form/prepopulate.rb +3 -2
- data/lib/reform/form/validate.rb +19 -12
- data/lib/reform/result.rb +36 -9
- data/lib/reform/validation.rb +10 -8
- data/lib/reform/validation/groups.rb +2 -3
- data/lib/reform/version.rb +1 -1
- data/reform.gemspec +10 -9
- data/test/benchmarking.rb +10 -11
- data/test/call_new_api.rb +23 -0
- data/test/{call_test.rb → call_old_api.rb} +3 -3
- data/test/changed_test.rb +7 -7
- data/test/coercion_test.rb +50 -18
- data/test/composition_new_api.rb +186 -0
- data/test/{composition_test.rb → composition_old_api.rb} +23 -26
- data/test/contract/custom_error_test.rb +55 -0
- data/test/contract_new_api.rb +77 -0
- data/test/{contract_test.rb → contract_old_api.rb} +8 -8
- data/test/default_test.rb +1 -1
- data/test/deserialize_test.rb +8 -11
- data/test/errors_new_api.rb +225 -0
- data/test/errors_old_api.rb +230 -0
- data/test/feature_test.rb +7 -9
- data/test/fixtures/dry_error_messages.yml +5 -2
- data/test/fixtures/dry_new_api_error_messages.yml +104 -0
- data/test/form_new_api.rb +57 -0
- data/test/{form_test.rb → form_old_api.rb} +2 -2
- data/test/form_option_new_api.rb +24 -0
- data/test/{form_option_test.rb → form_option_old_api.rb} +1 -1
- data/test/from_test.rb +8 -12
- data/test/inherit_new_api.rb +105 -0
- data/test/{inherit_test.rb → inherit_old_api.rb} +10 -17
- data/test/module_new_api.rb +137 -0
- data/test/{module_test.rb → module_old_api.rb} +19 -15
- data/test/parse_option_test.rb +5 -5
- data/test/parse_pipeline_test.rb +2 -2
- data/test/populate_new_api.rb +304 -0
- data/test/{populate_test.rb → populate_old_api.rb} +28 -34
- data/test/populator_skip_test.rb +1 -2
- data/test/prepopulator_test.rb +5 -6
- data/test/read_only_test.rb +12 -1
- data/test/readable_test.rb +5 -5
- data/test/reform_new_api.rb +204 -0
- data/test/{reform_test.rb → reform_old_api.rb} +17 -23
- data/test/save_new_api.rb +101 -0
- data/test/{save_test.rb → save_old_api.rb} +10 -13
- data/test/setup_test.rb +6 -6
- data/test/{skip_if_test.rb → skip_if_new_api.rb} +20 -9
- data/test/skip_if_old_api.rb +92 -0
- data/test/skip_setter_and_getter_test.rb +2 -3
- data/test/test_helper.rb +13 -5
- data/test/validate_new_api.rb +408 -0
- data/test/{validate_test.rb → validate_old_api.rb} +43 -53
- data/test/validation/dry_validation_new_api.rb +826 -0
- data/test/validation/{dry_validation_test.rb → dry_validation_old_api.rb} +223 -116
- data/test/validation/result_test.rb +20 -22
- data/test/validation_library_provided_test.rb +3 -3
- data/test/virtual_test.rb +46 -6
- data/test/writeable_test.rb +7 -7
- metadata +101 -51
- data/test/errors_test.rb +0 -180
- data/test/readonly_test.rb +0 -14
data/test/errors_test.rb
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
# TODO:
|
|
4
|
-
# This test should, at some point soon, only test the `Errors` object and its
|
|
5
|
-
# Rails-ish API. No validation specifics, etc. to be tested here.
|
|
6
|
-
|
|
7
|
-
class ErrorsTest < MiniTest::Spec
|
|
8
|
-
class AlbumForm < TestForm
|
|
9
|
-
property :title
|
|
10
|
-
|
|
11
|
-
property :hit do
|
|
12
|
-
property :title
|
|
13
|
-
validation do
|
|
14
|
-
required(:title).filled
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
collection :songs do
|
|
19
|
-
property :title
|
|
20
|
-
validation do
|
|
21
|
-
required(:title).filled
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
property :band do # yepp, people do crazy stuff like that.
|
|
26
|
-
property :name
|
|
27
|
-
property :label do
|
|
28
|
-
property :name
|
|
29
|
-
validation do
|
|
30
|
-
required(:name).filled
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
# TODO: make band a required object.
|
|
34
|
-
|
|
35
|
-
validation do
|
|
36
|
-
configure do
|
|
37
|
-
config.messages_file = "test/fixtures/dry_error_messages.yml"
|
|
38
|
-
|
|
39
|
-
def good_musical_taste?(value)
|
|
40
|
-
value != "Nickelback"
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
required(:name).filled(:good_musical_taste?)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
validation do
|
|
49
|
-
required(:title).filled
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
let (:album) do
|
|
54
|
-
OpenStruct.new(
|
|
55
|
-
:title => "Blackhawks Over Los Angeles",
|
|
56
|
-
:hit => song,
|
|
57
|
-
:songs => songs, # TODO: document this requirement,
|
|
58
|
-
:band => Struct.new(:name, :label).new("Epitaph", OpenStruct.new),
|
|
59
|
-
)
|
|
60
|
-
end
|
|
61
|
-
let (:song) { OpenStruct.new(:title => "Downtown") }
|
|
62
|
-
let (:songs) { [song=OpenStruct.new(:title => "Calling"), song] }
|
|
63
|
-
let (:form) { AlbumForm.new(album) }
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
describe "#errors without #validate" do
|
|
67
|
-
it do
|
|
68
|
-
form.errors.size.must_equal 0
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
describe "blank everywhere" do
|
|
73
|
-
before { form.validate(
|
|
74
|
-
"hit" =>{"title" => ""},
|
|
75
|
-
"title" => "",
|
|
76
|
-
"songs" => [{"title" => ""}, {"title" => ""}]) } # FIXME: what happens if item must be filled?
|
|
77
|
-
|
|
78
|
-
it do
|
|
79
|
-
form.errors.messages.must_equal({
|
|
80
|
-
:title => ["must be filled"],
|
|
81
|
-
:"hit.title"=>["must be filled"],
|
|
82
|
-
:"songs.title"=>["must be filled"],
|
|
83
|
-
:"band.label.name"=>["must be filled"]
|
|
84
|
-
})
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it do
|
|
88
|
-
#form.errors.must_equal({:title => ["must be filled"]})
|
|
89
|
-
# TODO: this should only contain local errors?
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# nested forms keep their own Errors:
|
|
93
|
-
it { form.hit.errors.messages.must_equal({:title=>["must be filled"]}) }
|
|
94
|
-
it { form.songs[0].errors.messages.must_equal({:title=>["must be filled"]}) }
|
|
95
|
-
|
|
96
|
-
it do
|
|
97
|
-
form.errors.messages.must_equal({
|
|
98
|
-
:title => ["must be filled"],
|
|
99
|
-
:"hit.title" => ["must be filled"],
|
|
100
|
-
:"songs.title"=> ["must be filled"],
|
|
101
|
-
:"band.label.name"=>["must be filled"]
|
|
102
|
-
})
|
|
103
|
-
form.errors.size.must_equal(4)
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
describe "#validate with main form invalid" do
|
|
109
|
-
it do
|
|
110
|
-
form.validate("title"=>"", "band"=>{"label"=>{:name => "Fat Wreck"}}).must_equal false
|
|
111
|
-
form.errors.messages.must_equal({:title=>["must be filled"]})
|
|
112
|
-
form.errors.size.must_equal(1)
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
describe "#validate with middle nested form invalid" do
|
|
118
|
-
before { @result = form.validate("hit"=>{"title" => ""}, "band"=>{"label"=>{:name => "Fat Wreck"}}) }
|
|
119
|
-
|
|
120
|
-
it { @result.must_equal false }
|
|
121
|
-
it { form.errors.messages.must_equal({:"hit.title"=>["must be filled"]}) }
|
|
122
|
-
it { form.errors.size.must_equal(1) }
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
describe "#validate with collection form invalid" do
|
|
127
|
-
before { @result = form.validate("songs"=>[{"title" => ""}], "band"=>{"label"=>{:name => "Fat Wreck"}}) }
|
|
128
|
-
|
|
129
|
-
it { @result.must_equal false }
|
|
130
|
-
it { form.errors.messages.must_equal({:"songs.title"=>["must be filled"]}) }
|
|
131
|
-
it { form.errors.size.must_equal(1) }
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
describe "#validate with collection and 2-level-nested invalid" do
|
|
136
|
-
before { @result = form.validate("songs"=>[{"title" => ""}], "band" => {"label" => {}}) }
|
|
137
|
-
|
|
138
|
-
it { @result.must_equal false }
|
|
139
|
-
it { form.errors.messages.must_equal({:"songs.title"=>["must be filled"], :"band.label.name"=>["must be filled"]}) }
|
|
140
|
-
it { form.errors.size.must_equal(2) }
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
describe "#validate with nested form using :base invalid" do
|
|
144
|
-
it do
|
|
145
|
-
result = form.validate("songs"=>[{"title" => "Someday"}], "band" => {"name" => "Nickelback", "label" => {"name" => "Roadrunner Records"}})
|
|
146
|
-
result.must_equal false
|
|
147
|
-
form.errors.messages.must_equal({:"band.name"=>["you're a bad person"]})
|
|
148
|
-
form.errors.size.must_equal(1)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
describe "correct #validate" do
|
|
153
|
-
before { @result = form.validate(
|
|
154
|
-
"hit" => {"title" => "Sacrifice"},
|
|
155
|
-
"title" => "Second Heat",
|
|
156
|
-
"songs" => [{"title"=>"Heart Of A Lion"}],
|
|
157
|
-
"band" => {"label"=>{:name => "Fat Wreck"}}
|
|
158
|
-
) }
|
|
159
|
-
|
|
160
|
-
it { @result.must_equal true }
|
|
161
|
-
it { form.hit.title.must_equal "Sacrifice" }
|
|
162
|
-
it { form.title.must_equal "Second Heat" }
|
|
163
|
-
it { form.songs.first.title.must_equal "Heart Of A Lion" }
|
|
164
|
-
it do
|
|
165
|
-
skip "WE DON'T NEED COUNT AND EMPTY? ON THE CORE ERRORS OBJECT"
|
|
166
|
-
form.errors.size.must_equal(0)
|
|
167
|
-
form.errors.empty?.must_equal(true)
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
describe "Errors#to_s" do
|
|
173
|
-
before { form.validate("songs"=>[{"title" => ""}], "band" => {"label" => {}}) }
|
|
174
|
-
|
|
175
|
-
# to_s is aliased to messages
|
|
176
|
-
it {
|
|
177
|
-
skip "why do we need Errors#to_s ?"
|
|
178
|
-
form.errors.to_s.must_equal "{:\"songs.title\"=>[\"must be filled\"], :\"band.label.name\"=>[\"must be filled\"]}" }
|
|
179
|
-
end
|
|
180
|
-
end
|
data/test/readonly_test.rb
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class ReadonlyTest < MiniTest::Spec
|
|
4
|
-
class SongForm < TestForm
|
|
5
|
-
property :artist
|
|
6
|
-
property :title, writeable: false
|
|
7
|
-
# TODO: what to do with virtual values?
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
let (:form) { SongForm.new(OpenStruct.new) }
|
|
11
|
-
|
|
12
|
-
it { form.readonly?(:artist).must_equal false }
|
|
13
|
-
it { form.readonly?(:title).must_equal true }
|
|
14
|
-
end
|