representable 3.0.0 → 3.2.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 +23 -0
- data/CHANGES.md +33 -0
- data/Gemfile +4 -12
- data/LICENSE +1 -1
- data/README.md +12 -13
- data/Rakefile +1 -6
- data/TODO +1 -3
- data/TODO-4.0.md +72 -0
- 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/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.rb +9 -2
- data/lib/representable/hash_methods.rb +3 -2
- data/lib/representable/insert.rb +1 -1
- data/lib/representable/json/collection.rb +3 -0
- data/lib/representable/json.rb +8 -7
- data/lib/representable/object/binding.rb +5 -1
- data/lib/representable/object.rb +1 -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/xml/binding.rb +19 -13
- data/lib/representable/xml/namespace.rb +122 -0
- data/lib/representable/xml.rb +12 -10
- data/lib/representable/yaml/binding.rb +1 -0
- data/lib/representable/yaml.rb +6 -2
- data/lib/representable.rb +19 -25
- 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/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 +42 -35
- 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/xml_test.rb
CHANGED
@@ -1,22 +1,41 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'representable/xml'
|
3
2
|
|
4
|
-
class Band
|
5
|
-
include Representable::XML
|
6
|
-
property :name
|
7
|
-
attr_accessor :name
|
8
3
|
|
9
|
-
|
10
|
-
|
4
|
+
class XmlPublicMethodsTest < Minitest::Spec
|
5
|
+
#---
|
6
|
+
# from_hash
|
7
|
+
class BandRepresenter < Representable::Decorator
|
8
|
+
include Representable::XML
|
9
|
+
property :id
|
10
|
+
property :name
|
11
11
|
end
|
12
|
-
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
let(:data) { %{<data><id>1</id><name>Rancid</name></data>} }
|
14
|
+
|
15
|
+
it { _(BandRepresenter.new(Band.new).from_xml(data)[:id, :name]).must_equal ["1", "Rancid"] }
|
16
|
+
it { _(BandRepresenter.new(Band.new).parse(data)[:id, :name]).must_equal ["1", "Rancid"] }
|
17
17
|
|
18
|
+
#---
|
19
|
+
# to_hash
|
20
|
+
let(:band) { Band.new("1", "Rancid") }
|
21
|
+
|
22
|
+
it { BandRepresenter.new(band).to_xml.must_equal_xml data }
|
23
|
+
it { BandRepresenter.new(band).render.must_equal_xml data }
|
24
|
+
end
|
18
25
|
|
19
26
|
class XmlTest < MiniTest::Spec
|
27
|
+
|
28
|
+
class Band
|
29
|
+
include Representable::XML
|
30
|
+
property :name
|
31
|
+
attr_accessor :name
|
32
|
+
|
33
|
+
def initialize(name=nil)
|
34
|
+
name and self.name = name
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
20
39
|
XML = Representable::XML
|
21
40
|
Def = Representable::Definition
|
22
41
|
|
@@ -126,14 +145,12 @@ class XmlTest < MiniTest::Spec
|
|
126
145
|
module SongRepresenter
|
127
146
|
include Representable::XML
|
128
147
|
property :name
|
129
|
-
representation_wrap = :song
|
130
148
|
end
|
131
149
|
|
132
150
|
module AlbumRepresenter
|
133
151
|
include Representable::XML
|
134
152
|
property :best_song, :class => Song, :extend => SongRepresenter
|
135
153
|
collection :songs, :class => Song, :as => :song, :extend => SongRepresenter
|
136
|
-
representation_wrap = :album
|
137
154
|
end
|
138
155
|
|
139
156
|
|
@@ -156,14 +173,15 @@ class XmlTest < MiniTest::Spec
|
|
156
173
|
end
|
157
174
|
|
158
175
|
it "extends contained models when serializing" do
|
159
|
-
@album = Album.new(
|
176
|
+
@album = Album.new(
|
177
|
+
[Song.new("I Hate My Brain"), mr=Song.new("Mr. Charisma")], mr)
|
160
178
|
@album.extend(AlbumRepresenter)
|
161
179
|
|
162
|
-
|
180
|
+
@album.to_xml.must_equal_xml "<album>
|
163
181
|
<song><name>Mr. Charisma</name></song>
|
164
182
|
<song><name>I Hate My Brain</name></song>
|
165
183
|
<song><name>Mr. Charisma</name></song>
|
166
|
-
</album>"
|
184
|
+
</album>"
|
167
185
|
end
|
168
186
|
|
169
187
|
it "extends contained models when deserializing" do
|
@@ -222,6 +240,16 @@ class CDataBand
|
|
222
240
|
end
|
223
241
|
|
224
242
|
class TypedPropertyTest < MiniTest::Spec
|
243
|
+
class Band
|
244
|
+
include Representable::XML
|
245
|
+
property :name
|
246
|
+
attr_accessor :name
|
247
|
+
|
248
|
+
def initialize(name=nil)
|
249
|
+
name and self.name = name
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
225
253
|
module AlbumRepresenter
|
226
254
|
include Representable::XML
|
227
255
|
property :band, :class => Band
|
@@ -286,21 +314,54 @@ class TypedPropertyTest < MiniTest::Spec
|
|
286
314
|
end
|
287
315
|
end
|
288
316
|
|
317
|
+
# TODO: add parsing tests.
|
318
|
+
class XMLPropertyTest < Minitest::Spec
|
319
|
+
Band = Struct.new(:name, :genre)
|
320
|
+
Manager = Struct.new(:managed)
|
321
|
+
|
322
|
+
#---
|
323
|
+
#- :as with scalar
|
324
|
+
class BandRepresenter < Representable::Decorator
|
325
|
+
include Representable::XML
|
326
|
+
property :name, as: :theyCallUs
|
327
|
+
property :genre, attribute: true
|
328
|
+
end
|
329
|
+
|
330
|
+
it { BandRepresenter.new(Band.new("Mute")).to_xml.must_equal_xml %{<band><theyCallUs>Mute</theyCallUs></band>} }
|
331
|
+
|
332
|
+
class ManagerRepresenter < Representable::Decorator
|
333
|
+
include Representable::XML
|
334
|
+
property :managed, as: :band, decorator: BandRepresenter
|
335
|
+
end
|
289
336
|
|
290
|
-
|
337
|
+
#- :as with nested property
|
338
|
+
it { ManagerRepresenter.new(Manager.new(Band.new("Mute", "Punkrock"))).to_xml.must_equal_xml %{<manager><band genre="Punkrock"><theyCallUs>Mute</theyCallUs></band></manager>} }
|
339
|
+
end
|
340
|
+
|
341
|
+
|
342
|
+
class XMLCollectionTest < MiniTest::Spec
|
343
|
+
Band = Struct.new(:name)
|
344
|
+
Compilation = Struct.new(:bands)
|
345
|
+
|
346
|
+
class BandRepresenter < Representable::Decorator
|
347
|
+
include Representable::XML
|
348
|
+
property :name
|
349
|
+
end
|
350
|
+
|
351
|
+
#---
|
352
|
+
#- :as, :decorator, :class
|
291
353
|
describe ":class => Band, :as => :band, :collection => true" do
|
292
|
-
class
|
354
|
+
class CompilationRepresenter < Representable::Decorator
|
293
355
|
include Representable::XML
|
294
|
-
collection :bands, :
|
295
|
-
attr_accessor :bands
|
356
|
+
collection :bands, class: Band, as: :group, decorator: BandRepresenter
|
296
357
|
end
|
297
358
|
|
298
359
|
describe "#from_xml" do
|
299
360
|
it "pushes collection items to array" do
|
300
|
-
cd = Compilation.new.from_xml(%{
|
361
|
+
cd = CompilationRepresenter.new(Compilation.new).from_xml(%{
|
301
362
|
<compilation>
|
302
|
-
<
|
303
|
-
<
|
363
|
+
<group><name>Diesel Boy</name></group>
|
364
|
+
<group><name>Cobra Skulls</name></group>
|
304
365
|
</compilation>
|
305
366
|
})
|
306
367
|
assert_equal ["Cobra Skulls", "Diesel Boy"], cd.bands.map(&:name).sort
|
@@ -308,13 +369,12 @@ class CollectionTest < MiniTest::Spec
|
|
308
369
|
end
|
309
370
|
|
310
371
|
it "responds to #to_xml" do
|
311
|
-
cd = Compilation.new
|
312
|
-
cd.bands = [Band.new("Diesel Boy"), Band.new("Bad Religion")]
|
372
|
+
cd = Compilation.new([Band.new("Diesel Boy"), Band.new("Bad Religion")])
|
313
373
|
|
314
|
-
|
315
|
-
<
|
316
|
-
<
|
317
|
-
</compilation>}
|
374
|
+
CompilationRepresenter.new(cd).to_xml.must_equal_xml %{<compilation>
|
375
|
+
<group><name>Diesel Boy</name></group>
|
376
|
+
<group><name>Bad Religion</name></group>
|
377
|
+
</compilation>}
|
318
378
|
end
|
319
379
|
end
|
320
380
|
|
@@ -340,8 +400,8 @@ class CollectionTest < MiniTest::Spec
|
|
340
400
|
|
341
401
|
|
342
402
|
describe ":wrap" do
|
343
|
-
let
|
344
|
-
let
|
403
|
+
let(:album) { Album.new.extend(xml_doc) }
|
404
|
+
let(:xml_doc) {
|
345
405
|
Module.new do
|
346
406
|
include Representable::XML
|
347
407
|
collection :songs, :as => :song, :wrap => :songs
|
@@ -387,7 +447,7 @@ class CollectionTest < MiniTest::Spec
|
|
387
447
|
self.representation_wrap = :song
|
388
448
|
end
|
389
449
|
|
390
|
-
let
|
450
|
+
let(:decorator) { rpr = representer; Class.new(Representable::Decorator) { include Representable::XML; include rpr } }
|
391
451
|
|
392
452
|
describe "XML::Collection" do
|
393
453
|
describe "with contained objects" do
|
@@ -396,8 +456,8 @@ class CollectionTest < MiniTest::Spec
|
|
396
456
|
self.representation_wrap= :songs
|
397
457
|
end
|
398
458
|
|
399
|
-
let
|
400
|
-
let
|
459
|
+
let(:songs) { [Song.new("Days Go By"), Song.new("Can't Take Them All")] }
|
460
|
+
let(:xml_doc) { "<songs><song><name>Days Go By</name></song><song><name>Can't Take Them All</name></song></songs>" }
|
401
461
|
|
402
462
|
it "renders array" do
|
403
463
|
songs.extend(representer).to_xml.must_equal_xml xml_doc
|
@@ -408,11 +468,11 @@ class CollectionTest < MiniTest::Spec
|
|
408
468
|
end
|
409
469
|
|
410
470
|
it "parses array" do
|
411
|
-
[].extend(representer).from_xml(xml_doc).must_equal songs
|
471
|
+
_([].extend(representer).from_xml(xml_doc)).must_equal songs
|
412
472
|
end
|
413
473
|
|
414
474
|
it "parses array with decorator" do
|
415
|
-
decorator.new([]).from_xml(xml_doc).must_equal songs
|
475
|
+
_(decorator.new([]).from_xml(xml_doc)).must_equal songs
|
416
476
|
end
|
417
477
|
end
|
418
478
|
end
|
@@ -422,8 +482,8 @@ class CollectionTest < MiniTest::Spec
|
|
422
482
|
self.representation_wrap= :songs
|
423
483
|
end
|
424
484
|
|
425
|
-
let
|
426
|
-
let
|
485
|
+
let(:songs) { {"one" => "Graveyards", "two" => "Can't Take Them All"} }
|
486
|
+
let(:xml_doc) { "<favs one=\"Graveyards\" two=\"Can't Take Them All\" />" }
|
427
487
|
|
428
488
|
describe "#to_xml" do
|
429
489
|
it "renders hash" do
|
@@ -445,7 +505,7 @@ class CollectionTest < MiniTest::Spec
|
|
445
505
|
|
446
506
|
describe "#from_json" do
|
447
507
|
it "returns hash" do
|
448
|
-
{}.extend(representer).from_xml(xml_doc).must_equal songs
|
508
|
+
_({}.extend(representer).from_xml(xml_doc)).must_equal songs
|
449
509
|
end
|
450
510
|
|
451
511
|
it "respects :exclude" do
|
@@ -457,7 +517,7 @@ class CollectionTest < MiniTest::Spec
|
|
457
517
|
end
|
458
518
|
|
459
519
|
it "parses hash with decorator" do
|
460
|
-
decorator.new({}).from_xml(xml_doc).must_equal songs
|
520
|
+
_(decorator.new({}).from_xml(xml_doc)).must_equal songs
|
461
521
|
end
|
462
522
|
end
|
463
523
|
end
|
@@ -471,7 +531,7 @@ class XmlHashTest < MiniTest::Spec
|
|
471
531
|
hash :songs
|
472
532
|
end
|
473
533
|
|
474
|
-
let
|
534
|
+
let(:doc) { "<open_struct><first>The Gargoyle</first><second>Bronx</second></open_struct>" }
|
475
535
|
|
476
536
|
# to_xml
|
477
537
|
it { OpenStruct.new(songs: {"first" => "The Gargoyle", "second" => "Bronx"}).extend(representer).to_xml.must_equal_xml(doc) }
|
@@ -486,7 +546,7 @@ class XmlHashTest < MiniTest::Spec
|
|
486
546
|
end
|
487
547
|
end
|
488
548
|
|
489
|
-
let
|
549
|
+
let(:doc) { "<open_struct>
|
490
550
|
<open_struct>
|
491
551
|
<title>The Gargoyle</title>
|
492
552
|
</open_struct>
|
@@ -500,4 +560,4 @@ class XmlHashTest < MiniTest::Spec
|
|
500
560
|
# FIXME: this NEVER worked!
|
501
561
|
# it { OpenStruct.new.extend(representer).from_xml(doc).songs.must_equal({"first" => "The Gargoyle", "second" => "Bronx"}) }
|
502
562
|
end
|
503
|
-
end
|
563
|
+
end
|
data/test/yaml_test.rb
CHANGED
@@ -1,10 +1,35 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
+
class YamlPublicMethodsTest < Minitest::Spec
|
4
|
+
#---
|
5
|
+
# from_yaml
|
6
|
+
class BandRepresenter < Representable::Decorator
|
7
|
+
include Representable::YAML
|
8
|
+
property :id
|
9
|
+
property :name
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:data) { %{---
|
13
|
+
id: 1
|
14
|
+
name: Rancid
|
15
|
+
} }
|
16
|
+
|
17
|
+
it { _(BandRepresenter.new(Band.new).from_yaml(data)[:id, :name]).must_equal [1, "Rancid"] }
|
18
|
+
it { _(BandRepresenter.new(Band.new).parse(data)[:id, :name]).must_equal [1, "Rancid"] }
|
19
|
+
|
20
|
+
#---
|
21
|
+
# to_yaml
|
22
|
+
let(:band) { Band.new("1", "Rancid") }
|
23
|
+
|
24
|
+
it { _(BandRepresenter.new(band).to_yaml).must_equal data }
|
25
|
+
it { _(BandRepresenter.new(band).render).must_equal data }
|
26
|
+
end
|
27
|
+
|
3
28
|
class YamlTest < MiniTest::Spec
|
4
29
|
def self.yaml_representer(&block)
|
5
30
|
Module.new do
|
6
31
|
include Representable::YAML
|
7
|
-
instance_exec
|
32
|
+
instance_exec(&block)
|
8
33
|
end
|
9
34
|
end
|
10
35
|
|
@@ -14,22 +39,22 @@ class YamlTest < MiniTest::Spec
|
|
14
39
|
|
15
40
|
|
16
41
|
describe "property" do
|
17
|
-
let
|
42
|
+
let(:yaml) { yaml_representer do property :best_song end }
|
18
43
|
|
19
|
-
let
|
44
|
+
let(:album) { Album.new.tap do |album|
|
20
45
|
album.best_song = "Liar"
|
21
46
|
end }
|
22
47
|
|
23
48
|
describe "#to_yaml" do
|
24
49
|
it "renders plain property" do
|
25
|
-
album.extend(yaml).to_yaml.must_equal(
|
50
|
+
_(album.extend(yaml).to_yaml).must_equal(
|
26
51
|
"---
|
27
52
|
best_song: Liar
|
28
53
|
")
|
29
54
|
end
|
30
55
|
|
31
56
|
it "always renders values into strings" do
|
32
|
-
Album.new.tap { |a| a.best_song = 8675309 }.extend(yaml).to_yaml.must_equal(
|
57
|
+
_(Album.new.tap { |a| a.best_song = 8675309 }.extend(yaml).to_yaml).must_equal(
|
33
58
|
"---
|
34
59
|
best_song: 8675309
|
35
60
|
"
|
@@ -40,29 +65,29 @@ best_song: 8675309
|
|
40
65
|
|
41
66
|
describe "#from_yaml" do
|
42
67
|
it "parses plain property" do
|
43
|
-
album.extend(yaml).from_yaml(
|
68
|
+
_(album.extend(yaml).from_yaml(
|
44
69
|
"---
|
45
70
|
best_song: This Song Is Recycled
|
46
|
-
").best_song.must_equal "This Song Is Recycled"
|
71
|
+
").best_song).must_equal "This Song Is Recycled"
|
47
72
|
end
|
48
73
|
end
|
49
74
|
|
50
75
|
|
51
76
|
describe "with :class and :extend" do
|
52
77
|
yaml_song = yaml_representer do property :name end
|
53
|
-
let
|
78
|
+
let(:yaml_album) { Module.new do
|
54
79
|
include Representable::YAML
|
55
80
|
property :best_song, :extend => yaml_song, :class => Song
|
56
81
|
end }
|
57
82
|
|
58
|
-
let
|
83
|
+
let(:album) { Album.new.tap do |album|
|
59
84
|
album.best_song = Song.new("Liar")
|
60
85
|
end }
|
61
86
|
|
62
87
|
|
63
88
|
describe "#to_yaml" do
|
64
89
|
it "renders embedded typed property" do
|
65
|
-
album.extend(yaml_album).to_yaml.must_equal "---
|
90
|
+
_(album.extend(yaml_album).to_yaml).must_equal "---
|
66
91
|
best_song:
|
67
92
|
name: Liar
|
68
93
|
"
|
@@ -71,10 +96,10 @@ best_song:
|
|
71
96
|
|
72
97
|
describe "#from_yaml" do
|
73
98
|
it "parses embedded typed property" do
|
74
|
-
album.extend(yaml_album).from_yaml("---
|
99
|
+
_(album.extend(yaml_album).from_yaml("---
|
75
100
|
best_song:
|
76
101
|
name: Go With Me
|
77
|
-
").must_equal Album.new(nil,Song.new("Go With Me"))
|
102
|
+
")).must_equal Album.new(nil,Song.new("Go With Me"))
|
78
103
|
end
|
79
104
|
end
|
80
105
|
end
|
@@ -82,16 +107,16 @@ best_song:
|
|
82
107
|
|
83
108
|
|
84
109
|
describe "collection" do
|
85
|
-
let
|
110
|
+
let(:yaml) { yaml_representer do collection :songs end }
|
86
111
|
|
87
|
-
let
|
112
|
+
let(:album) { Album.new.tap do |album|
|
88
113
|
album.songs = ["Jackhammer", "Terrible Man"]
|
89
114
|
end }
|
90
115
|
|
91
116
|
|
92
117
|
describe "#to_yaml" do
|
93
118
|
it "renders a block style list per default" do
|
94
|
-
album.extend(yaml).to_yaml.must_equal "---
|
119
|
+
_(album.extend(yaml).to_yaml).must_equal "---
|
95
120
|
songs:
|
96
121
|
- Jackhammer
|
97
122
|
- Terrible Man
|
@@ -100,7 +125,7 @@ songs:
|
|
100
125
|
|
101
126
|
it "renders a flow style list when :style => :flow set" do
|
102
127
|
yaml = yaml_representer { collection :songs, :style => :flow }
|
103
|
-
album.extend(yaml).to_yaml.must_equal "---
|
128
|
+
_(album.extend(yaml).to_yaml).must_equal "---
|
104
129
|
songs: [Jackhammer, Terrible Man]
|
105
130
|
"
|
106
131
|
end
|
@@ -109,22 +134,22 @@ songs: [Jackhammer, Terrible Man]
|
|
109
134
|
|
110
135
|
describe "#from_yaml" do
|
111
136
|
it "parses a block style list" do
|
112
|
-
album.extend(yaml).from_yaml("---
|
137
|
+
_(album.extend(yaml).from_yaml("---
|
113
138
|
songs:
|
114
139
|
- Off Key Melody
|
115
|
-
- Sinking").must_equal Album.new(["Off Key Melody", "Sinking"])
|
140
|
+
- Sinking")).must_equal Album.new(["Off Key Melody", "Sinking"])
|
116
141
|
|
117
142
|
end
|
118
143
|
|
119
144
|
it "parses a flow style list" do
|
120
|
-
album.extend(yaml).from_yaml("---
|
121
|
-
songs: [Off Key Melody, Sinking]").must_equal Album.new(["Off Key Melody", "Sinking"])
|
145
|
+
_(album.extend(yaml).from_yaml("---
|
146
|
+
songs: [Off Key Melody, Sinking]")).must_equal Album.new(["Off Key Melody", "Sinking"])
|
122
147
|
end
|
123
148
|
end
|
124
149
|
|
125
150
|
|
126
151
|
describe "with :class and :extend" do
|
127
|
-
let
|
152
|
+
let(:yaml_album) { Module.new do
|
128
153
|
include Representable::YAML
|
129
154
|
collection :songs, :class => Song do
|
130
155
|
property :name
|
@@ -132,12 +157,12 @@ songs: [Off Key Melody, Sinking]").must_equal Album.new(["Off Key Melody", "Sink
|
|
132
157
|
end
|
133
158
|
end }
|
134
159
|
|
135
|
-
let
|
160
|
+
let(:album) { Album.new([Song.new("Liar", 1), Song.new("What I Know", 2)]) }
|
136
161
|
|
137
162
|
|
138
163
|
describe "#to_yaml" do
|
139
164
|
it "renders collection of typed property" do
|
140
|
-
album.extend(yaml_album).to_yaml.must_equal "---
|
165
|
+
_(album.extend(yaml_album).to_yaml).must_equal "---
|
141
166
|
songs:
|
142
167
|
- name: Liar
|
143
168
|
track: 1
|
@@ -149,14 +174,14 @@ songs:
|
|
149
174
|
|
150
175
|
describe "#from_yaml" do
|
151
176
|
it "parses collection of typed property" do
|
152
|
-
album.extend(yaml_album).from_yaml("---
|
177
|
+
_(album.extend(yaml_album).from_yaml("---
|
153
178
|
songs:
|
154
179
|
- name: One Shot Deal
|
155
180
|
track: 4
|
156
181
|
- name: Three Way Dance
|
157
|
-
track: 5").must_equal Album.new([Song.new("One Shot Deal", 4), Song.new("Three Way Dance", 5)])
|
182
|
+
track: 5")).must_equal Album.new([Song.new("One Shot Deal", 4), Song.new("Three Way Dance", 5)])
|
158
183
|
end
|
159
184
|
end
|
160
185
|
end
|
161
186
|
end
|
162
|
-
end
|
187
|
+
end
|