disposable 0.4.5 → 0.6.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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +29 -0
  3. data/.gitignore +1 -0
  4. data/CHANGES.md +20 -0
  5. data/Gemfile +2 -0
  6. data/Gemfile_builder_test.rb +6 -0
  7. data/README.md +4 -0
  8. data/Rakefile +8 -2
  9. data/disposable.gemspec +3 -6
  10. data/lib/disposable/twin/builder.rb +1 -0
  11. data/lib/disposable/twin/coercion.rb +7 -2
  12. data/lib/disposable/twin/default.rb +3 -3
  13. data/lib/disposable/twin/property/struct.rb +3 -1
  14. data/lib/disposable/twin/property/unnest.rb +4 -3
  15. data/lib/disposable/twin.rb +10 -4
  16. data/lib/disposable/version.rb +1 -1
  17. data/test/callback_group_test.rb +27 -27
  18. data/test/callbacks_test.rb +44 -44
  19. data/test/expose_test.rb +16 -16
  20. data/test/persisted_test.rb +30 -30
  21. data/test/rescheme_test.rb +22 -22
  22. data/test/skip_getter_test.rb +14 -14
  23. data/test/test_helper.rb +1 -1
  24. data/test/twin/builder_test.rb +7 -3
  25. data/test/twin/changed_test.rb +38 -38
  26. data/test/twin/coercion_test.rb +63 -26
  27. data/test/twin/collection_test.rb +46 -46
  28. data/test/twin/composition_test.rb +20 -20
  29. data/test/twin/default_test.rb +15 -15
  30. data/test/twin/expose_test.rb +15 -15
  31. data/test/twin/feature_test.rb +10 -10
  32. data/test/twin/from_collection_test.rb +4 -4
  33. data/test/twin/from_test.rb +3 -3
  34. data/test/twin/hash_test.rb +38 -38
  35. data/test/twin/inherit_test.rb +7 -7
  36. data/test/twin/inheritance_test.rb +6 -6
  37. data/test/twin/parent_test.rb +5 -5
  38. data/test/twin/property_processor_test.rb +3 -3
  39. data/test/twin/readable_test.rb +9 -9
  40. data/test/twin/save_test.rb +44 -44
  41. data/test/twin/setup_test.rb +25 -25
  42. data/test/twin/skip_unchanged_test.rb +6 -6
  43. data/test/twin/struct/coercion_test.rb +5 -5
  44. data/test/twin/struct_test.rb +41 -38
  45. data/test/twin/sync_test.rb +29 -29
  46. data/test/twin/twin_test.rb +24 -14
  47. data/test/twin/unnest_test.rb +7 -7
  48. data/test/twin/virtual_test.rb +3 -3
  49. data/test/twin/writeable_test.rb +8 -8
  50. metadata +14 -69
  51. data/.travis.yml +0 -31
@@ -44,16 +44,16 @@ class TwinSetupTest < MiniTest::Spec
44
44
  it do
45
45
  twin = Twin::Album.new(album)
46
46
 
47
- twin.songs.size.must_equal 2
48
- twin.songs.must_be_instance_of Disposable::Twin::Collection
47
+ expect(twin.songs.size).must_equal 2
48
+ expect(twin.songs).must_be_instance_of Disposable::Twin::Collection
49
49
 
50
- twin.songs[0].must_be_instance_of Twin::Song
51
- twin.songs[0].id.must_equal 1
50
+ expect(twin.songs[0]).must_be_instance_of Twin::Song
51
+ expect(twin.songs[0].id).must_equal 1
52
52
 
53
- twin.songs[1].must_be_instance_of Twin::Song
54
- twin.songs[1].id.must_equal 1
55
- twin.songs[1].composer.must_be_instance_of Twin::Artist
56
- twin.songs[1].composer.id.must_equal 2
53
+ expect(twin.songs[1]).must_be_instance_of Twin::Song
54
+ expect(twin.songs[1].id).must_equal 1
55
+ expect(twin.songs[1].composer).must_be_instance_of Twin::Artist
56
+ expect(twin.songs[1].composer.id).must_equal 2
57
57
  end
58
58
  end
59
59
 
@@ -63,8 +63,8 @@ class TwinSetupTest < MiniTest::Spec
63
63
  it do
64
64
  twin = Twin::Album.new(album)
65
65
 
