reform 2.3.2 → 2.6.1

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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +17 -0
  3. data/.gitignore +1 -1
  4. data/CHANGES.md +23 -0
  5. data/Gemfile +1 -1
  6. data/LICENSE.txt +1 -1
  7. data/README.md +5 -5
  8. data/Rakefile +1 -12
  9. data/lib/reform/contract/validate.rb +1 -1
  10. data/lib/reform/form/dry.rb +47 -9
  11. data/lib/reform/form/populator.rb +13 -3
  12. data/lib/reform/form/prepopulate.rb +1 -1
  13. data/lib/reform/form/validate.rb +3 -3
  14. data/lib/reform/validation/groups.rb +0 -1
  15. data/lib/reform/version.rb +1 -1
  16. data/reform.gemspec +2 -2
  17. data/test/call_test.rb +23 -0
  18. data/test/changed_test.rb +6 -6
  19. data/test/coercion_test.rb +17 -17
  20. data/test/{composition_new_api.rb → composition_test.rb} +27 -28
  21. data/test/{contract_new_api.rb → contract_test.rb} +8 -8
  22. data/test/default_test.rb +2 -2
  23. data/test/deserialize_test.rb +8 -8
  24. data/test/docs/validation_test.rb +134 -0
  25. data/test/{errors_new_api.rb → errors_test.rb} +41 -41
  26. data/test/feature_test.rb +2 -2
  27. data/test/fixtures/dry_error_messages.yml +64 -54
  28. data/test/{form_option_new_api.rb → form_option_test.rb} +1 -1
  29. data/test/{form_new_api.rb → form_test.rb} +3 -3
  30. data/test/from_test.rb +10 -10
  31. data/test/{inherit_new_api.rb → inherit_test.rb} +17 -17
  32. data/test/{module_new_api.rb → module_test.rb} +10 -10
  33. data/test/parse_option_test.rb +7 -7
  34. data/test/parse_pipeline_test.rb +1 -1
  35. data/test/{populate_new_api.rb → populate_test.rb} +136 -53
  36. data/test/populator_skip_test.rb +2 -2
  37. data/test/prepopulator_test.rb +16 -16
  38. data/test/read_only_test.rb +2 -2
  39. data/test/readable_test.rb +3 -3
  40. data/test/{reform_new_api.rb → reform_test.rb} +19 -19
  41. data/test/{save_new_api.rb → save_test.rb} +4 -4
  42. data/test/setup_test.rb +9 -9
  43. data/test/{skip_if_new_api.rb → skip_if_test.rb} +12 -12
  44. data/test/skip_setter_and_getter_test.rb +6 -6
  45. data/test/test_helper.rb +5 -6
  46. data/test/{validate_new_api.rb → validate_test.rb} +65 -78
  47. data/test/validation/{dry_validation_new_api.rb → dry_validation_test.rb} +128 -128
  48. data/test/validation/result_test.rb +14 -14
  49. data/test/virtual_test.rb +7 -7
  50. data/test/writeable_test.rb +8 -8
  51. metadata +42 -75
  52. data/.travis.yml +0 -16
  53. data/Appraisals +0 -8
  54. data/gemfiles/0.13.0.gemfile +0 -8
  55. data/gemfiles/1.5.0.gemfile +0 -9
  56. data/lib/reform/form/dry/new_api.rb +0 -47
  57. data/lib/reform/form/dry/old_api.rb +0 -61
  58. data/test/call_new_api.rb +0 -23
  59. data/test/call_old_api.rb +0 -23
  60. data/test/composition_old_api.rb +0 -184
  61. data/test/contract_old_api.rb +0 -77
  62. data/test/errors_old_api.rb +0 -230
  63. data/test/fixtures/dry_new_api_error_messages.yml +0 -104
  64. data/test/form_old_api.rb +0 -57
  65. data/test/form_option_old_api.rb +0 -24
  66. data/test/inherit_old_api.rb +0 -105
  67. data/test/module_old_api.rb +0 -146
  68. data/test/populate_old_api.rb +0 -304
  69. data/test/reform_old_api.rb +0 -202
  70. data/test/save_old_api.rb +0 -101
  71. data/test/skip_if_old_api.rb +0 -92
  72. data/test/validate_old_api.rb +0 -410
  73. data/test/validation/dry_validation_old_api.rb +0 -772
