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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +0 -3
  4. data/CHANGES.md +9 -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/validation/groups.rb +0 -1
  12. data/lib/reform/version.rb +1 -1
  13. data/test/call_test.rb +23 -0
  14. data/test/changed_test.rb +6 -6
  15. data/test/coercion_test.rb +17 -17
  16. data/test/{composition_new_api.rb → composition_test.rb} +27 -28
  17. data/test/{contract_new_api.rb → contract_test.rb} +8 -8
  18. data/test/default_test.rb +2 -2
  19. data/test/deserialize_test.rb +8 -8
  20. data/test/docs/validation_test.rb +134 -0
  21. data/test/{errors_new_api.rb → errors_test.rb} +41 -41
  22. data/test/feature_test.rb +2 -2
  23. data/test/fixtures/dry_error_messages.yml +64 -54
  24. data/test/{form_option_new_api.rb → form_option_test.rb} +1 -1
  25. data/test/{form_new_api.rb → form_test.rb} +3 -3
  26. data/test/from_test.rb +10 -10
  27. data/test/{inherit_new_api.rb → inherit_test.rb} +17 -17
  28. data/test/{module_new_api.rb → module_test.rb} +10 -10
  29. data/test/parse_option_test.rb +7 -7
  30. data/test/parse_pipeline_test.rb +1 -1
  31. data/test/{populate_new_api.rb → populate_test.rb} +112 -53
  32. data/test/populator_skip_test.rb +2 -2
  33. data/test/prepopulator_test.rb +15 -15
  34. data/test/read_only_test.rb +2 -2
  35. data/test/readable_test.rb +3 -3
  36. data/test/{reform_new_api.rb → reform_test.rb} +19 -19
  37. data/test/{save_new_api.rb → save_test.rb} +4 -4
  38. data/test/setup_test.rb +9 -9
  39. data/test/{skip_if_new_api.rb → skip_if_test.rb} +12 -12
  40. data/test/skip_setter_and_getter_test.rb +6 -6
  41. data/test/test_helper.rb +5 -6
  42. data/test/{validate_new_api.rb → validate_test.rb} +65 -78
  43. data/test/validation/{dry_validation_new_api.rb → dry_validation_test.rb} +124 -123
  44. data/test/validation/result_test.rb +14 -14
  45. data/test/virtual_test.rb +7 -7
  46. data/test/writeable_test.rb +8 -8
  47. metadata +35 -68
  48. data/Appraisals +0 -8
  49. data/gemfiles/0.13.0.gemfile +0 -8
  50. data/gemfiles/1.5.0.gemfile +0 -9
  51. data/lib/reform/form/dry/new_api.rb +0 -45
  52. data/lib/reform/form/dry/old_api.rb +0 -61
  53. data/test/call_new_api.rb +0 -23
  54. data/test/call_old_api.rb +0 -23
  55. data/test/composition_old_api.rb +0 -184
  56. data/test/contract_old_api.rb +0 -77
  57. data/test/errors_old_api.rb +0 -230
  58. data/test/fixtures/dry_new_api_error_messages.yml +0 -104
  59. data/test/form_old_api.rb +0 -57
  60. data/test/form_option_old_api.rb +0 -24
  61. data/test/inherit_old_api.rb +0 -105
  62. data/test/module_old_api.rb +0 -146
  63. data/test/populate_old_api.rb +0 -304
  64. data/test/reform_old_api.rb +0 -202
  65. data/test/save_old_api.rb +0 -101
  66. data/test/skip_if_old_api.rb +0 -92
  67. data/test/validate_old_api.rb +0 -410
  68. data/test/validation/dry_validation_old_api.rb +0 -772
@@ -21,8 +21,8 @@ class PopulatorSkipTest < MiniTest::Spec
21
21
 
22
22
  form.validate(hash)
23
23
 
24
- _(form.songs.size).must_equal 2
24
+ assert_equal form.songs.size, 2
25
25
  assert_nil form.songs[0].title
26
- _(form.songs[1].title).must_equal "Bad"
26
+ assert_equal form.songs[1].title, "Bad"
27
27
  end
28
28
  end
@@ -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
- _(form.length).must_equal 1
41
- _(form.title).must_equal "Another Day At Work"
42
- _(form.hit.model).must_equal Song.new("Potemkin City Limits")
43
- _(form.songs.size).must_equal 2
44
- _(form.songs[0].model).must_equal Song.new
45
- _(form.songs[1].model).must_equal Song.new
46
- _(form.songs[1].model).must_equal Song.new
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
- _(form.hit.band.model).must_equal Band.new("Potemkin City Limits")
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
- _(form.songs.size).must_equal 2
57
- _(form.songs[0].model).must_equal Song.new
58
- _(form.songs[1].model).must_equal Song.new
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 { _(subject.songs.size).must_equal 0 }
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
- _(form.length).must_equal 1
108
- _(form.hit.model).must_equal Song.new("Potemkin City Limits")
109
- _(form.hit.title).must_equal "Potemkin City Limits"
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
@@ -9,6 +9,6 @@ class ReadonlyTest < MiniTest::Spec
9
9
 
10
10
  let(:form) { SongForm.new(OpenStruct.new) }
11
11
 
12
- it { _(form.readonly?(:artist)).must_equal false }
13
- it { _(form.readonly?(:title)).must_equal true }
12
+ it { refute form.readonly?(:artist) }
13
+ it { assert form.readonly?(:title) }
14
14
  end
@@ -15,16 +15,16 @@ class ReadableTest < MiniTest::Spec
15
15
 
16
16
  form.validate("password" => "123")
17
17
 
18
- _(form.password).must_equal "123"
18
+ assert_equal form.password, "123"
19
19
 
20
20
  form.sync
21
- _(cred.password).must_equal "123" # password written.
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
- _(hash).must_equal("password" => "123")
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
- _(form.name).must_be_nil
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
- _(form.name).must_equal "Duran Duran"
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
- _(form.name).must_equal "Duran Duran"
38
- _(form.title).must_equal "Rio"
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
- _(form.validate("name" => "Duran Duran")).must_equal true
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
- _(form.name).must_equal "Duran Duran"
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
- _(form.validate({})).must_equal false
84
+ assert_equal form.validate({}), false
85
85
  end
86
86
 
87
87
  it "populates errors" do
88
88
  form.validate({})
89
- _(form.errors.messages).must_equal(name: ["must be filled"], title: ["must be filled"])
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
- _(comp.name).must_equal "Diesel Boy"
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
- _(hash).must_equal("name" => "Diesel Boy", "title" => nil)
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 { _(form.model).must_equal comp }
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
- _(form.title).must_equal "The Body"
135
+ assert_equal form.title, "The Body"
136
136
  assert_nil form.position
137
- _(form.errors.messages).must_equal(name: ["must be filled"], position: ["must be filled"])
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 { _(subject.title).must_equal "pray" }
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 { _(subject.title).must_equal "hey little worldhey little world" }
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
- _(hash["title"]).must_equal "Hey Little WorldHey Little World"
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
- _(song.title).must_equal "Hey Little WorldHey Little World"
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 { _(subject.title).must_equal "The Suffer And The Witness" }
203
- it { _(subject.hit.title).must_equal "Drones" }
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
- _(album.saved?).must_equal true
57
- _(album.songs[0].title).must_equal "Fixed"
58
- _(album.songs[0].saved?).must_equal true
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
- _(nested_hash).must_equal({"name" => nil, "artist" => nil})
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
- _(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