representable 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +17 -0
  3. data/CHANGES.md +25 -0
  4. data/Gemfile +4 -12
  5. data/LICENSE +1 -1
  6. data/README.md +6 -6
  7. data/Rakefile +1 -6
  8. data/TODO +1 -3
  9. data/TODO-4.0.md +72 -0
  10. data/lib/representable.rb +19 -25
  11. data/lib/representable/binding.rb +32 -12
  12. data/lib/representable/cached.rb +1 -1
  13. data/lib/representable/coercion.rb +8 -6
  14. data/lib/representable/config.rb +13 -3
  15. data/lib/representable/debug.rb +23 -15
  16. data/lib/representable/declarative.rb +12 -7
  17. data/lib/representable/decorator.rb +1 -1
  18. data/lib/representable/definition.rb +7 -3
  19. data/lib/representable/deserializer.rb +5 -4
  20. data/lib/representable/for_collection.rb +1 -1
  21. data/lib/representable/hash.rb +9 -2
  22. data/lib/representable/hash/allow_symbols.rb +9 -11
  23. data/lib/representable/hash/binding.rb +1 -0
  24. data/lib/representable/hash/collection.rb +4 -2
  25. data/lib/representable/hash_methods.rb +3 -2
  26. data/lib/representable/insert.rb +1 -1
  27. data/lib/representable/json.rb +8 -7
  28. data/lib/representable/json/collection.rb +3 -0
  29. data/lib/representable/object.rb +1 -1
  30. data/lib/representable/object/binding.rb +5 -1
  31. data/lib/representable/option.rb +19 -0
  32. data/lib/representable/pipeline.rb +3 -2
  33. data/lib/representable/pipeline_factories.rb +4 -2
  34. data/lib/representable/populator.rb +1 -1
  35. data/lib/representable/represent.rb +1 -0
  36. data/lib/representable/serializer.rb +3 -2
  37. data/lib/representable/version.rb +1 -1
  38. data/lib/representable/virtus_coercion.rb +38 -0
  39. data/lib/representable/xml.rb +12 -10
  40. data/lib/representable/xml/binding.rb +19 -13
  41. data/lib/representable/xml/namespace.rb +122 -0
  42. data/lib/representable/yaml.rb +6 -2
  43. data/lib/representable/yaml/binding.rb +1 -0
  44. data/representable.gemspec +8 -9
  45. data/test/as_test.rb +7 -7
  46. data/test/binding_test.rb +14 -14
  47. data/test/cached_test.rb +59 -49
  48. data/test/class_test.rb +9 -9
  49. data/test/coercion_test.rb +33 -22
  50. data/test/config/inherit_test.rb +14 -14
  51. data/test/config_test.rb +20 -20
  52. data/test/decorator_scope_test.rb +4 -4
  53. data/test/decorator_test.rb +33 -20
  54. data/test/default_test.rb +8 -8
  55. data/test/defaults_options_test.rb +3 -3
  56. data/test/definition_test.rb +38 -40
  57. data/test/{example.rb → examples/example.rb} +0 -1
  58. data/test/examples/object.rb +1 -5
  59. data/test/exec_context_test.rb +8 -8
  60. data/test/features_test.rb +6 -6
  61. data/test/filter_test.rb +8 -8
  62. data/test/for_collection_test.rb +10 -10
  63. data/test/generic_test.rb +13 -13
  64. data/test/getter_setter_test.rb +5 -5
  65. data/test/hash_bindings_test.rb +1 -1
  66. data/test/hash_test.rb +45 -23
  67. data/test/heritage_test.rb +16 -13
  68. data/test/if_test.rb +9 -9
  69. data/test/include_exclude_test.rb +14 -14
  70. data/test/inherit_test.rb +18 -18
  71. data/test/inline_test.rb +24 -24
  72. data/test/instance_test.rb +31 -31
  73. data/test/is_representable_test.rb +10 -10
  74. data/test/json_test.rb +29 -7
  75. data/test/lonely_test.rb +31 -31
  76. data/test/nested_test.rb +13 -13
  77. data/test/object_test.rb +9 -9
  78. data/test/option_test.rb +36 -0
  79. data/test/parse_pipeline_test.rb +3 -5
  80. data/test/pipeline_test.rb +50 -50
  81. data/test/populator_test.rb +18 -18
  82. data/test/prepare_test.rb +4 -4
  83. data/test/private_options_test.rb +2 -2
  84. data/test/reader_writer_test.rb +2 -2
  85. data/test/render_nil_test.rb +2 -2
  86. data/test/represent_test.rb +14 -14
  87. data/test/representable_test.rb +34 -36
  88. data/test/schema_test.rb +8 -11
  89. data/test/serialize_deserialize_test.rb +2 -2
  90. data/test/skip_test.rb +14 -14
  91. data/test/stringify_hash_test.rb +3 -3
  92. data/test/test_helper.rb +26 -14
  93. data/test/uncategorized_test.rb +10 -10
  94. data/test/user_options_test.rb +4 -4
  95. data/test/virtus_coercion_test.rb +52 -0
  96. data/test/wrap_test.rb +19 -19
  97. data/test/xml_bindings_test.rb +0 -4
  98. data/test/xml_namespace_test.rb +186 -0
  99. data/test/xml_test.rb +103 -43
  100. data/test/yaml_test.rb +51 -26
  101. metadata +101 -39
  102. data/.travis.yml +0 -7
  103. data/lib/representable/TODO.getting_serious +0 -11
  104. data/lib/representable/autoload.rb +0 -10
  105. data/test/mongoid_test.rb +0 -31