66
- twin.songs.size.must_equal 0
67
- twin.songs.must_be_instance_of Disposable::Twin::Collection
66
+ expect(twin.songs.size).must_equal 0
67
+ expect(twin.songs).must_be_instance_of Disposable::Twin::Collection
68
68
  end
69
69
  end
70
70
 
@@ -75,7 +75,7 @@ class TwinSetupTest < MiniTest::Spec
75
75
  # it do
76
76
  # twin = Twin::Album.new(album)
77
77
 
78
- # twin.songs.size.must_equal 0
78
+ # twin.songs.size).must_equal 0
79
79
  # twin.songs.must_be_instance_of Disposable::Twin::Collection
80
80
  # end
81
81
  # end
@@ -118,23 +118,23 @@ class TwinSetupWithInlineTwinsTest < MiniTest::Spec
118
118
  twin = AlbumForm.new(album)
119
119
  # pp twin
120
120
 
121
- twin.id.must_equal 0
122
- twin.name.must_equal "Toto Live"
121
+ expect(twin.id).must_equal 0
122
+ expect(twin.name).must_equal "Toto Live"
123
123
 
124
- twin.artist.must_be_kind_of Disposable::Twin
125
- twin.artist.id.must_equal 9
124
+ expect(twin.artist).must_be_kind_of Disposable::Twin
125
+ expect(twin.artist.id).must_equal 9
126
126
 
127
- twin.songs.must_be_instance_of Disposable::Twin::Collection
127
+ expect(twin.songs).must_be_instance_of Disposable::Twin::Collection
128
128
 
129
129
  # nil nested objects work (no composer)
130
- twin.songs[0].must_be_kind_of Disposable::Twin
131
- twin.songs[0].id.must_equal 1
130
+ expect(twin.songs[0]).must_be_kind_of Disposable::Twin
131
+ expect(twin.songs[0].id).must_equal 1
132
132
 
133
- twin.songs[1].must_be_kind_of Disposable::Twin
134
- twin.songs[1].id.must_equal 3
133
+ expect(twin.songs[1]).must_be_kind_of Disposable::Twin
134
+ expect(twin.songs[1].id).must_equal 3
135
135
 
136
- twin.songs[1].composer.must_be_kind_of Disposable::Twin
137
- twin.songs[1].composer.id.must_equal 2
136
+ expect(twin.songs[1].composer).must_be_kind_of Disposable::Twin
137
+ expect(twin.songs[1].composer.id).must_equal 2
138
138
  end
139
139
  end
140
140
 
@@ -149,7 +149,7 @@ class TwinWithVirtualSetupTest < MiniTest::Spec
149
149
 
150
150
  it do
151
151
  twin = AlbumTwin.new(Song.new(1), is_online: true)
152
- twin.id.must_equal 1
153
- twin.is_online.must_equal true
152
+ expect(twin.id).must_equal 1
153
+ expect(twin.is_online).must_equal true
154
154
  end
155
- end
155
+ end
@@ -53,12 +53,12 @@ class SkipUnchangedTest < MiniTest::Spec
53
53
  twin.sync
54
54
 
55
55
  # unchanged, and no exception raised.
56
- album.name.must_equal "30 Years Live"
57
- song_with_composer.title.must_equal "American Jesus"
58
- artist.name.must_equal "Bad Religion"
56
+ expect(album.name).must_equal "30 Years Live"
57
+ expect(song_with_composer.title).must_equal "American Jesus"
58
+ expect(artist.name).must_equal "Bad Religion"
59
59
 
60
60
  # this actually got synced.
61
- song_with_composer.composer.name.must_equal "Greg Graffin" # was nil.
62
- song.title.must_equal "Resist Stance" # was nil.
61
+ expect(song_with_composer.composer.name).must_equal "Greg Graffin" # was nil.
62
+ expect(song.title).must_equal "Resist Stance" # was nil.
63
63
  end
64
- end
64
+ end
@@ -10,7 +10,7 @@ class StructCoercionTest < Minitest::Spec
10
10
  feature Coercion
11
11
 
12
12
  property :content do
13
- property :amount, type: DRY_TYPES_CONSTANT::Float
13
+ property :amount, type: DRY_TYPES_CONSTANT::Float | DRY_TYPES_CONSTANT::Nil
14
14
  end
15
15
 
16
16
  unnest :amount, from: :content
