representable 3.0.4 → 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.
Files changed (96) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +23 -0
  3. data/CHANGES.md +14 -0
  4. data/Gemfile +4 -7
  5. data/LICENSE +1 -1
  6. data/README.md +12 -12
  7. data/Rakefile +1 -6
  8. data/lib/representable/binding.rb +32 -12
  9. data/lib/representable/cached.rb +1 -1
  10. data/lib/representable/coercion.rb +8 -6
  11. data/lib/representable/config.rb +8 -3
  12. data/lib/representable/debug.rb +23 -15
  13. data/lib/representable/declarative.rb +8 -3
  14. data/lib/representable/decorator.rb +1 -1
  15. data/lib/representable/definition.rb +7 -2
  16. data/lib/representable/deserializer.rb +4 -3
  17. data/lib/representable/for_collection.rb +1 -1
  18. data/lib/representable/hash/allow_symbols.rb +9 -11
  19. data/lib/representable/hash/binding.rb +1 -0
  20. data/lib/representable/hash/collection.rb +4 -2
  21. data/lib/representable/hash.rb +6 -2
  22. data/lib/representable/hash_methods.rb +3 -2
  23. data/lib/representable/insert.rb +1 -1
  24. data/lib/representable/json/collection.rb +3 -0
  25. data/lib/representable/json/hash.rb +1 -0
  26. data/lib/representable/json.rb +5 -7
  27. data/lib/representable/object/binding.rb +5 -1
  28. data/lib/representable/object.rb +1 -1
  29. data/lib/representable/option.rb +19 -0
  30. data/lib/representable/pipeline.rb +3 -2
  31. data/lib/representable/pipeline_factories.rb +4 -2
  32. data/lib/representable/populator.rb +1 -1
  33. data/lib/representable/represent.rb +1 -0
  34. data/lib/representable/serializer.rb +2 -1
  35. data/lib/representable/version.rb +1 -1
  36. data/lib/representable/xml/binding.rb +5 -6
  37. data/lib/representable/xml.rb +7 -10
  38. data/lib/representable/yaml/binding.rb +1 -0
  39. data/lib/representable/yaml.rb +3 -3
  40. data/lib/representable.rb +18 -25
  41. data/representable.gemspec +3 -3
  42. data/test/as_test.rb +4 -4
  43. data/test/binding_test.rb +10 -10
  44. data/test/cached_test.rb +19 -19
  45. data/test/class_test.rb +7 -7
  46. data/test/coercion_test.rb +33 -22
  47. data/test/config/inherit_test.rb +14 -14
  48. data/test/config_test.rb +18 -18
  49. data/test/decorator_scope_test.rb +3 -3
  50. data/test/decorator_test.rb +17 -17
  51. data/test/default_test.rb +7 -7
  52. data/test/definition_test.rb +32 -32
  53. data/test/{example.rb → examples/example.rb} +0 -0
  54. data/test/exec_context_test.rb +6 -6
  55. data/test/features_test.rb +3 -3
  56. data/test/filter_test.rb +6 -6
  57. data/test/for_collection_test.rb +2 -2
  58. data/test/generic_test.rb +3 -3
  59. data/test/getter_setter_test.rb +5 -5
  60. data/test/hash_test.rb +19 -19
  61. data/test/heritage_test.rb +4 -4
  62. data/test/if_test.rb +6 -6
  63. data/test/include_exclude_test.rb +12 -12
  64. data/test/inherit_test.rb +15 -15
  65. data/test/inline_test.rb +11 -11
  66. data/test/instance_test.rb +29 -29
  67. data/test/is_representable_test.rb +10 -10
  68. data/test/json_test.rb +7 -7
  69. data/test/lonely_test.rb +16 -16
  70. data/test/nested_test.rb +7 -7
  71. data/test/object_test.rb +7 -7
  72. data/test/option_test.rb +36 -0
  73. data/test/parse_pipeline_test.rb +3 -3
  74. data/test/pipeline_test.rb +43 -43
  75. data/test/populator_test.rb +15 -15
  76. data/test/prepare_test.rb +2 -2
  77. data/test/private_options_test.rb +2 -2
  78. data/test/reader_writer_test.rb +2 -2
  79. data/test/render_nil_test.rb +2 -2
  80. data/test/represent_test.rb +4 -4
  81. data/test/representable_test.rb +27 -27
  82. data/test/schema_test.rb +5 -5
  83. data/test/serialize_deserialize_test.rb +2 -2
  84. data/test/skip_test.rb +10 -10
  85. data/test/stringify_hash_test.rb +3 -3
  86. data/test/test_helper.rb +4 -2
  87. data/test/uncategorized_test.rb +10 -10
  88. data/test/user_options_test.rb +4 -4
  89. data/test/wrap_test.rb +11 -11
  90. data/test/xml_namespace_test.rb +1 -1
  91. data/test/xml_test.rb +6 -6
  92. data/test/yaml_test.rb +20 -20
  93. metadata +16 -11
  94. data/.travis.yml +0 -16
  95. data/lib/representable/autoload.rb +0 -14
  96. data/test/mongoid_test.rb +0 -31