data/test/prepare_test.rb CHANGED
@@ -24,11 +24,11 @@ class PrepareTest < BaseTest
24
24
  :representable => false # don't call #to_hash.
25
25
  end
26
26
 
27
- let (:hit) { Struct.new(:song).new(song).extend(representer) }
27
+ let(:hit) { Struct.new(:song).new(song).extend(representer) }
28
28
 
29
29
  it "calls prepare:, nothing else" do
30
30
  # render(hit).must_equal_document(output)
31
- hit.to_hash.must_equal({"song" => PreparerClass.new(song)})
31
+ _(hit.to_hash).must_equal({"song" => PreparerClass.new(song)})
32
32
  end
33
33
 
34
34
 
@@ -54,13 +54,13 @@ class PrepareTest < BaseTest
54
54
  :representable => false # don't call #to_hash.
55
55
  end
56
56
 
57
- let (:hit) { Struct.new(:song).new.extend(representer) }
57
+ let(:hit) { Struct.new(:song).new.extend(representer) }
58
58
 
59
59
  it "calls prepare:, nothing else" do
60
60
  # render(hit).must_equal_document(output)
61
61
  hit.from_hash("song" => {})
62
62
 
63
- hit.song.must_equal(PreparerClass.new(String.new))
63
+ _(hit.song).must_equal(PreparerClass.new(String.new))
64
64
  end
65
65
  end
66
66
  end
@@ -8,11 +8,11 @@ class PrivateOptionsTest < MiniTest::Spec # TODO: move me to separate file.
8
8
 
9
9
  it "render: doesn't modify options" do
10
10
  representer.new(nil).to_hash(options)
11
- options.must_equal({exclude: "name"})
11
+ _(options).must_equal({exclude: "name"})
12
12
  end
13
13
 
14
14
  it "parse: doesn't modify options" do
15
15
  representer.new(nil).from_hash(options)
16
- options.must_equal({exclude: "name"})
16
+ _(options).must_equal({exclude: "name"})
17
17
  end
18
18
  end
@@ -10,10 +10,10 @@ class ReaderWriterTest < BaseTest
10
10
  subject { OpenStruct.new(:name => "Disorder And Disarray").extend(representer) }
11
11
 
12
12
  it "uses :writer when rendering" do
13
- subject.to_hash(user_options: {nr: 14}).must_equal({"title" => "14) Disorder And Disarray"})
13
+ _(subject.to_hash(user_options: {nr: 14})).must_equal({"title" => "14) Disorder And Disarray"})
14
14
  end
15
15
 
16
16
  it "uses :reader when parsing" do
17
- subject.from_hash({"title" => "15) The Wars End"}).name.must_equal "The Wars End"
17
+ _(subject.from_hash({"title" => "15) The Wars End"}).name).must_equal "The Wars End"
18
18
  end
19
19
  end
@@ -8,7 +8,7 @@ class RenderNilTest < MiniTest::Spec
8
8
  property :title, render_nil: true
