representable 3.0.4 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +17 -0
  3. data/CHANGES.md +10 -0
  4. data/Gemfile +4 -7
  5. data/LICENSE +1 -1
  6. data/README.md +4 -3
  7. data/Rakefile +1 -6
  8. data/lib/representable.rb +18 -25
  9. data/lib/representable/binding.rb +32 -12
  10. data/lib/representable/cached.rb +1 -1
  11. data/lib/representable/coercion.rb +8 -6
  12. data/lib/representable/config.rb +8 -3
  13. data/lib/representable/debug.rb +23 -15
  14. data/lib/representable/declarative.rb +8 -3
  15. data/lib/representable/decorator.rb +1 -1
  16. data/lib/representable/definition.rb +7 -2
  17. data/lib/representable/deserializer.rb +4 -3
  18. data/lib/representable/for_collection.rb +1 -1
  19. data/lib/representable/hash.rb +6 -2
  20. data/lib/representable/hash/allow_symbols.rb +9 -11
  21. data/lib/representable/hash/binding.rb +1 -0
  22. data/lib/representable/hash/collection.rb +4 -2
  23. data/lib/representable/hash_methods.rb +3 -2
  24. data/lib/representable/insert.rb +1 -1
  25. data/lib/representable/json.rb +5 -7
  26. data/lib/representable/json/collection.rb +3 -0
  27. data/lib/representable/json/hash.rb +1 -0
  28. data/lib/representable/object.rb +1 -1
  29. data/lib/representable/object/binding.rb +5 -1
  30. data/lib/representable/option.rb +19 -0
  31. data/lib/representable/pipeline.rb +3 -2
  32. data/lib/representable/pipeline_factories.rb +4 -2
  33. data/lib/representable/populator.rb +1 -1
  34. data/lib/representable/represent.rb +1 -0
  35. data/lib/representable/serializer.rb +2 -1
  36. data/lib/representable/version.rb +1 -1
  37. data/lib/representable/virtus_coercion.rb +38 -0
  38. data/lib/representable/xml.rb +7 -10
  39. data/lib/representable/xml/binding.rb +2 -3
  40. data/lib/representable/yaml.rb +3 -3
  41. data/lib/representable/yaml/binding.rb +1 -0
  42. data/representable.gemspec +3 -3
  43. data/test/as_test.rb +4 -4
  44. data/test/binding_test.rb +10 -10
  45. data/test/cached_test.rb +19 -19
  46. data/test/class_test.rb +7 -7
  47. data/test/coercion_test.rb +33 -22
  48. data/test/config/inherit_test.rb +14 -14
  49. data/test/config_test.rb +18 -18
  50. data/test/decorator_scope_test.rb +3 -3
  51. data/test/decorator_test.rb +17 -17
  52. data/test/default_test.rb +7 -7
  53. data/test/definition_test.rb +32 -32
  54. data/test/{example.rb → examples/example.rb} +0 -0
  55. data/test/exec_context_test.rb +6 -6
  56. data/test/features_test.rb +3 -3
  57. data/test/filter_test.rb +6 -6
  58. data/test/for_collection_test.rb +2 -2
  59. data/test/generic_test.rb +3 -3
  60. data/test/getter_setter_test.rb +5 -5
  61. data/test/hash_test.rb +19 -19
  62. data/test/heritage_test.rb +4 -4
  63. data/test/if_test.rb +6 -6
  64. data/test/include_exclude_test.rb +12 -12
  65. data/test/inherit_test.rb +15 -15
  66. data/test/inline_test.rb +11 -11
  67. data/test/instance_test.rb +29 -29
  68. data/test/is_representable_test.rb +10 -10
  69. data/test/json_test.rb +7 -7
  70. data/test/lonely_test.rb +16 -16
  71. data/test/nested_test.rb +7 -7
  72. data/test/object_test.rb +7 -7
  73. data/test/option_test.rb +36 -0
  74. data/test/parse_pipeline_test.rb +3 -3
  75. data/test/pipeline_test.rb +43 -43
  76. data/test/populator_test.rb +15 -15
  77. data/test/prepare_test.rb +2 -2
  78. data/test/private_options_test.rb +2 -2
  79. data/test/reader_writer_test.rb +2 -2
  80. data/test/render_nil_test.rb +2 -2
  81. data/test/represent_test.rb +4 -4
  82. data/test/representable_test.rb +27 -27
  83. data/test/schema_test.rb +5 -5
  84. data/test/serialize_deserialize_test.rb +2 -2
  85. data/test/skip_test.rb +10 -10
  86. data/test/stringify_hash_test.rb +3 -3
  87. data/test/test_helper.rb +4 -2
  88. data/test/uncategorized_test.rb +10 -10
  89. data/test/user_options_test.rb +4 -4
  90. data/test/virtus_coercion_test.rb +52 -0
  91. data/test/wrap_test.rb +11 -11
  92. data/test/xml_namespace_test.rb +1 -1
  93. data/test/xml_test.rb +6 -6
  94. data/test/yaml_test.rb +20 -20
  95. metadata +81 -15
  96. data/.travis.yml +0 -16
  97. data/lib/representable/autoload.rb +0 -14
  98. data/test/mongoid_test.rb +0 -31