@@ -21,16 +21,16 @@ class StructCoercionTest < Minitest::Spec
21
21
  twin = Expense.new( ExpenseModel.new({}) )
22
22
 
23
23
  #- direct access, without unnest
24
- twin.content.amount.must_be_nil
24
+ expect(twin.content.amount).must_be_nil
25
25
  twin.content.amount = "1.8"
26
- twin.content.amount.must_equal 1.8
26
+ expect(twin.content.amount).must_equal 1.8
27
27
  end
28
28
 
29
29
  it "via unnest" do
30
30
  twin = Expense.new( ExpenseModel.new({}) )
31
31
 
32
- twin.amount.must_be_nil
32
+ expect(twin.amount).must_be_nil
33
33
  twin.amount = "1.8"
34
- twin.amount.must_equal 1.8
34
+ expect(twin.amount).must_equal 1.8
35
35
  end
36
36
  end
@@ -11,19 +11,22 @@ class TwinStructTest < MiniTest::Spec
11
11
  end
12
12
 
13
13
  # empty hash
14
- # it { Song.new({}).number.must_equal 1 }
15
- it { Song.new({}).number.must_be_nil } # TODO: implement default.
14
+ # it { Song.new({}).number).must_equal 1 }
15
+ it { expect(Song.new({}).number).must_be_nil } # TODO: implement default.
16
16
 
17
17
  # model hash
18
- it { Song.new(number: 2).number.must_equal 2 }
18
+ it { expect(Song.new(number: 2).number).must_equal 2 }
19
19
 
20
20
  # with hash and options as one hash.
21
- it { Song.new(number: 3, cool?: true).cool?.must_equal true }
22
- it { Song.new(number: 3, cool?: true).number.must_equal 3 }
21
+ it { expect(Song.new(number: 3, cool?: true).cool?).must_equal true }
22
+ it { expect(Song.new(number: 3, cool?: true).number).must_equal 3 }
23
23
 
24
24
  # with model hash and options hash separated.
25
- it { Song.new({number: 3}, {cool?: true}).cool?.must_equal true }
26
- it { Song.new({number: 3}, {cool?: true}).number.must_equal 3 }
25
+ it { expect(Song.new({number: 3}, {cool?: true}).cool?).must_equal true }
26
+ it { expect(Song.new({number: 3}, {cool?: true}).number).must_equal 3 }
27
+
28
+ # with string key and false value
29
+ it { Song.new('number' => 3, 'cool?' => false).cool?.must_equal false }
27
30
 
28
31
 
29
32
  describe "writing" do
@@ -33,8 +36,8 @@ class TwinStructTest < MiniTest::Spec
33
36
  # writer
34
37
  it do
35
38
  song.number = 9
36
- song.number.must_equal 9
37
- model[:number].must_equal 3
39
+ expect(song.number).must_equal 9
40
+ expect(model[:number]).must_equal 3
38
41
  end
39
42
 
40
43
  # writer with sync
@@ -42,10 +45,10 @@ class TwinStructTest < MiniTest::Spec
42
45
  song.number = 9
43
46
  model = song.sync
44
47
 
45
- song.number.must_equal 9
46
- model["number"].must_equal 9
48
+ expect(song.number).must_equal 9
49
+ expect(model["number"]).must_equal 9
47
50
 
48
- # song.send(:model).object_id.must_equal model.object_id
51
+ # song.send(:model).object_id).must_equal model.object_id
49
52
  end
50
53
  end
51
54
  end
@@ -79,26 +82,26 @@ class TwinWithNestedStructTest < MiniTest::Spec
79
82
  preferences: {show_image: true, play_teaser: 2}, roles: [{name: "user"}]}) }
80
83
 
81
84
  # public "hash" reader
82
- it { Song.new(model).options.recorded.must_equal true }
85
+ it { expect(Song.new(model).options.recorded).must_equal true }
83
86
 
84
87
  # public "hash" writer