@@ -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
@@ -24,7 +24,7 @@ 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.
@@ -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
 
@@ -65,7 +65,7 @@ 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
 
@@ -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
@@ -132,8 +132,8 @@ class RepresentableTest < MiniTest::Spec
132
132
 
133
133
  # test ::inherited.
134
134
  it do
135
- BaseClass.respond_to?(:other).must_equal false
136
- SubClass.respond_to?(:other).must_equal true
135
+ _(BaseClass.respond_to?(:other)).must_equal false
136
+ _(SubClass.respond_to?(:other)).must_equal true
137
137
  end
138
138
 
139
139
  module DifferentIncluded
@@ -164,13 +164,13 @@ class RepresentableTest < MiniTest::Spec
164
164
  it "doesn't modify options hash" do
165
165
  options = {}
166
166
  representer.property(:title, options)
167
- options.must_equal({})
167
+ _(options).must_equal({})
168
168
  end
169
169
 
170
170
  representer! {}
171
171
 
172
172
  it "returns the Definition instance" do
173
- representer.property(:name).must_be_kind_of Representable::Definition
173
+ _(representer.property(:name)).must_be_kind_of Representable::Definition
174
174
  end
175
175
  end
176
176
 
@@ -233,7 +233,7 @@ class RepresentableTest < MiniTest::Spec
233
233
 
234
234
  it "includes false attributes" do
235
235
  @band.from_hash({"groupies"=>false})
236
- assert_equal false, @band.groupies
236
+ refute @band.groupies
237
237
  end
238
238
 
239
239
  it "ignores properties not present in the incoming document" do
@@ -300,14 +300,14 @@ class RepresentableTest < MiniTest::Spec
300
300
  end
301
301
 
302
302
  it "#to_hash propagates to nested objects" do
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}}})
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}}})
305
305
  end
306
306
 
307
307
  it "#from_hash propagates to nested objects" do
308
308
  song = OpenStruct.new.extend(representer).from_hash({"track"=>{"nr" => "replace me", "length"=>{"seconds"=>"replacing"}}}, user_options: {nr: 9})
309
- song.track.nr.must_equal 9
310
- song.track.length.seconds.must_equal 9
309
+ _(song.track.nr).must_equal 9
310
+ _(song.track.length.seconds).must_equal 9
311
311
  end
312
312
  end
313
313
  end
@@ -364,12 +364,12 @@ class RepresentableTest < MiniTest::Spec
364
364
  end
365
365
 
366
366
  it "executes lambda in represented instance context" do