@@ -27,7 +27,7 @@ class FeaturesTest < MiniTest::Spec
27
27
  instance_exec(&definition)
28
28
  end
29
29
 
30
- it { song.extend(representer).to_hash.must_equal({"title"=>"Is It A Lie", "length"=>"2:31", "details"=>{"title"=>"Is It A Lie"}}) }
30
+ it { _(song.extend(representer).to_hash).must_equal({"title"=>"Is It A Lie", "length"=>"2:31", "details"=>{"title"=>"Is It A Lie"}}) }
31
31
  end
32
32
 
33
33
 
@@ -36,7 +36,7 @@ class FeaturesTest < MiniTest::Spec
36
36
  instance_exec(&definition)
37
37
  end
38
38
 
39
- it { representer.new(song).to_hash.must_equal({"title"=>"Is It A Lie", "length"=>"2:31", "details"=>{"title"=>"Is It A Lie"}}) }
39
+ it { _(representer.new(song).to_hash).must_equal({"title"=>"Is It A Lie", "length"=>"2:31", "details"=>{"title"=>"Is It A Lie"}}) }
40
40
  end
41
41
  end
42
42
 
@@ -65,6 +65,6 @@ class FeatureInclusionOrderTest < MiniTest::Spec
65
65
  end
66
66
 
67
67
  it do
68
- representer.new(OpenStruct.new(song: Object)).to_hash.must_equal({"title"=>"I am number two, I was first!", "song"=>{"title"=>"I am number two, I was first!"}})
68
+ _(representer.new(OpenStruct.new(song: Object)).to_hash).must_equal({"title"=>"I am number two, I was first!", "song"=>{"title"=>"I am number two, I was first!"}})
69
69
  end
70
70
  end
data/test/filter_test.rb CHANGED
@@ -6,7 +6,7 @@ class FilterPipelineTest < MiniTest::Spec
6
6
 
7
7
  subject { Representable::Pipeline[block1, block2] }
8
8
 
9
- it { subject.call("Horowitz", {}).must_equal "2: 1: Horowitz" }
9
+ it { _(subject.call("Horowitz", {})).must_equal "2: 1: Horowitz" }
10
10
  end
11
11
 
12
12
 
@@ -22,11 +22,11 @@ class FilterTest < MiniTest::Spec
22
22
  # gets doc and options.
23
23
  it {
24
24
  song = OpenStruct.new.extend(representer).from_hash("title" => "VULCAN EARS", "track" => "Nine")
25
- song.title.must_equal "VULCAN EARS"
26
- song.track.must_equal "nine,{\"title\"=>\"VULCAN EARS\", \"track\"=>\"Nine\"}"
25
+ _(song.title).must_equal "VULCAN EARS"
26
+ _(song.track).must_equal "nine,{\"title\"=>\"VULCAN EARS\", \"track\"=>\"Nine\"}"
27
27
  }
28
28
 
29
- it { OpenStruct.new("title" => "vulcan ears", "track" => "Nine").extend(representer).to_hash.must_equal( {"title"=>"vulcan ears", "track"=>"NINE,{\"title\"=>\"vulcan ears\"},{}"}) }
29
+ it { _(OpenStruct.new("title" => "vulcan ears", "track" => "Nine").extend(representer).to_hash).must_equal( {"title"=>"vulcan ears", "track"=>"NINE,{\"title\"=>\"vulcan ears\"},{}"}) }
30
30
 