85
88
  it {
86
89
  song = Song.new(model)
87
90
 
88
91
  song.options.recorded = "yo"
89
- song.options.recorded.must_equal "yo"
92
+ expect(song.options.recorded).must_equal "yo"
90
93
 
91
- song.options.preferences.show_image.must_equal true
92
- song.options.preferences.play_teaser.must_equal 2
94
+ expect(song.options.preferences.show_image).must_equal true
95
+ expect(song.options.preferences.play_teaser).must_equal 2
93
96
 
94
97
  song.options.preferences.show_image= 9
95
98
 
96
99
 
97
100
  song.sync # this is only called on the top model, e.g. in Reform#save.
98
101
 
99
- model.title.must_equal "Seed of Fear and Anger"
100
- model.options["recorded"].must_equal "yo"
101
- model.options["preferences"].must_equal({"show_image" => 9, "play_teaser"=>2})
102
+ expect(model.title).must_equal "Seed of Fear and Anger"
103
+ expect(model.options["recorded"]).must_equal "yo"
104
+ expect(model.options["preferences"]).must_equal({"show_image" => 9, "play_teaser"=>2})
102
105
  }
103
106
 
104
107
  describe "nested writes" do
@@ -111,14 +114,14 @@ class TwinWithNestedStructTest < MiniTest::Spec
111
114
  role = song.options.roles.append({}) # add empty "model" to hash collection.
112
115
  role.name = "admin"
113
116
 
114
- song.options.roles.size.must_equal 2
115
- song.options.roles[0].name.must_equal "user"
116
- song.options.roles[1].name.must_equal "admin"
117
- model.options[:roles].must_equal([{:name=>"user"}]) # model hasn't changed, of course.
117
+ expect(song.options.roles.size).must_equal 2
118
+ expect(song.options.roles[0].name).must_equal "user"
119
+ expect(song.options.roles[1].name).must_equal "admin"
120
+ expect(model.options[:roles]).must_equal([{:name=>"user"}]) # model hasn't changed, of course.
118
121
 
119
122
  song.sync
120
123
 
121
- model.options.must_equal({"recorded"=>true, "released"=>1, "preferences"=>{"show_image"=>true, "play_teaser"=>2}, "roles"=>[{"name"=>"user"}, {"name"=>"admin"}]})
124
+ expect(model.options).must_equal({"recorded"=>true, "released"=>1, "preferences"=>{"show_image"=>true, "play_teaser"=>2}, "roles"=>[{"name"=>"user"}, {"name"=>"admin"}]})
122
125
  end
123
126
 
124
127
  # overwriting nested property via #preferences=.
@@ -126,7 +129,7 @@ class TwinWithNestedStructTest < MiniTest::Spec
126
129
  song.options.preferences = {play_teaser: :maybe}
127
130
  song.sync
128
131
 
129
- model.options.must_equal({"recorded"=>true, "released"=>1, "preferences"=>{"play_teaser"=>:maybe}, "roles"=>[{"name"=>"user"}]})
132
+ expect(model.options).must_equal({"recorded"=>true, "released"=>1, "preferences"=>{"play_teaser"=>:maybe}, "roles"=>[{"name"=>"user"}]})
130
133
  end
131
134
 
132
135
  # overwriting collection via #roles=.
@@ -134,7 +137,7 @@ class TwinWithNestedStructTest < MiniTest::Spec
134
137
  song.options.roles = [{name: "wizard"}]
135
138
  song.sync
136
139
 
137
- model.options.must_equal({"recorded"=>true, "released"=>1, "preferences"=>{"show_image"=>true, "play_teaser"=>2}, "roles"=>[{"name"=>"wizard"}]})
140
+ expect(model.options).must_equal({"recorded"=>true, "released"=>1, "preferences"=>{"show_image"=>true, "play_teaser"=>2}, "roles"=>[{"name"=>"wizard"}]})
138
141
  end
139
142
  end
140
143
 
@@ -146,7 +149,7 @@ class TwinWithNestedStructTest < MiniTest::Spec
146
149
 
147
150
  # song.sync
148
151
 
149
- # model[:options][:roles].must_equal({ })
152
+ # model[:options][:roles]).must_equal({ })
150
153
 
151
154
  # pp song
152
155
 
@@ -178,8 +181,8 @@ class StructReadableWriteableTest < Minitest::Spec
178
181
 
179
182
  it "ignores readable: false" do
180
183
  song = Song.new(length: 123, id: 1)
181
- song.length.must_equal 123
182
- song.id.must_be_nil
184
+ expect(song.length).must_equal 123
185
+ expect(song.id).must_be_nil
183
186
  end
184
187
 
185
188
  it "ignores writeable: false" do