data/test/setup_test.rb CHANGED
@@ -31,18 +31,18 @@ class SetupTest < MiniTest::Spec
31
31
  it do
32
32
  form = AlbumForm.new(album)
33
33
 
34
- form.name.must_equal "The Dissent Of Man"
35
- form.songs[0].title.must_equal "Broken"
34
+ assert_equal form.name, "The Dissent Of Man"
35
+ assert_equal form.songs[0].title, "Broken"
36
36
  assert_nil form.songs[0].composer
37
- form.songs[1].title.must_equal "Resist Stance"
38
- form.songs[1].composer.name.must_equal "Greg Graffin"
39
- form.artist.name.must_equal "Bad Religion"
37
+ assert_equal form.songs[1].title, "Resist Stance"
38
+ assert_equal form.songs[1].composer.name, "Greg Graffin"
39
+ assert_equal form.artist.name, "Bad Religion"
40
40
 
41
41
  # make sure all is wrapped in forms.
42
- form.songs[0].must_be_kind_of Reform::Form
43
- form.songs[1].must_be_kind_of Reform::Form
44
- form.songs[1].composer.must_be_kind_of Reform::Form
45
- form.artist.must_be_kind_of Reform::Form
42
+ assert form.songs[0].is_a? Reform::Form
43
+ assert form.songs[1].is_a? Reform::Form
44
+ assert form.songs[1].composer.is_a? Reform::Form
45
+ assert form.artist.is_a? Reform::Form
46
46
  end
47
47
  end
48
48
  end
@@ -26,23 +26,23 @@ class SkipIfTest < BaseTest
26
26
  # deserializes when present.
27
27
  it do
28
28
  form = AlbumForm.new(album)
29
- form.validate("hit" => {"title" => "Altar Of Sacrifice"}).must_equal true
30
- form.hit.title.must_equal "Altar Of Sacrifice"
29
+ assert form.validate("hit" => {"title" => "Altar Of Sacrifice"})
30
+ assert_equal form.hit.title, "Altar Of Sacrifice"
31
31
  end
32
32
 
33
33
  # skips deserialization when not present.
34
34
  it do
35
35
  form = AlbumForm.new(Album.new)
36
- form.validate("hit" => {"title" => ""}).must_equal true
36
+ assert form.validate("hit" => {"title" => ""})
37
37
  assert_nil form.hit # hit hasn't been deserialised.
38
38
  end
39
39
 
40
40
  # skips deserialization when not present.
41
41
  it do
42
42
  form = AlbumForm.new(Album.new(nil, nil, []))
43
- form.validate("songs" => [{"title" => "Waste Of Breath"}, {"title" => nil}]).must_equal true
44
- form.songs.size.must_equal 1
45
- form.songs[0].title.must_equal "Waste Of Breath"
43
+ assert form.validate("songs" => [{"title" => "Waste Of Breath"}, {"title" => nil}])
44
+ assert_equal form.songs.size, 1
45
+ assert_equal form.songs[0].title, "Waste Of Breath"
46
46
  end
47
47
  end
48
48
 
@@ -58,16 +58,16 @@ class SkipIfAllBlankTest < BaseTest
58
58
  # create only one object.
59
59
  it do
60
60
  form = AlbumForm.new(OpenStruct.new(songs: []))
61
- form.validate("songs" => [{"title" => "Apathy"}, {"title" => "", "length" => ""}]).must_equal true
62
- form.songs.size.must_equal 1
63
- form.songs[0].title.must_equal "Apathy"
61
+ assert form.validate("songs" => [{"title" => "Apathy"}, {"title" => "", "length" => ""}])
62
+ assert_equal form.songs.size, 1
63
+ assert_equal form.songs[0].title, "Apathy"
64
64
  end