31
31
 
32
32
  describe "#parse_filter" do
@@ -41,8 +41,8 @@ class FilterTest < MiniTest::Spec
41
41
  end
42
42
 
43
43
  # order matters.
44
- it { OpenStruct.new.extend(representer).from_hash("track" => "Nine").track.must_equal "Nine-1-2" }
45
- it { OpenStruct.new("track" => "Nine").extend(representer).to_hash.must_equal({"track"=>"Nine-1-2"}) }
44
+ it { _(OpenStruct.new.extend(representer).from_hash("track" => "Nine").track).must_equal "Nine-1-2" }
45
+ it { _(OpenStruct.new("track" => "Nine").extend(representer).to_hash).must_equal({"track"=>"Nine-1-2"}) }
46
46
  end
47
47
  end
48
48
 
@@ -36,7 +36,7 @@ class ForCollectionTest < MiniTest::Spec
36
36
  it { render(songs.extend(representer.for_collection)).must_equal_document output }
37
37
  it { render(representer.for_collection.prepare(songs)).must_equal_document output }
38
38
  # parsing needs the class set, at least
39
- it { parse([].extend(representer.for_collection), input).must_equal songs }
39
+ it { _(parse([].extend(representer.for_collection), input)).must_equal songs }
40
40
  end
41
41
 
42
42
  describe "Module::for_collection without configuration [#{format}]" do
@@ -66,7 +66,7 @@ class ForCollectionTest < MiniTest::Spec
66
66
  }
67
67
 
68
68
  it { render(representer.for_collection.new(songs)).must_equal_document output }
69
- it { parse(representer.for_collection.new([]), input).must_equal songs }
69
+ it { _(parse(representer.for_collection.new([]), input)).must_equal songs }
70
70
  end
71
71
  end
72
72
 
data/test/generic_test.rb CHANGED
@@ -14,13 +14,13 @@ class GenericTest < MiniTest::Spec # TODO: rename/restructure to CollectionTest.
14
14
 
15
15
  it "doesn't initialize property" do
16
16
  new_album.from_hash({})
17
- new_album.songs.must_be_nil
17
+ _(new_album.songs).must_be_nil
18
18
  end
19
19
 
20
20
  it "leaves properties untouched" do
21
21
  album.from_hash({})
22
22
  # TODO: test property.
23
- album.songs.must_equal ["Fuck Armageddon"] # when the collection is not present in the incoming hash, this propery stays untouched.
23
+ _(album.songs).must_equal ["Fuck Armageddon"] # when the collection is not present in the incoming hash, this propery stays untouched.
24
24
  end
25
25
 
26
26
 
@@ -109,7 +109,7 @@ class GenericTest < MiniTest::Spec # TODO: rename/restructure to CollectionTest.
109
109
  end
110
110
 
111
111
  it "doesn't change represented object" do
112
- song.extend(representer).send("from_#{format}", input).title.must_equal "Resist Stance"
112
+ _(song.extend(representer).send("from_#{format}", input).title).must_equal "Resist Stance"
113
113
  end
114
114
  end
115
115
  end
@@ -3,19 +3,19 @@ require 'test_helper'
3
3
  class GetterSetterTest < BaseTest
4
4
  representer! do
5
5
  property :name, # key under :name.
6
- :getter => lambda { |options| "#{options[:user_options][:welcome]} #{song_name}" },
7
- :setter => lambda { |options| self.song_name = "#{options[:user_options][:welcome]} #{options[:input]}" }
6
+ :getter => lambda { |user_options:, **| "#{user_options[:welcome]} #{song_name}" },
7
+ :setter => lambda { |user_options:, input:, **| self.song_name = "#{user_options[:welcome]} #{input}" }
8
8
  end
9
9
 
10
10
  subject { Struct.new(:song_name).new("Mony Mony").extend(representer) }
11
11
 
12
12
  it "uses :getter when rendering" do
13
13
  subject.instance_eval { def name; raise; end }
14
- subject.to_hash(user_options: {welcome: "Hi"}).must_equal({"name" => "Hi Mony Mony"})
14
+ _(subject.to_hash(user_options: {welcome: "Hi"})).must_equal({"name" => "Hi Mony Mony"})
15
15
  end
16
16
 
17
17
  it "uses :setter when parsing" do
18
18
  subject.instance_eval { def name=(*); raise; end; self }