@@ -209,20 +212,20 @@ class DefaultWithStructTest < Minitest::Spec
209
212
  # all given.
210
213
  it do
211
214
  twin = Twin.new(Song.new({enabled: true, roles: {admin: false}}))
212
- twin.settings.enabled.must_equal true
213
- twin.settings.roles.admin.must_equal false
215
+ expect(twin.settings.enabled).must_equal true
216
+ expect(twin.settings.roles.admin).must_equal false
214
217
  end
215
218
 
216
219
  # defaults, please.
217
220
  it do
218
221
  song = Song.new
219
222
  twin = Twin.new(song)
220
- twin.settings.enabled.must_equal "yes"
221
- twin.settings.roles.admin.must_equal "maybe"
223
+ expect(twin.settings.enabled).must_equal "yes"
224
+ expect(twin.settings.roles.admin).must_equal "maybe"
222
225
 
223
226
  twin.sync
224
227
 
225
- song.settings.must_equal({"enabled"=>"yes", "roles"=>{"admin"=>"maybe"}})
228
+ expect(song.settings).must_equal({"enabled"=>"yes", "roles"=>{"admin"=>"maybe"}})
226
229
  end
227
230
  end
228
231
 
@@ -258,7 +261,7 @@ class CompositionWithStructTest < Minitest::Spec
258
261
 
259
262
  twin.sync
260
263
 
261
- model.content.must_equal({"tags"=>["history"], "notes"=>[{"text"=>"Freedom", "index"=>0}, {"text"=>"Like", "index"=>1}, {"text"=>"Canberra trip", "index"=>2}]})
264
+ expect(model.content).must_equal({"tags"=>["history"], "notes"=>[{"text"=>"Freedom", "index"=>0}, {"text"=>"Like", "index"=>1}, {"text"=>"Canberra trip", "index"=>2}]})
262
265
  end
263
266
 
264
267
  class Sheet < Disposable::Twin
@@ -319,9 +322,9 @@ class CompositionWithStructTest < Minitest::Spec
319
322
 
320
323
 
321
324
 
322
- sheet.tags.must_equal "#hashtag"
323
- sheet.notes[0].text.must_equal "Freedom"
324
- sheet.notes[0].index.must_equal 0
325
+ expect(sheet.tags).must_equal "#hashtag"
326
+ expect(sheet.notes[0].text).must_equal "Freedom"
327
+ expect(sheet.notes[0].index).must_equal 0
325
328
 
326
329
  sheet.notes[0].index = 2
327
330
 
@@ -47,23 +47,23 @@ class TwinSyncTest < MiniTest::Spec
47
47
  fill_out!(twin)
48
48
 
49
49
  # not written to model, yet.
50
- album.name.must_be_nil
51
- album.songs[0].title.must_be_nil
52
- album.songs[1].title.must_be_nil
53
- album.songs[1].composer.name.must_be_nil
54
- album.artist.name.must_be_nil
50
+ expect(album.name).must_be_nil
51
+ expect(album.songs[0].title).must_be_nil
52
+ expect(album.songs[1].title).must_be_nil
53
+ expect(album.songs[1].composer.name).must_be_nil
54
+ expect(album.artist.name).must_be_nil
55
55
 
56
56
  twin.sync
57
57
 
58
- album.name.must_equal "Live And Dangerous"
59
- album.songs[0].must_be_instance_of Model::Song
60
- album.songs[1].must_be_instance_of Model::Song
61
- album.songs[0].title.must_equal "Southbound"
62
- album.songs[1].title.must_equal "The Boys Are Back In Town"
63
- album.songs[1].composer.must_be_instance_of Model::Artist
64
- album.songs[1].composer.name.must_equal "Lynott"
65
- album.artist.must_be_instance_of Model::Artist
66
- album.artist.name.must_equal "Thin Lizzy"
58
+ expect(album.name).must_equal "Live And Dangerous"
59
+ expect(album.songs[0]).must_be_instance_of Model::Song
60
+ expect(album.songs[1]).must_be_instance_of Model::Song
61
+ expect(album.songs[0].title).must_equal "Southbound"
62
+ expect(album.songs[1].title).must_equal "The Boys Are Back In Town"
63
+ expect(album.songs[1].composer).must_be_instance_of Model::Artist
64
+ expect(album.songs[1].composer.name).must_equal "Lynott"
65
+ expect(album.artist).must_be_instance_of Model::Artist
66
+ expect(album.artist.name).must_equal "Thin Lizzy"
67
67
  end