367
- Song.new("Carnage").instance_eval do
367
+ _(Song.new("Carnage").instance_eval do
368
368
  def compute_representer(name)
369
369
  UpcaseRepresenter
370
370
  end
371
371
  self
372
- end.extend(representer).to_hash.must_equal({"name" => "CARNAGE"})
372
+ end.extend(representer).to_hash).must_equal({"name" => "CARNAGE"})
373
373
  end
374
374
  end
375
375
 
@@ -382,8 +382,8 @@ class RepresentableTest < MiniTest::Spec
382
382
 
383
383
  it "uses object from :instance but still extends it" do
384
384
  song = Song.new.extend(representer).from_hash("name" => "Eric's Had A Bad Day")
385
- song.name.must_equal obj
386
- song.name.must_be_kind_of mod
385
+ _(song.name).must_equal obj
386
+ _(song.name).must_be_kind_of mod
387
387
  end
388
388
  end
389
389
 
@@ -398,8 +398,8 @@ class RepresentableTest < MiniTest::Spec
398
398
  end
399
399
 
400
400
  it "uses lambda when parsing" do
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)
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)
403
403
  end
404
404
 
405
405
  describe "with :class lambda" do
@@ -410,12 +410,12 @@ class RepresentableTest < MiniTest::Spec
410
410
 
411
411
  it "creates instance from :class lambda when parsing" do
412
412
  song = OpenStruct.new.extend(representer).from_hash({"name" => "Quitters Never Win"})
413
- song.name.must_be_kind_of UpcaseString
414
- song.name.must_equal "QUITTERS NEVER WIN"
413
+ _(song.name).must_be_kind_of UpcaseString
414
+ _(song.name).must_equal "QUITTERS NEVER WIN"
415
415
 
416
416
  song = OpenStruct.new.extend(representer).from_hash({"name" => "Still Failing?"})
417
- song.name.must_be_kind_of String
418
- song.name.must_equal "still failing?"
417
+ _(song.name).must_be_kind_of String
418
+ _(song.name).must_equal "still failing?"
419
419
  end
420
420
  end
421
421
  end
@@ -427,12 +427,12 @@ class RepresentableTest < MiniTest::Spec
427
427
  end
428
428
 
429
429
  it "uses lambda for each item when rendering" do
430
- 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"])
431
431
  end
432
432
 
433
433
  it "uses lambda for each item when parsing" do
434
434
  album = Album.new.extend(representer).from_hash("songs"=>["DEAN MARTIN", "charlie still smirks"])
435
- 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)
436
436
  end
437
437
 
438
438
  describe "with :class lambda" do
@@ -443,7 +443,7 @@ class RepresentableTest < MiniTest::Spec
443
443
 
444
444
  it "creates instance from :class lambda for each item when parsing" do
445
445
  album = Album.new.extend(representer).from_hash("songs"=>["Still Failing?", "charlie still smirks"])
446
- album.songs.must_equal ["still failing?", "CHARLIE STILL SMIRKS"]
446
+ _(album.songs).must_equal ["still failing?", "CHARLIE STILL SMIRKS"]
447
447
  end
448
448
  end
449
449
  end
@@ -454,7 +454,7 @@ class RepresentableTest < MiniTest::Spec
454
454
  let(:songs) { [Song.new("Bloody Mary")] }
455
455
 
456
456
  it "is aliased to :extend" do
457
- 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
458
458
  end
459
459
  end
460
460
 
@@ -477,15 +477,15 @@ class RepresentableTest < MiniTest::Spec
477
477
  it "uses :extend strategy" do
478
478
  album_rpr = Module.new { include Representable::Hash; collection :songs, :class => Song, :extend => SongRepresenter}
479
479
 
480
- album_rpr.prepare(album).to_hash.must_equal({"songs"=>[{"name"=>"Still Friends In The End"}]})
481
- 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
482
482
  end
483
483
  end
484
484
 
485
485
  describe "Decorator subclass" do
486
486
  it "uses :decorate strategy" do