65
65
 
66
66
  it do
67
67
  form = AlbumForm.new(OpenStruct.new(songs: []))
68
- form.validate("songs" => [{"title" => "", "length" => ""}, {"title" => "Apathy"}]).must_equal true
69
- form.songs.size.must_equal 1
70
- form.songs[0].title.must_equal "Apathy"
68
+ assert form.validate("songs" => [{"title" => "", "length" => ""}, {"title" => "Apathy"}])
69
+ assert_equal form.songs.size, 1
70
+ assert_equal form.songs[0].title, "Apathy"
71
71
  end
72
72
  end
73
73
 
@@ -37,17 +37,17 @@ class SetupSkipSetterAndGetterTest < MiniTest::Spec
37
37
  album = Album.new("Greatest Hits", artist)
38
38
  form = AlbumForm.new(album)
39
39
 
40
- form.title.must_equal "GREATEST HITS"
41
- form.artist.name.must_equal "bad religion"
40
+ assert_equal form.title, "GREATEST HITS"
41
+ assert_equal form.artist.name, "bad religion"
42
42
 
43
43
  form.validate("title" => "Resiststance", "artist" => {"name" => "Greg Graffin"})
44
44
 
45
- form.title.must_equal "ECNATSTSISER" # first, setter called, then getter.
46
- form.artist.name.must_equal "greg graffi"
45
+ assert_equal form.title, "ECNATSTSISER" # first, setter called, then getter.
46
+ assert_equal form.artist.name, "greg graffi"
47
47
 
48
48
  form.sync
49
49
 
50
- album.title.must_equal "ecnatstsiseR" # setter called, but not getter.
51
- album.artist.name.must_equal "Greg Graffi"
50
+ assert_equal album.title, "ecnatstsiseR" # setter called, but not getter.
51
+ assert_equal album.artist.name, "Greg Graffi"
52
52
  end
53
53
  end
data/test/test_helper.rb CHANGED
@@ -17,14 +17,9 @@ class TestContract < Reform::Contract
17
17
  end
18
18
 
19
19
  module Types
20
- DRY_MODULE = Gem::Version.new(Dry::Types::VERSION) < Gem::Version.new("0.15.0") ? Dry::Types.module : Dry.Types()
21
- include DRY_MODULE
20
+ include Dry.Types()
22
21
  end
23
22
 
24
- DRY_TYPES_VERSION = Gem::Version.new(Dry::Types::VERSION)
25
- DRY_TYPES_CONSTANT = DRY_TYPES_VERSION < Gem::Version.new("0.13.0") ? Types::Form : Types::Params
26
- DRY_TYPES_INT_CONSTANT = DRY_TYPES_VERSION < Gem::Version.new("0.13.0") ? Types::Form::Int : Types::Params::Integer
27
-
28
23
  class BaseTest < MiniTest::Spec
29
24
  class AlbumForm < TestForm
30
25
  property :title
@@ -48,6 +43,10 @@ class BaseTest < MiniTest::Spec
48
43
  end
49
44
 
50
45
  MiniTest::Spec.class_eval do
46
+ Song = Struct.new(:title, :album, :composer)
47
+ Album = Struct.new(:name, :songs, :artist)
48
+ Artist = Struct.new(:name)
49
+
51
50
  module Saveable
52
51
  def save
53
52
  @saved = true
@@ -1,10 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
3
  class ContractValidateTest < MiniTest::Spec
4
- Song = Struct.new(:title, :album, :composer)
5
- Album = Struct.new(:name, :songs, :artist)
6
- Artist = Struct.new(:name)
7
-
8
4
  class AlbumForm < TestContract
9
5
  property :name
10
6
  validation do