19
- subject.from_hash({"name" => "Eyes Without A Face"}, user_options: {welcome: "Hello"}).song_name.must_equal "Hello Eyes Without A Face"
19
+ _(subject.from_hash({"name" => "Eyes Without A Face"}, user_options: {welcome: "Hello"}).song_name).must_equal "Hello Eyes Without A Face"
20
20
  end
21
- end
21
+ end
data/test/hash_test.rb CHANGED
@@ -11,15 +11,15 @@ class HashPublicMethodsTest < Minitest::Spec
11
11
 
12
12
  let(:data) { {"id"=>1,"name"=>"Rancid"} }
13
13
 
14
- it { BandRepresenter.new(Band.new).from_hash(data)[:id, :name].must_equal [1, "Rancid"] }
15
- it { BandRepresenter.new(Band.new).parse(data)[:id, :name].must_equal [1, "Rancid"] }
14
+ it { _(BandRepresenter.new(Band.new).from_hash(data)[:id, :name]).must_equal [1, "Rancid"] }
15
+ it { _(BandRepresenter.new(Band.new).parse(data)[:id, :name]).must_equal [1, "Rancid"] }
16
16
 
17
17
  #---
18
18
  # to_hash
19
19
  let(:band) { Band.new(1, "Rancid") }
20
20
 
21
- it { BandRepresenter.new(band).to_hash.must_equal data }
22
- it { BandRepresenter.new(band).render.must_equal data }
21
+ it { _(BandRepresenter.new(band).to_hash).must_equal data }
22
+ it { _(BandRepresenter.new(band).render).must_equal data }
23
23
  end
24
24
 
25
25
  class HashWithScalarPropertyTest < MiniTest::Spec
@@ -33,20 +33,20 @@ class HashWithScalarPropertyTest < MiniTest::Spec
33
33
 
34
34
  describe "#to_hash" do
35
35
  it "renders plain property" do
36
- album.extend(representer).to_hash.must_equal("title" => "Liar")
36
+ _(album.extend(representer).to_hash).must_equal("title" => "Liar")
37
37
  end
38
38
  end
39
39
 
40
40
 
41
41
  describe "#from_hash" do
42
42
  it "parses plain property" do
43
- album.extend(representer).from_hash("title" => "This Song Is Recycled").title.must_equal "This Song Is Recycled"
43
+ _(album.extend(representer).from_hash("title" => "This Song Is Recycled").title).must_equal "This Song Is Recycled"
44
44
  end
45
45
 
46
46
  # Fixes issue #115
47
47
  it "allows nil value in the incoming document and corresponding nil value for the represented" do
48
48
  album = Album.new
49
- album.title.must_be_nil
49
+ _(album.title).must_be_nil
50
50
  album.extend(representer).from_hash("title" => nil)
51
51
  end
52
52
  end
@@ -66,35 +66,35 @@ class HashWithTypedPropertyTest < MiniTest::Spec
66
66
 
67
67
  describe "#to_hash" do
68
68
  it "renders embedded typed property" do
69
- album.extend(representer).to_hash.must_equal("best_song" => {"name" => "Liar"})
69
+ _(album.extend(representer).to_hash).must_equal("best_song" => {"name" => "Liar"})
70
70
  end
71
71
  end
72
72
 
73
73
  describe "#from_hash" do
74
74
  it "parses embedded typed property" do
75
75
  album.extend(representer).from_hash("best_song" => {"name" => "Go With Me"})
76
- album.best_song.name.must_equal "Go With Me"
76
+ _(album.best_song.name).must_equal "Go With Me"
77
77
  end
78
78
 
79
79
  # nested nil removes nested object.
80
80
  it do
81
81
  album = Album.new(Song.new("Pre-medicated Murder"))
82
82
  album.extend(representer).from_hash("best_song" => nil)
83
- album.best_song.must_be_nil
83
+ _(album.best_song).must_be_nil
84
84
  end
85
85
 
86
86
  # nested blank hash creates blank object when not populated.
87
87
  it do
88
88
  album = Album.new#(Song.new("Pre-medicated Murder"))
89
89
  album.extend(representer).from_hash("best_song" => {})
90
- album.best_song.name.must_be_nil
90
+ _(album.best_song.name).must_be_nil
91
91
  end
92
92
 
