reform 2.2.4 → 2.3.3
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 +5 -5
- data/.gitignore +5 -1
- data/.travis.yml +11 -6
- data/Appraisals +8 -0
- data/CHANGES.md +57 -4
- data/CONTRIBUTING.md +31 -0
- data/Gemfile +2 -16
- data/ISSUE_TEMPLATE.md +25 -0
- data/LICENSE.txt +1 -1
- data/README.md +5 -7
- data/Rakefile +16 -9
- data/gemfiles/0.13.0.gemfile +8 -0
- data/gemfiles/1.5.0.gemfile +9 -0
- data/lib/reform.rb +1 -0
- data/lib/reform/contract.rb +7 -17
- data/lib/reform/contract/custom_error.rb +41 -0
- data/lib/reform/contract/validate.rb +53 -23
- data/lib/reform/errors.rb +61 -0
- data/lib/reform/form.rb +36 -10
- data/lib/reform/form/call.rb +1 -1
- data/lib/reform/form/composition.rb +2 -2
- data/lib/reform/form/dry.rb +10 -58
- data/lib/reform/form/dry/input_hash.rb +37 -0
- data/lib/reform/form/dry/new_api.rb +45 -0
- data/lib/reform/form/dry/old_api.rb +61 -0
- data/lib/reform/form/populator.rb +11 -27
- data/lib/reform/form/prepopulate.rb +4 -3
- data/lib/reform/form/validate.rb +28 -13
- data/lib/reform/result.rb +90 -0
- data/lib/reform/validation.rb +19 -11
- data/lib/reform/validation/groups.rb +12 -27
- data/lib/reform/version.rb +1 -1
- data/reform.gemspec +14 -13
- data/test/benchmarking.rb +39 -6
- data/test/call_new_api.rb +23 -0
- data/test/call_old_api.rb +23 -0
- data/test/changed_test.rb +14 -14
- data/test/coercion_test.rb +57 -25
- data/test/composition_new_api.rb +186 -0
- data/test/composition_old_api.rb +184 -0
- data/test/contract/custom_error_test.rb +55 -0
- data/test/contract_new_api.rb +77 -0
- data/test/contract_old_api.rb +77 -0
- data/test/default_test.rb +4 -4
- data/test/deserialize_test.rb +17 -20
- data/test/errors_new_api.rb +225 -0
- data/test/errors_old_api.rb +230 -0
- data/test/feature_test.rb +10 -12
- data/test/fixtures/dry_error_messages.yml +73 -23
- 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} +8 -8
- data/test/form_option_new_api.rb +24 -0
- data/test/{form_option_test.rb → form_option_old_api.rb} +5 -5
- data/test/from_test.rb +18 -22
- data/test/inherit_new_api.rb +105 -0
- data/test/inherit_old_api.rb +105 -0
- data/test/{module_test.rb → module_new_api.rb} +26 -31
- data/test/module_old_api.rb +146 -0
- data/test/parse_option_test.rb +40 -0
- data/test/parse_pipeline_test.rb +4 -4
- data/test/populate_new_api.rb +304 -0
- data/test/populate_old_api.rb +304 -0
- data/test/populator_skip_test.rb +11 -11
- data/test/prepopulator_test.rb +23 -24
- data/test/read_only_test.rb +12 -1
- data/test/readable_test.rb +9 -9
- data/test/reform_new_api.rb +204 -0
- data/test/{reform_test.rb → reform_old_api.rb} +44 -65
- data/test/save_new_api.rb +101 -0
- data/test/save_old_api.rb +101 -0
- data/test/setup_test.rb +17 -17
- data/test/skip_if_new_api.rb +85 -0
- data/test/skip_if_old_api.rb +92 -0
- data/test/skip_setter_and_getter_test.rb +9 -10
- data/test/test_helper.rb +25 -14
- data/test/validate_new_api.rb +453 -0
- data/test/{validate_test.rb → validate_old_api.rb} +121 -131
- data/test/validation/dry_validation_new_api.rb +835 -0
- data/test/validation/dry_validation_old_api.rb +772 -0
- data/test/validation/result_test.rb +77 -0
- data/test/validation_library_provided_test.rb +16 -0
- data/test/virtual_test.rb +47 -7
- data/test/writeable_test.rb +38 -9
- metadata +111 -56
- data/gemfiles/Gemfile.disposable-0.3 +0 -6
- data/lib/reform/contract/errors.rb +0 -43
- data/lib/reform/form/mongoid.rb +0 -37
- data/lib/reform/form/orm.rb +0 -26
- data/lib/reform/mongoid.rb +0 -4
- data/test/call_test.rb +0 -23
- data/test/composition_test.rb +0 -149
- data/test/contract_test.rb +0 -77
- data/test/deprecation_test.rb +0 -27
- data/test/errors_test.rb +0 -165
- data/test/inherit_test.rb +0 -119
- data/test/populate_test.rb +0 -270
- data/test/readonly_test.rb +0 -14
- data/test/save_test.rb +0 -89
- data/test/skip_if_test.rb +0 -74
- data/test/validation/dry_test.rb +0 -60
- data/test/validation/dry_validation_test.rb +0 -352
- data/test/validation/errors.yml +0 -4
@@ -0,0 +1,101 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SaveTest < BaseTest
|
4
|
+
Song = Struct.new(:title, :album, :composer)
|
5
|
+
Album = Struct.new(:name, :songs, :artist)
|
6
|
+
Artist = Struct.new(:name)
|
7
|
+
|
8
|
+
class AlbumForm < TestForm
|
9
|
+
property :name
|
10
|
+
validation do
|
11
|
+
params { required(:name).filled }
|
12
|
+
end
|
13
|
+
|
14
|
+
collection :songs do
|
15
|
+
property :title
|
16
|
+
validation do
|
17
|
+
params { required(:title).filled }
|
18
|
+
end
|
19
|
+
|
20
|
+
property :composer do
|
21
|
+
property :name
|
22
|
+
validation do
|
23
|
+
params { required(:name).filled }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
property :artist, save: false do
|
29
|
+
property :name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Saveable
|
34
|
+
def save
|
35
|
+
@saved = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def saved?
|
39
|
+
defined?(@saved) && @saved
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:song) { Song.new("Broken").extend(Saveable) }
|
44
|
+
# let(:song_with_composer) { Song.new("Resist Stance", nil, composer).extend(Saveable) }
|
45
|
+
let(:composer) { Artist.new("Greg Graffin").extend(Saveable) }
|
46
|
+
let(:artist) { Artist.new("Bad Religion").extend(Saveable).extend(Saveable) }
|
47
|
+
let(:album) { Album.new("The Dissent Of Man", [song], artist).extend(Saveable) }
|
48
|
+
|
49
|
+
let(:form) { AlbumForm.new(album) }
|
50
|
+
|
51
|
+
it do
|
52
|
+
form.validate("songs" => [{"title" => "Fixed"}])
|
53
|
+
|
54
|
+
form.save
|
55
|
+
|
56
|
+
_(album.saved?).must_equal true
|
57
|
+
_(album.songs[0].title).must_equal "Fixed"
|
58
|
+
_(album.songs[0].saved?).must_equal true
|
59
|
+
assert_nil album.artist.saved?
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#sync with block" do
|
63
|
+
it do
|
64
|
+
form = AlbumForm.new(Album.new("Greatest Hits"))
|
65
|
+
|
66
|
+
form.validate(name: nil) # nil-out the title.
|
67
|
+
|
68
|
+
nested_hash = nil
|
69
|
+
form.sync do |hash|
|
70
|
+
nested_hash = hash
|
71
|
+
end
|
72
|
+
|
73
|
+
_(nested_hash).must_equal({"name" => nil, "artist" => nil})
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# class SaveWithDynamicOptionsTest < MiniTest::Spec
|
79
|
+
# Song = Struct.new(:id, :title, :length) do
|
80
|
+
# include Saveable
|
81
|
+
# end
|
82
|
+
|
83
|
+
# class SongForm < TestForm
|
84
|
+
# property :title#, save: false
|
85
|
+
# property :length, virtual: true
|
86
|
+
# end
|
87
|
+
|
88
|
+
# let(:song) { Song.new }
|
89
|
+
# let(:form) { SongForm.new(song) }
|
90
|
+
|
91
|
+
# # we have access to original input value and outside parameters.
|
92
|
+
# it "xxx" do
|
93
|
+
# form.validate("title" => "A Poor Man's Memory", "length" => 10)
|
94
|
+
# length_seconds = 120
|
95
|
+
# form.save(length: lambda { |value, options| form.model.id = "#{value}: #{length_seconds}" })
|
96
|
+
|
97
|
+
# song.title.must_equal "A Poor Man's Memory"
|
98
|
+
# assert_nil song.length
|
99
|
+
# song.id.must_equal "10: 120"
|
100
|
+
# end
|
101
|
+
# end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SaveTest < BaseTest
|
4
|
+
Song = Struct.new(:title, :album, :composer)
|
5
|
+
Album = Struct.new(:name, :songs, :artist)
|
6
|
+
Artist = Struct.new(:name)
|
7
|
+
|
8
|
+
class AlbumForm < TestForm
|
9
|
+
property :name
|
10
|
+
validation do
|
11
|
+
required(:name).filled
|
12
|
+
end
|
13
|
+
|
14
|
+
collection :songs do
|
15
|
+
property :title
|
16
|
+
validation do
|
17
|
+
required(:title).filled
|
18
|
+
end
|
19
|
+
|
20
|
+
property :composer do
|
21
|
+
property :name
|
22
|
+
validation do
|
23
|
+
required(:name).filled
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
property :artist, save: false do
|
29
|
+
property :name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Saveable
|
34
|
+
def save
|
35
|
+
@saved = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def saved?
|
39
|
+
defined?(@saved) && @saved
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:song) { Song.new("Broken").extend(Saveable) }
|
44
|
+
# let(:song_with_composer) { Song.new("Resist Stance", nil, composer).extend(Saveable) }
|
45
|
+
let(:composer) { Artist.new("Greg Graffin").extend(Saveable) }
|
46
|
+
let(:artist) { Artist.new("Bad Religion").extend(Saveable).extend(Saveable) }
|
47
|
+
let(:album) { Album.new("The Dissent Of Man", [song], artist).extend(Saveable) }
|
48
|
+
|
49
|
+
let(:form) { AlbumForm.new(album) }
|
50
|
+
|
51
|
+
it do
|
52
|
+
form.validate("songs" => [{"title" => "Fixed"}])
|
53
|
+
|
54
|
+
form.save
|
55
|
+
|
56
|
+
_(album.saved?).must_equal true
|
57
|
+
_(album.songs[0].title).must_equal "Fixed"
|
58
|
+
_(album.songs[0].saved?).must_equal true
|
59
|
+
assert_nil album.artist.saved?
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#sync with block" do
|
63
|
+
it do
|
64
|
+
form = AlbumForm.new(Album.new("Greatest Hits"))
|
65
|
+
|
66
|
+
form.validate(name: nil) # nil-out the title.
|
67
|
+
|
68
|
+
nested_hash = nil
|
69
|
+
form.sync do |hash|
|
70
|
+
nested_hash = hash
|
71
|
+
end
|
72
|
+
|
73
|
+
_(nested_hash).must_equal({"name" => nil, "artist" => nil})
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# class SaveWithDynamicOptionsTest < MiniTest::Spec
|
79
|
+
# Song = Struct.new(:id, :title, :length) do
|
80
|
+
# include Saveable
|
81
|
+
# end
|
82
|
+
|
83
|
+
# class SongForm < TestForm
|
84
|
+
# property :title#, save: false
|
85
|
+
# property :length, virtual: true
|
86
|
+
# end
|
87
|
+
|
88
|
+
# let(:song) { Song.new }
|
89
|
+
# let(:form) { SongForm.new(song) }
|
90
|
+
|
91
|
+
# # we have access to original input value and outside parameters.
|
92
|
+
# it "xxx" do
|
93
|
+
# form.validate("title" => "A Poor Man's Memory", "length" => 10)
|
94
|
+
# length_seconds = 120
|
95
|
+
# form.save(length: lambda { |value, options| form.model.id = "#{value}: #{length_seconds}" })
|
96
|
+
|
97
|
+
# song.title.must_equal "A Poor Man's Memory"
|
98
|
+
# assert_nil song.length
|
99
|
+
# song.id.must_equal "10: 120"
|
100
|
+
# end
|
101
|
+
# end
|
data/test/setup_test.rb
CHANGED
@@ -5,7 +5,7 @@ class SetupTest < MiniTest::Spec
|
|
5
5
|
Album = Struct.new(:name, :songs, :artist)
|
6
6
|
Artist = Struct.new(:name)
|
7
7
|
|
8
|
-
class AlbumForm <
|
8
|
+
class AlbumForm < TestForm
|
9
9
|
property :name
|
10
10
|
collection :songs do
|
11
11
|
property :title
|
@@ -20,29 +20,29 @@ class SetupTest < MiniTest::Spec
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
let
|
24
|
-
let
|
25
|
-
let
|
26
|
-
let
|
23
|
+
let(:song) { Song.new("Broken") }
|
24
|
+
let(:song_with_composer) { Song.new("Resist Stance", nil, composer) }
|
25
|
+
let(:composer) { Artist.new("Greg Graffin") }
|
26
|
+
let(:artist) { Artist.new("Bad Religion") }
|
27
27
|
|
28
28
|
describe "with nested objects" do
|
29
|
-
let
|
29
|
+
let(:album) { Album.new("The Dissent Of Man", [song, song_with_composer], artist) }
|
30
30
|
|
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"
|
36
|
-
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"
|
34
|
+
_(form.name).must_equal "The Dissent Of Man"
|
35
|
+
_(form.songs[0].title).must_equal "Broken"
|
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"
|
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
|
+
_(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
|
46
46
|
end
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SkipIfTest < BaseTest
|
4
|
+
let(:hit) { Song.new }
|
5
|
+
let(:album) { Album.new(nil, hit, [], nil) }
|
6
|
+
|
7
|
+
class AlbumForm < TestForm
|
8
|
+
property :title
|
9
|
+
|
10
|
+
property :hit, skip_if: ->(options) { options[:fragment]["title"] == "" } do
|
11
|
+
property :title
|
12
|
+
validation do
|
13
|
+
params { required(:title).filled }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
collection :songs, skip_if: :skip_song?, populate_if_empty: BaseTest::Song do
|
18
|
+
property :title
|
19
|
+
end
|
20
|
+
|
21
|
+
def skip_song?(options)
|
22
|
+
options[:fragment]["title"].nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# deserializes when present.
|
27
|
+
it do
|
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"
|
31
|
+
end
|
32
|
+
|
33
|
+
# skips deserialization when not present.
|
34
|
+
it do
|
35
|
+
form = AlbumForm.new(Album.new)
|
36
|
+
_(form.validate("hit" => {"title" => ""})).must_equal true
|
37
|
+
assert_nil form.hit # hit hasn't been deserialised.
|
38
|
+
end
|
39
|
+
|
40
|
+
# skips deserialization when not present.
|
41
|
+
it do
|
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"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class SkipIfAllBlankTest < BaseTest
|
50
|
+
# skip_if: :all_blank"
|
51
|
+
class AlbumForm < TestForm
|
52
|
+
collection :songs, skip_if: :all_blank, populate_if_empty: BaseTest::Song do
|
53
|
+
property :title
|
54
|
+
property :length
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# create only one object.
|
59
|
+
it do
|
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"
|
64
|
+
end
|
65
|
+
|
66
|
+
it do
|
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"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class InvalidOptionsCombinationTest < BaseTest
|
75
|
+
it do
|
76
|
+
assert_raises(Reform::Form::InvalidOptionsCombinationError) do
|
77
|
+
class AlbumForm < TestForm
|
78
|
+
collection :songs, skip_if: :all_blank, populator: -> {} do
|
79
|
+
property :title
|
80
|
+
property :length
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SkipIfTest < BaseTest
|
4
|
+
let(:hit) { Song.new }
|
5
|
+
let(:album) { Album.new(nil, hit, [], nil) }
|
6
|
+
|
7
|
+
class AlbumForm < TestForm
|
8
|
+
property :title
|
9
|
+
|
10
|
+
property :hit, skip_if: ->(options) { options[:fragment]["title"] == "" } do
|
11
|
+
property :title
|
12
|
+
validation do
|
13
|
+
required(:title).filled
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
collection :songs, skip_if: :skip_song?, populate_if_empty: BaseTest::Song do
|
18
|
+
property :title
|
19
|
+
end
|
20
|
+
|
21
|
+
def skip_song?(options)
|
22
|
+
options[:fragment]["title"].nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# deserializes when present.
|
27
|
+
it do
|
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"
|
31
|
+
end
|
32
|
+
|
33
|
+
# skips deserialization when not present.
|
34
|
+
it do
|
35
|
+
form = AlbumForm.new(Album.new)
|
36
|
+
_(form.validate("hit" => {"title" => ""})).must_equal true
|
37
|
+
assert_nil form.hit # hit hasn't been deserialised.
|
38
|
+
end
|
39
|
+
|
40
|
+
# skips deserialization when not present.
|
41
|
+
it do
|
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"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class SkipIfAllBlankTest < BaseTest
|
50
|
+
# skip_if: :all_blank"
|
51
|
+
class AlbumForm < TestForm
|
52
|
+
collection :songs, skip_if: :all_blank, populate_if_empty: BaseTest::Song do
|
53
|
+
property :title
|
54
|
+
property :length
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# create only one object.
|
59
|
+
it do
|
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"
|
64
|
+
end
|
65
|
+
|
66
|
+
it do
|
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"
|
71
|
+
end
|
72
|
+
|
73
|
+
it do
|
74
|
+
form = AlbumForm.new(OpenStruct.new(songs: []))
|
75
|
+
_(form.validate(:songs => [{:title=>"", :length => ""}, {:title=>"Apathy"}])).must_equal true
|
76
|
+
_(form.songs.size).must_equal 1
|
77
|
+
_(form.songs[0].title).must_equal "Apathy"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class InvalidOptionsCombinationTest < BaseTest
|
82
|
+
it do
|
83
|
+
assert_raises(Reform::Form::InvalidOptionsCombinationError) do
|
84
|
+
class AlbumForm < TestForm
|
85
|
+
collection :songs, skip_if: :all_blank, populator: -> {} do
|
86
|
+
property :title
|
87
|
+
property :length
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -7,7 +7,7 @@ class SetupSkipSetterAndGetterTest < MiniTest::Spec
|
|
7
7
|
Album = Struct.new(:title, :artist)
|
8
8
|
Artist = Struct.new(:name)
|
9
9
|
|
10
|
-
class AlbumForm <
|
10
|
+
class AlbumForm < TestForm
|
11
11
|
property :title
|
12
12
|
|
13
13
|
def title
|
@@ -31,24 +31,23 @@ class SetupSkipSetterAndGetterTest < MiniTest::Spec
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
let
|
35
|
-
|
34
|
+
let(:artist) { Artist.new("Bad Religion") }
|
36
35
|
|
37
36
|
it do
|
38
37
|
album = Album.new("Greatest Hits", artist)
|
39
38
|
form = AlbumForm.new(album)
|
40
39
|
|
41
|
-
form.title.must_equal "GREATEST HITS"
|
42
|
-
form.artist.name.must_equal "bad religion"
|
40
|
+
_(form.title).must_equal "GREATEST HITS"
|
41
|
+
_(form.artist.name).must_equal "bad religion"
|
43
42
|
|
44
43
|
form.validate("title" => "Resiststance", "artist" => {"name" => "Greg Graffin"})
|
45
44
|
|
46
|
-
form.title.must_equal "ECNATSTSISER" # first, setter called, then getter.
|
47
|
-
form.artist.name.must_equal "greg graffi"
|
45
|
+
_(form.title).must_equal "ECNATSTSISER" # first, setter called, then getter.
|
46
|
+
_(form.artist.name).must_equal "greg graffi"
|
48
47
|
|
49
48
|
form.sync
|
50
49
|
|
51
|
-
album.title.must_equal "ecnatstsiseR" # setter called, but not getter.
|
52
|
-
album.artist.name.must_equal "Greg Graffi"
|
50
|
+
_(album.title).must_equal "ecnatstsiseR" # setter called, but not getter.
|
51
|
+
_(album.artist.name).must_equal "Greg Graffi"
|
53
52
|
end
|
54
|
-
end
|
53
|
+
end
|