487
- AlbumRepresentation.prepare(album).to_hash.must_equal({"songs"=>[{"name"=>"Still Friends In The End"}]})
488
- 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
489
489
  end
490
490
  end
491
491
  end
data/test/schema_test.rb CHANGED
@@ -61,10 +61,10 @@ class SchemaTest < MiniTest::Spec
61
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
 
@@ -84,7 +84,7 @@ class SchemaTest < MiniTest::Spec
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
 
@@ -117,7 +117,7 @@ class SchemaTest < MiniTest::Spec
117
117
  end
118
118
 
119
119
  it do
120
- 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"}}})
121
121
  end
122
122
  end
123
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
@@ -24,9 +24,9 @@ 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.
@@ -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_be_nil
43
- song.band.must_be_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
 
@@ -63,19 +63,19 @@ class SkipRenderTest < MiniTest::Spec
63
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
@@ -17,11 +17,11 @@ describe "#from_hash" do
17
17
  end
18
18
 
19
19
  it "parses symbols, too" do
20
- OpenStruct.new.extend(representer).from_hash({:song => {:title => "Der Optimist"}}).song.title.must_equal "Der Optimist"
20
+ _(OpenStruct.new.extend(representer).from_hash({:song => {:title => "Der Optimist"}}).song.title).must_equal "Der Optimist"
21
21
  end
22
22
 
23
23
  it "still parses strings" do
24
- OpenStruct.new.extend(representer).from_hash({"song" => {"title" => "Der Optimist"}}).song.title.must_equal "Der Optimist"
24
+ _(OpenStruct.new.extend(representer).from_hash({"song" => {"title" => "Der Optimist"}}).song.title).must_equal "Der Optimist"
25
25
  end
26
26
 
27
27
  describe "with :wrap" do
@@ -33,7 +33,7 @@ describe "#from_hash" do
33
33
  end
34
34
 
35
35
  it "parses symbols, too" do
36
- OpenStruct.new.extend(representer).from_hash({:album => {:song => {:title => "Der Optimist"}}}).song.title.must_equal "Der Optimist"
36
+ _(OpenStruct.new.extend(representer).from_hash({:album => {:song => {:title => "Der Optimist"}}}).song.title).must_equal "Der Optimist"
37
37
  end
38
38
  end
39
39
  end
data/test/test_helper.rb CHANGED
@@ -1,13 +1,15 @@
1
+ require 'pry-byebug'
1
2
  require 'representable'
2
3
 
3
4
  require 'minitest/autorun'
4
5
  require 'test_xml/mini_test'
5
6
 
6
7
  require "representable/debug"
8
+ require 'minitest/assertions'
7
9
 
8
10
  module MiniTest::Assertions
9
11
  def assert_equal_xml(text, subject)
10
- subject.gsub("\n", "").gsub(/(\s\s+)/, "").must_equal(text.gsub("\n", "").gsub(/(\s\s+)/, ""))
12
+ assert_equal (text.gsub("\n", "").gsub(/(\s\s+)/, "")), subject.gsub("\n", "").gsub(/(\s\s+)/, "")
11
13
  end
12
14
  end
13
15
  String.infect_an_assertion :assert_equal_xml, :must_xml
@@ -47,7 +49,7 @@ module AssertJson
47
49
  module Assertions
48
50
  def assert_json(expected, actual, msg=nil)
49
51
  msg = message(msg, "") { diff expected, actual }
50
- assert(expected.split("").sort == actual.split("").sort, msg)
52
+ assert_equal(expected.split("").sort, actual.split("").sort, msg)
51
53
  end
52
54
  end
53
55
  end
@@ -15,12 +15,12 @@ class StopWhenIncomingObjectFragmentIsNilTest < MiniTest::Spec
15
15
 
16
16
  it do
17
17
  album = Album.new