93
93
  # Fixes issue #115
94
94
  it "allows nil value in the incoming document and corresponding nil value for the represented" do
95
95
  album = Album.new
96
96
  album.extend(representer).from_hash("best_song" => nil)
97
- album.best_song.must_be_nil
97
+ _(album.best_song).must_be_nil
98
98
  end
99
99
  end
100
100
  end
@@ -109,8 +109,8 @@ class HashWithTypedPropertyAndAs < MiniTest::Spec
109
109
 
110
110
  let(:album) { OpenStruct.new(:song => Song.new("Liar")).extend(representer) }
111
111
 
112
- it { album.to_hash.must_equal("hit" => {"name" => "Liar"}) }
113
- it { album.from_hash("hit" => {"name" => "Go With Me"}).must_equal OpenStruct.new(:song => Song.new("Go With Me")) }
112
+ it { _(album.to_hash).must_equal("hit" => {"name" => "Liar"}) }
113
+ it { _(album.from_hash("hit" => {"name" => "Go With Me"})).must_equal OpenStruct.new(:song => Song.new("Go With Me")) }
114
114
  end
115
115
  # # describe "FIXME COMBINE WITH ABOVE with :extend and :as" do
116
116
  # # hash_song = Module.new do
@@ -148,14 +148,14 @@ class HashWithTypedCollectionTest < MiniTest::Spec
148
148
 
149
149
  describe "#to_hash" do
150
150
  it "renders collection of typed property" do
151
- album.extend(representer).to_hash.must_equal("songs" => [{"name" => "Liar", "track" => 1}, {"name" => "What I Know", "track" => 2}])
151
+ _(album.extend(representer).to_hash).must_equal("songs" => [{"name" => "Liar", "track" => 1}, {"name" => "What I Know", "track" => 2}])
152
152
  end
153
153
  end
154
154
 
155
155
  describe "#from_hash" do
156
156
  it "parses collection of typed property" do
157
- album.extend(representer).from_hash("songs" => [{"name" => "One Shot Deal", "track" => 4},
158
- {"name" => "Three Way Dance", "track" => 5}]).must_equal Album.new([Song.new("One Shot Deal", 4), Song.new("Three Way Dance", 5)])
157
+ _(album.extend(representer).from_hash("songs" => [{"name" => "One Shot Deal", "track" => 4},
158
+ {"name" => "Three Way Dance", "track" => 5}])).must_equal Album.new([Song.new("One Shot Deal", 4), Song.new("Three Way Dance", 5)])
159
159
  end
160
160
  end
161
161
  end
@@ -169,14 +169,14 @@ class HashWithScalarCollectionTest < MiniTest::Spec
169
169
 
170
170
  describe "#to_hash" do
171
171
  it "renders a block style list per default" do
172
- album.extend(representer).to_hash.must_equal("songs" => ["Jackhammer", "Terrible Man"])
172
+ _(album.extend(representer).to_hash).must_equal("songs" => ["Jackhammer", "Terrible Man"])
173
173
  end
174
174
  end
175
175
 
176
176
 
177
177
  describe "#from_hash" do
178
178
  it "parses a block style list" do
179
- album.extend(representer).from_hash("songs" => ["Off Key Melody", "Sinking"]).must_equal Album.new(["Off Key Melody", "Sinking"])
179
+ _(album.extend(representer).from_hash("songs" => ["Off Key Melody", "Sinking"])).must_equal Album.new(["Off Key Melody", "Sinking"])
180
180
  end
181
181
  end
182
182
  end
@@ -35,15 +35,15 @@ class HeritageTest < Minitest::Spec
35
35
  end
36
36
 
37
37
  it "B must inherit Hello! feature from A" do
38
- B.representable_attrs.get(:id)[:extend].(nil).new(nil).hello.must_equal "Hello!"
38
+ _(B.representable_attrs.get(:id)[:extend].(nil).new(nil).hello).must_equal "Hello!"
39
39
  end
40
40
 
41
41
  it "B must have Ciao from module (feauture) Ciao" do
42
- B.representable_attrs.get(:id)[:extend].(nil).new(nil).ciao.must_equal "Ciao!"
42
+ _(B.representable_attrs.get(:id)[:extend].(nil).new(nil).ciao).must_equal "Ciao!"
43
43
  end
44
44
 
45
45
  it "C must inherit Hello! feature from A" do