@@ -40,8 +36,8 @@ class ContractValidateTest < MiniTest::Spec
40
36
 
41
37
  # valid
42
38
  it do
43
- form.validate.must_equal true
44
- form.errors.messages.inspect.must_equal "{}"
39
+ assert form.validate
40
+ assert_equal form.errors.messages.inspect, "{}"
45
41
  end
46
42
 
47
43
  # invalid
@@ -49,17 +45,13 @@ class ContractValidateTest < MiniTest::Spec
49
45
  album.songs[1].composer.name = nil
50
46
  album.name = nil
51
47
 
52
- form.validate.must_equal false
53
- form.errors.messages.inspect.must_equal "{:name=>[\"must be filled\"], :\"songs.composer.name\"=>[\"must be filled\"]}"
48
+ assert_equal form.validate, false
49
+ assert_equal form.errors.messages.inspect, "{:name=>[\"must be filled\"], :\"songs.composer.name\"=>[\"must be filled\"]}"
54
50
  end
55
51
  end
56
52
 
57
53
  # no configuration results in "sync" (formerly known as parse_strategy: :sync).
58
54
  class ValidateWithoutConfigurationTest < MiniTest::Spec
59
- Song = Struct.new(:title, :album, :composer)
60
- Album = Struct.new(:name, :songs, :artist)
61
- Artist = Struct.new(:name)
62
-
63
55
  class AlbumForm < TestForm
64
56
  property :name
65
57
  validation do
@@ -100,48 +92,48 @@ class ValidateWithoutConfigurationTest < MiniTest::Spec
100
92
  artist: form.artist.object_id, composer: form.songs[1].composer.object_id
101
93
  }
102
94
 
103
- form.validate(
95
+ assert form.validate(
104
96
  "name" => "Best Of",
105
97
  "songs" => [{"title" => "Fallout"}, {"title" => "Roxanne", "composer" => {"name" => "Sting"}}],
106
98
  "artist" => {"name" => "The Police"}
107
- ).must_equal true
99
+ )
108
100
 
109
- form.errors.messages.inspect.must_equal "{}"
101
+ assert_equal form.errors.messages.inspect, "{}"
110
102
 
111
103
  # form has updated.
112
- form.name.must_equal "Best Of"
113
- form.songs[0].title.must_equal "Fallout"
114
- form.songs[1].title.must_equal "Roxanne"
115
- form.songs[1].composer.name.must_equal "Sting"
116
- form.artist.name.must_equal "The Police"
104
+ assert_equal form.name, "Best Of"
105
+ assert_equal form.songs[0].title, "Fallout"
106
+ assert_equal form.songs[1].title, "Roxanne"
107
+ assert_equal form.songs[1].composer.name, "Sting"
108
+ assert_equal form.artist.name, "The Police"
117
109
 
118
110
  # objects are still the same.
119
- form.songs[0].object_id.must_equal object_ids[:song]
120
- form.songs[1].object_id.must_equal object_ids[:song_with_composer]
121
- form.songs[1].composer.object_id.must_equal object_ids[:composer]
122
- form.artist.object_id.must_equal object_ids[:artist]
111
+ assert_equal form.songs[0].object_id, object_ids[:song]
112
+ assert_equal form.songs[1].object_id, object_ids[:song_with_composer]
113
+ assert_equal form.songs[1].composer.object_id, object_ids[:composer]
114
+ assert_equal form.artist.object_id, object_ids[:artist]
123
115
 
124
116
  # model has not changed, yet.
125
- album.name.must_equal "The Dissent Of Man"
126
- album.songs[0].title.must_equal "Broken"
127
- album.songs[1].title.must_equal "Resist Stance"
128
- album.songs[1].composer.name.must_equal "Greg Graffin"
129
- album.artist.name.must_equal "Bad Religion"
117
+ assert_equal album.name, "The Dissent Of Man"
118
+ assert_equal album.songs[0].title, "Broken"
119
+ assert_equal album.songs[1].title, "Resist Stance"
120
+ assert_equal album.songs[1].composer.name, "Greg Graffin"
121
+ assert_equal album.artist.name, "Bad Religion"
130
122
  end