18
- representer.new(album).from_hash({"id"=>1, "songs"=>[{"title"=>"Walkie Talkie"}]}).songs.must_equal [Song.new("Walkie Talkie")]
18
+ _(representer.new(album).from_hash({"id"=>1, "songs"=>[{"title"=>"Walkie Talkie"}]}).songs).must_equal [Song.new("Walkie Talkie")]
19
19
  end
20
20
 
21
21
  it do
22
22
  album = Album.new(2, ["original"])
23
- representer.new(album).from_hash({"id"=>1, "songs"=>nil}).songs.must_equal ["original"]
23
+ _(representer.new(album).from_hash({"id"=>1, "songs"=>nil}).songs).must_equal ["original"]
24
24
  end
25
25
 
26
26
  end
@@ -35,13 +35,13 @@ class RenderPipelineOptionTest < MiniTest::Spec
35
35
  end
36
36
  end
37
37
 
38
- it { representer.new(Album.new).to_hash(user_options: {function: NilToNA}).must_equal({"id"=>"n/a"}) }
39
- it { representer.new(Album.new(1)).to_hash(user_options: {function: NilToNA}).must_equal({"id"=>1}) }
38
+ it { _(representer.new(Album.new).to_hash(user_options: {function: NilToNA})).must_equal({"id"=>"n/a"}) }
39
+ it { _(representer.new(Album.new(1)).to_hash(user_options: {function: NilToNA})).must_equal({"id"=>1}) }
40
40
 
41
41
  it "is cached" do
42
42
  decorator = representer.new(Album.new)
43
- decorator.to_hash(user_options: {function: NilToNA}).must_equal({"id"=>"n/a"})
44
- decorator.to_hash(user_options: {function: nil}).must_equal({"id"=>"n/a"}) # non-sense function is not applied.
43
+ _(decorator.to_hash(user_options: {function: NilToNA})).must_equal({"id"=>"n/a"})
44
+ _(decorator.to_hash(user_options: {function: nil})).must_equal({"id"=>"n/a"}) # non-sense function is not applied.
45
45
  end
46
46
 
47
47
  end
@@ -56,12 +56,12 @@ class ParsePipelineOptionTest < MiniTest::Spec
56
56
  end
57
57
  end
58
58
 
59
- it { representer.new(Album.new).from_hash({"id"=>nil}, user_options: {function: NilToNA}).id.must_equal "n/a" }
60
- it { representer.new(Album.new(1)).to_hash(user_options: {function: NilToNA}).must_equal({"id"=>1}) }
59
+ it { _(representer.new(Album.new).from_hash({"id"=>nil}, user_options: {function: NilToNA}).id).must_equal "n/a" }
60
+ it { _(representer.new(Album.new(1)).to_hash(user_options: {function: NilToNA})).must_equal({"id"=>1}) }
61
61
 
62
62
  it "is cached" do
63
63
  decorator = representer.new(Album.new)
64
- decorator.from_hash({"id"=>nil}, user_options: {function: NilToNA}).id.must_equal "n/a"
65
- decorator.from_hash({"id"=>nil}, user_options: {function: "nonsense"}).id.must_equal "n/a" # non-sense function is not applied.
64
+ _(decorator.from_hash({"id"=>nil}, user_options: {function: NilToNA}).id).must_equal "n/a"
65
+ _(decorator.from_hash({"id"=>nil}, user_options: {function: "nonsense"}).id).must_equal "n/a" # non-sense function is not applied.
66
66
  end
67
67
  end
@@ -7,9 +7,9 @@ class UserOptionsTest < Minitest::Spec
7
7
  property :title, if: ->(options) { options[:user_options][:visible] }
8
8
  end
9
9
 