46
- C.representable_attrs.get(:id)[:extend].(nil).new(nil).hello.must_equal "Hello!"
46
+ _(C.representable_attrs.get(:id)[:extend].(nil).new(nil).hello).must_equal "Hello!"
47
47
  end
48
48
 
49
49
  module M
@@ -60,6 +60,6 @@ class HeritageTest < Minitest::Spec
60
60
  let(:obj_extending_N) { Object.new.extend(N) }
61
61
 
62
62
  it "obj should inherit from N, and N from M" do
63
- obj_extending_N.hello.must_equal "Hello!"
63
+ _(obj_extending_N.hello).must_equal "Hello!"
64
64
  end
65
65
  end
data/test/if_test.rb CHANGED
@@ -44,20 +44,20 @@ class IfTest < MiniTest::Spec
44
44
  subject { OpenStruct.new(:signed_contract => false, :label => "Fat") }
45
45
 
46
46
  it "skips when false" do
47
- subject.extend(representer).to_hash.must_equal({})
47
+ _(subject.extend(representer).to_hash).must_equal({})
48
48
  end
49
49
 
50
50
  it "represents when true" do
51
51
  subject.signed_contract= true
52
- subject.extend(representer).to_hash.must_equal({"label"=>"Fat"})
52
+ _(subject.extend(representer).to_hash).must_equal({"label"=>"Fat"})
53
53
  end
54
54
 
55
55
  it "works with decorator" do
56
56
  rpr = representer
57
- Class.new(Representable::Decorator) do
57
+ _(Class.new(Representable::Decorator) do
58
58
  include Representable::Hash
59
59
  include rpr
60
- end.new(subject).to_hash.must_equal({})
60
+ end.new(subject).to_hash).must_equal({})
61
61
  end
62
62
  end
63
63
 
@@ -69,11 +69,11 @@ class IfTest < MiniTest::Spec
69
69
  subject { OpenStruct.new(:name => "Outbound").extend(representer) }
70
70
 
71
71
  it "works without specifying options" do
72
- subject.to_hash.must_equal({})
72
+ _(subject.to_hash).must_equal({})
73
73
  end
74
74
 
75
75
  it "passes user options to block" do
76
- subject.to_hash(user_options: { include_name: true }).must_equal({"name" => "Outbound"})
76
+ _(subject.to_hash(user_options: { include_name: true })).must_equal({"name" => "Outbound"})
77
77
  end
78
78
  end
79
79
  end
@@ -24,15 +24,15 @@ class IncludeExcludeTest < Minitest::Spec
24
24
  it "accepts :exclude option" do
25
25
  decorator.from_hash({"title"=>"Don't Smile In Trouble", "artist"=>{"id"=>2}}, exclude: [:title])
26
26
 
27
- song.title.must_equal "Listless"
28
- song.artist.must_equal Artist.new(nil, 2)
27
+ _(song.title).must_equal "Listless"
28
+ _(song.artist).must_equal Artist.new(nil, 2)
29
29
  end
30
30
 
31
31
  it "accepts :include option" do
32
32
  decorator.from_hash({"title"=>"Don't Smile In Trouble", "artist"=>{"id"=>2}}, include: [:title])
33
33
 
34
- song.title.must_equal "Don't Smile In Trouble"
35
- song.artist.must_equal Artist.new("7yearsbadluck", 1)
34
+ _(song.title).must_equal "Don't Smile In Trouble"
35
+ _(song.artist).must_equal Artist.new("7yearsbadluck", 1)
36
36
  end
37
37
 
38
38
  it "accepts nested :exclude/:include option" do
@@ -44,30 +44,30 @@ class IncludeExcludeTest < Minitest::Spec
44
44
  }
45
45
  )
46
46
 
47
- song.title.must_equal "Listless"
48
- song.artist.must_equal Artist.new("Foo", nil, [Song.new("Listless", nil, nil)])
47
+ _(song.title).must_equal "Listless"
48
+ _(song.artist).must_equal Artist.new("Foo", nil, [Song.new("Listless", nil, nil)])
49
49
  end
50
50
  end
51
51
 
52
52
  describe "#to_hash" do
53
53
  it "accepts :exclude option" do
