disposable 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +31 -29
- data/CHANGES.md +5 -0
- data/Gemfile +1 -1
- data/disposable.gemspec +0 -1
- data/lib/disposable/twin/coercion.rb +4 -1
- data/lib/disposable/twin/property/struct.rb +3 -1
- data/lib/disposable/version.rb +1 -1
- data/test/callback_group_test.rb +27 -27
- data/test/callbacks_test.rb +44 -44
- data/test/expose_test.rb +16 -16
- data/test/persisted_test.rb +30 -30
- data/test/rescheme_test.rb +22 -22
- data/test/skip_getter_test.rb +14 -14
- data/test/twin/builder_test.rb +3 -3
- data/test/twin/changed_test.rb +36 -36
- data/test/twin/coercion_test.rb +61 -23
- data/test/twin/collection_test.rb +46 -46
- data/test/twin/composition_test.rb +20 -20
- data/test/twin/default_test.rb +15 -15
- data/test/twin/expose_test.rb +15 -15
- data/test/twin/feature_test.rb +10 -10
- data/test/twin/from_collection_test.rb +4 -4
- data/test/twin/from_test.rb +3 -3
- data/test/twin/hash_test.rb +38 -38
- data/test/twin/inherit_test.rb +7 -7
- data/test/twin/inheritance_test.rb +6 -6
- data/test/twin/parent_test.rb +5 -5
- data/test/twin/property_processor_test.rb +3 -3
- data/test/twin/readable_test.rb +9 -9
- data/test/twin/save_test.rb +44 -44
- data/test/twin/setup_test.rb +25 -25
- data/test/twin/skip_unchanged_test.rb +6 -6
- data/test/twin/struct/coercion_test.rb +4 -4
- data/test/twin/struct_test.rb +41 -38
- data/test/twin/sync_test.rb +29 -29
- data/test/twin/twin_test.rb +14 -14
- data/test/twin/unnest_test.rb +7 -7
- data/test/twin/virtual_test.rb +3 -3
- data/test/twin/writeable_test.rb +8 -8
- metadata +3 -18
data/test/expose_test.rb
CHANGED
@@ -24,8 +24,8 @@ class ExposeTest < MiniTest::Spec
|
|
24
24
|
|
25
25
|
describe "readers" do
|
26
26
|
it do
|
27
|
-
subject.id.must_equal 1
|
28
|
-
subject.title.must_equal "Dick Sandwich"
|
27
|
+
expect(subject.id).must_equal 1
|
28
|
+
expect(subject.title).must_equal "Dick Sandwich"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -35,10 +35,10 @@ class ExposeTest < MiniTest::Spec
|
|
35
35
|
subject.id = 3
|
36
36
|
subject.title = "Eclipse"
|
37
37
|
|
38
|
-
subject.id.must_equal 3
|
39
|
-
subject.title.must_equal "Eclipse"
|
40
|
-
album.id.must_equal 3
|
41
|
-
album.name.must_equal "Eclipse"
|
38
|
+
expect(subject.id).must_equal 3
|
39
|
+
expect(subject.title).must_equal "Eclipse"
|
40
|
+
expect(album.id).must_equal 3
|
41
|
+
expect(album.name).must_equal "Eclipse"
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -69,9 +69,9 @@ class ExposeCompositionTest < MiniTest::Spec
|
|
69
69
|
|
70
70
|
|
71
71
|
describe "readers" do
|
72
|
-
it { subject.id.must_equal 2 }
|
73
|
-
it { subject.band_id.must_equal 1 }
|
74
|
-
it { subject.name.must_equal "Dick Sandwich" }
|
72
|
+
it { expect(subject.id).must_equal 2 }
|
73
|
+
it { expect(subject.band_id).must_equal 1 }
|
74
|
+
it { expect(subject.name).must_equal "Dick Sandwich" }
|
75
75
|
end
|
76
76
|
|
77
77
|
|
@@ -81,12 +81,12 @@ class ExposeCompositionTest < MiniTest::Spec
|
|
81
81
|
subject.band_id = 4
|
82
82
|
subject.name = "Eclipse"
|
83
83
|
|
84
|
-
subject.id.must_equal 3
|
85
|
-
subject.band_id.must_equal 4
|
86
|
-
subject.name.must_equal "Eclipse"
|
87
|
-
band.id.must_equal 4
|
88
|
-
album.id.must_equal 3
|
89
|
-
album.name.must_equal "Eclipse"
|
84
|
+
expect(subject.id).must_equal 3
|
85
|
+
expect(subject.band_id).must_equal 4
|
86
|
+
expect(subject.name).must_equal "Eclipse"
|
87
|
+
expect(band.id).must_equal 4
|
88
|
+
expect(album.id).must_equal 3
|
89
|
+
expect(album.name).must_equal "Eclipse"
|
90
90
|
end
|
91
91
|
end
|
92
|
-
end
|
92
|
+
end
|
data/test/persisted_test.rb
CHANGED
@@ -29,36 +29,36 @@ class PersistedTest < MiniTest::Spec
|
|
29
29
|
album = Album.new(artist: artist, songs: [ex_song, song])
|
30
30
|
|
31
31
|
|
32
|
-
artist.persisted
|
33
|
-
album.persisted
|
34
|
-
ex_song.persisted
|
35
|
-
song.persisted
|
32
|
+
expect(artist.persisted?).must_equal false
|
33
|
+
expect(album.persisted?).must_equal false
|
34
|
+
expect(ex_song.persisted?).must_equal true
|
35
|
+
expect(song.persisted?).must_equal false
|
36
36
|
|
37
37
|
twin = AlbumTwin.new(album)
|
38
|
-
twin.persisted
|
39
|
-
twin.changed?(:persisted?).must_equal false
|
40
|
-
twin.artist.persisted
|
41
|
-
twin.artist.changed?(:persisted?).must_equal false
|
42
|
-
twin.songs[0].persisted
|
43
|
-
twin.songs[0].changed?(:persisted?).must_equal false
|
44
|
-
twin.songs[1].persisted
|
45
|
-
twin.songs[1].changed?(:persisted?).must_equal false
|
38
|
+
expect(twin.persisted?).must_equal false
|
39
|
+
expect(twin.changed?(:persisted?)).must_equal false
|
40
|
+
expect(twin.artist.persisted?).must_equal false
|
41
|
+
expect(twin.artist.changed?(:persisted?)).must_equal false
|
42
|
+
expect(twin.songs[0].persisted?).must_equal true
|
43
|
+
expect(twin.songs[0].changed?(:persisted?)).must_equal false
|
44
|
+
expect(twin.songs[1].persisted?).must_equal false
|
45
|
+
expect(twin.songs[1].changed?(:persisted?)).must_equal false
|
46
46
|
|
47
47
|
twin.save
|
48
48
|
|
49
|
-
artist.persisted
|
50
|
-
album.persisted
|
51
|
-
ex_song.persisted
|
52
|
-
song.persisted
|
53
|
-
|
54
|
-
twin.persisted
|
55
|
-
twin.changed?(:persisted?).must_equal true
|
56
|
-
twin.artist.persisted
|
57
|
-
twin.artist.changed?(:persisted?).must_equal true
|
58
|
-
twin.songs[0].persisted
|
59
|
-
twin.songs[0].changed?(:persisted?).must_equal false
|
60
|
-
twin.songs[1].persisted
|
61
|
-
twin.songs[1].changed?(:persisted?).must_equal true
|
49
|
+
expect(artist.persisted?).must_equal true
|
50
|
+
expect(album.persisted?).must_equal true
|
51
|
+
expect(ex_song.persisted?).must_equal true
|
52
|
+
expect(song.persisted?).must_equal true
|
53
|
+
|
54
|
+
expect(twin.persisted?).must_equal true
|
55
|
+
expect(twin.changed?(:persisted?)).must_equal true
|
56
|
+
expect(twin.artist.persisted?).must_equal true
|
57
|
+
expect(twin.artist.changed?(:persisted?)).must_equal true
|
58
|
+
expect(twin.songs[0].persisted?).must_equal true
|
59
|
+
expect(twin.songs[0].changed?(:persisted?)).must_equal false
|
60
|
+
expect(twin.songs[1].persisted?).must_equal true
|
61
|
+
expect(twin.songs[1].changed?(:persisted?)).must_equal true
|
62
62
|
end
|
63
63
|
|
64
64
|
|
@@ -66,17 +66,17 @@ class PersistedTest < MiniTest::Spec
|
|
66
66
|
it do
|
67
67
|
twin = AlbumTwin.new(Album.new)
|
68
68
|
|
69
|
-
twin.created
|
69
|
+
expect(twin.created?).must_equal false
|
70
70
|
twin.save
|
71
|
-
twin.created
|
71
|
+
expect(twin.created?).must_equal true
|
72
72
|
end
|
73
73
|
|
74
74
|
it do
|
75
75
|
twin = AlbumTwin.new(Album.create)
|
76
76
|
|
77
|
-
twin.created
|
77
|
+
expect(twin.created?).must_equal false
|
78
78
|
twin.save
|
79
|
-
twin.created
|
79
|
+
expect(twin.created?).must_equal false
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -98,4 +98,4 @@ class PersistedTest < MiniTest::Spec
|
|
98
98
|
# twin.updated?.must_equal true
|
99
99
|
# end
|
100
100
|
# end
|
101
|
-
end
|
101
|
+
end
|
data/test/rescheme_test.rb
CHANGED
@@ -37,22 +37,22 @@ class ReschemeTest < MiniTest::Spec
|
|
37
37
|
)
|
38
38
|
|
39
39
|
# include: works.
|
40
|
-
decorator.new(nil).hello.must_equal "hello"
|
41
|
-
decorator.new(nil).ciao.must_equal "ciao"
|
40
|
+
expect(decorator.new(nil).hello).must_equal "hello"
|
41
|
+
expect(decorator.new(nil).ciao).must_equal "ciao"
|
42
42
|
|
43
|
-
decorator.representable_attrs.get(:id).inspect.must_equal "#<Representable::Definition ==>id @options={:name=>\"id\", :parse_filter=>[], :render_filter=>[]}>"
|
44
|
-
decorator.representable_attrs.get(:title).inspect.must_equal "#<Representable::Definition ==>title @options={:writeable=>false, :deserializer=>{:skip_parse=>\"skip lambda\"}, :name=>\"title\", :parse_filter=>[], :render_filter=>[], :skip_parse=>\"skip lambda\"}>"
|
43
|
+
expect(decorator.representable_attrs.get(:id).inspect).must_equal "#<Representable::Definition ==>id @options={:name=>\"id\", :parse_filter=>[], :render_filter=>[]}>"
|
44
|
+
expect(decorator.representable_attrs.get(:title).inspect).must_equal "#<Representable::Definition ==>title @options={:writeable=>false, :deserializer=>{:skip_parse=>\"skip lambda\"}, :name=>\"title\", :parse_filter=>[], :render_filter=>[], :skip_parse=>\"skip lambda\"}>"
|
45
45
|
|
46
46
|
songs = decorator.representable_attrs.get(:songs)
|
47
47
|
options = songs.instance_variable_get(:@options)
|
48
48
|
options[:nested].extend(Declarative::Inspect)
|
49
|
-
options.inspect.must_equal "{:readable=>false, :deserializer=>{:skip_parse=>\"another lambda\", :music=>true, :writeable=>false}, :nested=>#<Class:>, :extend=>#<Class:>, :name=>\"songs\", :parse_filter=>[], :render_filter=>[], :skip_parse=>\"another lambda\", :music=>true, :writeable=>false}"
|
49
|
+
expect(options.inspect).must_equal "{:readable=>false, :deserializer=>{:skip_parse=>\"another lambda\", :music=>true, :writeable=>false}, :nested=>#<Class:>, :extend=>#<Class:>, :name=>\"songs\", :parse_filter=>[], :render_filter=>[], :skip_parse=>\"another lambda\", :music=>true, :writeable=>false}"
|
50
50
|
|
51
51
|
# nested works.
|
52
|
-
options[:nested].new(nil).hello.must_equal "hello"
|
53
|
-
options[:nested].new(nil).ciao.must_equal "ciao"
|
52
|
+
expect(options[:nested].new(nil).hello).must_equal "hello"
|
53
|
+
expect(options[:nested].new(nil).ciao).must_equal "ciao"
|
54
54
|
|
55
|
-
options[:nested].representable_attrs.get(:name).inspect.must_equal "#<Representable::Definition ==>name @options={:as=>\"Name\", :deserializer=>{:skip_parse=>\"a crazy cool instance method\"}, :name=>\"name\", :parse_filter=>[], :render_filter=>[], :skip_parse=>\"a crazy cool instance method\"}>"
|
55
|
+
expect(options[:nested].representable_attrs.get(:name).inspect).must_equal "#<Representable::Definition ==>name @options={:as=>\"Name\", :deserializer=>{:skip_parse=>\"a crazy cool instance method\"}, :name=>\"name\", :parse_filter=>[], :render_filter=>[], :skip_parse=>\"a crazy cool instance method\"}>"
|
56
56
|
end
|
57
57
|
|
58
58
|
# :options_from and :include is optional
|
@@ -61,8 +61,8 @@ class ReschemeTest < MiniTest::Spec
|
|
61
61
|
definitions_from: lambda { |nested| nested.definitions }
|
62
62
|
)
|
63
63
|
|
64
|
-
decorator.representable_attrs.get(:id).inspect.must_equal "#<Representable::Definition ==>id @options={:name=>\"id\", :parse_filter=>[], :render_filter=>[]}>"
|
65
|
-
decorator.representable_attrs.get(:title).inspect.must_equal "#<Representable::Definition ==>title @options={:writeable=>false, :deserializer=>{:skip_parse=>\"skip lambda\"}, :name=>\"title\", :parse_filter=>[], :render_filter=>[]}>"
|
64
|
+
expect(decorator.representable_attrs.get(:id).inspect).must_equal "#<Representable::Definition ==>id @options={:name=>\"id\", :parse_filter=>[], :render_filter=>[]}>"
|
65
|
+
expect(decorator.representable_attrs.get(:title).inspect).must_equal "#<Representable::Definition ==>title @options={:writeable=>false, :deserializer=>{:skip_parse=>\"skip lambda\"}, :name=>\"title\", :parse_filter=>[], :render_filter=>[]}>"
|
66
66
|
end
|
67
67
|
|
68
68
|
|
@@ -73,9 +73,9 @@ class ReschemeTest < MiniTest::Spec
|
|
73
73
|
exclude_options: [:deserializer]
|
74
74
|
)
|
75
75
|
|
76
|
-
decorator.representable_attrs.get(:id).inspect.must_equal "#<Representable::Definition ==>id @options={:name=>\"id\", :parse_filter=>[], :render_filter=>[]}>"
|
77
|
-
decorator.representable_attrs.get(:title).inspect.must_equal "#<Representable::Definition ==>title @options={:writeable=>false, :name=>\"title\", :parse_filter=>[], :render_filter=>[]}>"
|
78
|
-
decorator.representable_attrs.get(:songs).representer_module.representable_attrs.get(:name).inspect.must_equal "#<Representable::Definition ==>name @options={:as=>\"Name\", :name=>\"name\", :parse_filter=>[], :render_filter=>[]}>"
|
76
|
+
expect(decorator.representable_attrs.get(:id).inspect).must_equal "#<Representable::Definition ==>id @options={:name=>\"id\", :parse_filter=>[], :render_filter=>[]}>"
|
77
|
+
expect(decorator.representable_attrs.get(:title).inspect).must_equal "#<Representable::Definition ==>title @options={:writeable=>false, :name=>\"title\", :parse_filter=>[], :render_filter=>[]}>"
|
78
|
+
expect(decorator.representable_attrs.get(:songs).representer_module.representable_attrs.get(:name).inspect).must_equal "#<Representable::Definition ==>name @options={:as=>\"Name\", :name=>\"name\", :parse_filter=>[], :render_filter=>[]}>"
|
79
79
|
end
|
80
80
|
|
81
81
|
|
@@ -85,8 +85,8 @@ class ReschemeTest < MiniTest::Spec
|
|
85
85
|
definitions_from: lambda { |nested| nested.definitions },
|
86
86
|
) { |dfn| dfn.merge!(amazing: true) }
|
87
87
|
|
88
|
-
decorator.representable_attrs.get(:id).inspect.must_equal "#<Representable::Definition ==>id @options={:name=>\"id\", :parse_filter=>[], :render_filter=>[], :amazing=>true}>"
|
89
|
-
decorator.representable_attrs.get(:songs).representer_module.representable_attrs.get(:name).inspect.must_equal "#<Representable::Definition ==>name @options={:as=>\"Name\", :deserializer=>{:skip_parse=>\"a crazy cool instance method\"}, :name=>\"name\", :parse_filter=>[], :render_filter=>[], :amazing=>true}>"
|
88
|
+
expect(decorator.representable_attrs.get(:id).inspect).must_equal "#<Representable::Definition ==>id @options={:name=>\"id\", :parse_filter=>[], :render_filter=>[], :amazing=>true}>"
|
89
|
+
expect(decorator.representable_attrs.get(:songs).representer_module.representable_attrs.get(:name).inspect).must_equal "#<Representable::Definition ==>name @options={:as=>\"Name\", :deserializer=>{:skip_parse=>\"a crazy cool instance method\"}, :name=>\"name\", :parse_filter=>[], :render_filter=>[], :amazing=>true}>"
|
90
90
|
end
|
91
91
|
|
92
92
|
it "recursive: false only copies first level" do
|
@@ -97,8 +97,8 @@ class ReschemeTest < MiniTest::Spec
|
|
97
97
|
exclude_options: [:deserializer]
|
98
98
|
)
|
99
99
|
|
100
|
-
decorator.representable_attrs.get(:title).inspect.must_equal "#<Representable::Definition ==>title @options={:writeable=>false, :name=>\"title\", :parse_filter=>[], :render_filter=>[]}>"
|
101
|
-
decorator.representable_attrs.get(:songs).representer_module.representable_attrs.get(:name).inspect.must_equal "#<Representable::Definition ==>name @options={:as=>\"Name\", :deserializer=>{:skip_parse=>\"a crazy cool instance method\"}, :name=>\"name\", :parse_filter=>[], :render_filter=>[]}>"
|
100
|
+
expect(decorator.representable_attrs.get(:title).inspect).must_equal "#<Representable::Definition ==>title @options={:writeable=>false, :name=>\"title\", :parse_filter=>[], :render_filter=>[]}>"
|
101
|
+
expect(decorator.representable_attrs.get(:songs).representer_module.representable_attrs.get(:name).inspect).must_equal "#<Representable::Definition ==>name @options={:as=>\"Name\", :deserializer=>{:skip_parse=>\"a crazy cool instance method\"}, :name=>\"name\", :parse_filter=>[], :render_filter=>[]}>"
|
102
102
|
end
|
103
103
|
|
104
104
|
describe ":exclude_properties" do
|
@@ -121,8 +121,8 @@ class ReschemeTest < MiniTest::Spec
|
|
121
121
|
exclude_properties: [:id]
|
122
122
|
)
|
123
123
|
|
124
|
-
decorator.definitions.keys.must_equal ["songs"]
|
125
|
-
decorator.definitions.get(:songs).representer_module.definitions.keys.must_equal ["name"]
|
124
|
+
expect(decorator.definitions.keys).must_equal ["songs"]
|
125
|
+
expect(decorator.definitions.get(:songs).representer_module.definitions.keys).must_equal ["name"]
|
126
126
|
end
|
127
127
|
end
|
128
128
|
end
|
@@ -145,8 +145,8 @@ class TwinReschemeTest < MiniTest::Spec
|
|
145
145
|
artist = decorator.representable_attrs.get(:artist)
|
146
146
|
options = artist.instance_variable_get(:@options)
|
147
147
|
nested_extend = options[:nested]
|
148
|
-
options.extend(Declarative::Inspect).inspect.must_equal "{:private_name=>:artist, :nested=>#<Class:>, :name=>\"artist\", :extend=>#<Class:>, :parse_filter=>[], :render_filter=>[]}"
|
148
|
+
expect(options.extend(Declarative::Inspect).inspect).must_equal "{:private_name=>:artist, :nested=>#<Class:>, :name=>\"artist\", :extend=>#<Class:>, :parse_filter=>[], :render_filter=>[]}"
|
149
149
|
assert nested_extend < Representable::Decorator
|
150
|
-
nested_extend.representable_attrs.get(:name).inspect.must_equal "#<Representable::Definition ==>name @options={:private_name=>:name, :name=>\"name\", :parse_filter=>[], :render_filter=>[]}>"
|
150
|
+
expect(nested_extend.representable_attrs.get(:name).inspect).must_equal "#<Representable::Definition ==>name @options={:private_name=>:name, :name=>\"name\", :parse_filter=>[], :render_filter=>[]}>"
|
151
151
|
end
|
152
|
-
end
|
152
|
+
end
|
data/test/skip_getter_test.rb
CHANGED
@@ -26,20 +26,20 @@ class SkipGetterTest < MiniTest::Spec
|
|
26
26
|
album = Album.new("Wild Frontier", Artist.new("Gary Moore"))
|
27
27
|
twin = AlbumTwin.new(album)
|
28
28
|
|
29
|
-
twin.title.must_equal "reitnorF dliW"
|
30
|
-
twin.artist.name.must_equal "GARY MOORE"
|
29
|
+
expect(twin.title).must_equal "reitnorF dliW"
|
30
|
+
expect(twin.artist.name).must_equal "GARY MOORE"
|
31
31
|
|
32
32
|
twin.sync # does NOT call getter.
|
33
33
|
|
34
|
-
album.title.must_equal "Wild Frontier"
|
35
|
-
album.artist.name.must_equal "Gary Moore"
|
34
|
+
expect(album.title).must_equal "Wild Frontier"
|
35
|
+
expect(album.artist.name).must_equal "Gary Moore"
|
36
36
|
|
37
37
|
# nested hash.
|
38
38
|
nested_hash = nil
|
39
39
|
twin.sync do |hash|
|
40
40
|
nested_hash = hash
|
41
41
|
end
|
42
|
-
nested_hash.must_equal({"title"=>"Wild Frontier", "artist"=>{"name"=>"Gary Moore"}})
|
42
|
+
expect(nested_hash).must_equal({"title"=>"Wild Frontier", "artist"=>{"name"=>"Gary Moore"}})
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -68,8 +68,8 @@ class SkipSetterTest < MiniTest::Spec
|
|
68
68
|
it do
|
69
69
|
twin = AlbumTwin.new(Album.new("Wild Frontier", Artist.new("Gary Moore")))
|
70
70
|
|
71
|
-
twin.title.must_equal "Wild Frontier"
|
72
|
-
twin.artist.name.must_equal "Gary Moore"
|
71
|
+
expect(twin.title).must_equal "Wild Frontier"
|
72
|
+
expect(twin.artist.name).must_equal "Gary Moore"
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -111,18 +111,18 @@ class SkipGetterAndSetterWithChangedTest < MiniTest::Spec
|
|
111
111
|
twin = AlbumTwin.new(album) # does not call getter (Changed).
|
112
112
|
|
113
113
|
|
114
|
-
twin.title.must_equal "reitnorF dliW"
|
115
|
-
twin.artist.name.must_equal "GARY MOORE"
|
114
|
+
expect(twin.title).must_equal "reitnorF dliW"
|
115
|
+
expect(twin.artist.name).must_equal "GARY MOORE"
|
116
116
|
|
117
|
-
twin.changed
|
118
|
-
twin.artist.changed
|
117
|
+
expect(twin.changed?).must_equal false
|
118
|
+
expect(twin.artist.changed?).must_equal false
|
119
119
|
|
120
120
|
twin.title = "Self-Entitled"
|
121
121
|
twin.artist.name = "Nofx"
|
122
122
|
|
123
123
|
twin.sync # does NOT call getter.
|
124
124
|
|
125
|
-
album.title.must_equal "deltitnE-fleS"
|
126
|
-
album.artist.name.must_equal "Nof"
|
125
|
+
expect(album.title).must_equal "deltitnE-fleS"
|
126
|
+
expect(album.artist.name).must_equal "Nof"
|
127
127
|
end
|
128
|
-
end
|
128
|
+
end
|
data/test/twin/builder_test.rb
CHANGED
@@ -26,7 +26,7 @@ class BuilderTest < MiniTest::Spec
|
|
26
26
|
end
|
27
27
|
|
28
28
|
|
29
|
-
it { Twin.build(Model::Song.new).must_be_instance_of Twin }
|
30
|
-
it { Twin.build(Model::Hit.new).must_be_instance_of Hit }
|
31
|
-
it { Twin.build(Model::Evergreen.new, evergreen: true).must_be_instance_of Evergreen }
|
29
|
+
it { expect(Twin.build(Model::Song.new)).must_be_instance_of Twin }
|
30
|
+
it { expect(Twin.build(Model::Hit.new)).must_be_instance_of Hit }
|
31
|
+
it { expect(Twin.build(Model::Evergreen.new, evergreen: true)).must_be_instance_of Evergreen }
|
32
32
|
end
|
data/test/twin/changed_test.rb
CHANGED
@@ -39,19 +39,19 @@ class ChangedWithSetupTest < MiniTest::Spec
|
|
39
39
|
|
40
40
|
# setup: changed? is always false
|
41
41
|
it do
|
42
|
-
twin.changed?(:name).must_equal false
|
43
|
-
twin.changed
|
42
|
+
expect(twin.changed?(:name)).must_equal false
|
43
|
+
expect(twin.changed?).must_equal false
|
44
44
|
|
45
|
-
twin.songs[0].changed
|
46
|
-
twin.songs[0].changed?(:title).must_equal false
|
47
|
-
twin.songs[1].changed
|
48
|
-
twin.songs[1].changed?(:title).must_equal false
|
45
|
+
expect(twin.songs[0].changed?).must_equal false
|
46
|
+
expect(twin.songs[0].changed?(:title)).must_equal false
|
47
|
+
expect(twin.songs[1].changed?).must_equal false
|
48
|
+
expect(twin.songs[1].changed?(:title)).must_equal false
|
49
49
|
|
50
|
-
twin.songs[1].composer.changed?(:name).must_equal false
|
51
|
-
twin.songs[1].composer.changed
|
50
|
+
expect(twin.songs[1].composer.changed?(:name)).must_equal false
|
51
|
+
expect(twin.songs[1].composer.changed?).must_equal false
|
52
52
|
|
53
|
-
twin.artist.changed?(:name).must_equal false
|
54
|
-
twin.artist.changed
|
53
|
+
expect(twin.artist.changed?(:name)).must_equal false
|
54
|
+
expect(twin.artist.changed?).must_equal false
|
55
55
|
end
|
56
56
|
|
57
57
|
# only when a property is assigned, it's changed.
|
@@ -62,46 +62,46 @@ class ChangedWithSetupTest < MiniTest::Spec
|
|
62
62
|
twin.songs[1].composer.name= "Ingemar Jansson & Mikael Danielsson"
|
63
63
|
twin.artist.name = "No Fun At All"
|
64
64
|
|
65
|
-
twin.changed?(:name).must_equal true
|
66
|
-
twin.changed
|
65
|
+
expect(twin.changed?(:name)).must_equal true
|
66
|
+
expect(twin.changed?).must_equal true
|
67
67
|
|
68
|
-
twin.songs[0].changed
|
69
|
-
twin.songs[0].changed?(:title).must_equal true
|
70
|
-
twin.songs[1].changed
|
71
|
-
twin.songs[1].changed?(:title).must_equal true
|
68
|
+
expect(twin.songs[0].changed?).must_equal true
|
69
|
+
expect(twin.songs[0].changed?(:title)).must_equal true
|
70
|
+
expect(twin.songs[1].changed?).must_equal true
|
71
|
+
expect(twin.songs[1].changed?(:title)).must_equal true
|
72
72
|
|
73
|
-
twin.songs[1].composer.changed?(:name).must_equal true
|
74
|
-
twin.songs[1].composer.changed
|
73
|
+
expect(twin.songs[1].composer.changed?(:name)).must_equal true
|
74
|
+
expect(twin.songs[1].composer.changed?).must_equal true
|
75
75
|
|
76
|
-
twin.artist.changed?(:name).must_equal true
|
77
|
-
twin.artist.changed
|
76
|
+
expect(twin.artist.changed?(:name)).must_equal true
|
77
|
+
expect(twin.artist.changed?).must_equal true
|
78
78
|
|
79
79
|
# you can also ask for nested twins by name.
|
80
|
-
twin.changed?(:songs).must_equal true
|
81
|
-
twin.songs[0].changed?(:composer).must_equal false
|
82
|
-
twin.songs[1].changed?(:composer).must_equal true
|
83
|
-
twin.changed?(:artist).must_equal true
|
80
|
+
expect(twin.changed?(:songs)).must_equal true
|
81
|
+
expect(twin.songs[0].changed?(:composer)).must_equal false
|
82
|
+
expect(twin.songs[1].changed?(:composer)).must_equal true
|
83
|
+
expect(twin.changed?(:artist)).must_equal true
|
84
84
|
end
|
85
85
|
|
86
86
|
# nested changes should propagate up.
|
87
87
|
it do
|
88
|
-
twin.changed
|
88
|
+
expect(twin.changed?).must_equal false
|
89
89
|
|
90
90
|
twin.songs[1].composer.name = "Nofx"
|
91
91
|
|
92
|
-
twin.changed
|
92
|
+
expect(twin.changed?).must_equal true
|
93
93
|
|
94
94
|
assert twin.songs.changed?
|
95
|
-
twin.songs[1].changed
|
96
|
-
twin.songs[0].changed
|
95
|
+
expect(twin.songs[1].changed?).must_equal true
|
96
|
+
expect(twin.songs[0].changed?).must_equal false
|
97
97
|
|
98
|
-
twin.artist.changed
|
98
|
+
expect(twin.artist.changed?).must_equal false
|
99
99
|
end
|
100
100
|
|
101
101
|
# setting identical value doesn't change.
|
102
102
|
it do
|
103
103
|
twin.name = "The Rest Is Silence"
|
104
|
-
twin.changed
|
104
|
+
expect(twin.changed?).must_equal false
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -119,18 +119,18 @@ class ChangedWithCoercionTest < MiniTest::Spec
|
|
119
119
|
|
120
120
|
it do
|
121
121
|
twin = SongTwin.new(Song.new)
|
122
|
-
twin.changed?(:released).must_equal false
|
122
|
+
expect(twin.changed?(:released)).must_equal false
|
123
123
|
twin.released = 'true'
|
124
|
-
twin.released.must_equal true
|
125
|
-
twin.changed?(:released).must_equal true
|
124
|
+
expect(twin.released).must_equal true
|
125
|
+
expect(twin.changed?(:released)).must_equal true
|
126
126
|
end
|
127
127
|
|
128
128
|
it do
|
129
129
|
twin = SongTwin.new(Song.new(true))
|
130
|
-
twin.changed?(:released).must_equal false
|
130
|
+
expect(twin.changed?(:released)).must_equal false
|
131
131
|
twin.released = 'true' # it coerces, then assigns, then compares, which makes this NOT changed.
|
132
|
-
twin.changed?(:released).must_equal false
|
132
|
+
expect(twin.changed?(:released)).must_equal false
|
133
133
|
twin.released = 'false'
|
134
|
-
twin.changed?(:released).must_equal true
|
134
|
+
expect(twin.changed?(:released)).must_equal true
|
135
135
|
end
|
136
136
|
end
|
data/test/twin/coercion_test.rb
CHANGED
@@ -37,9 +37,9 @@ class CoercionTest < MiniTest::Spec
|
|
37
37
|
}
|
38
38
|
|
39
39
|
it "NOT coerce values in setup" do
|
40
|
-
subject.released_at.must_equal "31/03/1981"
|
41
|
-
subject.hit.length.must_equal "312"
|
42
|
-
subject.band.label.value.must_equal "9999.99"
|
40
|
+
expect(subject.released_at).must_equal "31/03/1981"
|
41
|
+
expect(subject.hit.length).must_equal "312"
|
42
|
+
expect(subject.band.label.value).must_equal "9999.99"
|
43
43
|
end
|
44
44
|
|
45
45
|
|
@@ -49,11 +49,11 @@ class CoercionTest < MiniTest::Spec
|
|
49
49
|
subject.hit.length = "312"
|
50
50
|
subject.band.label.value = "9999.99"
|
51
51
|
|
52
|
-
subject.released_at.must_be_kind_of DateTime
|
53
|
-
subject.released_at.must_equal DateTime.parse("30/03/1981")
|
54
|
-
subject.hit.length.must_equal 312
|
55
|
-
subject.hit.good.must_be_nil
|
56
|
-
subject.band.label.value.must_equal 9999.99
|
52
|
+
expect(subject.released_at).must_be_kind_of DateTime
|
53
|
+
expect(subject.released_at).must_equal DateTime.parse("30/03/1981")
|
54
|
+
expect(subject.hit.length).must_equal 312
|
55
|
+
expect(subject.hit.good).must_be_nil
|
56
|
+
expect(subject.band.label.value).must_equal 9999.99
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -69,9 +69,9 @@ class CoercionTest < MiniTest::Spec
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it "coerce values in setup and when using a setter" do
|
72
|
-
subject.id.must_equal 1
|
72
|
+
expect(subject.id).must_equal 1
|
73
73
|
subject.id = "2"
|
74
|
-
subject.id.must_equal 2
|
74
|
+
expect(subject.id).must_equal 2
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -85,8 +85,15 @@ class CoercionTest < MiniTest::Spec
|
|
85
85
|
property :id, type: const_get("Types::Coercible::#{DRY_TYPES_INT_CONSTANT}"), nilify: true
|
86
86
|
end
|
87
87
|
|
88
|
-
|
88
|
+
class TwinWithoutTypeWithNilify < Disposable::Twin
|
89
|
+
feature Coercion
|
90
|
+
|
91
|
+
property :date_of_birth, nilify: true
|
92
|
+
property :date_of_death_by_unicorns, type: DRY_TYPES_CONSTANT::Nil | DRY_TYPES_CONSTANT::Date
|
93
|
+
property :id, type: const_get("Types::Coercible::#{DRY_TYPES_INT_CONSTANT}"), nilify: true
|
94
|
+
end
|
89
95
|
|
96
|
+
describe "with Nilify" do
|
90
97
|
subject do
|
91
98
|
TwinWithNilify.new(OpenStruct.new(date_of_birth: '1990-01-12',
|
92
99
|
date_of_death_by_unicorns: '2037-02-18',
|
@@ -94,23 +101,54 @@ class CoercionTest < MiniTest::Spec
|
|
94
101
|
end
|
95
102
|
|
96
103
|
it "coerce values correctly" do
|
97
|
-
subject.date_of_birth.must_equal Date.parse('1990-01-12')
|
98
|
-
subject.date_of_death_by_unicorns.must_equal Date.parse('2037-02-18')
|
104
|
+
expect(subject.date_of_birth).must_equal Date.parse('1990-01-12')
|
105
|
+
expect(subject.date_of_death_by_unicorns).must_equal Date.parse('2037-02-18')
|
99
106
|
end
|
100
107
|
|
101
108
|
it "coerce empty values to nil when using option nilify: true" do
|
102
109
|
subject.date_of_birth = ""
|
103
|
-
subject.date_of_birth.must_be_nil
|
110
|
+
expect(subject.date_of_birth).must_be_nil
|
104
111
|
end
|
105
112
|
|
106
113
|
it "coerce empty values to nil when using dry-types | operator" do
|
107
114
|
subject.date_of_death_by_unicorns = ""
|
108
|
-
subject.date_of_death_by_unicorns.must_be_nil
|
115
|
+
expect(subject.date_of_death_by_unicorns).must_be_nil
|
109
116
|
end
|
110
117
|
|
111
118
|
it "converts blank string to nil, without :type option" do
|
112
119
|
subject.id = ""
|
113
|
-
subject.id.must_be_nil
|
120
|
+
expect(subject.id).must_be_nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "without Type With Nilify" do
|
125
|
+
let(:date_of_birth) { '1990-01-12' }
|
126
|
+
subject do
|
127
|
+
TwinWithoutTypeWithNilify.new(
|
128
|
+
OpenStruct.new(
|
129
|
+
date_of_birth: date_of_birth,
|
130
|
+
date_of_death_by_unicorns: '2037-02-18',
|
131
|
+
id: 1
|
132
|
+
)
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'raise error for new dry-types v - work as expected for older versions' do
|
137
|
+
if Disposable::Twin::Coercion::DRY_TYPES_VERSION >= Gem::Version.new("1.0")
|
138
|
+
assert_raises(Dry::Types::CoercionError) { subject.date_of_birth }
|
139
|
+
assert_raises(Dry::Types::CoercionError) { subject.date_of_death_by_unicorns }
|
140
|
+
else
|
141
|
+
expect(subject.date_of_birth).must_equal '1990-01-12'
|
142
|
+
expect(subject.date_of_death_by_unicorns).must_equal Date.parse('2037-02-18')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe 'when passing nil' do
|
147
|
+
let(:date_of_birth) { '' }
|
148
|
+
|
149
|
+
it 'coerce values correctly' do
|
150
|
+
expect(subject.date_of_birth).must_be_nil
|
151
|
+
end
|
114
152
|
end
|
115
153
|
end
|
116
154
|
end
|
@@ -135,13 +173,13 @@ class CoercionTypingTest < MiniTest::Spec
|
|
135
173
|
# with type: Dry::Types::Strict::String
|
136
174
|
# assert_raises(Dry::Types::ConstraintError) { twin.title = nil }
|
137
175
|
twin.title = nil
|
138
|
-
twin.title.must_be_nil
|
176
|
+
expect(twin.title).must_be_nil
|
139
177
|
|
140
178
|
twin.title = "Yo"
|
141
|
-
twin.title.must_equal "Yo"
|
179
|
+
expect(twin.title).must_equal "Yo"
|
142
180
|
|
143
181
|
twin.title = ""
|
144
|
-
twin.title.must_equal ""
|
182
|
+
expect(twin.title).must_equal ""
|
145
183
|
|
146
184
|
assert_raises(Dry::Types::ConstraintError) { twin.title = :bla }
|
147
185
|
assert_raises(Dry::Types::ConstraintError) { twin.title = 1 }
|
@@ -167,16 +205,16 @@ class CoercionTypingTest < MiniTest::Spec
|
|
167
205
|
|
168
206
|
# assert_raises(Dry::Types::ConstraintError) { twin.title = nil } # in form, we either have a blank string or the key's not present at all.
|
169
207
|
twin.title = nil
|
170
|
-
twin.title.must_be_nil
|
208
|
+
expect(twin.title).must_be_nil
|
171
209
|
|
172
210
|
twin.title = "" # nilify blank strings
|
173
|
-
twin.title.must_be_nil
|
211
|
+
expect(twin.title).must_be_nil
|
174
212
|
|
175
213
|
twin.title = "Yo"
|
176
|
-
twin.title.must_equal "Yo"
|
214
|
+
expect(twin.title).must_equal "Yo"
|
177
215
|
|
178
216
|
# twin.enabled = " TRUE"
|
179
|
-
#
|
217
|
+
#expect(twin.enabled).must_equal true
|
180
218
|
end
|
181
219
|
end
|
182
220
|
|