68
68
 
69
69
  # with empty, not populated model.
@@ -82,16 +82,16 @@ class TwinSyncTest < MiniTest::Spec
82
82
  twin.songs[1].composer.name = "Lynott"
83
83
 
84
84
  # not written to model, yet.
85
- album.name.must_be_nil
86
- album.songs.must_equal []
87
- album.artist.must_be_nil
85
+ expect(album.name).must_be_nil
86
+ expect(album.songs).must_equal []
87
+ expect(album.artist).must_be_nil
88
88
 
89
89
  twin.sync # this assigns a new collection via #songs=.
90
90
 
91
- album.name.must_equal "Live And Dangerous"
92
- album.songs[0].title.must_equal "Southbound"
93
- album.songs[1].title.must_equal "The Boys Are Back In Town"
94
- album.songs[1].composer.name.must_equal "Lynott"
91
+ expect(album.name).must_equal "Live And Dangerous"
92
+ expect(album.songs[0].title).must_equal "Southbound"
93
+ expect(album.songs[1].title).must_equal "The Boys Are Back In Town"
94
+ expect(album.songs[1].composer.name).must_equal "Lynott"
95
95
  end
96
96
 
97
97
  # save with block.
@@ -107,14 +107,14 @@ class TwinSyncTest < MiniTest::Spec
107
107
  nested_hash = hash
108
108
  end
109
109
 
110
- nested_hash.must_equal({"name"=>"Live And Dangerous", "songs"=>[{"title"=>"Southbound", "composer"=>nil}, {"title"=>"The Boys Are Back In Town", "composer"=>{"name"=>"Lynott"}}], "artist"=>{"name"=>"Thin Lizzy"}})
110
+ expect(nested_hash).must_equal({"name"=>"Live And Dangerous", "songs"=>[{"title"=>"Southbound", "composer"=>nil}, {"title"=>"The Boys Are Back In Town", "composer"=>{"name"=>"Lynott"}}], "artist"=>{"name"=>"Thin Lizzy"}})
111
111
 
112
112
  # nothing written to model.
113
- album.name.must_be_nil
114
- album.songs[0].title.must_be_nil
115
- album.songs[1].title.must_be_nil
116
- album.songs[1].composer.name.must_be_nil
117
- album.artist.name.must_be_nil
113
+ expect(album.name).must_be_nil
114
+ expect(album.songs[0].title).must_be_nil
115
+ expect(album.songs[1].title).must_be_nil
116
+ expect(album.songs[1].composer.name).must_be_nil
117
+ expect(album.artist.name).must_be_nil
118
118
  end
119
119
 
120
120
  describe "nil values" do
@@ -127,7 +127,7 @@ class TwinSyncTest < MiniTest::Spec
127
127
  nested_hash = nil
128
128
  twin.sync { |hash| nested_hash = hash }
129
129
 
130
- nested_hash.must_equal({"name"=>nil, "artist"=>nil})
130
+ expect(nested_hash).must_equal({"name"=>nil, "artist"=>nil})
131
131
  end
132
132
 
133
133
  it "includes empty collections" do
@@ -139,7 +139,7 @@ class TwinSyncTest < MiniTest::Spec
139
139
  nested_hash = nil
140
140
  twin.sync { |hash| nested_hash = hash }
141
141
 
142
- nested_hash.must_equal({"name"=>nil, "songs"=>[], "artist"=>nil})
142
+ expect(nested_hash).must_equal({"name"=>nil, "songs"=>[], "artist"=>nil})
143
143
  end
144
144
  end
145
145
  end
@@ -35,17 +35,17 @@ class TwinTest < MiniTest::Spec
35
35
  twin = Twin::Song.new(song)
36
36
  song.id = 2
37
37
  # :from maps public name
38
- twin.title.must_equal "Broken" # public: #record_name
39
- twin.id.must_equal 1
38
+ expect(twin.title).must_equal "Broken" # public: #record_name
39
+ expect(twin.id).must_equal 1
40
40
  end
41
41
 
42
42
  # allows passing options.
43
43
  it do
44
44
  # override twin's value...