10
- it { Song.new("Run With It").extend(representer).to_hash.must_equal({}) }
11
- it { Song.new("Run With It").extend(representer).to_hash(user_options: {visible: true}).must_equal({"title"=>"Run With It"}) }
12
- it { Song.new("Run With It").extend(representer).from_hash("title"=>"Business Conduct").title.must_equal "Run With It" }
13
- it { Song.new("Run With It").extend(representer).from_hash({"title"=>"Business Conduct"}, user_options: {visible: true}).title.must_equal "Business Conduct" }
10
+ it { _(Song.new("Run With It").extend(representer).to_hash).must_equal({}) }
11
+ it { _(Song.new("Run With It").extend(representer).to_hash(user_options: {visible: true})).must_equal({"title"=>"Run With It"}) }
12
+ it { _(Song.new("Run With It").extend(representer).from_hash("title"=>"Business Conduct").title).must_equal "Run With It" }
13
+ it { _(Song.new("Run With It").extend(representer).from_hash({"title"=>"Business Conduct"}, user_options: {visible: true}).title).must_equal "Business Conduct" }
14
14
  end
15
15
  # Representable.deprecations=false
data/test/wrap_test.rb CHANGED
@@ -36,13 +36,13 @@ class WrapTest < MiniTest::Spec
36
36
  let(:format) { format }
37
37
 
38
38
  representer!(:module => mod) do
39
- self.representation_wrap = lambda { |args| "#{name}#{args[:number]}" }
39
+ self.representation_wrap = lambda { |number:, **| "#{name}#{number}" }
40
40
  property :genre
41
41
  end
42
42
 
43
43
  it { render(band, {:number => 182}).must_equal_document(output) }
44
44
 
45
- it { parse(band, input, {:number => 182}).genre.must_equal "Poppunk" } # TODO: better test. also, xml parses _any_ wrap.
45
+ it { _(parse(band, input, {:number => 182}).genre).must_equal "Poppunk" } # TODO: better test. also, xml parses _any_ wrap.
46
46
  end
47
47
  end
48
48
  end
@@ -69,15 +69,15 @@ class HashDisableWrapTest < MiniTest::Spec
69
69
 
70
70
  # direct, local api.
71
71
  it do
72
- band.to_hash.must_equal({"bands" => {"name"=>"Social Distortion"}})
73
- band.to_hash(wrap: false).must_equal({"name"=>"Social Distortion"})
74
- band.to_hash(wrap: :band).must_equal(:band=>{"name"=>"Social Distortion"})
72
+ _(band.to_hash).must_equal({"bands" => {"name"=>"Social Distortion"}})
73
+ _(band.to_hash(wrap: false)).must_equal({"name"=>"Social Distortion"})
74
+ _(band.to_hash(wrap: :band)).must_equal(:band=>{"name"=>"Social Distortion"})
75
75
  end
76
76
 
77
77
  it do
78
- band.from_hash({"bands" => {"name"=>"Social Distortion"}}).name.must_equal "Social Distortion"
79
- band.from_hash({"name"=>"Social Distortion"}, wrap: false).name.must_equal "Social Distortion"
80
- band.from_hash({band: {"name"=>"Social Distortion"}}, wrap: :band).name.must_equal "Social Distortion"
78
+ _(band.from_hash({"bands" => {"name"=>"Social Distortion"}}).name).must_equal "Social Distortion"
79
+ _(band.from_hash({"name"=>"Social Distortion"}, wrap: false).name).must_equal "Social Distortion"
80
+ _(band.from_hash({band: {"name"=>"Social Distortion"}}, wrap: :band).name).must_equal "Social Distortion"
81
81
  end
82
82
 
83
83
 
@@ -94,11 +94,11 @@ class HashDisableWrapTest < MiniTest::Spec
94
94
 
95
95
  # band has wrap turned off per property definition, however, label still has wrap.
96
96
  it "renders" do
97
- album.to_hash.must_equal({"albums" => {"band" => {"name"=>"Social Distortion", "label"=>{"important"=>{"name"=>"Epitaph"}}}}})
97
+ _(album.to_hash).must_equal({"albums" => {"band" => {"name"=>"Social Distortion", "label"=>{"important"=>{"name"=>"Epitaph"}}}}})
98
98
  end