9
9
  end
10
10
 
11
- it { Song.new.extend(representer).to_hash.must_equal({"title"=>nil}) }
11
+ it { _(Song.new.extend(representer).to_hash).must_equal({"title"=>nil}) }
12
12
  end
13
13
 
14
14
  describe "with :extend it shouldn't extend nil" do
@@ -16,6 +16,6 @@ class RenderNilTest < MiniTest::Spec
16
16
  property :title, render_nil: true, extend: Class
17
17
  end
18
18
 
19
- it { Song.new.extend(representer).to_hash.must_equal({"title"=>nil}) }
19
+ it { _(Song.new.extend(representer).to_hash).must_equal({"title"=>nil}) }
20
20
  end
21
21
  end
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class RepresentTest < MiniTest::Spec
4
- let (:songs) { [song, Song.new("Can't Take Them All")] }
5
- let (:song) { Song.new("Days Go By") }
4
+ let(:songs) { [song, Song.new("Can't Take Them All")] }
5
+ let(:song) { Song.new("Days Go By") }
6
6
 
7
7
  for_formats(
8
8
  :hash => [Representable::Hash, out=[{"name" => "Days Go By"}, {"name"=>"Can't Take Them All"}], out],
@@ -12,9 +12,9 @@ class RepresentTest < MiniTest::Spec
12
12
 
13
13
  # Representer.represents detects collection.
14
14
  describe "Module#to_/from_#{format}" do
15
- let (:format) { format }
15
+ let(:format) { format }
16
16
 
17
- let (:representer) {
17
+ let(:representer) {
18
18
  Module.new do
19
19
  include mod
20
20
  property :name
@@ -24,13 +24,13 @@ class RepresentTest < MiniTest::Spec
24
24
  }
25
25
 
26
26
  it { render(representer.represent(songs)).must_equal_document output }
27
- it { parse(representer.represent([]), input).must_equal songs }
27
+ it { _(parse(representer.represent([]), input)).must_equal songs }
28
28
  end
29
29
 
30
30
  # Decorator.represents detects collection.
31
31
  describe "Decorator#to_/from_#{format}" do
32
- let (:format) { format }
33
- let (:representer) {
32
+ let(:format) { format }
33
+ let(:representer) {
34
34
  Class.new(Representable::Decorator) do
35
35
  include mod
36
36
  property :name
@@ -40,7 +40,7 @@ class RepresentTest < MiniTest::Spec
40
40
  }
41
41
 
42
42
  it { render(representer.represent(songs)).must_equal_document output }
43
- it("ficken") { parse(representer.represent([]), input).must_equal songs }
43
+ it("ficken") { _(parse(representer.represent([]), input)).must_equal songs }
44
44
  end
45
45
  end
46
46
 
@@ -53,9 +53,9 @@ class RepresentTest < MiniTest::Spec
53
53
 
54
54
  # Representer.represents detects singular.
55
55
  describe "Module#to_/from_#{format}" do
56
- let (:format) { format }
56
+ let(:format) { format }
57
57
 
58
- let (:representer) {
58
+ let(:representer) {
59
59
  Module.new do
60
60
  include mod
61
61
  property :name
@@ -65,14 +65,14 @@ class RepresentTest < MiniTest::Spec
65
65
  }
66
66
 
67
67
  it { render(representer.represent(song)).must_equal_document output }
68
- it { parse(representer.represent(Song.new), input).must_equal song }
68
+ it { _(parse(representer.represent(Song.new), input)).must_equal song }
69
69
  end
70
70
 
71
71
 
72
72
  # Decorator.represents detects singular.
73
73
  describe "Decorator#to_/from_#{format}" do
74
- let (:format) { format }
75
- let (:representer) {
74
+ let(:format) { format }
75
+ let(:representer) {
76
76
  Class.new(Representable::Decorator) do
77
77
  include mod
78
78
  property :name
@@ -82,7 +82,7 @@ class RepresentTest < MiniTest::Spec
82
82
  }
83
83
 
84
84
  it { render(representer.represent(song)).must_equal_document output }
85
- it { parse(representer.represent(Song.new), input).must_equal song }
85
+ it { _(parse(representer.represent(Song.new), input)).must_equal song }
86
86
  end
87
87
  end
88
88
  end
@@ -76,8 +76,6 @@ class RepresentableTest < MiniTest::Spec
76
76
  end
77
77
 
78
78
  it "allows mixing in multiple representers" do
79
- require 'representable/json'
80
- require 'representable/xml'
81
79
  class Bodyjar
82
80
  include Representable::XML
83
81
  include Representable::JSON
@@ -134,8 +132,8 @@ class RepresentableTest < MiniTest::Spec
134
132
 
135
133
  # test ::inherited.
136
134
  it do
137
- BaseClass.respond_to?(:other).must_equal false
138
- SubClass.respond_to?(:other).must_equal true
135
+ _(BaseClass.respond_to?(:other)).must_equal false
136
+ _(SubClass.respond_to?(:other)).must_equal true
139
137
  end
140
138
 
141
139
  module DifferentIncluded
@@ -166,13 +164,13 @@ class RepresentableTest < MiniTest::Spec
166
164
  it "doesn't modify options hash" do
167
165
  options = {}
168
166
  representer.property(:title, options)
169
- options.must_equal({})
167
+ _(options).must_equal({})
170
168
  end
171
169
 
172
170
  representer! {}
173
171
 
174
172
  it "returns the Definition instance" do
175
- representer.property(:name).must_be_kind_of Representable::Definition
173
+ _(representer.property(:name)).must_be_kind_of Representable::Definition
176
174
  end
177
175
  end
178
176
 
@@ -226,7 +224,7 @@ class RepresentableTest < MiniTest::Spec
226
224
  @band = Class.new(Band) { property :name; collection :founders, :writeable => false; attr_accessor :founders }.new
227
225
  @band.from_hash("name" => "Iron Maiden", "groupies" => 2, "founders" => ["Steve Harris"])
228
226
  assert_equal "Iron Maiden", @band.name
229
- assert_equal nil, @band.founders
227
+ assert_nil @band.founders
230
228
  end
231
229
 
232
230
  it "always returns the represented" do
@@ -235,7 +233,7 @@ class RepresentableTest < MiniTest::Spec
235
233
 
236
234
  it "includes false attributes" do
237
235
  @band.from_hash({"groupies"=>false})
238
- assert_equal false, @band.groupies
236
+ refute @band.groupies
239
237
  end
240
238
 
241
239
  it "ignores properties not present in the incoming document" do
@@ -263,7 +261,7 @@ class RepresentableTest < MiniTest::Spec
263
261
 
264
262
  @band = Band.new.extend(repr)
265
263
  @band.send(config.first, config.last)
266
- assert_equal nil, @band.name, "Failed in #{format}"
264
+ assert_nil @band.name, "Failed in #{format}"
267
265
  end
268
266
  end
269
267
 
@@ -302,14 +300,14 @@ class RepresentableTest < MiniTest::Spec
302
300
  end
303
301
 
304
302
  it "#to_hash propagates to nested objects" do
305
- OpenStruct.new(track: OpenStruct.new(nr: 1, length: OpenStruct.new(seconds: nil))).extend(representer).extend(Representable::Debug).
306
- to_hash(user_options: {nr: 9}).must_equal({"track"=>{"nr"=>9, "length"=>{seconds: 9}}})
303
+ _(OpenStruct.new(track: OpenStruct.new(nr: 1, length: OpenStruct.new(seconds: nil))).extend(representer).extend(Representable::Debug).
304
+ to_hash(user_options: {nr: 9})).must_equal({"track"=>{"nr"=>9, "length"=>{seconds: 9}}})
307
305
  end
308
306
 
309
307
  it "#from_hash propagates to nested objects" do
310
308
  song = OpenStruct.new.extend(representer).from_hash({"track"=>{"nr" => "replace me", "length"=>{"seconds"=>"replacing"}}}, user_options: {nr: 9})
311
- song.track.nr.must_equal 9
312
- song.track.length.seconds.must_equal 9
309
+ _(song.track.nr).must_equal 9
310
+ _(song.track.length.seconds).must_equal 9
313
311
  end
314
312
  end
315
313
  end
@@ -366,12 +364,12 @@ class RepresentableTest < MiniTest::Spec
366
364
  end
367
365
 
368
366
  it "executes lambda in represented instance context" do
369
- Song.new("Carnage").instance_eval do
367
+ _(Song.new("Carnage").instance_eval do
370
368
  def compute_representer(name)
371
369
  UpcaseRepresenter
372
370
  end
373
371
  self
374
- end.extend(representer).to_hash.must_equal({"name" => "CARNAGE"})
372
+ end.extend(representer).to_hash).must_equal({"name" => "CARNAGE"})
375
373
  end
376
374
  end
377
375
 
@@ -384,8 +382,8 @@ class RepresentableTest < MiniTest::Spec
384
382
 
385
383
  it "uses object from :instance but still extends it" do
386
384
  song = Song.new.extend(representer).from_hash("name" => "Eric's Had A Bad Day")
387
- song.name.must_equal obj
388
- song.name.must_be_kind_of mod
385
+ _(song.name).must_equal obj
386
+ _(song.name).must_be_kind_of mod
389
387
  end
390
388
  end
391
389
 
@@ -400,8 +398,8 @@ class RepresentableTest < MiniTest::Spec
400
398
  end
401
399
 
402
400
  it "uses lambda when parsing" do
403
- Song.new.extend(representer).from_hash({"name" => "You Make Me Thick"}).name.must_equal "you make me thick"
404
- Song.new.extend(representer).from_hash({"name" => "Stepstranger"}).name.must_equal "stepstranger" # DISCUSS: we compare "".is_a?(UpcaseString)
401
+ _(Song.new.extend(representer).from_hash({"name" => "You Make Me Thick"}).name).must_equal "you make me thick"
402
+ _(Song.new.extend(representer).from_hash({"name" => "Stepstranger"}).name).must_equal "stepstranger" # DISCUSS: we compare "".is_a?(UpcaseString)
405
403
  end
406
404
 
407
405
  describe "with :class lambda" do
@@ -412,12 +410,12 @@ class RepresentableTest < MiniTest::Spec
412
410
 
413
411
  it "creates instance from :class lambda when parsing" do
414
412
  song = OpenStruct.new.extend(representer).from_hash({"name" => "Quitters Never Win"})
415
- song.name.must_be_kind_of UpcaseString
416
- song.name.must_equal "QUITTERS NEVER WIN"
413
+ _(song.name).must_be_kind_of UpcaseString
414
+ _(song.name).must_equal "QUITTERS NEVER WIN"
417
415
 
418
416
  song = OpenStruct.new.extend(representer).from_hash({"name" => "Still Failing?"})
419
- song.name.must_be_kind_of String
420
- song.name.must_equal "still failing?"
417
+ _(song.name).must_be_kind_of String
418
+ _(song.name).must_equal "still failing?"
421
419
  end
422
420
  end
423
421
  end
@@ -429,12 +427,12 @@ class RepresentableTest < MiniTest::Spec
429
427
  end
430
428
 
431
429
  it "uses lambda for each item when rendering" do
432
- Album.new([UpcaseString.new("Dean Martin"), "Charlie Still Smirks"]).extend(representer).to_hash.must_equal("songs"=>["DEAN MARTIN", "charlie still smirks"])
430
+ _(Album.new([UpcaseString.new("Dean Martin"), "Charlie Still Smirks"]).extend(representer).to_hash).must_equal("songs"=>["DEAN MARTIN", "charlie still smirks"])
433
431
  end
434
432
 
435
433
  it "uses lambda for each item when parsing" do
436
434
  album = Album.new.extend(representer).from_hash("songs"=>["DEAN MARTIN", "charlie still smirks"])
437
- album.songs.must_equal ["dean martin", "charlie still smirks"] # DISCUSS: we compare "".is_a?(UpcaseString)
435
+ _(album.songs).must_equal ["dean martin", "charlie still smirks"] # DISCUSS: we compare "".is_a?(UpcaseString)
438
436
  end
439
437
 
440
438
  describe "with :class lambda" do
@@ -445,18 +443,18 @@ class RepresentableTest < MiniTest::Spec
445
443
 
446
444
  it "creates instance from :class lambda for each item when parsing" do
447
445
  album = Album.new.extend(representer).from_hash("songs"=>["Still Failing?", "charlie still smirks"])
448
- album.songs.must_equal ["still failing?", "CHARLIE STILL SMIRKS"]
446
+ _(album.songs).must_equal ["still failing?", "CHARLIE STILL SMIRKS"]
449
447
  end
450
448
  end
451
449
  end
452
450
 
453
451
  describe ":decorator" do
454
- let (:extend_rpr) { Module.new { include Representable::Hash; collection :songs, :extend => SongRepresenter } }
455
- let (:decorator_rpr) { Module.new { include Representable::Hash; collection :songs, :decorator => SongRepresenter } }
456
- let (:songs) { [Song.new("Bloody Mary")] }
452
+ let(:extend_rpr) { Module.new { include Representable::Hash; collection :songs, :extend => SongRepresenter } }
453
+ let(:decorator_rpr) { Module.new { include Representable::Hash; collection :songs, :decorator => SongRepresenter } }
454
+ let(:songs) { [Song.new("Bloody Mary")] }
457
455
 
458
456
  it "is aliased to :extend" do
459
- Album.new(songs).extend(extend_rpr).to_hash.must_equal Album.new(songs).extend(decorator_rpr).to_hash
457
+ _(Album.new(songs).extend(extend_rpr).to_hash).must_equal Album.new(songs).extend(decorator_rpr).to_hash
460
458
  end
461
459
  end
462
460
 
@@ -472,22 +470,22 @@ class RepresentableTest < MiniTest::Spec
472
470
  end
473
471
 
474
472
  describe "::prepare" do
475
- let (:song) { Song.new("Still Friends In The End") }
476
- let (:album) { Album.new([song]) }
473
+ let(:song) { Song.new("Still Friends In The End") }
474
+ let(:album) { Album.new([song]) }
477
475
 
478
476
  describe "module including Representable" do
479
477
  it "uses :extend strategy" do
480
478
  album_rpr = Module.new { include Representable::Hash; collection :songs, :class => Song, :extend => SongRepresenter}
481
479
 
482
- album_rpr.prepare(album).to_hash.must_equal({"songs"=>[{"name"=>"Still Friends In The End"}]})
483
- album.must_respond_to :to_hash
480
+ _(album_rpr.prepare(album).to_hash).must_equal({"songs"=>[{"name"=>"Still Friends In The End"}]})
481
+ _(album).must_respond_to :to_hash
484
482
  end
485
483
  end
486
484
 
487
485
  describe "Decorator subclass" do
488
486
  it "uses :decorate strategy" do
489
- AlbumRepresentation.prepare(album).to_hash.must_equal({"songs"=>[{"name"=>"Still Friends In The End"}]})
490
- album.wont_respond_to :to_hash
487
+ _(AlbumRepresentation.prepare(album).to_hash).must_equal({"songs"=>[{"name"=>"Still Friends In The End"}]})
488
+ _(album).wont_respond_to :to_hash
491
489
  end
492
490
  end
493
491
  end
data/test/schema_test.rb CHANGED
@@ -58,13 +58,13 @@ class SchemaTest < MiniTest::Spec
58
58
  end
59
59
 
60
60
  describe "3-level deep with features" do
61
- let (:label) { OpenStruct.new(:name => "Epitaph", :location => OpenStruct.new(:city => "Sanfran", :name => "DON'T SHOW ME!")) }
61
+ let(:label) { OpenStruct.new(:name => "Epitaph", :location => OpenStruct.new(:city => "Sanfran", :name => "DON'T SHOW ME!")) }
62
62
 
63
63
  # Module does correctly include features in inlines.
64
- it { band.extend(Module).to_hash.must_equal({"label"=>{"name"=>"Epitaph", "location"=>{"city"=>"Sanfran"}}, "genre"=>"Punkrock"}) }
64
+ it { _(band.extend(Module).to_hash).must_equal({"label"=>{"name"=>"Epitaph", "location"=>{"city"=>"Sanfran"}}, "genre"=>"Punkrock"}) }
65
65
 
66
66
  # Decorator does correctly include features in inlines.
67
- it { Decorator.new(band).to_hash.must_equal({"label"=>{"name"=>"Epitaph", "location"=>{"city"=>"Sanfran"}}, "genre"=>"Punkrock"}) }
67
+ it { _(Decorator.new(band).to_hash).must_equal({"label"=>{"name"=>"Epitaph", "location"=>{"city"=>"Sanfran"}}, "genre"=>"Punkrock"}) }
68
68
  end
69
69
 
70
70
 
@@ -77,14 +77,14 @@ class SchemaTest < MiniTest::Spec
77
77
 
78
78
  # puts Decorator.representable_attrs[:definitions].inspect
79
79
 
80
- let (:label) { OpenStruct.new(:name => "Fat Wreck", :city => "San Francisco", :employees => [OpenStruct.new(:name => "Mike")], :location => OpenStruct.new(:city => "Sanfran")) }
81
- let (:band) { OpenStruct.new(:genre => "Punkrock", :label => label) }
80
+ let(:label) { OpenStruct.new(:name => "Fat Wreck", :city => "San Francisco", :employees => [OpenStruct.new(:name => "Mike")], :location => OpenStruct.new(:city => "Sanfran")) }
81
+ let(:band) { OpenStruct.new(:genre => "Punkrock", :label => label) }
82
82
 
83
83
 
84
84
  # it { FlatlinersDecorator.new( OpenStruct.new(label: OpenStruct.new) ).
85
85
  # to_hash.must_equal({}) }
86
86
  it do
87
- Decorator.new(band).to_hash.must_equal({"genre"=>"Punkrock", "label"=>{"name"=>"Fat Wreck", "location"=>{"city"=>"Sanfran"}}})
87
+ _(Decorator.new(band).to_hash).must_equal({"genre"=>"Punkrock", "label"=>{"name"=>"Fat Wreck", "location"=>{"city"=>"Sanfran"}}})
88
88
  end
89
89
 
90
90
 
@@ -103,7 +103,7 @@ class SchemaTest < MiniTest::Spec
103
103
  end
104
104
 
105
105
  it do
106
- InheritDecorator.new(band).to_hash.must_equal({"genre"=>"Punkrock", "label"=>{"name"=>"Fat Wreck", "city"=>"San Francisco", "location"=>{"city"=>"Sanfran"}}})
106
+ _(InheritDecorator.new(band).to_hash).must_equal({"genre"=>"Punkrock", "label"=>{"name"=>"Fat Wreck", "city"=>"San Francisco", "location"=>{"city"=>"Sanfran"}}})
107
107
  end
108
108
 
109
109
 
@@ -116,11 +116,8 @@ class SchemaTest < MiniTest::Spec
116
116
  end
117
117
  end
118
118
 
119
- require "pp"
120
- pp InheritFromDecorator.representable_attrs.get(:label)[:extend].(nil).representable_attrs
121
-
122
119
  it do
123
- InheritFromDecorator.new(band).to_hash.must_equal({"genre"=>"Punkrock", "label"=>{"name"=>"Fat Wreck", "city"=>"San Francisco", "employees"=>[{"name"=>"Mike"}], "location"=>{"city"=>"Sanfran"}}})
120
+ _(InheritFromDecorator.new(band).to_hash).must_equal({"genre"=>"Punkrock", "label"=>{"name"=>"Fat Wreck", "city"=>"San Francisco", "employees"=>[{"name"=>"Mike"}], "location"=>{"city"=>"Sanfran"}}})
124
121
  end
125
122
  end
126
123
 
@@ -13,7 +13,7 @@ class SerializeDeserializeTest < BaseTest
13
13
  }
14
14
  end
15
15
 
16
- it { subject.from_hash({"song" => Object}, user_options: {volume: 9}).song.must_equal "OBJECT Object {:volume=>9}" }
16
+ it { _(subject.from_hash({"song" => Object}, user_options: {volume: 9}).song).must_equal "OBJECT Object {:volume=>9}" }
17
17
  end
18
18
 
19
19
  describe "serialize" do
@@ -28,6 +28,6 @@ class SerializeDeserializeTest < BaseTest
28
28
 
29
29
  before { subject.song = "Arrested In Shanghai" }
30
30
 
31
- it { subject.to_hash(user_options: {volume: 9}).must_equal({"song"=>"Arrested In Shanghai {:volume=>9}"}) }
31
+ it { _(subject.to_hash(user_options: {volume: 9})).must_equal({"song"=>"Arrested In Shanghai {:volume=>9}"}) }
32
32
  end
33
33
  end
data/test/skip_test.rb CHANGED
@@ -14,7 +14,7 @@ class SkipParseTest < MiniTest::Spec
14
14
  end
15
15
  end
16
16
 
17
- let (:song) { OpenStruct.new.extend(representer) }
17
+ let(:song) { OpenStruct.new.extend(representer) }
18
18
 
19
19
  # do parse.
20
20
  it do
@@ -24,13 +24,13 @@ class SkipParseTest < MiniTest::Spec
24
24
  "airplays" => [{"station" => "JJJ"}]
25
25
  }, user_options: { skip?: true })
26
26
 
27
- song.title.must_equal "Victim Of Fate"
28
- song.band.name.must_equal "Mute 98"
29
- song.airplays[0].station.must_equal "JJJ"
27
+ _(song.title).must_equal "Victim Of Fate"
28
+ _(song.band.name).must_equal "Mute 98"
29
+ _(song.airplays[0].station).must_equal "JJJ"
30
30
  end
31
31
 
32
32
  # skip parsing.
33
- let (:airplay) { OpenStruct.new(station: "JJJ") }
33
+ let(:airplay) { OpenStruct.new(station: "JJJ") }
34
34
 
35
35
  it do
36
36
  song.from_hash({
@@ -39,9 +39,9 @@ class SkipParseTest < MiniTest::Spec
39
39
  "airplays" => [{}, {"station" => "JJJ"}, {}],
40
40
  }, user_options: { skip?: true })
41
41
 
42
- song.title.must_equal nil
43
- song.band.must_equal nil
44
- song.airplays.must_equal [airplay]
42
+ _(song.title).must_be_nil
43
+ _(song.band).must_be_nil
44
+ _(song.airplays).must_equal [airplay]
45
45
  end
46
46
  end
47
47
 
@@ -59,23 +59,23 @@ class SkipRenderTest < MiniTest::Spec
59
59
  end
60
60
  end
61
61
 
62
- let (:song) { OpenStruct.new(title: "Black Night", band: OpenStruct.new(name: "Time Again")).extend(representer) }
63
- let (:skip_song) { OpenStruct.new(title: "Time Bomb", band: OpenStruct.new(name: "Rancid")).extend(representer) }
62
+ let(:song) { OpenStruct.new(title: "Black Night", band: OpenStruct.new(name: "Time Again")).extend(representer) }
63
+ let(:skip_song) { OpenStruct.new(title: "Time Bomb", band: OpenStruct.new(name: "Rancid")).extend(representer) }
64
64
 
65
65
  # do render.
66
- it { song.to_hash(user_options: { skip?: true }).must_equal({"title"=>"Black Night", "band"=>{"name"=>"Time Again"}}) }
66
+ it { _(song.to_hash(user_options: { skip?: true })).must_equal({"title"=>"Black Night", "band"=>{"name"=>"Time Again"}}) }
67
67
  # skip.
68
- it { skip_song.to_hash(user_options: { skip?: true }).must_equal({"title"=>"Time Bomb"}) }
68
+ it { _(skip_song.to_hash(user_options: { skip?: true })).must_equal({"title"=>"Time Bomb"}) }
69
69
 
70
70
  # do render all collection items.
71
71
  it do
72
72
  song = OpenStruct.new(airplays: [OpenStruct.new(station: "JJJ"), OpenStruct.new(station: "ABC")]).extend(representer)
73
- song.to_hash(user_options: { skip?: true }).must_equal({"airplays"=>[{"station"=>"JJJ"}, {"station"=>"ABC"}]})
73
+ _(song.to_hash(user_options: { skip?: true })).must_equal({"airplays"=>[{"station"=>"JJJ"}, {"station"=>"ABC"}]})
74
74
  end
75
75
 
76
76
  # skip middle item.
77
77
  it do
78
78
  song = OpenStruct.new(airplays: [OpenStruct.new(station: "JJJ"), OpenStruct.new(station: "Radio Dreyeckland"), OpenStruct.new(station: "ABC")]).extend(representer)
79
- song.to_hash(user_options: { skip?: true }).must_equal({"airplays"=>[{"station"=>"JJJ"}, {"station"=>"ABC"}]})
79
+ _(song.to_hash(user_options: { skip?: true })).must_equal({"airplays"=>[{"station"=>"JJJ"}, {"station"=>"ABC"}]})
80
80
  end
81
81
  end