54
- decorator.to_hash(exclude: [:title]).must_equal({"artist"=>{"name"=>"7yearsbadluck", "id"=>1}})
54
+ _(decorator.to_hash(exclude: [:title])).must_equal({"artist"=>{"name"=>"7yearsbadluck", "id"=>1}})
55
55
  end
56
56
 
57
57
  it "accepts :include option" do
58
- decorator.to_hash(include: [:title]).must_equal({"title"=>"Listless"})
58
+ _(decorator.to_hash(include: [:title])).must_equal({"title"=>"Listless"})
59
59
  end
60
60
 
61
61
  it "accepts nested :exclude/:include option" do
62
62
  decorator = representer.new(Song.new("Listless", Artist.new("7yearsbadluck", 1, [Song.new("C.O.A.B.I.E.T.L.")])))
63
63
 
64
- decorator.to_hash(
64
+ _(decorator.to_hash(
65
65
  exclude: [:title],
66
66
  artist: {
67
67
  exclude: [:id],
68
68
  songs: { include: [:title] }
69
69
  }
70
- ).must_equal({"artist"=>{"name"=>"7yearsbadluck", "songs"=>[{"title"=>"C.O.A.B.I.E.T.L."}]}})
70
+ )).must_equal({"artist"=>{"name"=>"7yearsbadluck", "songs"=>[{"title"=>"C.O.A.B.I.E.T.L."}]}})
71
71
  end
72
72
  end
73
73
 
@@ -82,7 +82,7 @@ class IncludeExcludeTest < Minitest::Spec
82
82
 
83
83
  # FIXME: we should test all representable-options (:include, :exclude, ?)
84
84
 
85
- Cover.new("Roxanne", Cover.new("Roxanne (Don't Put On The Red Light)")).extend(cover_rpr).
86
- to_hash(:include => [:original]).must_equal({"original"=>{"title"=>"Roxanne (Don't Put On The Red Light)"}})
85
+ _(Cover.new("Roxanne", Cover.new("Roxanne (Don't Put On The Red Light)")).extend(cover_rpr).
86
+ to_hash(:include => [:original])).must_equal({"original"=>{"title"=>"Roxanne (Don't Put On The Red Light)"}})
87
87
  end
88
88
  end
data/test/inherit_test.rb CHANGED
@@ -19,8 +19,8 @@ class InheritTest < MiniTest::Spec
19
19
  property :track, :inherit => true, :getter => lambda { |*| "n/a" }
20
20
  end
21
21
 
22
- it { SongRepresenter.prepare(song).to_hash.must_equal({"title"=>{"str"=>"Roxanne"}, "no"=>1}) }
23
- it { representer.prepare(song).to_hash.must_equal({"title"=>{"str"=>"Roxanne"}, "no"=>"n/a"}) } # as: inherited.
22
+ it { _(SongRepresenter.prepare(song).to_hash).must_equal({"title"=>{"str"=>"Roxanne"}, "no"=>1}) }
23
+ it { _(representer.prepare(song).to_hash).must_equal({"title"=>{"str"=>"Roxanne"}, "no"=>"n/a"}) } # as: inherited.
24
24
  end
25
25
 
26
26
  describe ":inherit with empty inline representer" do
@@ -32,9 +32,9 @@ class InheritTest < MiniTest::Spec
32
32
  end
33
33
  end
34
34
 