99
99
 
100
100
  it "parses" do
101
- album.from_hash({"albums" => {"band" => {"name"=>"Rvivr"}}}).band.name.must_equal "Rvivr"
101
+ _(album.from_hash({"albums" => {"band" => {"name"=>"Rvivr"}}}).band.name).must_equal "Rvivr"
102
102
  end
103
103
  end
104
104
 
@@ -142,7 +142,7 @@ class XMLDisableWrapTest < MiniTest::Spec
142
142
  # band has wrap turned of per property definition, however, label still has wrap.
143
143
  it "rendersxx" do
144
144
  skip
145
- album.to_xml.must_equal({"albums" => {"band" => {"name"=>"Social Distortion", "label"=>{"important"=>{"name"=>"Epitaph"}}}}})
145
+ _(album.to_xml).must_equal({"albums" => {"band" => {"name"=>"Social Distortion", "label"=>{"important"=>{"name"=>"Epitaph"}}}}})
146
146
  end
147
147
 
148
148
  # it "parses" do
@@ -177,7 +177,7 @@ class Namespace2XMLTest < Minitest::Spec
177
177
  #:parse-call end
178
178
  )
179
179
 
180
- lib.book.inspect.must_equal %{#<struct Namespace2XMLTest::Model::Book id=\"1\", isbn=\"666\", author=#<struct Namespace2XMLTest::Model::Character name=\"Fowler\", born=nil, qualification=nil>, character=[#<struct Namespace2XMLTest::Model::Character name=\"Frau Java\", born=\"1991\", qualification=\"typed\">]>}
180
+ _(lib.book.inspect).must_equal %{#<struct Namespace2XMLTest::Model::Book id=\"1\", isbn=\"666\", author=#<struct Namespace2XMLTest::Model::Character name=\"Fowler\", born=nil, qualification=nil>, character=[#<struct Namespace2XMLTest::Model::Character name=\"Frau Java\", born=\"1991\", qualification=\"typed\">]>}
181
181
 
182
182
  #:parse-res
183
183
  lib.book.character[0].name #=> "Frau Java"
data/test/xml_test.rb CHANGED
@@ -12,8 +12,8 @@ class XmlPublicMethodsTest < Minitest::Spec
12
12
 
13
13
  let(:data) { %{<data><id>1</id><name>Rancid</name></data>} }
14
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"] }
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
18
  #---
19
19
  # to_hash
@@ -468,11 +468,11 @@ class XMLCollectionTest < MiniTest::Spec
468
468
  end
469
469
 
470
470
  it "parses array" do
471
- [].extend(representer).from_xml(xml_doc).must_equal songs
471
+ _([].extend(representer).from_xml(xml_doc)).must_equal songs
472
472
  end
473
473
 
474
474
  it "parses array with decorator" do
475
- decorator.new([]).from_xml(xml_doc).must_equal songs
475
+ _(decorator.new([]).from_xml(xml_doc)).must_equal songs
476
476
  end
477
477
  end
478
478
  end
@@ -505,7 +505,7 @@ class XMLCollectionTest < MiniTest::Spec
505
505
 
506
506
  describe "#from_json" do
507
507
  it "returns hash" do
508
- {}.extend(representer).from_xml(xml_doc).must_equal songs
508
+ _({}.extend(representer).from_xml(xml_doc)).must_equal songs
509
509
  end
510
510
 
511
511
  it "respects :exclude" do
@@ -517,7 +517,7 @@ class XMLCollectionTest < MiniTest::Spec
517
517
  end
518
518
 
519
519
  it "parses hash with decorator" do
520
- decorator.new({}).from_xml(xml_doc).must_equal songs
520
+ _(decorator.new({}).from_xml(xml_doc)).must_equal songs
521
521
  end
522
522
  end
523
523
  end