disposable 0.4.6 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +29 -0
- data/.gitignore +1 -0
- data/CHANGES.md +18 -0
- data/Gemfile +2 -0
- data/Gemfile_builder_test.rb +6 -0
- data/README.md +4 -0
- data/Rakefile +8 -2
- data/disposable.gemspec +2 -5
- data/lib/disposable/twin/builder.rb +1 -0
- data/lib/disposable/twin/coercion.rb +4 -1
- data/lib/disposable/twin/default.rb +3 -3
- data/lib/disposable/twin/property/struct.rb +3 -1
- data/lib/disposable/twin/property/unnest.rb +4 -3
- data/lib/disposable/twin.rb +2 -2
- 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/test_helper.rb +1 -1
- data/test/twin/builder_test.rb +7 -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 +11 -67
- data/.travis.yml +0 -42
data/test/test_helper.rb
CHANGED
data/test/twin/builder_test.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# BUNDLE_GEMFILE=Gemfile_builder_test.rb be rake test_builder
|
2
|
+
|
1
3
|
require "test_helper"
|
2
4
|
|
5
|
+
require "disposable/twin/builder"
|
6
|
+
|
3
7
|
class BuilderTest < MiniTest::Spec
|
4
8
|
module Model
|
5
9
|
Song = Struct.new(:id, :title)
|
@@ -26,7 +30,7 @@ class BuilderTest < MiniTest::Spec
|
|
26
30
|
end
|
27
31
|
|
28
32
|
|
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 }
|
33
|
+
it { expect(Twin.build(Model::Song.new)).must_be_instance_of Twin }
|
34
|
+
it { expect(Twin.build(Model::Hit.new)).must_be_instance_of Hit }
|
35
|
+
it { expect(Twin.build(Model::Evergreen.new, evergreen: true)).must_be_instance_of Evergreen }
|
32
36
|
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
|
|
@@ -33,9 +33,9 @@ class TwinCollectionTest < MiniTest::Spec
|
|
33
33
|
it do
|
34
34
|
twin = Twin::Album.new(album)
|
35
35
|
|
36
|
-
twin.songs.size.must_equal 1
|
37
|
-
twin.songs[0].title.must_equal "Broken"
|
38
|
-
twin.songs.must_be_instance_of Disposable::Twin::Collection
|
36
|
+
expect(twin.songs.size).must_equal 1
|
37
|
+
expect(twin.songs[0].title).must_equal "Broken"
|
38
|
+
expect(twin.songs).must_be_instance_of Disposable::Twin::Collection
|
39
39
|
|
40
40
|
end
|
41
41
|
end
|
@@ -44,10 +44,10 @@ class TwinCollectionTest < MiniTest::Spec
|
|
44
44
|
let (:album) { Model::Album.new(1, "The Rest Is Silence", [Model::Song.new(3), Model::Song.new(4)]) }
|
45
45
|
let (:twin) { Twin::Album.new(album) }
|
46
46
|
|
47
|
-
it { twin.songs.find_by(id: 1).must_be_nil }
|
48
|
-
it { twin.songs.find_by(id: 3).must_equal twin.songs[0] }
|
49
|
-
it { twin.songs.find_by(id: 4).must_equal twin.songs[1] }
|
50
|
-
it { twin.songs.find_by(id: "4").must_equal twin.songs[1] }
|
47
|
+
it { expect(twin.songs.find_by(id: 1)).must_be_nil }
|
48
|
+
it { expect(twin.songs.find_by(id: 3)).must_equal twin.songs[0] }
|
49
|
+
it { expect(twin.songs.find_by(id: 4)).must_equal twin.songs[1] }
|
50
|
+
it { expect(twin.songs.find_by(id: "4")).must_equal twin.songs[1] }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -92,31 +92,31 @@ class TwinCollectionActiveRecordTest < MiniTest::Spec
|
|
92
92
|
twin.songs << song1 # assuming that we add AR model here.
|
93
93
|
twin.songs << song2
|
94
94
|
|
95
|
-
twin.songs.size.must_equal 2
|
95
|
+
expect(twin.songs.size).must_equal 2
|
96
96
|
|
97
|
-
twin.songs[0].must_be_instance_of Twin::Song # twin wraps << added in twin.
|
98
|
-
twin.songs[1].must_be_instance_of Twin::Song
|
97
|
+
expect(twin.songs[0]).must_be_instance_of Twin::Song # twin wraps << added in twin.
|
98
|
+
expect(twin.songs[1]).must_be_instance_of Twin::Song
|
99
99
|
|
100
|
-
# twin.songs[0].persisted
|
101
|
-
twin.songs[0].send(:model).persisted
|
102
|
-
twin.songs[1].send(:model).persisted
|
100
|
+
# expect(twin.songs[0].persisted?).must_equal false
|
101
|
+
expect(twin.songs[0].send(:model).persisted?).must_equal false
|
102
|
+
expect(twin.songs[1].send(:model).persisted?).must_equal true
|
103
103
|
|
104
|
-
album.songs.size.must_equal 0 # nothing synced, yet.
|
104
|
+
expect(album.songs.size).must_equal 0 # nothing synced, yet.
|
105
105
|
|
106
106
|
# sync: delete removed items, add new?
|
107
107
|
|
108
108
|
# save
|
109
109
|
twin.save
|
110
110
|
|
111
|
-
album.persisted
|
112
|
-
album.name.must_equal "The Rest Is Silence"
|
111
|
+
expect(album.persisted?).must_equal true
|
112
|
+
expect(album.name).must_equal "The Rest Is Silence"
|
113
113
|
|
114
|
-
album.songs.size.must_equal 2 # synced!
|
114
|
+
expect(album.songs.size).must_equal 2 # synced!
|
115
115
|
|
116
|
-
album.songs[0].persisted
|
117
|
-
album.songs[1].persisted
|
118
|
-
album.songs[0].title.must_equal "Snorty Pacifical Rascal"
|
119
|
-
album.songs[1].title.must_equal "At Any Cost"
|
116
|
+
expect(album.songs[0].persisted?).must_equal true
|
117
|
+
expect(album.songs[1].persisted?).must_equal true
|
118
|
+
expect(album.songs[0].title).must_equal "Snorty Pacifical Rascal"
|
119
|
+
expect(album.songs[1].title).must_equal "At Any Cost"
|
120
120
|
end
|
121
121
|
|
122
122
|
# test with adding to existing collection [song1] << song2
|
@@ -128,20 +128,20 @@ class TwinCollectionActiveRecordTest < MiniTest::Spec
|
|
128
128
|
it do
|
129
129
|
twin.songs.delete(twin.songs.first)
|
130
130
|
|
131
|
-
twin.songs.size.must_equal 0
|
132
|
-
album.songs.size.must_equal 1 # not synced, yet.
|
131
|
+
expect(twin.songs.size).must_equal 0
|
132
|
+
expect(album.songs.size).must_equal 1 # not synced, yet.
|
133
133
|
|
134
134
|
twin.save
|
135
135
|
|
136
|
-
twin.songs.size.must_equal 0
|
137
|
-
album.songs.size.must_equal 0
|
138
|
-
song1.persisted
|
136
|
+
expect(twin.songs.size).must_equal 0
|
137
|
+
expect(album.songs.size).must_equal 0
|
138
|
+
expect(song1.persisted?).must_equal true
|
139
139
|
end
|
140
140
|
|
141
141
|
# non-existant delete.
|
142
142
|
it do
|
143
143
|
twin.songs.delete("non-existant") # won't delete anything.
|
144
|
-
twin.songs.size.must_equal 1
|
144
|
+
expect(twin.songs.size).must_equal 1
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
@@ -151,14 +151,14 @@ class TwinCollectionActiveRecordTest < MiniTest::Spec
|
|
151
151
|
it do
|
152
152
|
twin.songs.destroy(twin.songs.first)
|
153
153
|
|
154
|
-
twin.songs.size.must_equal 0
|
155
|
-
album.songs.size.must_equal 1 # not synced, yet.
|
154
|
+
expect(twin.songs.size).must_equal 0
|
155
|
+
expect(album.songs.size).must_equal 1 # not synced, yet.
|
156
156
|
|
157
157
|
twin.save
|
158
158
|
|
159
|
-
twin.songs.size.must_equal 0
|
160
|
-
album.songs.size.must_equal 0
|
161
|
-
song1.persisted
|
159
|
+
expect(twin.songs.size).must_equal 0
|
160
|
+
expect(album.songs.size).must_equal 0
|
161
|
+
expect(song1.persisted?).must_equal false
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
@@ -169,11 +169,11 @@ class TwinCollectionActiveRecordTest < MiniTest::Spec
|
|
169
169
|
it do
|
170
170
|
twin = Twin::Album.new(album)
|
171
171
|
|
172
|
-
twin.songs.added.must_equal []
|
172
|
+
expect(twin.songs.added).must_equal []
|
173
173
|
twin.songs << song2
|
174
|
-
twin.songs.added.must_equal [twin.songs[1]]
|
174
|
+
expect(twin.songs.added).must_equal [twin.songs[1]]
|
175
175
|
twin.songs.insert(2, Song.new)
|
176
|
-
twin.songs.added.must_equal [twin.songs[1], twin.songs[2]]
|
176
|
+
expect(twin.songs.added).must_equal [twin.songs[1], twin.songs[2]]
|
177
177
|
|
178
178
|
# TODO: what to do if we override an item (insert)?
|
179
179
|
end
|
@@ -185,20 +185,20 @@ class TwinCollectionActiveRecordTest < MiniTest::Spec
|
|
185
185
|
it do
|
186
186
|
twin = Twin::Album.new(album)
|
187
187
|
|
188
|
-
twin.songs.deleted.must_equal []
|
188
|
+
expect(twin.songs.deleted).must_equal []
|
189
189
|
|
190
190
|
twin.songs.delete(deleted1 = twin.songs[-1])
|
191
191
|
twin.songs.delete(deleted2 = twin.songs[-1])
|
192
192
|
|
193
|
-
twin.songs.must_equal [twin.songs[0]]
|
193
|
+
expect(twin.songs).must_equal [twin.songs[0]]
|
194
194
|
|
195
|
-
twin.songs.deleted.must_equal [deleted1, deleted2]
|
195
|
+
expect(twin.songs.deleted).must_equal [deleted1, deleted2]
|
196
196
|
end
|
197
197
|
|
198
198
|
# non-existant delete.
|
199
199
|
it do
|
200
200
|
twin.songs.delete("non-existant") # won't delete anything.
|
201
|
-
twin.songs.deleted.must_equal []
|
201
|
+
expect(twin.songs.deleted).must_equal []
|
202
202
|
end
|
203
203
|
end
|
204
204
|
end
|
@@ -223,24 +223,24 @@ class CollectionUnitTest < MiniTest::Spec
|
|
223
223
|
|
224
224
|
# #insert(index, model)
|
225
225
|
it do
|
226
|
-
collection.insert(0, Model::Album.new).must_be_instance_of Twin::Album
|
226
|
+
expect(collection.insert(0, Model::Album.new)).must_be_instance_of Twin::Album
|
227
227
|
end
|
228
228
|
|
229
229
|
# #append(model)
|
230
230
|
it do
|
231
|
-
collection.append(Model::Album.new).must_be_instance_of Twin::Album
|
232
|
-
collection[0].must_be_instance_of Twin::Album
|
231
|
+
expect(collection.append(Model::Album.new)).must_be_instance_of Twin::Album
|
232
|
+
expect(collection[0]).must_be_instance_of Twin::Album
|
233
233
|
|
234
234
|
# allows subsequent calls.
|
235
235
|
collection.append(Model::Album.new)
|
236
|
-
collection[1].must_be_instance_of Twin::Album
|
236
|
+
expect(collection[1]).must_be_instance_of Twin::Album
|
237
237
|
|
238
|
-
collection.size.must_equal 2
|
238
|
+
expect(collection.size).must_equal 2
|
239
239
|
end
|
240
240
|
|
241
241
|
# #<<
|
242
242
|
it do
|
243
|
-
(collection << Model::Album.new).must_be_instance_of Array
|
244
|
-
collection[0].must_be_instance_of Twin::Album
|
243
|
+
expect((collection << Model::Album.new)).must_be_instance_of Array
|
244
|
+
expect(collection[0]).must_be_instance_of Twin::Album
|
245
245
|
end
|
246
246
|
end
|
@@ -26,34 +26,34 @@ class TwinCompositionTest < MiniTest::Spec
|
|
26
26
|
let (:request) { Request.new(song: song, requester: requester) }
|
27
27
|
|
28
28
|
it do
|
29
|
-
request.song_title.must_equal "Extraction"
|
30
|
-
request.song_id.must_equal 2
|
31
|
-
request.name.must_equal "Greg Howe"
|
32
|
-
request.id.must_equal 1
|
29
|
+
expect(request.song_title).must_equal "Extraction"
|
30
|
+
expect(request.song_id).must_equal 2
|
31
|
+
expect(request.name).must_equal "Greg Howe"
|
32
|
+
expect(request.id).must_equal 1
|
33
33
|
|
34
34
|
request.song_title = "Tease"
|
35
35
|
request.name = "Wooten"
|
36
36
|
|
37
37
|
|
38
|
-
request.song_title.must_equal "Tease"
|
39
|
-
request.name.must_equal "Wooten"
|
38
|
+
expect(request.song_title).must_equal "Tease"
|
39
|
+
expect(request.name).must_equal "Wooten"
|
40
40
|
|
41
41
|
# does not write to model.
|
42
|
-
song.title.must_equal "Extraction"
|
43
|
-
requester.name.must_equal "Greg Howe"
|
42
|
+
expect(song.title).must_equal "Extraction"
|
43
|
+
expect(requester.name).must_equal "Greg Howe"
|
44
44
|
|
45
45
|
|
46
46
|
res = request.save
|
47
|
-
res.must_equal true
|
47
|
+
expect(res).must_equal true
|
48
48
|
|
49
49
|
# make sure models got synced and saved.
|
50
|
-
song.id.must_equal 2
|
51
|
-
song.title.must_equal "Tease"
|
52
|
-
requester.id.must_equal 1
|
53
|
-
requester.name.must_equal "Wooten"
|
50
|
+
expect(song.id).must_equal 2
|
51
|
+
expect(song.title).must_equal "Tease"
|
52
|
+
expect(requester.id).must_equal 1
|
53
|
+
expect(requester.name).must_equal "Wooten"
|
54
54
|
|
55
|
-
song.saved
|
56
|
-
requester.saved
|
55
|
+
expect(song.saved?).must_equal true
|
56
|
+
expect(requester.saved?).must_equal true
|
57
57
|
end
|
58
58
|
|
59
59
|
# save with block.
|
@@ -63,8 +63,8 @@ class TwinCompositionTest < MiniTest::Spec
|
|
63
63
|
request.captcha = "Awesome!"
|
64
64
|
|
65
65
|
# does not write to model.
|
66
|
-
song.title.must_equal "Extraction"
|
67
|
-
requester.name.must_equal "Greg Howe"
|
66
|
+
expect(song.title).must_equal "Extraction"
|
67
|
+
expect(requester.name).must_equal "Greg Howe"
|
68
68
|
|
69
69
|
|
70
70
|
nested_hash = nil
|
@@ -72,13 +72,13 @@ class TwinCompositionTest < MiniTest::Spec
|
|
72
72
|
nested_hash = hash
|
73
73
|
end
|
74
74
|
|
75
|
-
nested_hash.must_equal(:song=>{"title"=>"Tease", "id"=>2}, :requester=>{"name"=>"Wooten", "id"=>1, "captcha"=>"Awesome!"})
|
75
|
+
expect(nested_hash).must_equal(:song=>{"title"=>"Tease", "id"=>2}, :requester=>{"name"=>"Wooten", "id"=>1, "captcha"=>"Awesome!"})
|
76
76
|
end
|
77
77
|
|
78
78
|
# save with one unsaveable model.
|
79
79
|
#save returns result.
|
80
80
|
it do
|
81
81
|
song.instance_eval { def save; false; end }
|
82
|
-
request.save.must_equal false
|
82
|
+
expect(request.save).must_equal false
|
83
83
|
end
|
84
|
-
end
|
84
|
+
end
|
data/test/twin/default_test.rb
CHANGED
@@ -19,28 +19,28 @@ class DefaultTest < Minitest::Spec
|
|
19
19
|
# all given.
|
20
20
|
it do
|
21
21
|
twin = Twin.new(Song.new("Anarchy Camp", false, true, "Punk", Composer.new("Nofx")))
|
22
|
-
twin.title.must_equal "Anarchy Camp"
|
23
|
-
twin.genre.must_equal "Punk"
|
24
|
-
twin.composer.name.must_equal "Nofx"
|
25
|
-
twin.published.must_equal true
|
26
|
-
twin.new_album.must_equal false
|
22
|
+
expect(twin.title).must_equal "Anarchy Camp"
|
23
|
+
expect(twin.genre).must_equal "Punk"
|
24
|
+
expect(twin.composer.name).must_equal "Nofx"
|
25
|
+
expect(twin.published).must_equal true
|
26
|
+
expect(twin.new_album).must_equal false
|
27
27
|
end
|
28
28
|
|
29
29
|
# defaults, please.
|
30
30
|
it do
|
31
31
|
twin = Twin.new(Song.new)
|
32
|
-
twin.title.must_equal "Medio-Core"
|
33
|
-
twin.composer.name.must_equal "NOFX"
|
34
|
-
twin.genre.must_equal "Punk Rock DefaultTest::Song"
|
35
|
-
twin.published.must_equal false
|
36
|
-
twin.new_album.must_equal true
|
32
|
+
expect(twin.title).must_equal "Medio-Core"
|
33
|
+
expect(twin.composer.name).must_equal "NOFX"
|
34
|
+
expect(twin.genre).must_equal "Punk Rock DefaultTest::Song"
|
35
|
+
expect(twin.published).must_equal false
|
36
|
+
expect(twin.new_album).must_equal true
|
37
37
|
end
|
38
38
|
|
39
39
|
# false value is not defaulted.
|
40
40
|
it do
|
41
41
|
twin = Twin.new(Song.new(false, false))
|
42
|
-
twin.title.must_equal false
|
43
|
-
twin.new_album.must_equal false
|
42
|
+
expect(twin.title).must_equal false
|
43
|
+
expect(twin.new_album).must_equal false
|
44
44
|
end
|
45
45
|
|
46
46
|
describe "inheritance" do
|
@@ -51,7 +51,7 @@ class DefaultTest < Minitest::Spec
|
|
51
51
|
class MegaTwin < SuperTwin
|
52
52
|
end
|
53
53
|
|
54
|
-
it { MegaTwin.new(Composer.new).name.must_equal "n/a" }
|
54
|
+
it { expect(MegaTwin.new(Composer.new).name).must_equal "n/a" }
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -65,8 +65,8 @@ class DefaultAndVirtualTest < Minitest::Spec
|
|
65
65
|
|
66
66
|
it do
|
67
67
|
twin = Twin.new(Object.new)
|
68
|
-
twin.title.must_equal "0"
|
69
|
-
# twin.changed.must_equal []
|
68
|
+
expect(twin.title).must_equal "0"
|
69
|
+
# expect(twin.changed).must_equal []
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|