131
123
 
132
124
  # with symbols.
133
125
  it do
134
- form.validate(
126
+ assert form.validate(
135
127
  name: "Best Of",
136
128
  songs: [{title: "The X-Creep"}, {title: "Trudging", composer: {name: "SNFU"}}],
137
129
  artist: {name: "The Police"}
138
- ).must_equal true
130
+ )
139
131
 
140
- form.name.must_equal "Best Of"
141
- form.songs[0].title.must_equal "The X-Creep"
142
- form.songs[1].title.must_equal "Trudging"
143
- form.songs[1].composer.name.must_equal "SNFU"
144
- form.artist.name.must_equal "The Police"
132
+ assert_equal form.name, "Best Of"
133
+ assert_equal form.songs[0].title, "The X-Creep"
134
+ assert_equal form.songs[1].title, "Trudging"
135
+ assert_equal form.songs[1].composer.name, "SNFU"
136
+ assert_equal form.artist.name, "The Police"
145
137
  end
146
138
 
147
139
  # throws exception when no populators.
@@ -155,10 +147,6 @@ class ValidateWithoutConfigurationTest < MiniTest::Spec
155
147
  end
156
148
 
157
149
  class ValidateWithInternalPopulatorOptionTest < MiniTest::Spec
158
- Song = Struct.new(:title, :album, :composer)
159
- Album = Struct.new(:name, :songs, :artist)
160
- Artist = Struct.new(:name)
161
-
162
150
  class AlbumForm < TestForm
163
151
  property :name
164
152
  validation do
@@ -201,66 +189,66 @@ class ValidateWithInternalPopulatorOptionTest < MiniTest::Spec
201
189
 
202
190
  # valid.
203
191
  it("xxx") do
204
- form.validate(
192
+ assert form.validate(
205
193
  "name" => "Best Of",
206
194
  "songs" => [{"title" => "Fallout"}, {"title" => "Roxanne", "composer" => {"name" => "Sting"}}],
207
- "artist" => {"name" => "The Police"},
208
- ).must_equal true
195
+ "artist" => {"name" => "The Police"}
196
+ )
209
197
 
210
- form.errors.messages.inspect.must_equal "{}"
198
+ assert_equal form.errors.messages.inspect, "{}"
211
199
 
212
200
  # form has updated.
213
- form.name.must_equal "Best Of"
214
- form.songs[0].title.must_equal "Fallout"
215
- form.songs[1].title.must_equal "Roxanne"
216
- form.songs[1].composer.name.must_equal "Sting"
217
- form.artist.name.must_equal "The Police"
201
+ assert_equal form.name, "Best Of"
202
+ assert_equal form.songs[0].title, "Fallout"
203
+ assert_equal form.songs[1].title, "Roxanne"
204
+ assert_equal form.songs[1].composer.name, "Sting"
205
+ assert_equal form.artist.name, "The Police"
218
206
 
219
207
  # model has not changed, yet.
220
- album.name.must_equal "The Dissent Of Man"
221
- album.songs[0].title.must_equal "Broken"
222
- album.songs[1].title.must_equal "Resist Stance"
223
- album.songs[1].composer.name.must_equal "Greg Graffin"
224
- album.artist.name.must_equal "Bad Religion"
208
+ assert_equal album.name, "The Dissent Of Man"
209
+ assert_equal album.songs[0].title, "Broken"
210
+ assert_equal album.songs[1].title, "Resist Stance"
211
+ assert_equal album.songs[1].composer.name, "Greg Graffin"
212
+ assert_equal album.artist.name, "Bad Religion"
225
213
  end
226
214
 
227
215
  # invalid.
228
216
  it do
