reform 2.3.0.rc2 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +17 -0
- data/.gitignore +4 -2
- data/CHANGES.md +24 -1
- data/Gemfile +1 -7
- data/LICENSE.txt +1 -1
- data/README.md +5 -5
- data/Rakefile +2 -15
- data/lib/reform/contract/validate.rb +1 -1
- data/lib/reform/form/dry.rb +47 -9
- data/lib/reform/form/populator.rb +13 -3
- data/lib/reform/form/prepopulate.rb +1 -1
- data/lib/reform/form/validate.rb +3 -3
- data/lib/reform/validation/groups.rb +0 -1
- data/lib/reform/version.rb +1 -1
- data/reform.gemspec +3 -4
- 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} +136 -53
- data/test/populator_skip_test.rb +2 -2
- data/test/prepopulator_test.rb +16 -16
- 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 +6 -7
- data/test/{validate_new_api.rb → validate_test.rb} +108 -76
- data/test/validation/{dry_validation_new_api.rb → dry_validation_test.rb} +145 -135
- data/test/validation/result_test.rb +14 -14
- data/test/virtual_test.rb +7 -7
- data/test/writeable_test.rb +8 -8
- metadata +46 -99
- data/.rubocop.yml +0 -30
- data/.rubocop_todo.yml +0 -460
- data/.travis.yml +0 -32
- data/lib/reform/form/dry/new_api.rb +0 -58
- 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
@@ -33,8 +33,8 @@ class FormCompositionInheritanceTest < MiniTest::Spec
|
|
33
33
|
Tshirt = Struct.new(:price, :size)
|
34
34
|
Measurement = Struct.new(:size)
|
35
35
|
|
36
|
-
it { form.price
|
37
|
-
it { form.price(for_size: :s)
|
36
|
+
it { assert_equal form.price, 6 }
|
37
|
+
it { assert_equal form.price(for_size: :s), 2 }
|
38
38
|
end
|
39
39
|
|
40
40
|
class FormCompositionTest < MiniTest::Spec
|
@@ -71,24 +71,24 @@ class FormCompositionTest < MiniTest::Spec
|
|
71
71
|
let(:band) { Band.new("Duran^2") }
|
72
72
|
|
73
73
|
# delegation form -> composition works
|
74
|
-
it { form.id
|
75
|
-
it { form.title
|
76
|
-
it { form.name
|
77
|
-
it { form.requester_id
|
74
|
+
it { assert_equal form.id, 1 }
|
75
|
+
it { assert_equal form.title, "Rio" }
|
76
|
+
it { assert_equal form.name, "Duran Duran" }
|
77
|
+
it { assert_equal form.requester_id, 2 }
|
78
78
|
it { assert_nil form.channel }
|
79
|
-
it { form.requester
|
79
|
+
it { assert_equal form.requester, "MCP" } # same name as composed model.
|
80
80
|
it { assert_nil form.captcha }
|
81
81
|
|
82
82
|
# #model just returns <Composition>.
|
83
|
-
it { form.mapper.
|
83
|
+
it { assert form.mapper.is_a? Disposable::Composition }
|
84
84
|
|
85
85
|
# #model[] -> composed models
|
86
|
-
it { form.model[:requester]
|
87
|
-
it { form.model[:song]
|
86
|
+
it { assert_equal form.model[:requester], requester }
|
87
|
+
it { assert_equal form.model[:song], song }
|
88
88
|
|
89
89
|
it "creates Composition for you" do
|
90
|
-
form.validate("title" => "Greyhound", "name" => "Frenzal Rhomb")
|
91
|
-
form.validate("title" => "", "name" => "Frenzal Rhomb")
|
90
|
+
assert_equal form.validate("title" => "Greyhound", "name" => "Frenzal Rhomb"), true
|
91
|
+
assert_equal form.validate("title" => "", "name" => "Frenzal Rhomb"), false
|
92
92
|
end
|
93
93
|
|
94
94
|
describe "#save" do
|
@@ -101,7 +101,7 @@ class FormCompositionTest < MiniTest::Spec
|
|
101
101
|
hash[:title] = form.title
|
102
102
|
end
|
103
103
|
|
104
|
-
hash
|
104
|
+
assert_equal hash, name: "Duran Duran", title: "Rio"
|
105
105
|
end
|
106
106
|
|
107
107
|
it "provides nested symbolized hash as second block argument" do
|
@@ -113,11 +113,10 @@ class FormCompositionTest < MiniTest::Spec
|
|
113
113
|
hash = map
|
114
114
|
end
|
115
115
|
|
116
|
-
hash
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
)
|
116
|
+
assert_equal hash, {
|
117
|
+
song: {"title" => "Greyhound", "id" => 1, "channel" => "JJJ", "captcha" => "wonderful", "band" => {"title" => "Duran^2"}},
|
118
|
+
requester: {"name" => "Frenzal Rhomb", "id" => 2, "requester" => "MCP"}
|
119
|
+
}
|
121
120
|
end
|
122
121
|
|
123
122
|
it "xxx pushes data to models and calls #save when no block passed" do
|
@@ -126,16 +125,16 @@ class FormCompositionTest < MiniTest::Spec
|
|
126
125
|
band.extend(Saveable)
|
127
126
|
|
128
127
|
form.validate("title" => "Greyhound", "name" => "Frenzal Rhomb", "captcha" => "1337")
|
129
|
-
form.captcha
|
128
|
+
assert_equal form.captcha, "1337" # TODO: move to separate test.
|
130
129
|
|
131
130
|
form.save
|
132
131
|
|
133
|
-
requester.name
|
134
|
-
requester.saved
|
135
|
-
song.title
|
136
|
-
song.saved
|
137
|
-
song.band.title
|
138
|
-
song.band.saved
|
132
|
+
assert_equal requester.name, "Frenzal Rhomb"
|
133
|
+
assert_equal requester.saved?, true
|
134
|
+
assert_equal song.title, "Greyhound"
|
135
|
+
assert_equal song.saved?, true
|
136
|
+
assert_equal song.band.title, "Duran^2"
|
137
|
+
assert_equal song.band.saved?, true
|
139
138
|
end
|
140
139
|
|
141
140
|
it "returns true when models all save successfully" do
|
@@ -143,7 +142,7 @@ class FormCompositionTest < MiniTest::Spec
|
|
143
142
|
requester.extend(Saveable)
|
144
143
|
band.extend(Saveable)
|
145
144
|
|
146
|
-
form.save
|
145
|
+
assert_equal form.save, true
|
147
146
|
end
|
148
147
|
|
149
148
|
it "returns false when one or more models don't save successfully" do
|
@@ -157,7 +156,7 @@ class FormCompositionTest < MiniTest::Spec
|
|
157
156
|
requester.extend(Saveable)
|
158
157
|
band.extend(Saveable)
|
159
158
|
|
160
|
-
form.save
|
159
|
+
assert_equal form.save, false
|
161
160
|
end
|
162
161
|
end
|
163
162
|
end
|
@@ -182,5 +181,5 @@ class FormCompositionCollectionTest < MiniTest::Spec
|
|
182
181
|
let(:form) { LibraryForm.new(library: library) }
|
183
182
|
let(:library) { Library.new(2) }
|
184
183
|
|
185
|
-
it { form.save { |hash| hash
|
184
|
+
it { form.save { |hash| assert_equal hash, { library: { "books" => [{ "id" => 1, "name" => "My book" }] } } } }
|
186
185
|
end
|
@@ -46,32 +46,32 @@ class ContractTest < MiniTest::Spec
|
|
46
46
|
|
47
47
|
# accept `property form: SongForm`.
|
48
48
|
it do
|
49
|
-
form.artist.
|
49
|
+
assert form.artist.is_a? ArtistForm
|
50
50
|
end
|
51
51
|
|
52
52
|
describe ".properties" do
|
53
53
|
it "defines a property when called with one argument" do
|
54
|
-
form
|
54
|
+
assert_respond_to form, :duration
|
55
55
|
end
|
56
56
|
|
57
57
|
it "defines several properties when called with multiple arguments" do
|
58
|
-
form
|
59
|
-
form
|
58
|
+
assert_respond_to form, :year
|
59
|
+
assert_respond_to form, :style
|
60
60
|
end
|
61
61
|
|
62
62
|
it "passes options to each property when options are provided" do
|
63
63
|
readable = AlbumForm.new(album).options_for(:style)[:readable]
|
64
|
-
readable
|
64
|
+
assert_equal readable, false
|
65
65
|
end
|
66
66
|
|
67
67
|
it "returns the list of defined properties" do
|
68
68
|
returned_value = AlbumForm.properties(:hello, :world, virtual: true)
|
69
|
-
returned_value
|
69
|
+
assert_equal returned_value, %i[hello world]
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
describe "#options_for" do
|
74
|
-
it { AlbumForm.options_for(:name).extend(Declarative::Inspect).inspect
|
75
|
-
it { AlbumForm.new(album).options_for(:name).extend(Declarative::Inspect).inspect
|
74
|
+
it { assert_equal AlbumForm.options_for(:name).extend(Declarative::Inspect).inspect, "#<Disposable::Twin::Definition: @options={:private_name=>:name, :name=>\"name\"}>" }
|
75
|
+
it { assert_equal AlbumForm.new(album).options_for(:name).extend(Declarative::Inspect).inspect, "#<Disposable::Twin::Definition: @options={:private_name=>:name, :name=>\"name\"}>" }
|
76
76
|
end
|
77
77
|
end
|
data/test/default_test.rb
CHANGED
@@ -16,7 +16,7 @@ class DefaultTest < Minitest::Spec
|
|
16
16
|
it do
|
17
17
|
form = AlbumForm.new(Album.new(nil, [Song.new]))
|
18
18
|
|
19
|
-
form.name
|
20
|
-
form.songs[0].title
|
19
|
+
assert_equal form.name, "Wrong"
|
20
|
+
assert_equal form.songs[0].title, "It's Catching Up"
|
21
21
|
end
|
22
22
|
end
|
data/test/deserialize_test.rb
CHANGED
@@ -41,9 +41,9 @@ class DeserializeTest < MiniTest::Spec
|
|
41
41
|
|
42
42
|
form.validate(json)
|
43
43
|
|
44
|
-
form.title
|
45
|
-
form.artist.name
|
46
|
-
form.artist.model.object_id
|
44
|
+
assert_equal form.title, "Apocalypse Soon"
|
45
|
+
assert_equal form.artist.name, "Mute"
|
46
|
+
assert_equal form.artist.model.object_id, artist_id
|
47
47
|
end
|
48
48
|
|
49
49
|
describe "infering the deserializer from another form should NOT copy its populators" do
|
@@ -62,7 +62,7 @@ class DeserializeTest < MiniTest::Spec
|
|
62
62
|
form = CompilationForm.new(Album.new)
|
63
63
|
form.validate("artist" => {"name" => "Horowitz"}) # the deserializer doesn't know symbols.
|
64
64
|
form.sync
|
65
|
-
form.artist.model
|
65
|
+
assert_equal form.artist.model, Artist.new("Horowitz", %{{"name"=>"Horowitz"}})
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -91,11 +91,11 @@ class ValidateWithBlockTest < MiniTest::Spec
|
|
91
91
|
options_from: :deserializer
|
92
92
|
)
|
93
93
|
|
94
|
-
form.validate(json) { |params|
|
94
|
+
assert form.validate(json) { |params|
|
95
95
|
deserializer.new(form).from_json(params)
|
96
|
-
}
|
96
|
+
} # with block must return result, too.
|
97
97
|
|
98
|
-
form.title
|
99
|
-
form.artist.name
|
98
|
+
assert_equal form.title, "Apocalypse Soon"
|
99
|
+
assert_equal form.artist.name, "Mute"
|
100
100
|
end
|
101
101
|
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'reform/form/dry'
|
3
|
+
|
4
|
+
class DocsDryVTest < Minitest::Spec
|
5
|
+
#:basic
|
6
|
+
class AlbumForm < Reform::Form
|
7
|
+
feature Reform::Form::Dry
|
8
|
+
|
9
|
+
property :name
|
10
|
+
|
11
|
+
validation do
|
12
|
+
params do
|
13
|
+
required(:name).filled
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
#:basic end
|
18
|
+
|
19
|
+
it 'validates correctly' do
|
20
|
+
form = DocsDryVTest::AlbumForm.new(Album.new(nil, nil, nil))
|
21
|
+
result = form.call(name: nil)
|
22
|
+
|
23
|
+
refute result.success?
|
24
|
+
assert_equal({ name: ['must be filled'] }, form.errors.messages)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class DocsDryVWithRulesTest < Minitest::Spec
|
29
|
+
#:basic_with_rules
|
30
|
+
class AlbumForm < Reform::Form
|
31
|
+
feature Reform::Form::Dry
|
32
|
+
|
33
|
+
property :name
|
34
|
+
|
35
|
+
validation name: :default do
|
36
|
+
option :form
|
37
|
+
|
38
|
+
params do
|
39
|
+
required(:name).filled
|
40
|
+
end
|
41
|
+
|
42
|
+
rule(:name) do
|
43
|
+
key.failure('must be unique') if Album.where.not(id: form.model.id).where(name: value).exists?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
#:basic_with_rules end
|
48
|
+
|
49
|
+
it 'validates correctly' do
|
50
|
+
Album = Struct.new(:name, :songs, :artist, :user)
|
51
|
+
form = DocsDryVWithRulesTest::AlbumForm.new(Album.new(nil, nil, nil, nil))
|
52
|
+
result = form.call(name: nil)
|
53
|
+
|
54
|
+
refute result.success?
|
55
|
+
assert_equal({ name: ['must be filled'] }, form.errors.messages)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class DryVWithNestedTest < Minitest::Spec
|
60
|
+
#:nested
|
61
|
+
class AlbumForm < Reform::Form
|
62
|
+
feature Reform::Form::Dry
|
63
|
+
|
64
|
+
property :name
|
65
|
+
|
66
|
+
validation do
|
67
|
+
params { required(:name).filled }
|
68
|
+
end
|
69
|
+
|
70
|
+
property :artist do
|
71
|
+
property :name
|
72
|
+
|
73
|
+
validation do
|
74
|
+
params { required(:name).filled }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
#:nested end
|
79
|
+
|
80
|
+
it 'validates correctly' do
|
81
|
+
form = DryVWithNestedTest::AlbumForm.new(Album.new(nil, nil, Artist.new(nil)))
|
82
|
+
result = form.call(name: nil, artist: { name: '' })
|
83
|
+
|
84
|
+
refute result.success?
|
85
|
+
assert_equal({ name: ['must be filled'], 'artist.name': ['must be filled'] }, form.errors.messages)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class DryVValGroupTest < Minitest::Spec
|
90
|
+
class AlbumForm < Reform::Form
|
91
|
+
feature Reform::Form::Dry
|
92
|
+
|
93
|
+
property :name
|
94
|
+
property :artist
|
95
|
+
#:validation_groups
|
96
|
+
validation name: :default do
|
97
|
+
params { required(:name).filled }
|
98
|
+
end
|
99
|
+
|
100
|
+
validation name: :artist, if: :default do
|
101
|
+
params { required(:artist).filled }
|
102
|
+
end
|
103
|
+
|
104
|
+
validation name: :famous, after: :default do
|
105
|
+
params { optional(:artist) }
|
106
|
+
|
107
|
+
rule(:artist) do
|
108
|
+
if value
|
109
|
+
key.failure('only famous artist') unless value =~ /famous/
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
#:validation_groups end
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'validates correctly' do
|
117
|
+
form = DryVValGroupTest::AlbumForm.new(Album.new(nil, nil, nil))
|
118
|
+
result = form.call(name: nil)
|
119
|
+
|
120
|
+
refute result.success?
|
121
|
+
assert_equal({ name: ['must be filled'] }, result.errors.messages)
|
122
|
+
|
123
|
+
result = form.call(name: 'Title')
|
124
|
+
refute result.success?
|
125
|
+
assert_equal({ artist: ['must be filled'] }, result.errors.messages)
|
126
|
+
|
127
|
+
result = form.call(name: 'Title', artist: 'Artist')
|
128
|
+
refute result.success?
|
129
|
+
assert_equal({ artist: ['only famous artist'] }, result.errors.messages)
|
130
|
+
|
131
|
+
result = form.call(name: 'Title', artist: 'Artist famous')
|
132
|
+
assert result.success?
|
133
|
+
end
|
134
|
+
end
|
@@ -37,7 +37,7 @@ class ErrorsTest < MiniTest::Spec
|
|
37
37
|
# TODO: make band a required object.
|
38
38
|
|
39
39
|
validation do
|
40
|
-
config.messages.load_paths << "test/fixtures/
|
40
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
41
41
|
|
42
42
|
params { required(:name).filled }
|
43
43
|
|
@@ -72,22 +72,22 @@ class ErrorsTest < MiniTest::Spec
|
|
72
72
|
|
73
73
|
describe "#validate with invalid array property" do
|
74
74
|
it do
|
75
|
-
form.validate(
|
75
|
+
refute form.validate(
|
76
76
|
title: "Swimming Pool - EP",
|
77
77
|
band: {
|
78
78
|
name: "Marie Madeleine",
|
79
79
|
label: {name: "Ekler'o'shocK"}
|
80
80
|
},
|
81
81
|
artists: [42, "Good Charlotte", 43]
|
82
|
-
)
|
83
|
-
form.errors.messages
|
84
|
-
form.errors.size
|
82
|
+
)
|
83
|
+
assert_equal form.errors.messages, artists: {0 => ["must be a string"], 2 => ["must be a string"]}
|
84
|
+
assert_equal form.errors.size, 1
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
describe "#errors without #validate" do
|
89
89
|
it do
|
90
|
-
form.errors.size
|
90
|
+
assert_equal form.errors.size, 0
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -102,13 +102,13 @@ class ErrorsTest < MiniTest::Spec
|
|
102
102
|
end
|
103
103
|
|
104
104
|
it do
|
105
|
-
form.errors.messages
|
105
|
+
assert_equal form.errors.messages,{
|
106
106
|
title: ["must be filled"],
|
107
107
|
"hit.title": ["must be filled"],
|
108
108
|
"songs.title": ["must be filled"],
|
109
109
|
"band.label.name": ["must be filled"],
|
110
110
|
"producer.name": ["must be filled"]
|
111
|
-
|
111
|
+
}
|
112
112
|
end
|
113
113
|
|
114
114
|
# it do
|
@@ -117,60 +117,60 @@ class ErrorsTest < MiniTest::Spec
|
|
117
117
|
# end
|
118
118
|
|
119
119
|
# nested forms keep their own Errors:
|
120
|
-
it { form.producer.errors.messages
|
121
|
-
it { form.hit.errors.messages
|
122
|
-
it { form.songs[0].errors.messages
|
120
|
+
it { assert_equal form.producer.errors.messages, name: ["must be filled"] }
|
121
|
+
it { assert_equal form.hit.errors.messages, title: ["must be filled"] }
|
122
|
+
it { assert_equal form.songs[0].errors.messages, title: ["must be filled"] }
|
123
123
|
|
124
124
|
it do
|
125
|
-
form.errors.messages
|
125
|
+
assert_equal form.errors.messages, {
|
126
126
|
title: ["must be filled"],
|
127
127
|
"hit.title": ["must be filled"],
|
128
128
|
"songs.title": ["must be filled"],
|
129
129
|
"band.label.name": ["must be filled"],
|
130
130
|
"producer.name": ["must be filled"]
|
131
|
-
|
132
|
-
form.errors.size
|
131
|
+
}
|
132
|
+
assert_equal form.errors.size, 5
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
136
|
describe "#validate with main form invalid" do
|
137
137
|
it do
|
138
|
-
form.validate("title" => "", "band" => {"label" => {name: "Fat Wreck"}}, "producer" => nil)
|
139
|
-
form.errors.messages
|
140
|
-
form.errors.size
|
138
|
+
refute form.validate("title" => "", "band" => {"label" => {name: "Fat Wreck"}}, "producer" => nil)
|
139
|
+
assert_equal form.errors.messages, title: ["must be filled"], producer: ["must be a hash"]
|
140
|
+
assert_equal form.errors.size, 2
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
144
|
describe "#validate with middle nested form invalid" do
|
145
145
|
before { @result = form.validate("hit" => {"title" => ""}, "band" => {"label" => {name: "Fat Wreck"}}) }
|
146
146
|
|
147
|
-
it { @result
|
148
|
-
it { form.errors.messages
|
149
|
-
it { form.errors.size
|
147
|
+
it { refute @result }
|
148
|
+
it { assert_equal form.errors.messages, "hit.title": ["must be filled"] }
|
149
|
+
it { assert_equal form.errors.size, 1 }
|
150
150
|
end
|
151
151
|
|
152
152
|
describe "#validate with collection form invalid" do
|
153
153
|
before { @result = form.validate("songs" => [{"title" => ""}], "band" => {"label" => {name: "Fat Wreck"}}) }
|
154
154
|
|
155
|
-
it { @result
|
156
|
-
it { form.errors.messages
|
157
|
-
it { form.errors.size
|
155
|
+
it { refute @result }
|
156
|
+
it { assert_equal form.errors.messages, "songs.title": ["must be filled"] }
|
157
|
+
it { assert_equal form.errors.size, 1 }
|
158
158
|
end
|
159
159
|
|
160
160
|
describe "#validate with collection and 2-level-nested invalid" do
|
161
161
|
before { @result = form.validate("songs" => [{"title" => ""}], "band" => {"label" => {}}) }
|
162
162
|
|
163
|
-
it { @result
|
164
|
-
it { form.errors.messages
|
165
|
-
it { form.errors.size
|
163
|
+
it { refute @result }
|
164
|
+
it { assert_equal form.errors.messages, "songs.title": ["must be filled"], "band.label.name": ["must be filled"] }
|
165
|
+
it { assert_equal form.errors.size, 2 }
|
166
166
|
end
|
167
167
|
|
168
168
|
describe "#validate with nested form using :base invalid" do
|
169
169
|
it do
|
170
170
|
result = form.validate("songs" => [{"title" => "Someday"}], "band" => {"name" => "Nickelback", "label" => {"name" => "Roadrunner Records"}})
|
171
|
-
result
|
172
|
-
form.errors.messages
|
173
|
-
form.errors.size
|
171
|
+
refute result
|
172
|
+
assert_equal form.errors.messages, "band.name": ["you're a bad person"]
|
173
|
+
assert_equal form.errors.size, 1
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
@@ -178,17 +178,17 @@ class ErrorsTest < MiniTest::Spec
|
|
178
178
|
let(:album_title) { nil }
|
179
179
|
it do
|
180
180
|
result = form.validate("songs" => [{"title" => "Someday"}], "band" => {"name" => "Nickelback", "label" => {"name" => "Roadrunner Records"}})
|
181
|
-
result
|
182
|
-
form.errors.messages
|
181
|
+
refute result
|
182
|
+
assert_equal form.errors.messages, title: ["must be filled"], "band.name": ["you're a bad person"]
|
183
183
|
# add a new custom error
|
184
184
|
form.errors.add(:policy, "error_text")
|
185
|
-
form.errors.messages
|
185
|
+
assert_equal form.errors.messages, title: ["must be filled"], "band.name": ["you're a bad person"], policy: ["error_text"]
|
186
186
|
# does not duplicate errors
|
187
187
|
form.errors.add(:title, "must be filled")
|
188
|
-
form.errors.messages
|
188
|
+
assert_equal form.errors.messages, title: ["must be filled"], "band.name": ["you're a bad person"], policy: ["error_text"]
|
189
189
|
# merge existing errors
|
190
190
|
form.errors.add(:policy, "another error")
|
191
|
-
form.errors.messages
|
191
|
+
assert_equal form.errors.messages, title: ["must be filled"], "band.name": ["you're a bad person"], policy: ["error_text", "another error"]
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
@@ -202,14 +202,14 @@ class ErrorsTest < MiniTest::Spec
|
|
202
202
|
)
|
203
203
|
end
|
204
204
|
|
205
|
-
it { @result
|
206
|
-
it { form.hit.title
|
207
|
-
it { form.title
|
208
|
-
it { form.songs.first.title
|
205
|
+
it { assert @result }
|
206
|
+
it { assert_equal form.hit.title, "Sacrifice" }
|
207
|
+
it { assert_equal form.title, "Second Heat" }
|
208
|
+
it { assert_equal form.songs.first.title, "Heart Of A Lion" }
|
209
209
|
it do
|
210
210
|
skip "WE DON'T NEED COUNT AND EMPTY? ON THE CORE ERRORS OBJECT"
|
211
|
-
form.errors.size
|
212
|
-
form.errors.empty
|
211
|
+
assert_equal form.errors.size, 0
|
212
|
+
assert form.errors.empty
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
@@ -219,7 +219,7 @@ class ErrorsTest < MiniTest::Spec
|
|
219
219
|
# to_s is aliased to messages
|
220
220
|
it {
|
221
221
|
skip "why do we need Errors#to_s ?"
|
222
|
-
form.errors.to_s
|
222
|
+
assert_equal form.errors.to_s, "{:\"songs.title\"=>[\"must be filled\"], :\"band.label.name\"=>[\"must be filled\"]}"
|
223
223
|
}
|
224
224
|
end
|
225
225
|
end
|