35
- it { SongRepresenter.prepare(Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash.must_equal({"title"=>{"str"=>"Believe It"}, "no"=>1}) }
35
+ it { _(SongRepresenter.prepare(Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash).must_equal({"title"=>{"str"=>"Believe It"}, "no"=>1}) }
36
36
  # the block doesn't override the inline representer.
37
- it { representer.prepare( Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash.must_equal({"title"=>{"str"=>"Believe It"}, "no"=>1}) }
37
+ it { _(representer.prepare( Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash).must_equal({"title"=>{"str"=>"Believe It"}, "no"=>1}) }
38
38
  end
39
39
 
40
40
  describe ":inherit with overriding inline representer" do
@@ -48,7 +48,7 @@ class InheritTest < MiniTest::Spec
48
48
  end
49
49
  end
50
50
 
51
- it { representer.prepare( Song.new(Struct.new(:string, :length).new("Believe It", 10), 1)).to_hash.must_equal({"title"=>{"s"=>"Believe It","length"=>10}, "no"=>1}) }
51
+ it { _(representer.prepare( Song.new(Struct.new(:string, :length).new("Believe It", 10), 1)).to_hash).must_equal({"title"=>{"s"=>"Believe It","length"=>10}, "no"=>1}) }
52
52
  end
53
53
 
54
54
  describe ":inherit with empty inline and options" do
@@ -60,8 +60,8 @@ class InheritTest < MiniTest::Spec
60
60
  end
61
61
  end
62
62
 
63
- it { SongRepresenter.prepare(Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash.must_equal({"title"=>{"str"=>"Believe It"}, "no"=>1}) }
64
- it { representer.prepare( Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash.must_equal({"name"=>{"str"=>"Believe It"}, "no"=>1}) }
63
+ it { _(SongRepresenter.prepare(Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash).must_equal({"title"=>{"str"=>"Believe It"}, "no"=>1}) }
64
+ it { _(representer.prepare( Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash).must_equal({"name"=>{"str"=>"Believe It"}, "no"=>1}) }
65
65
  end
66
66
 
67
67
  describe ":inherit with inline without block but options" do
@@ -71,8 +71,8 @@ class InheritTest < MiniTest::Spec
71
71
  property :name, :inherit => true, :as => :name # FIXME: add :getter or something else dynamic since this is double-wrapped.
72
72
  end
73
73
 
74
- it { SongRepresenter.prepare(Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash.must_equal({"title"=>{"str"=>"Believe It"}, "no"=>1}) }
75
- it { representer.prepare( Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash.must_equal({"name"=>{"str"=>"Believe It"}, "no"=>1}) }
74
+ it { _(SongRepresenter.prepare(Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash).must_equal({"title"=>{"str"=>"Believe It"}, "no"=>1}) }
75
+ it { _(representer.prepare( Song.new(Struct.new(:string).new("Believe It"), 1)).to_hash).must_equal({"name"=>{"str"=>"Believe It"}, "no"=>1}) }
76
76
  end
77
77
 
78
78
 
@@ -86,12 +86,12 @@ class InheritTest < MiniTest::Spec
86
86
  end
87
87
 
88
88
  it "replaces inherited property" do
89
- representer.representable_attrs.size.must_equal 2
89
+ _(representer.representable_attrs.size).must_equal 2
90
90
 
91
91
  definition = representer.representable_attrs.get(:track) # TODO: find a better way to assert Definition identity.
92
92
  # definition.keys.size.must_equal 2
93
- definition[:representable]. must_equal true
94
- definition.name.must_equal "track" # was "no".
93
+ _(definition[:representable]). must_equal true
94
+ _(definition.name).must_equal "track" # was "no".
95
95
  end
96
96
  end
97
97
 
@@ -119,12 +119,12 @@ class InheritTest < MiniTest::Spec
119
119
  end
120
120
  }
121
121
 
122
- it { representer.new(OpenStruct.new(hit: OpenStruct.new(title: "I WILL BE OVERRIDDEN", :length => "2:59"))).to_hash.must_equal(
122
+ it { _(representer.new(OpenStruct.new(hit: OpenStruct.new(title: "I WILL BE OVERRIDDEN", :length => "2:59"))).to_hash).must_equal(
123
123
  {"hit"=>{"title"=>"Cheap Transistor Radio"}}) }
124
124
 
125
125
  # inheriting decorator inherits inline representer class (InlineRepresenter#title).
126
126
  # inheriting decorator adds :length.
127
- it { inheriting.new(OpenStruct.new(:hit => OpenStruct.new(:title => "Hole In Your Soul", :length => "2:59"))).to_hash.must_equal(
127
+ it { _(inheriting.new(OpenStruct.new(:hit => OpenStruct.new(:title => "Hole In Your Soul", :length => "2:59"))).to_hash).must_equal(
128
128
  {"hit"=>{"title"=>"Cheap Transistor Radio", "length"=>"2:59"}}) }
129
129
  end
130
130
 
@@ -135,7 +135,7 @@ class InheritTest < MiniTest::Spec
135
135
  property :name, :inherit => true
136
136
  end
137
137
 
138
- it { representer.prepare(Song.new("The Beginning")).to_hash.must_equal({"name"=>"The Beginning"})}
138
+ it { _(representer.prepare(Song.new("The Beginning")).to_hash).must_equal({"name"=>"The Beginning"})}
139
139
  end
140
140
  end
141
141