representable 3.0.0 → 3.1.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.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +17 -0
- data/CHANGES.md +25 -0
- data/Gemfile +4 -12
- data/LICENSE +1 -1
- data/README.md +6 -6
- data/Rakefile +1 -6
- data/TODO +1 -3
- data/TODO-4.0.md +72 -0
- data/lib/representable.rb +19 -25
- data/lib/representable/binding.rb +32 -12
- data/lib/representable/cached.rb +1 -1
- data/lib/representable/coercion.rb +8 -6
- data/lib/representable/config.rb +13 -3
- data/lib/representable/debug.rb +23 -15
- data/lib/representable/declarative.rb +12 -7
- data/lib/representable/decorator.rb +1 -1
- data/lib/representable/definition.rb +7 -3
- data/lib/representable/deserializer.rb +5 -4
- data/lib/representable/for_collection.rb +1 -1
- data/lib/representable/hash.rb +9 -2
- data/lib/representable/hash/allow_symbols.rb +9 -11
- data/lib/representable/hash/binding.rb +1 -0
- data/lib/representable/hash/collection.rb +4 -2
- data/lib/representable/hash_methods.rb +3 -2
- data/lib/representable/insert.rb +1 -1
- data/lib/representable/json.rb +8 -7
- data/lib/representable/json/collection.rb +3 -0
- data/lib/representable/object.rb +1 -1
- data/lib/representable/object/binding.rb +5 -1
- data/lib/representable/option.rb +19 -0
- data/lib/representable/pipeline.rb +3 -2
- data/lib/representable/pipeline_factories.rb +4 -2
- data/lib/representable/populator.rb +1 -1
- data/lib/representable/represent.rb +1 -0
- data/lib/representable/serializer.rb +3 -2
- data/lib/representable/version.rb +1 -1
- data/lib/representable/virtus_coercion.rb +38 -0
- data/lib/representable/xml.rb +12 -10
- data/lib/representable/xml/binding.rb +19 -13
- data/lib/representable/xml/namespace.rb +122 -0
- data/lib/representable/yaml.rb +6 -2
- data/lib/representable/yaml/binding.rb +1 -0
- data/representable.gemspec +8 -9
- data/test/as_test.rb +7 -7
- data/test/binding_test.rb +14 -14
- data/test/cached_test.rb +59 -49
- data/test/class_test.rb +9 -9
- data/test/coercion_test.rb +33 -22
- data/test/config/inherit_test.rb +14 -14
- data/test/config_test.rb +20 -20
- data/test/decorator_scope_test.rb +4 -4
- data/test/decorator_test.rb +33 -20
- data/test/default_test.rb +8 -8
- data/test/defaults_options_test.rb +3 -3
- data/test/definition_test.rb +38 -40
- data/test/{example.rb → examples/example.rb} +0 -1
- data/test/examples/object.rb +1 -5
- data/test/exec_context_test.rb +8 -8
- data/test/features_test.rb +6 -6
- data/test/filter_test.rb +8 -8
- data/test/for_collection_test.rb +10 -10
- data/test/generic_test.rb +13 -13
- data/test/getter_setter_test.rb +5 -5
- data/test/hash_bindings_test.rb +1 -1
- data/test/hash_test.rb +45 -23
- data/test/heritage_test.rb +16 -13
- data/test/if_test.rb +9 -9
- data/test/include_exclude_test.rb +14 -14
- data/test/inherit_test.rb +18 -18
- data/test/inline_test.rb +24 -24
- data/test/instance_test.rb +31 -31
- data/test/is_representable_test.rb +10 -10
- data/test/json_test.rb +29 -7
- data/test/lonely_test.rb +31 -31
- data/test/nested_test.rb +13 -13
- data/test/object_test.rb +9 -9
- data/test/option_test.rb +36 -0
- data/test/parse_pipeline_test.rb +3 -5
- data/test/pipeline_test.rb +50 -50
- data/test/populator_test.rb +18 -18
- data/test/prepare_test.rb +4 -4
- data/test/private_options_test.rb +2 -2
- data/test/reader_writer_test.rb +2 -2
- data/test/render_nil_test.rb +2 -2
- data/test/represent_test.rb +14 -14
- data/test/representable_test.rb +34 -36
- data/test/schema_test.rb +8 -11
- data/test/serialize_deserialize_test.rb +2 -2
- data/test/skip_test.rb +14 -14
- data/test/stringify_hash_test.rb +3 -3
- data/test/test_helper.rb +26 -14
- data/test/uncategorized_test.rb +10 -10
- data/test/user_options_test.rb +4 -4
- data/test/virtus_coercion_test.rb +52 -0
- data/test/wrap_test.rb +19 -19
- data/test/xml_bindings_test.rb +0 -4
- data/test/xml_namespace_test.rb +186 -0
- data/test/xml_test.rb +103 -43
- data/test/yaml_test.rb +51 -26
- metadata +101 -39
- data/.travis.yml +0 -7
- data/lib/representable/TODO.getting_serious +0 -11
- data/lib/representable/autoload.rb +0 -10
- data/test/mongoid_test.rb +0 -31
data/test/object_test.rb
CHANGED
@@ -18,23 +18,23 @@ class ObjectTest < MiniTest::Spec
|
|
18
18
|
# TODO: collection
|
19
19
|
end
|
20
20
|
|
21
|
-
let
|
22
|
-
let
|
21
|
+
let(:source) { Song.new("The King Is Dead", Album.new("Ruiner", [Song.new("In Vino Veritas II")])) }
|
22
|
+
let(:target) { Song.new }
|
23
23
|
|
24
24
|
it do
|
25
25
|
representer.prepare(target).from_object(source)
|
26
26
|
|
27
|
-
target.title.must_equal "The King Is Dead"
|
28
|
-
target.album.name.must_equal "RUINER"
|
29
|
-
target.album.songs[0].title.must_equal "IN VINO VERITAS II"
|
27
|
+
_(target.title).must_equal "The King Is Dead"
|
28
|
+
_(target.album.name).must_equal "RUINER"
|
29
|
+
_(target.album.songs[0].title).must_equal "IN VINO VERITAS II"
|
30
30
|
end
|
31
31
|
|
32
32
|
# ignore nested object when nil
|
33
33
|
it do
|
34
34
|
representer.prepare(Song.new("The King Is Dead")).from_object(Song.new)
|
35
35
|
|
36
|
-
target.title.
|
37
|
-
target.album.
|
36
|
+
_(target.title).must_be_nil # scalar property gets overridden when nil.
|
37
|
+
_(target.album).must_be_nil # nested property stays nil.
|
38
38
|
end
|
39
39
|
|
40
40
|
# to_object
|
@@ -53,8 +53,8 @@ class ObjectTest < MiniTest::Spec
|
|
53
53
|
|
54
54
|
it do
|
55
55
|
representer.prepare(source).to_object
|
56
|
-
source.album.name.must_equal "Live"
|
57
|
-
source.album.songs[0].title.must_equal 1
|
56
|
+
_(source.album.name).must_equal "Live"
|
57
|
+
_(source.album.songs[0].title).must_equal 1
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
data/test/option_test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class OptionTest < MiniTest::Spec
|
6
|
+
class Callable
|
7
|
+
include Uber::Callable
|
8
|
+
def call(*); "callable" end
|
9
|
+
end
|
10
|
+
|
11
|
+
class MyRepresenter < Representable::Decorator
|
12
|
+
include Representable::JSON
|
13
|
+
|
14
|
+
property :static, getter: "static"
|
15
|
+
property :symbol, getter: :symbol
|
16
|
+
property :proc, getter: ->(*) { "proc" }
|
17
|
+
property :callable, getter: Callable.new
|
18
|
+
end
|
19
|
+
|
20
|
+
Album = Struct.new(:static) do
|
21
|
+
def symbol(*); "symbol" end
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:album_representer) { MyRepresenter.new(Album.new) }
|
25
|
+
|
26
|
+
describe ::Representable::Option do
|
27
|
+
it "supports all types of callables (method, proc, static etc)" do
|
28
|
+
_(album_representer.to_hash).must_equal({
|
29
|
+
"static" => "static",
|
30
|
+
"symbol" => "symbol",
|
31
|
+
"proc" => "proc",
|
32
|
+
"callable" => "callable",
|
33
|
+
})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/test/parse_pipeline_test.rb
CHANGED
@@ -22,12 +22,12 @@ class ParsePipelineTest < MiniTest::Spec
|
|
22
22
|
|
23
23
|
it do
|
24
24
|
representer.new(album = Album.new).from_hash("songs"=>nil)
|
25
|
-
album.songs.must_equal []
|
25
|
+
_(album.songs).must_equal []
|
26
26
|
end
|
27
27
|
|
28
28
|
it do
|
29
29
|
representer.new(album = Album.new).from_hash("songs"=>[{"title" => "Business Conduct"}])
|
30
|
-
album.songs.must_equal [Song.new("Business Conduct")]
|
30
|
+
_(album.songs).must_equal [Song.new("Business Conduct")]
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -45,7 +45,6 @@ class ParsePipelineTest < MiniTest::Spec
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def instance!(*options)
|
48
|
-
puts "@@@@@ #{options.inspect}"
|
49
48
|
Song.new
|
50
49
|
end
|
51
50
|
|
@@ -58,7 +57,6 @@ class ParsePipelineTest < MiniTest::Spec
|
|
58
57
|
skip "TODO: implement :parse_pipeline and :render_pipeline, and before/after/replace semantics"
|
59
58
|
album = Album.new
|
60
59
|
Representer.new(album).from_hash({"artist"=>{"email"=>"yo"}, "songs"=>[{"title"=>"Affliction"}, {"title"=>"Dream Beater"}]})
|
61
|
-
album.songs.must_equal([Song.new("Affliction"), Song.new("Dream Beater")])
|
62
|
-
puts album.inspect
|
60
|
+
_(album.songs).must_equal([Song.new("Affliction"), Song.new("Dream Beater")])
|
63
61
|
end
|
64
62
|
end
|
data/test/pipeline_test.rb
CHANGED
@@ -24,15 +24,15 @@ class PipelineTest < MiniTest::Spec
|
|
24
24
|
AssignFragment = ->(input, options) { options[:fragment] = input }
|
25
25
|
|
26
26
|
it "linear" do
|
27
|
-
P[SkipParse, Setter].("doc", {fragment: 1}).must_equal "Setter(doc)"
|
27
|
+
_(P[SkipParse, Setter].("doc", {fragment: 1})).must_equal "Setter(doc)"
|
28
28
|
|
29
29
|
|
30
30
|
# parse style.
|
31
|
-
P[AssignFragment, SkipParse, CreateObject, Prepare].("Bla", {}).must_equal "Prepare(#<OpenStruct>)"
|
31
|
+
_(P[AssignFragment, SkipParse, CreateObject, Prepare].("Bla", {})).must_equal "Prepare(#<OpenStruct>)"
|
32
32
|
|
33
33
|
|
34
34
|
# render style.
|
35
|
-
P[Getter, StopOnNil, SkipRender, Prepare, Setter].(nil, {}).
|
35
|
+
_(P[Getter, StopOnNil, SkipRender, Prepare, Setter].(nil, {})).
|
36
36
|
must_equal "Setter(Prepare(Yo))"
|
37
37
|
|
38
38
|
# pipeline = Representable::Pipeline[SkipParse , SetResult, ModifyResult]
|
@@ -46,8 +46,8 @@ class PipelineTest < MiniTest::Spec
|
|
46
46
|
|
47
47
|
|
48
48
|
pipeline = Representable::Pipeline[SkipParse, Stopping, Prepare]
|
49
|
-
pipeline.(nil, fragment: "oy!").must_equal "Prepare()"
|
50
|
-
pipeline.(nil, fragment: "stop!").must_equal Representable::Pipeline::Stop
|
49
|
+
_(pipeline.(nil, fragment: "oy!")).must_equal "Prepare()"
|
50
|
+
_(pipeline.(nil, fragment: "stop!")).must_equal Representable::Pipeline::Stop
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "Collect" do
|
@@ -55,11 +55,11 @@ class PipelineTest < MiniTest::Spec
|
|
55
55
|
Add = ->(input, options) { "#{input}+" }
|
56
56
|
let(:pipeline) { R::Collect[Reverse, Add] }
|
57
57
|
|
58
|
-
it { pipeline.(["yo!", "oy!"], {}).must_equal ["!oy+", "!yo+"] }
|
58
|
+
it { _(pipeline.(["yo!", "oy!"], {})).must_equal ["!oy+", "!yo+"] }
|
59
59
|
|
60
60
|
describe "Pipeline with Collect" do
|
61
61
|
let(:pipeline) { P[Reverse, R::Collect[Reverse, Add]] }
|
62
|
-
it { pipeline.(["yo!", "oy!"], {}).must_equal ["!yo+", "!oy+"] }
|
62
|
+
it { _(pipeline.(["yo!", "oy!"], {})).must_equal ["!yo+", "!oy+"] }
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -68,7 +68,7 @@ class PipelineTest < MiniTest::Spec
|
|
68
68
|
|
69
69
|
######### scalar property
|
70
70
|
|
71
|
-
let
|
71
|
+
let(:title) {
|
72
72
|
dfn = R::Definition.new(:title)
|
73
73
|
|
74
74
|
R::Hash::Binding.new(dfn)
|
@@ -76,26 +76,26 @@ class PipelineTest < MiniTest::Spec
|
|
76
76
|
|
77
77
|
it "rendering scalar property" do
|
78
78
|
doc = {}
|
79
|
-
P[
|
79
|
+
_(P[
|
80
80
|
R::GetValue,
|
81
81
|
R::StopOnSkipable,
|
82
82
|
R::AssignName,
|
83
83
|
R::WriteFragment
|
84
|
-
].(nil, {represented: Song.new("Lime Green"), binding: title, doc: doc}).must_equal "Lime Green"
|
84
|
+
].(nil, {represented: Song.new("Lime Green"), binding: title, doc: doc})).must_equal "Lime Green"
|
85
85
|
|
86
|
-
doc.must_equal({"title"=>"Lime Green"})
|
86
|
+
_(doc).must_equal({"title"=>"Lime Green"})
|
87
87
|
end
|
88
88
|
|
89
89
|
it "parsing scalar property" do
|
90
|
-
P[
|
90
|
+
_(P[
|
91
91
|
R::AssignName,
|
92
92
|
R::ReadFragment,
|
93
93
|
R::StopOnNotFound,
|
94
94
|
R::OverwriteOnNil,
|
95
95
|
# R::SkipParse,
|
96
96
|
R::SetValue,
|
97
|
-
].extend(P::Debug).(doc={"title"=>"Eruption"}, {represented: song=Song.new("Lime Green"), binding: title, doc: doc}).must_equal "Eruption"
|
98
|
-
song.title.must_equal "Eruption"
|
97
|
+
].extend(P::Debug).(doc={"title"=>"Eruption"}, {represented: song=Song.new("Lime Green"), binding: title, doc: doc})).must_equal "Eruption"
|
98
|
+
_(song.title).must_equal "Eruption"
|
99
99
|
end
|
100
100
|
|
101
101
|
|
@@ -105,17 +105,17 @@ class PipelineTest < MiniTest::Spec
|
|
105
105
|
property :name
|
106
106
|
end
|
107
107
|
|
108
|
-
let
|
108
|
+
let(:artist) {
|
109
109
|
dfn = R::Definition.new(:artist, extend: ArtistRepresenter, class: Artist)
|
110
110
|
|
111
111
|
R::Hash::Binding.new(dfn)
|
112
112
|
}
|
113
113
|
|
114
|
-
let
|
114
|
+
let(:song_model) { Song.new("Lime Green", Artist.new("Diesel Boy")) }
|
115
115
|
|
116
116
|
it "rendering typed property" do
|
117
117
|
doc = {}
|
118
|
-
P[
|
118
|
+
_(P[
|
119
119
|
R::GetValue,
|
120
120
|
R::StopOnSkipable,
|
121
121
|
R::StopOnNil,
|
@@ -123,13 +123,13 @@ class PipelineTest < MiniTest::Spec
|
|
123
123
|
R::Serialize,
|
124
124
|
R::AssignName,
|
125
125
|
R::WriteFragment
|
126
|
-
].extend(P::Debug).(nil, {represented: song_model, binding: artist, doc: doc, options: {}}).must_equal({"name" => "Diesel Boy"})
|
126
|
+
].extend(P::Debug).(nil, {represented: song_model, binding: artist, doc: doc, options: {}})).must_equal({"name" => "Diesel Boy"})
|
127
127
|
|
128
|
-
doc.must_equal({"artist"=>{"name"=>"Diesel Boy"}})
|
128
|
+
_(doc).must_equal({"artist"=>{"name"=>"Diesel Boy"}})
|
129
129
|
end
|
130
130
|
|
131
131
|
it "parsing typed property" do
|
132
|
-
P[
|
132
|
+
_(P[
|
133
133
|
R::AssignName,
|
134
134
|
R::ReadFragment,
|
135
135
|
R::StopOnNotFound,
|
@@ -139,21 +139,21 @@ class PipelineTest < MiniTest::Spec
|
|
139
139
|
R::Decorate,
|
140
140
|
R::Deserialize,
|
141
141
|
R::SetValue,
|
142
|
-
].extend(P::Debug).(doc={"artist"=>{"name"=>"Doobie Brothers"}}, {represented: song_model, binding: artist, doc: doc, options: {}}).must_equal model=Artist.new("Doobie Brothers")
|
143
|
-
song_model.artist.must_equal model
|
142
|
+
].extend(P::Debug).(doc={"artist"=>{"name"=>"Doobie Brothers"}}, {represented: song_model, binding: artist, doc: doc, options: {}})).must_equal model=Artist.new("Doobie Brothers")
|
143
|
+
_(song_model.artist).must_equal model
|
144
144
|
end
|
145
145
|
|
146
146
|
|
147
147
|
######### collection :ratings
|
148
148
|
|
149
|
-
let
|
149
|
+
let(:ratings) {
|
150
150
|
dfn = R::Definition.new(:ratings, collection: true, skip_render: ->(*) { false })
|
151
151
|
|
152
152
|
R::Hash::Binding::Collection.new(dfn)
|
153
153
|
}
|
154
154
|
it "render scalar collection" do
|
155
155
|
doc = {}
|
156
|
-
P[
|
156
|
+
_(P[
|
157
157
|
R::GetValue,
|
158
158
|
R::StopOnSkipable,
|
159
159
|
R::Collect[
|
@@ -161,20 +161,20 @@ class PipelineTest < MiniTest::Spec
|
|
161
161
|
],
|
162
162
|
R::AssignName,
|
163
163
|
R::WriteFragment
|
164
|
-
].extend(P::Debug).(nil, {represented: Album.new([1,2,3]), binding: ratings, doc: doc, options: {}}).must_equal([1,2,3])
|
164
|
+
].extend(P::Debug).(nil, {represented: Album.new([1,2,3]), binding: ratings, doc: doc, options: {}})).must_equal([1,2,3])
|
165
165
|
|
166
|
-
doc.must_equal({"ratings"=>[1,2,3]})
|
166
|
+
_(doc).must_equal({"ratings"=>[1,2,3]})
|
167
167
|
end
|
168
168
|
|
169
169
|
######### collection :songs, extend: SongRepresenter
|
170
|
-
let
|
170
|
+
let(:artists) {
|
171
171
|
dfn = R::Definition.new(:artists, collection: true, extend: ArtistRepresenter, class: Artist)
|
172
172
|
|
173
173
|
R::Hash::Binding::Collection.new(dfn)
|
174
174
|
}
|
175
175
|
it "render typed collection" do
|
176
176
|
doc = {}
|
177
|
-
P[
|
177
|
+
_(P[
|
178
178
|
R::GetValue,
|
179
179
|
R::StopOnSkipable,
|
180
180
|
R::Collect[
|
@@ -183,16 +183,16 @@ class PipelineTest < MiniTest::Spec
|
|
183
183
|
],
|
184
184
|
R::AssignName,
|
185
185
|
R::WriteFragment
|
186
|
-
].extend(P::Debug).(nil, {represented: Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van Halen")]), binding: artists, doc: doc, options: {}}).must_equal([{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}])
|
186
|
+
].extend(P::Debug).(nil, {represented: Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van Halen")]), binding: artists, doc: doc, options: {}})).must_equal([{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}])
|
187
187
|
|
188
|
-
doc.must_equal({"artists"=>[{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}]})
|
188
|
+
_(doc).must_equal({"artists"=>[{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}]})
|
189
189
|
end
|
190
190
|
|
191
|
-
let
|
191
|
+
let(:album_model) { Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van Halen")]) }
|
192
192
|
|
193
193
|
it "parse typed collection" do
|
194
194
|
doc = {"artists"=>[{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}]}
|
195
|
-
P[
|
195
|
+
_(P[
|
196
196
|
R::AssignName,
|
197
197
|
R::ReadFragment,
|
198
198
|
R::StopOnNotFound,
|
@@ -205,51 +205,51 @@ let (:album_model) { Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van H
|
|
205
205
|
R::Deserialize,
|
206
206
|
],
|
207
207
|
R::SetValue,
|
208
|
-
].extend(P::Debug).(doc, {represented: album_model, binding: artists, doc: doc, options: {}}).must_equal([Artist.new("Diesel Boy"), Artist.new("Van Halen")])
|
208
|
+
].extend(P::Debug).(doc, {represented: album_model, binding: artists, doc: doc, options: {}})).must_equal([Artist.new("Diesel Boy"), Artist.new("Van Halen")])
|
209
209
|
|
210
|
-
album_model.artists.must_equal([Artist.new("Diesel Boy"), Artist.new("Van Halen")])
|
210
|
+
_(album_model.artists).must_equal([Artist.new("Diesel Boy"), Artist.new("Van Halen")])
|
211
211
|
end
|
212
212
|
|
213
213
|
# TODO: test with arrays, too, not "only" Pipeline instances.
|
214
214
|
describe "#Insert Pipeline[], Function, replace: OldFunction" do
|
215
|
-
let
|
215
|
+
let(:pipeline) { P[R::GetValue, R::StopOnSkipable, R::StopOnNil] }
|
216
216
|
|
217
217
|
it "returns Pipeline instance when passing in Pipeline instance" do
|
218
|
-
P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable).must_be_instance_of(R::Pipeline)
|
218
|
+
_(P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable)).must_be_instance_of(R::Pipeline)
|
219
219
|
end
|
220
220
|
|
221
221
|
it "replaces if exists" do
|
222
222
|
# pipeline.insert!(R::Default, replace: R::StopOnSkipable)
|
223
|
-
P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable).must_equal P[R::GetValue, R::Default, R::StopOnNil]
|
224
|
-
pipeline.must_equal P[R::GetValue, R::StopOnSkipable, R::StopOnNil]
|
223
|
+
_(P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable)).must_equal P[R::GetValue, R::Default, R::StopOnNil]
|
224
|
+
_(pipeline).must_equal P[R::GetValue, R::StopOnSkipable, R::StopOnNil]
|
225
225
|
end
|
226
226
|
|
227
227
|
it "replaces Function instance" do
|
228
228
|
pipeline = P[R::Prepare, R::StopOnSkipable, R::StopOnNil]
|
229
|
-
P::Insert.(pipeline, R::Default, replace: R::Prepare).must_equal P[R::Default, R::StopOnSkipable, R::StopOnNil]
|
230
|
-
pipeline.must_equal P[R::Prepare, R::StopOnSkipable, R::StopOnNil]
|
229
|
+
_(P::Insert.(pipeline, R::Default, replace: R::Prepare)).must_equal P[R::Default, R::StopOnSkipable, R::StopOnNil]
|
230
|
+
_(pipeline).must_equal P[R::Prepare, R::StopOnSkipable, R::StopOnNil]
|
231
231
|
end
|
232
232
|
|
233
233
|
it "does not replace when not existing" do
|
234
234
|
P::Insert.(pipeline, R::Default, replace: R::Prepare)
|
235
|
-
pipeline.must_equal P[R::GetValue, R::StopOnSkipable, R::StopOnNil]
|
235
|
+
_(pipeline).must_equal P[R::GetValue, R::StopOnSkipable, R::StopOnNil]
|
236
236
|
end
|
237
237
|
|
238
238
|
it "applies on nested Collect" do
|
239
239
|
pipeline = P[R::GetValue, R::Collect[R::GetValue, R::StopOnSkipable], R::StopOnNil]
|
240
240
|
|
241
|
-
P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable).extend(P::Debug).inspect.must_equal "Pipeline[GetValue, Collect[GetValue, Default], StopOnNil]"
|
242
|
-
pipeline.must_equal P[R::GetValue, R::Collect[R::GetValue, R::StopOnSkipable], R::StopOnNil]
|
241
|
+
_(P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable).extend(P::Debug).inspect).must_equal "Pipeline[GetValue, Collect[GetValue, Default], StopOnNil]"
|
242
|
+
_(pipeline).must_equal P[R::GetValue, R::Collect[R::GetValue, R::StopOnSkipable], R::StopOnNil]
|
243
243
|
|
244
244
|
|
245
|
-
P::Insert.(pipeline, R::Default, replace: R::StopOnNil).extend(P::Debug).inspect.must_equal "Pipeline[GetValue, Collect[GetValue, StopOnSkipable], Default]"
|
245
|
+
_(P::Insert.(pipeline, R::Default, replace: R::StopOnNil).extend(P::Debug).inspect).must_equal "Pipeline[GetValue, Collect[GetValue, StopOnSkipable], Default]"
|
246
246
|
end
|
247
247
|
|
248
248
|
it "applies on nested Collect with Function::CreateObject" do
|
249
249
|
pipeline = P[R::GetValue, R::Collect[R::GetValue, R::CreateObject], R::StopOnNil]
|
250
250
|
|
251
|
-
P::Insert.(pipeline, R::Default, replace: R::CreateObject).extend(P::Debug).inspect.must_equal "Pipeline[GetValue, Collect[GetValue, Default], StopOnNil]"
|
252
|
-
pipeline.must_equal P[R::GetValue, R::Collect[R::GetValue, R::CreateObject], R::StopOnNil]
|
251
|
+
_(P::Insert.(pipeline, R::Default, replace: R::CreateObject).extend(P::Debug).inspect).must_equal "Pipeline[GetValue, Collect[GetValue, Default], StopOnNil]"
|
252
|
+
_(pipeline).must_equal P[R::GetValue, R::Collect[R::GetValue, R::CreateObject], R::StopOnNil]
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
@@ -257,8 +257,8 @@ let (:album_model) { Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van H
|
|
257
257
|
let(:pipeline) { P[R::GetValue, R::StopOnNil] }
|
258
258
|
|
259
259
|
it do
|
260
|
-
P::Insert.(pipeline, R::GetValue, delete: true).extend(P::Debug).inspect.must_equal "Pipeline[StopOnNil]"
|
261
|
-
pipeline.extend(P::Debug).inspect.must_equal "Pipeline[GetValue, StopOnNil]"
|
260
|
+
_(P::Insert.(pipeline, R::GetValue, delete: true).extend(P::Debug).inspect).must_equal "Pipeline[StopOnNil]"
|
261
|
+
_(pipeline.extend(P::Debug).inspect).must_equal "Pipeline[GetValue, StopOnNil]"
|
262
262
|
end
|
263
263
|
end
|
264
264
|
|
@@ -266,8 +266,8 @@ let (:album_model) { Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van H
|
|
266
266
|
let(:pipeline) { P[R::GetValue, R::Collect[R::GetValue, R::StopOnSkipable], R::StopOnNil] }
|
267
267
|
|
268
268
|
it do
|
269
|
-
P::Insert.(pipeline, R::GetValue, delete: true).extend(P::Debug).inspect.must_equal "Pipeline[Collect[StopOnSkipable], StopOnNil]"
|
270
|
-
pipeline.extend(P::Debug).inspect.must_equal "Pipeline[GetValue, Collect[GetValue, StopOnSkipable], StopOnNil]"
|
269
|
+
_(P::Insert.(pipeline, R::GetValue, delete: true).extend(P::Debug).inspect).must_equal "Pipeline[Collect[StopOnSkipable], StopOnNil]"
|
270
|
+
_(pipeline.extend(P::Debug).inspect).must_equal "Pipeline[GetValue, Collect[GetValue, StopOnSkipable], StopOnNil]"
|
271
271
|
end
|
272
272
|
end
|
273
273
|
end
|
data/test/populator_test.rb
CHANGED
@@ -16,11 +16,11 @@ class PopulatorTest < Minitest::Spec
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
let
|
19
|
+
let(:album) { Album.new([]) }
|
20
20
|
|
21
21
|
it do
|
22
22
|
album.extend(representer).from_hash("songs"=>[{"id"=>1}, {"id"=>2}], "artist"=>{"name"=>"Waste"})
|
23
|
-
album.inspect.must_equal "#<struct PopulatorTest::Album songs=[#<struct PopulatorTest::Song id=1>, #<struct PopulatorTest::Song id=2>], artist=#<struct PopulatorTest::Artist name=\"Waste\">>"
|
23
|
+
_(album.inspect).must_equal "#<struct PopulatorTest::Album songs=[#<struct PopulatorTest::Song id=1>, #<struct PopulatorTest::Song id=2>], artist=#<struct PopulatorTest::Artist name=\"Waste\">>"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -37,7 +37,7 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
Composer =
|
40
|
+
Composer = Class.new
|
41
41
|
Composer.class_eval do
|
42
42
|
def song=(v)
|
43
43
|
@song = v
|
@@ -55,22 +55,22 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
let
|
58
|
+
let(:album) { Composer.new.extend(representer).extend(Representable::Debug) }
|
59
59
|
|
60
60
|
it "finds by :id and creates new without :id" do
|
61
61
|
album.from_hash({"song"=>{"id" => 1, "title"=>"Resist Stance"}})
|
62
62
|
|
63
|
-
album.song.title.must_equal "Resist Stance" # note how title is updated from "Resist Stan"
|
64
|
-
album.song.id.must_equal 1
|
65
|
-
album.song.uid.must_equal "abcd" # not changed via populator, indicating this is a formerly "persisted" object.
|
63
|
+
_(album.song.title).must_equal "Resist Stance" # note how title is updated from "Resist Stan"
|
64
|
+
_(album.song.id).must_equal 1
|
65
|
+
_(album.song.uid).must_equal "abcd" # not changed via populator, indicating this is a formerly "persisted" object.
|
66
66
|
end
|
67
67
|
|
68
68
|
it "creates new without :id" do
|
69
69
|
album.from_hash({"song"=>{"title"=>"Lower"}})
|
70
70
|
|
71
|
-
album.song.title.must_equal "Lower"
|
72
|
-
album.song.id.
|
73
|
-
album.song.uid.
|
71
|
+
_(album.song.title).must_equal "Lower"
|
72
|
+
_(album.song.id).must_be_nil
|
73
|
+
_(album.song.uid).must_be_nil
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -82,7 +82,7 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
let
|
85
|
+
let(:album) { Struct.new(:songs).new([]).extend(representer) }
|
86
86
|
|
87
87
|
it "finds by :id and creates new without :id" do
|
88
88
|
album.from_hash({"songs"=>[
|
@@ -90,16 +90,16 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
|
|
90
90
|
{"title"=>"Suffer"}
|
91
91
|
]})
|
92
92
|
|
93
|
-
album.songs[0].title.must_equal "Resist Stance" # note how title is updated from "Resist Stan"
|
94
|
-
album.songs[0].id.must_equal 1
|
95
|
-
album.songs[0].uid.must_equal "abcd" # not changed via populator, indicating this is a formerly "persisted" object.
|
93
|
+
_(album.songs[0].title).must_equal "Resist Stance" # note how title is updated from "Resist Stan"
|
94
|
+
_(album.songs[0].id).must_equal 1
|
95
|
+
_(album.songs[0].uid).must_equal "abcd" # not changed via populator, indicating this is a formerly "persisted" object.
|
96
96
|
|
97
|
-
album.songs[1].title.must_equal "Suffer"
|
98
|
-
album.songs[1].id.
|
99
|
-
album.songs[1].uid.
|
97
|
+
_(album.songs[1].title).must_equal "Suffer"
|
98
|
+
_(album.songs[1].id).must_be_nil
|
99
|
+
_(album.songs[1].uid).must_be_nil
|
100
100
|
end
|
101
101
|
|
102
102
|
# TODO: test with existing collection
|
103
103
|
end
|
104
104
|
|
105
|
-
end
|
105
|
+
end
|