45
- Twin::Song.new(song, :title => "Kenny").title.must_equal "Kenny"
45
+ expect(Twin::Song.new(song, :title => "Kenny").title).must_equal "Kenny"
46
46
 
47
47
  # .. but do not write to the model!
48
- song.title.must_equal "Broken"
48
+ expect(song.title).must_equal "Broken"
49
49
  end
50
50
  end
51
51
 
@@ -59,28 +59,28 @@ class TwinTest < MiniTest::Spec
59
59
  twin.album = album # this is a model, not a twin.
60
60
 
61
61
  # updates twin
62
- twin.id.must_equal 3
63
- twin.title.must_equal "Lucky"
62
+ expect(twin.id).must_equal 3
63
+ expect(twin.title).must_equal "Lucky"
64
64
 
65
65
  # setter for nested property will twin value.
66
66
  twin.album.extend(Disposable::Comparable)
67
- assert twin.album == Twin::Album.new(album) # FIXME: why does must_equal not call #== ?
67
+ assert twin.album == Twin::Album.new(album) # FIXME: why does) must_equal not call #== ?
68
68
 
69
69
  # setter for nested collection.
70
70
 
71
71
  # DOES NOT update model
72
- song.id.must_equal 1
73
- song.title.must_equal "Broken"
72
+ expect(song.id).must_equal 1
73
+ expect(song.title).must_equal "Broken"
74
74
  end
75
75
 
76
76
  describe "deleting" do
77
77
  it "allows overwriting nested twin with nil" do
78
78
  album = Model::Album.new(1, "Uncertain Terms", [], Model::Artist.new("Greg Howe"))
79
79
  twin = Twin::Album.new(album)
80
- twin.artist.id.must_equal "Greg Howe"
80
+ expect(twin.artist.id).must_equal "Greg Howe"
81
81
 
82
82
  twin.artist = nil
83
- twin.artist.must_be_nil
83
+ expect(twin.artist).must_be_nil
84
84
  end
85
85
  end
86
86
 
@@ -109,8 +109,8 @@ class OverridingAccessorsTest < TwinTest
109
109
  end
110
110
 
111
111
  let (:model) { Model::Song.new(1, "A Tale That Wasn't Right") }
112
- it { Song.new(model).title.must_equal "a tale that wasn't right" }
113
- it { Song.new(model).id.must_equal 2 }
112
+ it { expect(Song.new(model).title).must_equal "a tale that wasn't right" }
113
+ it { expect(Song.new(model).id).must_equal 2 }
114
114
  end
115
115
 
116
116
 
@@ -148,7 +148,17 @@ class AccessorsTest < Minitest::Spec
148
148
 
149
149
  it do
150
150
  twin = Twin.new(Song.new("bla"))
151
- twin.format.must_equal "bla"
151
+ expect(twin.format).must_equal "bla"
152
152
  twin.format = "blubb"
153
153
  end
154
154
  end
155
+
156
+ class InvalidPropertyNameTest < Minitest::Spec
157
+ it 'raises InvalidPropertyNameError' do
158
+ assert_raises(Disposable::Twin::InvalidPropertyNameError) {
159
+ class Twin < Disposable::Twin
160
+ property :class
161
+ end
162
+ }
163
+ end
164
+ end
@@ -16,22 +16,22 @@ class UnnestTest < MiniTest::Spec
16
16
  end
17
17
 
18
18
  it "copies property option" do
