reform 2.3.3 → 2.5.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/.gitignore +1 -1
- data/.travis.yml +0 -3
- data/CHANGES.md +9 -0
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +5 -5
- data/Rakefile +1 -12
- data/lib/reform/contract/validate.rb +1 -1
- data/lib/reform/form/dry.rb +47 -9
- data/lib/reform/validation/groups.rb +0 -1
- data/lib/reform/version.rb +1 -1
- 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} +112 -53
- data/test/populator_skip_test.rb +2 -2
- data/test/prepopulator_test.rb +15 -15
- 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 +5 -6
- data/test/{validate_new_api.rb → validate_test.rb} +65 -78
- data/test/validation/{dry_validation_new_api.rb → dry_validation_test.rb} +124 -123
- data/test/validation/result_test.rb +14 -14
- data/test/virtual_test.rb +7 -7
- data/test/writeable_test.rb +8 -8
- metadata +35 -68
- data/Appraisals +0 -8
- data/gemfiles/0.13.0.gemfile +0 -8
- data/gemfiles/1.5.0.gemfile +0 -9
- data/lib/reform/form/dry/new_api.rb +0 -45
- 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
data/test/populator_skip_test.rb
CHANGED
@@ -21,8 +21,8 @@ class PopulatorSkipTest < MiniTest::Spec
|
|
21
21
|
|
22
22
|
form.validate(hash)
|
23
23
|
|
24
|
-
|
24
|
+
assert_equal form.songs.size, 2
|
25
25
|
assert_nil form.songs[0].title
|
26
|
-
|
26
|
+
assert_equal form.songs[1].title, "Bad"
|
27
27
|
end
|
28
28
|
end
|
data/test/prepopulator_test.rb
CHANGED
@@ -37,25 +37,25 @@ class PrepopulatorTest < MiniTest::Spec
|
|
37
37
|
it do
|
38
38
|
form = AlbumForm.new(OpenStruct.new(length: 1)).prepopulate!(title: "Potemkin City Limits")
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
assert_equal form.length, 1
|
41
|
+
assert_equal form.title, "Another Day At Work"
|
42
|
+
assert_equal form.hit.model, Song.new("Potemkin City Limits")
|
43
|
+
assert_equal form.songs.size, 2
|
44
|
+
assert_equal form.songs[0].model, Song.new
|
45
|
+
assert_equal form.songs[1].model, Song.new
|
46
|
+
assert_equal form.songs[1].model, Song.new
|
47
47
|
# prepopulate works more than 1 level, recursive.
|
48
48
|
# it also passes options properly down there.
|
49
|
-
|
49
|
+
assert_equal form.hit.band.model, Band.new("Potemkin City Limits")
|
50
50
|
end
|
51
51
|
|
52
52
|
# add to existing collection.
|
53
53
|
it do
|
54
54
|
form = AlbumForm.new(OpenStruct.new(songs: [Song.new])).prepopulate!
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
assert_equal form.songs.size, 2
|
57
|
+
assert_equal form.songs[0].model, Song.new
|
58
|
+
assert_equal form.songs[1].model, Song.new
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -75,7 +75,7 @@ class PrepopulateWithoutConfiguration < MiniTest::Spec
|
|
75
75
|
|
76
76
|
subject { AlbumForm.new(OpenStruct.new(songs: [], hit: nil)).prepopulate! }
|
77
77
|
|
78
|
-
it {
|
78
|
+
it { assert_equal subject.songs.size, 0 }
|
79
79
|
end
|
80
80
|
|
81
81
|
class ManualPrepopulatorOverridingTest < MiniTest::Spec
|
@@ -104,8 +104,8 @@ class ManualPrepopulatorOverridingTest < MiniTest::Spec
|
|
104
104
|
it do
|
105
105
|
form = AlbumForm.new(OpenStruct.new(length: 1)).prepopulate!(title: "Potemkin City Limits")
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
assert_equal form.length, 1
|
108
|
+
assert_equal form.hit.model, Song.new("Potemkin City Limits")
|
109
|
+
assert_equal form.hit.title, "Potemkin City Limits"
|
110
110
|
end
|
111
111
|
end
|
data/test/read_only_test.rb
CHANGED
@@ -9,6 +9,6 @@ class ReadonlyTest < MiniTest::Spec
|
|
9
9
|
|
10
10
|
let(:form) { SongForm.new(OpenStruct.new) }
|
11
11
|
|
12
|
-
it {
|
13
|
-
it {
|
12
|
+
it { refute form.readonly?(:artist) }
|
13
|
+
it { assert form.readonly?(:title) }
|
14
14
|
end
|
data/test/readable_test.rb
CHANGED
@@ -15,16 +15,16 @@ class ReadableTest < MiniTest::Spec
|
|
15
15
|
|
16
16
|
form.validate("password" => "123")
|
17
17
|
|
18
|
-
|
18
|
+
assert_equal form.password, "123"
|
19
19
|
|
20
20
|
form.sync
|
21
|
-
|
21
|
+
assert_equal cred.password, "123" # password written.
|
22
22
|
|
23
23
|
hash = {}
|
24
24
|
form.save do |nested|
|
25
25
|
hash = nested
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
assert_equal hash, "password" => "123"
|
29
29
|
}
|
30
30
|
end
|
@@ -19,7 +19,7 @@ class ReformTest < Minitest::Spec
|
|
19
19
|
|
20
20
|
it "returns empty fields" do
|
21
21
|
assert_nil form.title
|
22
|
-
|
22
|
+
assert_nil form.name
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "and submitted values" do
|
@@ -27,15 +27,15 @@ class ReformTest < Minitest::Spec
|
|
27
27
|
form.validate("name" => "Duran Duran")
|
28
28
|
|
29
29
|
assert_nil form.title
|
30
|
-
|
30
|
+
assert_equal form.name, "Duran Duran"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "(edit) form with existing models" do
|
36
36
|
it "returns filled-out fields" do
|
37
|
-
|
38
|
-
|
37
|
+
assert_equal form.name, "Duran Duran"
|
38
|
+
assert_equal form.title, "Rio"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -50,13 +50,13 @@ class ReformTest < Minitest::Spec
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it "returns true when valid" do
|
53
|
-
|
53
|
+
assert_equal form.validate("name" => "Duran Duran"), true
|
54
54
|
end
|
55
55
|
|
56
56
|
it "exposes input via property accessors" do
|
57
57
|
form.validate("name" => "Duran Duran")
|
58
58
|
|
59
|
-
|
59
|
+
assert_equal form.name, "Duran Duran"
|
60
60
|
end
|
61
61
|
|
62
62
|
it "doesn't change model properties" do
|
@@ -81,12 +81,12 @@ class ReformTest < Minitest::Spec
|
|
81
81
|
let(:form) { ValidatingForm.new(comp) }
|
82
82
|
|
83
83
|
it "returns false when invalid" do
|
84
|
-
|
84
|
+
assert_equal form.validate({}), false
|
85
85
|
end
|
86
86
|
|
87
87
|
it "populates errors" do
|
88
88
|
form.validate({})
|
89
|
-
|
89
|
+
assert_equal form.errors.messages, name: ["must be filled"], title: ["must be filled"]
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
@@ -100,7 +100,7 @@ class ReformTest < Minitest::Spec
|
|
100
100
|
it "xxpushes data to models" do
|
101
101
|
form.save
|
102
102
|
|
103
|
-
|
103
|
+
assert_equal comp.name, "Diesel Boy"
|
104
104
|
assert_nil comp.title
|
105
105
|
end
|
106
106
|
|
@@ -112,13 +112,13 @@ class ReformTest < Minitest::Spec
|
|
112
112
|
hash = map
|
113
113
|
end
|
114
114
|
|
115
|
-
|
115
|
+
assert_equal hash, "name" => "Diesel Boy", "title" => nil
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
describe "#model" do
|
121
|
-
it {
|
121
|
+
it { assert_equal form.model, comp }
|
122
122
|
end
|
123
123
|
|
124
124
|
describe "inheritance" do
|
@@ -132,9 +132,9 @@ class ReformTest < Minitest::Spec
|
|
132
132
|
let(:form) { HitForm.new(OpenStruct.new()) }
|
133
133
|
it do
|
134
134
|
form.validate("title" => "The Body")
|
135
|
-
|
135
|
+
assert_equal form.title, "The Body"
|
136
136
|
assert_nil form.position
|
137
|
-
|
137
|
+
assert_equal form.errors.messages, name: ["must be filled"], position: ["must be filled"]
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
@@ -156,18 +156,18 @@ class OverridingAccessorsTest < BaseTest
|
|
156
156
|
subject { SongForm.new(song) }
|
157
157
|
|
158
158
|
# override reader for presentation.
|
159
|
-
it {
|
159
|
+
it { assert_equal subject.title, "pray" }
|
160
160
|
|
161
161
|
describe "#save" do
|
162
162
|
before { subject.validate("title" => "Hey Little World") }
|
163
163
|
|
164
164
|
# reader always used
|
165
|
-
it {
|
165
|
+
it { assert_equal subject.title, "hey little worldhey little world" }
|
166
166
|
|
167
167
|
# the reader is not used when saving/syncing.
|
168
168
|
it do
|
169
169
|
subject.save do |hash|
|
170
|
-
|
170
|
+
assert_equal hash["title"], "Hey Little WorldHey Little World"
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
@@ -175,7 +175,7 @@ class OverridingAccessorsTest < BaseTest
|
|
175
175
|
it do
|
176
176
|
song.extend(Saveable)
|
177
177
|
subject.save
|
178
|
-
|
178
|
+
assert_equal song.title, "Hey Little WorldHey Little World"
|
179
179
|
end
|
180
180
|
end
|
181
181
|
end
|
@@ -199,6 +199,6 @@ class MethodInFormTest < MiniTest::Spec
|
|
199
199
|
|
200
200
|
# methods can be used instead of created accessors.
|
201
201
|
subject { AlbumForm.new(OpenStruct.new(hit: OpenStruct.new)) }
|
202
|
-
it {
|
203
|
-
it {
|
202
|
+
it { assert_equal subject.title, "The Suffer And The Witness" }
|
203
|
+
it { assert_equal subject.hit.title, "Drones" }
|
204
204
|
end
|
@@ -53,9 +53,9 @@ class SaveTest < BaseTest
|
|
53
53
|
|
54
54
|
form.save
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
assert album.saved?
|
57
|
+
assert_equal album.songs[0].title, "Fixed"
|
58
|
+
assert album.songs[0].saved?
|
59
59
|
assert_nil album.artist.saved?
|
60
60
|
end
|
61
61
|
|
@@ -70,7 +70,7 @@ class SaveTest < BaseTest
|
|
70
70
|
nested_hash = hash
|
71
71
|
end
|
72
72
|
|
73
|
-
|
73
|
+
assert_equal nested_hash, "name" => nil, "artist" => nil
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
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
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
30
|
-
|
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
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
41
|
-
|
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
|
-
|
46
|
-
|
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
|
-
|
51
|
-
|
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
|
-
|
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
|
-
|
44
|
-
|
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
|
-
|
53
|
-
|
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
|
-
|
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
|
-
)
|
99
|
+
)
|
108
100
|
|
109
|
-
|
101
|
+
assert_equal form.errors.messages.inspect, "{}"
|
110
102
|
|
111
103
|
# form has updated.
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
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
|
-
)
|
130
|
+
)
|
139
131
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
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
|
-
)
|
195
|
+
"artist" => {"name" => "The Police"}
|
196
|
+
)
|
209
197
|
|
210
|
-
|
198
|
+
assert_equal form.errors.messages.inspect, "{}"
|
211
199
|
|
212
200
|
# form has updated.
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
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
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
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
|
-
|
217
|
+
assert_equal form.validate(
|
230
218
|
"name" => "",
|
231
219
|
"songs" => [{"title" => "Fallout"}, {"title" => "Roxanne", "composer" => {"name" => ""}}],
|
232
220
|
"artist" => {"name" => ""},
|
233
|
-
)
|
221
|
+
), false
|
234
222
|
|
235
|
-
|
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
|
-
|
242
|
-
"songs" => [{"title" => "Fallout"}, {"title" => "Roxanne"}, {"title" => "Rime Of The Ancient Mariner"}]
|
243
|
-
)
|
229
|
+
assert form.validate(
|
230
|
+
"songs" => [{"title" => "Fallout"}, {"title" => "Roxanne"}, {"title" => "Rime Of The Ancient Mariner"}]
|
231
|
+
)
|
244
232
|
|
245
|
-
|
233
|
+
assert_equal form.errors.messages.inspect, "{}"
|
246
234
|
|
247
235
|
# form has updated.
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
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
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
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
|
-
|
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
|
|