229
- form.validate(
217
+ assert_equal form.validate(
230
218
  "name" => "",
231
219
  "songs" => [{"title" => "Fallout"}, {"title" => "Roxanne", "composer" => {"name" => ""}}],
232
220
  "artist" => {"name" => ""},
233
- ).must_equal false
221
+ ), false
234
222
 
235
- form.errors.messages.inspect.must_equal "{:name=>[\"must be filled\"], :\"songs.composer.name\"=>[\"must be filled\"], :\"artist.name\"=>[\"must be filled\"]}"
223
+ assert_equal form.errors.messages.inspect, "{:name=>[\"must be filled\"], :\"songs.composer.name\"=>[\"must be filled\"], :\"artist.name\"=>[\"must be filled\"]}"
236
224
  end
237
225
 
238
226
  # adding to collection via :instance.
239
227
  # valid.
240
228
  it do
241
- form.validate(
242
- "songs" => [{"title" => "Fallout"}, {"title" => "Roxanne"}, {"title" => "Rime Of The Ancient Mariner"}],
243
- ).must_equal true
229
+ assert form.validate(
230
+ "songs" => [{"title" => "Fallout"}, {"title" => "Roxanne"}, {"title" => "Rime Of The Ancient Mariner"}]
231
+ )
244
232
 
245
- form.errors.messages.inspect.must_equal "{}"
233
+ assert_equal form.errors.messages.inspect, "{}"
246
234
 
247
235
  # form has updated.
248
- form.name.must_equal "The Dissent Of Man"
249
- form.songs[0].title.must_equal "Fallout"
250
- form.songs[1].title.must_equal "Roxanne"
251
- form.songs[1].composer.name.must_equal "Greg Graffin"
252
- form.songs[1].title.must_equal "Roxanne"
253
- form.songs[2].title.must_equal "Rime Of The Ancient Mariner" # new song added.
254
- form.songs.size.must_equal 3
255
- form.artist.name.must_equal "Bad Religion"
236
+ assert_equal form.name, "The Dissent Of Man"
237
+ assert_equal form.songs[0].title, "Fallout"
238
+ assert_equal form.songs[1].title, "Roxanne"
239
+ assert_equal form.songs[1].composer.name, "Greg Graffin"
240
+ assert_equal form.songs[1].title, "Roxanne"
241
+ assert_equal form.songs[2].title, "Rime Of The Ancient Mariner" # new song added.
242
+ assert_equal form.songs.size, 3
243
+ assert_equal form.artist.name, "Bad Religion"
256
244
 
257
245
  # model has not changed, yet.
258
- album.name.must_equal "The Dissent Of Man"
259
- album.songs[0].title.must_equal "Broken"
260
- album.songs[1].title.must_equal "Resist Stance"
261
- album.songs[1].composer.name.must_equal "Greg Graffin"
262
- album.songs.size.must_equal 2
263
- album.artist.name.must_equal "Bad Religion"
246
+ assert_equal album.name, "The Dissent Of Man"
247
+ assert_equal album.songs[0].title, "Broken"
248
+ assert_equal album.songs[1].title, "Resist Stance"
249
+ assert_equal album.songs[1].composer.name, "Greg Graffin"
250
+ assert_equal album.songs.size, 2
251
+ assert_equal album.artist.name, "Bad Religion"
264
252
  end
265
253
 
266
254
  # allow writeable: false even in the deserializer.
@@ -274,13 +262,12 @@ class ValidateWithInternalPopulatorOptionTest < MiniTest::Spec
274
262
  assert_nil form.title
275
263
  form.title = "Unopened"
276
264
  form.sync # only the deserializer is marked as not-writeable.
277
- song.title.must_equal "Unopened"
265
+ assert_equal song.title, "Unopened"
278
266
  end
279
267
  end
280
268
 
269
+ # memory leak test
281
270
  class ValidateUsingDifferentFormObject < MiniTest::Spec
282
- Album = Struct.new(:name)
283
-
284
271
  class AlbumForm < TestForm
285
272
  property :name
286
273