19
- Twin.definitions.get(:id).extend(Declarative::Inspect).inspect.must_equal %{#<Disposable::Twin::Definition: @options={:nice=>\"yes\", :private_name=>:id, :name=>\"id\", :readable=>false, :writeable=>false}>}
20
- Twin.definitions.get(:ids).extend(Declarative::Inspect).inspect.must_equal %{#<Disposable::Twin::Definition: @options={:status=>\"healthy\", :collection=>true, :private_name=>:ids, :name=>\"ids\", :readable=>false, :writeable=>false}>}
19
+ expect(Twin.definitions.get(:id).extend(Declarative::Inspect).inspect).must_equal %{#<Disposable::Twin::Definition: @options={:nice=>\"yes\", :private_name=>:id, :name=>\"id\", :readable=>false, :writeable=>false}>}
20
+ expect(Twin.definitions.get(:ids).extend(Declarative::Inspect).inspect).must_equal %{#<Disposable::Twin::Definition: @options={:status=>\"healthy\", :collection=>true, :private_name=>:ids, :name=>\"ids\", :readable=>false, :writeable=>false}>}
21
21
  # also copies :nested.
22
- Twin.definitions.get(:email).extend(Declarative::Inspect).inspect.must_equal %{#<Disposable::Twin::Definition: @options={:private_name=>:email, :nested=>#<Class:>, :name=>\"email\", :readable=>false, :writeable=>false}>}
22
+ expect(Twin.definitions.get(:email).extend(Declarative::Inspect).inspect).must_equal %{#<Disposable::Twin::Definition: @options={:private_name=>:email, :nested=>#<Class:>, :name=>\"email\", :readable=>false, :writeable=>false}>}
23
23
  end
24
24
 
25
25
  it "exposes accessors on top-level twin" do
26
26
  twin = Twin.new(OpenStruct.new(content: OpenStruct.new()))
27
27
 
28
- twin.email.must_be_nil
28
+ expect(twin.email).must_be_nil
29
29
  twin.email= 2
30
- twin.email.model.must_equal 2
30
+ expect(twin.email.model).must_equal 2
31
31
 
32
32
 
33
- twin.id.must_be_nil
33
+ expect(twin.id).must_be_nil
34
34
  twin.id = 1
35
- twin.id.must_equal 1
35
+ expect(twin.id).must_equal 1
36
36
  end
37
37
  end
@@ -11,7 +11,7 @@ class VirtualTest < MiniTest::Spec
11
11
  it {
12
12
  twin.credit_card_number = "123"
13
13
 
14
- twin.credit_card_number.must_equal "123" # this is still readable in the UI.
14
+ expect(twin.credit_card_number).must_equal "123" # this is still readable in the UI.
15
15
 
16
16
  twin.sync
17
17
 
@@ -20,7 +20,7 @@ class VirtualTest < MiniTest::Spec
20
20
  hash = nested
21
21
  end
22
22
 
23
- hash.must_equal("credit_card_number"=> "123")
23
+ expect(hash).must_equal("credit_card_number"=> "123")
24
24
  }
25
25
 
26
26
  describe "setter should never be called with virtual:true" do
@@ -33,7 +33,7 @@ class VirtualTest < MiniTest::Spec
33
33
  end
34
34
 
35
35
  it "what" do
36
- Raising.new(Object.new).id.must_be_nil
36
+ expect(Raising.new(Object.new).id).must_be_nil
37
37
  end
38
38
  end
39
39
  end
@@ -30,20 +30,20 @@ class WriteableTest < MiniTest::Spec
30
30
  let (:twin) { PasswordForm.new(cred) }
31
31
 
32
32
  it {
33
- twin.password.must_equal "secret"
34
- twin.credit_card.name.must_equal "Jonny"
35
- twin.credit_card.number.must_equal "0987654321"
33
+ expect(twin.password).must_equal "secret"
34
+ expect(twin.credit_card.name).must_equal "Jonny"
35
+ expect(twin.credit_card.number).must_equal "0987654321"
36
36
 
37
37
  # manual setting on the twin works.
38
38
  twin.password = "123"
39
- twin.password.must_equal "123"
39
+ expect(twin.password).must_equal "123"
40
40
 
41
41
  twin.credit_card.number = "456"
42
- twin.credit_card.number.must_equal "456"
42
+ expect(twin.credit_card.number).must_equal "456"
43
43
 
44
44
  twin.sync
45
45
 
46
- cred.inspect.must_equal '#<struct WriteableTest::Credentials password="secret", credit_card=#<struct WriteableTest::CreditCard name="Jonny", number="0987654321">>'
46
+ expect(cred.inspect).must_equal '#<struct WriteableTest::Credentials password="secret", credit_card=#<struct WriteableTest::CreditCard name="Jonny", number="0987654321">>'
47
47
 
48
48
  # test sync{}.
49
49
  hash = {}
@@ -51,6 +51,6 @@ class WriteableTest < MiniTest::Spec
51
51
  hash = nested
52
52
  end
53
53
 
54
- hash.must_equal("password"=> "123", "credit_card"=>{"name"=>"Jonny", "number"=>"456"})
54
+ expect(hash).must_equal("password"=> "123", "credit_card"=>{"name"=>"Jonny", "number"=>"456"})
55
55
  }
56
- end
56
+ end