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
@@ -9,9 +9,9 @@ class IsRepresentableTest < BaseTest
9
9
  end
10
10
 
11
11
  it "does extend but doesn't call #to_hash" do
12
- Struct.new(:song).new(song = Object.new).extend(representer).
13
- to_hash.must_equal("song" => song)
14
- song.must_be_kind_of Representable::Hash
12
+ _(Struct.new(:song).new(song = Object.new).extend(representer).
13
+ to_hash).must_equal("song" => song)
14
+ _(song).must_be_kind_of Representable::Hash
15
15
  end
16
16
  end
17
17
 
@@ -30,9 +30,9 @@ class IsRepresentableTest < BaseTest
30
30
  end
31
31
  end
32
32
 
33
- Struct.new(:song).new(song).extend(representer).
34
- to_hash.must_equal("song" => 1)
35
- song.wont_be_kind_of Representable::Hash
33
+ _(Struct.new(:song).new(song).extend(representer).
34
+ to_hash).must_equal("song" => 1)
35
+ _(song).wont_be_kind_of Representable::Hash
36
36
  end
37
37
  end
38
38
 
@@ -48,8 +48,8 @@ class IsRepresentableTest < BaseTest
48
48
  hit = Struct.new(:song).new.extend(representer).
49
49
  from_hash("song" => 1)
50
50
 
51
- hit.song.must_equal OpenStruct.new
52
- hit.song.must_be_kind_of Representable::Hash
51
+ _(hit.song).must_equal OpenStruct.new
52
+ _(hit.song).must_be_kind_of Representable::Hash
53
53
  end
54
54
  end
55
55
 
@@ -70,8 +70,8 @@ class IsRepresentableTest < BaseTest
70
70
  hit = Struct.new(:song).new.extend(representer).
71
71
  from_hash("song" => "Sonata No.2")
72
72
 
73
- hit.song.must_equal "Piano?"
74
- hit.song.wont_be_kind_of Representable::Hash
73
+ _(hit.song).must_equal "Piano?"
74
+ _(hit.song).wont_be_kind_of Representable::Hash
75
75
  end
76
76
  end
77
77
  end
data/test/json_test.rb CHANGED
@@ -13,15 +13,15 @@ class JSONPublicMethodsTest < Minitest::Spec
13
13
 
14
14
  let(:json) { '{"id":1,"name":"Rancid"}' }
15
15
 
16
- it { BandRepresenter.new(Band.new).from_json(json)[:id, :name].must_equal [1, "Rancid"] }
17
- it { BandRepresenter.new(Band.new).parse(json)[:id, :name].must_equal [1, "Rancid"] }
16
+ it { _(BandRepresenter.new(Band.new).from_json(json)[:id, :name]).must_equal [1, "Rancid"] }
17
+ it { _(BandRepresenter.new(Band.new).parse(json)[:id, :name]).must_equal [1, "Rancid"] }
18
18
 
19
19
  #---
20
20
  # to_json
21
21
  let(:band) { Band.new(1, "Rancid") }
22
22
 
23
- it { BandRepresenter.new(band).to_json.must_equal json }
24
- it { BandRepresenter.new(band).render.must_equal json }
23
+ it { _(BandRepresenter.new(band).to_json).must_equal json }
24
+ it { _(BandRepresenter.new(band).render).must_equal json }
25
25
  end
26
26
 
27
27
  class APITest < MiniTest::Spec
@@ -356,7 +356,7 @@ end
356
356
  end
357
357
 
358
358
  it "renders" do
359
- OpenStruct.new(:songs => {"7" => Song.new("Contemplation")}).extend(representer).to_hash.must_equal("songs"=>{"7"=>{"name"=>"Contemplation"}})
359
+ _(OpenStruct.new(:songs => {"7" => Song.new("Contemplation")}).extend(representer).to_hash).must_equal("songs"=>{"7"=>{"name"=>"Contemplation"}})
360
360
  end
361
361
 
362
362
  describe "parsing" do
@@ -364,12 +364,12 @@ end
364
364
  let(:hsh) { {"7"=>{"name"=>"Contemplation"}} }
365
365
 
366
366
  it "parses incoming hash" do
367
- subject.from_hash("songs"=>hsh).songs.must_equal({"7"=>Song.new("Contemplation")})
367
+ _(subject.from_hash("songs"=>hsh).songs).must_equal({"7"=>Song.new("Contemplation")})
368
368
  end
369
369
 
370
370
  it "doesn't modify the incoming hash" do
371
371
  subject.from_hash("songs"=> incoming_hash = hsh.dup)
372
- hsh.must_equal incoming_hash
372
+ _(hsh).must_equal incoming_hash
373
373
  end
374
374
  end
375
375
  end
data/test/lonely_test.rb CHANGED
@@ -60,11 +60,11 @@ class LonelyRepresenterTest < MiniTest::Spec
60
60
  end
61
61
 
62
62
  it "parses array" do
63
- [].extend(representer).from_json(json).must_equal songs
63
+ _([].extend(representer).from_json(json)).must_equal songs
64
64
  end
65
65
 
66
66
  it "parses array with decorator" do
67
- decorator.new([]).from_json(json).must_equal songs
67
+ _(decorator.new([]).from_json(json)).must_equal songs
68
68
  end
69
69
  end
70
70
 
@@ -75,8 +75,8 @@ class LonelyRepresenterTest < MiniTest::Spec
75
75
  end
76
76
  end
77
77
 
78
- it { songs.extend(representer).to_json.must_equal json }
79
- it { [].extend(representer).from_json(json).must_equal songs }
78
+ it { _(songs.extend(representer).to_json).must_equal json }
79
+ it { _([].extend(representer).from_json(json)).must_equal songs }
80
80
  end
81
81
 
82
82
  describe "with contained text" do
@@ -93,7 +93,7 @@ class LonelyRepresenterTest < MiniTest::Spec
93
93
  end
94
94
 
95
95
  it "returns objects array from #from_json" do
96
- [].extend(representer).from_json(json).must_equal songs
96
+ _([].extend(representer).from_json(json)).must_equal songs
97
97
  end
98
98
  end
99
99
  end
@@ -112,7 +112,7 @@ class LonelyRepresenterTest < MiniTest::Spec
112
112
  end
113
113
 
114
114
 
115
- it { [1,2].extend(representer).to_hash(user_options: {one: One, two: Two}).must_equal(["One: 1", "Two: 2"]) }
115
+ it { _([1,2].extend(representer).to_hash(user_options: {one: One, two: Two})).must_equal(["One: 1", "Two: 2"]) }
116
116
  end
117
117
 
118
118
 
@@ -129,11 +129,11 @@ class LonelyRepresenterTest < MiniTest::Spec
129
129
 
130
130
  describe "#to_json" do
131
131
  it "renders hash" do
132
- songs.extend(representer).to_json.must_equal json
132
+ _(songs.extend(representer).to_json).must_equal json
133
133
  end
134
134
 
135
135
  it "renders hash with decorator" do
136
- decorator.new(songs).to_json.must_equal json
136
+ _(decorator.new(songs).to_json).must_equal json
137
137
  end
138
138
 
139
139
  it "respects :exclude" do
@@ -147,11 +147,11 @@ class LonelyRepresenterTest < MiniTest::Spec
147
147
 
148
148
  describe "#from_json" do
149
149
  it "returns objects array" do
150
- {}.extend(representer).from_json(json).must_equal songs
150
+ _({}.extend(representer).from_json(json)).must_equal songs
151
151
  end
152
152
 
153
153
  it "parses hash with decorator" do
154
- decorator.new({}).from_json(json).must_equal songs
154
+ _(decorator.new({}).from_json(json)).must_equal songs
155
155
  end
156
156
 
157
157
  it "respects :exclude" do
@@ -171,8 +171,8 @@ class LonelyRepresenterTest < MiniTest::Spec
171
171
  end
172
172
  end
173
173
 
174
- it { songs.extend(representer).to_json.must_equal json }
175
- it { {}.extend(representer).from_json(json).must_equal songs }
174
+ it { _(songs.extend(representer).to_json).must_equal json }
175
+ it { _({}.extend(representer).from_json(json)).must_equal songs }
176
176
  end
177
177
  end
178
178
 
@@ -187,7 +187,7 @@ class LonelyRepresenterTest < MiniTest::Spec
187
187
  let(:data) { {one: 2, two: 3} }
188
188
 
189
189
  describe "#to_json" do
190
- it { data.extend(representer).to_json.must_equal %{{"one":2,"two":3}} }
190
+ it { _(data.extend(representer).to_json).must_equal %{{"one":2,"two":3}} }
191
191
 
192
192
  # it "respects :exclude" do
193
193
  # assert_json "{\"two\":{\"name\":\"Can't Take Them All\"}}", {:one => Song.new("Days Go By"), :two => Song.new("Can't Take Them All")}.extend(representer).to_json(:exclude => [:one])
@@ -199,7 +199,7 @@ class LonelyRepresenterTest < MiniTest::Spec
199
199
  end
200
200
 
201
201
  describe "#from_json" do # FIXME: what's the point of this?
202
- it { data.extend(representer).from_hash(data).must_equal data }
202
+ it { _(data.extend(representer).from_hash(data)).must_equal data }
203
203
  end
204
204
  end
205
205
 
@@ -234,6 +234,6 @@ class CollectionWithIncludeTest < MiniTest::Spec
234
234
  end
235
235
  end
236
236
 
237
- it { representer.new([Song.new(1, "ACAB")]).to_hash.must_equal([{"id"=>1, "title"=>"ACAB"}]) }
238
- it { representer.new([Song.new(1, "ACAB")]).to_hash(include: [:title]).must_equal([{"title"=>"ACAB"}]) }
237
+ it { _(representer.new([Song.new(1, "ACAB")]).to_hash).must_equal([{"id"=>1, "title"=>"ACAB"}]) }
238
+ it { _(representer.new([Song.new(1, "ACAB")]).to_hash(include: [:title])).must_equal([{"title"=>"ACAB"}]) }
239
239
  end
data/test/nested_test.rb CHANGED
@@ -35,14 +35,14 @@ class NestedTest < MiniTest::Spec
35
35
 
36
36
  # do not use extend on the nested object. # FIXME: make this a proper test with two describes instead of this pseudo-meta stuff.
37
37
  if is_decorator==true
38
- album.wont_be_kind_of(Representable::Hash)
38
+ _(album).wont_be_kind_of(Representable::Hash)
39
39
  end
40
40
  end
41
41
 
42
42
  it "parses nested properties to Album instance" do
43
43
  album = parse(representer.prepare(Album.new), output)
44
- album.label.must_equal "Epitaph"
45
- album.owner.must_equal "Brett Gurewitz"
44
+ _(album.label).must_equal "Epitaph"
45
+ _(album.owner).must_equal "Brett Gurewitz"
46
46
  end
47
47
  end
48
48
  end
@@ -76,9 +76,9 @@ class NestedTest < MiniTest::Spec
76
76
 
77
77
  it "parses nested properties to Album instance" do
78
78
  album = parse(representer.prepare(Album.new), output)
79
- album.label.must_equal "Epitaph"
80
- album.owner.must_equal "Brett Gurewitz"
81
- album.amount.must_equal 19
79
+ _(album.label).must_equal "Epitaph"
80
+ _(album.owner).must_equal "Brett Gurewitz"
81
+ _(album.amount).must_equal 19
82
82
  end
83
83
  end
84
84
  end
@@ -102,7 +102,7 @@ class NestedTest < MiniTest::Spec
102
102
  let(:album) { representer.prepare(Album.new("Epitaph", "Brett Gurewitz", 19)) }
103
103
 
104
104
  it "renders nested Album-properties in separate section" do
105
- representer.prepare(album).to_hash.must_equal({"Label"=>{"owner"=>"Brett Gurewitz"}})
105
+ _(representer.prepare(album).to_hash).must_equal({"Label"=>{"owner"=>"Brett Gurewitz"}})
106
106
  end
107
107
 
108
108
  # it "parses nested properties to Album instance" do
data/test/object_test.rb CHANGED
@@ -24,17 +24,17 @@ class ObjectTest < MiniTest::Spec
24
24
  it do
25
25
  representer.prepare(target).from_object(source)
26
26
 
27
- target.title.must_equal "The King Is Dead"
28
- target.album.name.must_equal "RUINER"
29
- target.album.songs[0].title.must_equal "IN VINO VERITAS II"
27
+ _(target.title).must_equal "The King Is Dead"
28
+ _(target.album.name).must_equal "RUINER"
29
+ _(target.album.songs[0].title).must_equal "IN VINO VERITAS II"
30
30
  end
31
31
 
32
32
  # ignore nested object when nil
33
33
  it do
34
34
  representer.prepare(Song.new("The King Is Dead")).from_object(Song.new)
35
35
 
36
- target.title.must_be_nil # scalar property gets overridden when nil.
37
- target.album.must_be_nil # nested property stays nil.
36
+ _(target.title).must_be_nil # scalar property gets overridden when nil.
37
+ _(target.album).must_be_nil # nested property stays nil.
38
38
  end
39
39
 
40
40
  # to_object
@@ -53,8 +53,8 @@ class ObjectTest < MiniTest::Spec
53
53
 
54
54
  it do
55
55
  representer.prepare(source).to_object
56
- source.album.name.must_equal "Live"
57
- source.album.songs[0].title.must_equal 1
56
+ _(source.album.name).must_equal "Live"
57
+ _(source.album.songs[0].title).must_equal 1
58
58
  end
59
59
  end
60
60
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class OptionTest < MiniTest::Spec
6
+ class Callable
7
+ include Uber::Callable
8
+ def call(*); "callable" end
9
+ end
10
+
11
+ class MyRepresenter < Representable::Decorator
12
+ include Representable::JSON
13
+
14
+ property :static, getter: "static"
15
+ property :symbol, getter: :symbol
16
+ property :proc, getter: ->(*) { "proc" }
17
+ property :callable, getter: Callable.new
18
+ end
19
+
20
+ Album = Struct.new(:static) do
21
+ def symbol(*); "symbol" end
22
+ end
23
+
24
+ let(:album_representer) { MyRepresenter.new(Album.new) }
25
+
26
+ describe ::Representable::Option do
27
+ it "supports all types of callables (method, proc, static etc)" do
28
+ _(album_representer.to_hash).must_equal({
29
+ "static" => "static",
30
+ "symbol" => "symbol",
31
+ "proc" => "proc",
32
+ "callable" => "callable",
33
+ })
34
+ end
35
+ end
36
+ end
@@ -22,12 +22,12 @@ class ParsePipelineTest < MiniTest::Spec
22
22
 
23
23
  it do
24
24
  representer.new(album = Album.new).from_hash("songs"=>nil)
25
- album.songs.must_equal []
25
+ _(album.songs).must_equal []
26
26
  end
27
27
 
28
28
  it do
29
29
  representer.new(album = Album.new).from_hash("songs"=>[{"title" => "Business Conduct"}])
30
- album.songs.must_equal [Song.new("Business Conduct")]
30
+ _(album.songs).must_equal [Song.new("Business Conduct")]
31
31
  end
32
32
  end
33
33
 
@@ -57,6 +57,6 @@ class ParsePipelineTest < MiniTest::Spec
57
57
  skip "TODO: implement :parse_pipeline and :render_pipeline, and before/after/replace semantics"
58
58
  album = Album.new
59
59
  Representer.new(album).from_hash({"artist"=>{"email"=>"yo"}, "songs"=>[{"title"=>"Affliction"}, {"title"=>"Dream Beater"}]})
60
- album.songs.must_equal([Song.new("Affliction"), Song.new("Dream Beater")])
60
+ _(album.songs).must_equal([Song.new("Affliction"), Song.new("Dream Beater")])
61
61
  end
62
62
  end
@@ -24,15 +24,15 @@ class PipelineTest < MiniTest::Spec
24
24
  AssignFragment = ->(input, options) { options[:fragment] = input }
25
25
 
26
26
  it "linear" do
27
- P[SkipParse, Setter].("doc", {fragment: 1}).must_equal "Setter(doc)"
27
+ _(P[SkipParse, Setter].("doc", {fragment: 1})).must_equal "Setter(doc)"
28
28
 
29
29
 
30
30
  # parse style.
31
- P[AssignFragment, SkipParse, CreateObject, Prepare].("Bla", {}).must_equal "Prepare(#<OpenStruct>)"
31
+ _(P[AssignFragment, SkipParse, CreateObject, Prepare].("Bla", {})).must_equal "Prepare(#<OpenStruct>)"
32
32
 
33
33
 
34
34
  # render style.
35
- P[Getter, StopOnNil, SkipRender, Prepare, Setter].(nil, {}).
35
+ _(P[Getter, StopOnNil, SkipRender, Prepare, Setter].(nil, {})).
36
36
  must_equal "Setter(Prepare(Yo))"
37
37
 
38
38
  # pipeline = Representable::Pipeline[SkipParse , SetResult, ModifyResult]
@@ -46,8 +46,8 @@ class PipelineTest < MiniTest::Spec
46
46
 
47
47
 
48
48
  pipeline = Representable::Pipeline[SkipParse, Stopping, Prepare]
49
- pipeline.(nil, fragment: "oy!").must_equal "Prepare()"
50
- pipeline.(nil, fragment: "stop!").must_equal Representable::Pipeline::Stop
49
+ _(pipeline.(nil, fragment: "oy!")).must_equal "Prepare()"
50
+ _(pipeline.(nil, fragment: "stop!")).must_equal Representable::Pipeline::Stop
51
51
  end
52
52
 
53
53
  describe "Collect" do
@@ -55,11 +55,11 @@ class PipelineTest < MiniTest::Spec
55
55
  Add = ->(input, options) { "#{input}+" }
56
56
  let(:pipeline) { R::Collect[Reverse, Add] }
57
57
 
58
- it { pipeline.(["yo!", "oy!"], {}).must_equal ["!oy+", "!yo+"] }
58
+ it { _(pipeline.(["yo!", "oy!"], {})).must_equal ["!oy+", "!yo+"] }
59
59
 
60
60
  describe "Pipeline with Collect" do
61
61
  let(:pipeline) { P[Reverse, R::Collect[Reverse, Add]] }
62
- it { pipeline.(["yo!", "oy!"], {}).must_equal ["!yo+", "!oy+"] }
62
+ it { _(pipeline.(["yo!", "oy!"], {})).must_equal ["!yo+", "!oy+"] }
63
63
  end
64
64
  end
65
65
 
@@ -76,26 +76,26 @@ class PipelineTest < MiniTest::Spec
76
76
 
77
77
  it "rendering scalar property" do
78
78
  doc = {}
79
- P[
79
+ _(P[
80
80
  R::GetValue,
81
81
  R::StopOnSkipable,
82
82
  R::AssignName,
83
83
  R::WriteFragment
84
- ].(nil, {represented: Song.new("Lime Green"), binding: title, doc: doc}).must_equal "Lime Green"
84
+ ].(nil, {represented: Song.new("Lime Green"), binding: title, doc: doc})).must_equal "Lime Green"
85
85
 
86
- doc.must_equal({"title"=>"Lime Green"})
86
+ _(doc).must_equal({"title"=>"Lime Green"})
87
87
  end
88
88
 
89
89
  it "parsing scalar property" do
90
- P[
90
+ _(P[
91
91
  R::AssignName,
92
92
  R::ReadFragment,
93
93
  R::StopOnNotFound,
94
94
  R::OverwriteOnNil,
95
95
  # R::SkipParse,
96
96
  R::SetValue,
97
- ].extend(P::Debug).(doc={"title"=>"Eruption"}, {represented: song=Song.new("Lime Green"), binding: title, doc: doc}).must_equal "Eruption"
98
- song.title.must_equal "Eruption"
97
+ ].extend(P::Debug).(doc={"title"=>"Eruption"}, {represented: song=Song.new("Lime Green"), binding: title, doc: doc})).must_equal "Eruption"
98
+ _(song.title).must_equal "Eruption"
99
99
  end
100
100
 
101
101
 
@@ -115,7 +115,7 @@ class PipelineTest < MiniTest::Spec
115
115
 
116
116
  it "rendering typed property" do
117
117
  doc = {}
118
- P[
118
+ _(P[
119
119
  R::GetValue,
120
120
  R::StopOnSkipable,
121
121
  R::StopOnNil,
@@ -123,13 +123,13 @@ class PipelineTest < MiniTest::Spec
123
123
  R::Serialize,
124
124
  R::AssignName,
125
125
  R::WriteFragment
126
- ].extend(P::Debug).(nil, {represented: song_model, binding: artist, doc: doc, options: {}}).must_equal({"name" => "Diesel Boy"})
126
+ ].extend(P::Debug).(nil, {represented: song_model, binding: artist, doc: doc, options: {}})).must_equal({"name" => "Diesel Boy"})
127
127
 
128
- doc.must_equal({"artist"=>{"name"=>"Diesel Boy"}})
128
+ _(doc).must_equal({"artist"=>{"name"=>"Diesel Boy"}})
129
129
  end
130
130
 
131
131
  it "parsing typed property" do
132
- P[
132
+ _(P[
133
133
  R::AssignName,
134
134
  R::ReadFragment,
135
135
  R::StopOnNotFound,
@@ -139,8 +139,8 @@ class PipelineTest < MiniTest::Spec
139
139
  R::Decorate,
140
140
  R::Deserialize,
141
141
  R::SetValue,
142
- ].extend(P::Debug).(doc={"artist"=>{"name"=>"Doobie Brothers"}}, {represented: song_model, binding: artist, doc: doc, options: {}}).must_equal model=Artist.new("Doobie Brothers")
143
- song_model.artist.must_equal model
142
+ ].extend(P::Debug).(doc={"artist"=>{"name"=>"Doobie Brothers"}}, {represented: song_model, binding: artist, doc: doc, options: {}})).must_equal model=Artist.new("Doobie Brothers")
143
+ _(song_model.artist).must_equal model
144
144
  end
145
145
 
146
146
 
@@ -153,7 +153,7 @@ class PipelineTest < MiniTest::Spec
153
153
  }
154
154
  it "render scalar collection" do
155
155
  doc = {}
156
- P[
156
+ _(P[
157
157
  R::GetValue,
158
158
  R::StopOnSkipable,
159
159
  R::Collect[
@@ -161,9 +161,9 @@ class PipelineTest < MiniTest::Spec
161
161
  ],
162
162
  R::AssignName,
163
163
  R::WriteFragment
164
- ].extend(P::Debug).(nil, {represented: Album.new([1,2,3]), binding: ratings, doc: doc, options: {}}).must_equal([1,2,3])
164
+ ].extend(P::Debug).(nil, {represented: Album.new([1,2,3]), binding: ratings, doc: doc, options: {}})).must_equal([1,2,3])
165
165
 
166
- doc.must_equal({"ratings"=>[1,2,3]})
166
+ _(doc).must_equal({"ratings"=>[1,2,3]})
167
167
  end
168
168
 
169
169
  ######### collection :songs, extend: SongRepresenter
@@ -174,7 +174,7 @@ class PipelineTest < MiniTest::Spec
174
174
  }
175
175
  it "render typed collection" do
176
176
  doc = {}
177
- P[
177
+ _(P[
178
178
  R::GetValue,
179
179
  R::StopOnSkipable,
180
180
  R::Collect[
@@ -183,16 +183,16 @@ class PipelineTest < MiniTest::Spec
183
183
  ],
184
184
  R::AssignName,
185
185
  R::WriteFragment
186
- ].extend(P::Debug).(nil, {represented: Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van Halen")]), binding: artists, doc: doc, options: {}}).must_equal([{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}])
186
+ ].extend(P::Debug).(nil, {represented: Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van Halen")]), binding: artists, doc: doc, options: {}})).must_equal([{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}])
187
187
 
188
- doc.must_equal({"artists"=>[{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}]})
188
+ _(doc).must_equal({"artists"=>[{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}]})
189
189
  end
190
190
 
191
191
  let(:album_model) { Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van Halen")]) }
192
192
 
193
193
  it "parse typed collection" do
194
194
  doc = {"artists"=>[{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}]}
195
- P[
195
+ _(P[
196
196
  R::AssignName,
197
197
  R::ReadFragment,
198
198
  R::StopOnNotFound,
@@ -205,9 +205,9 @@ let(:album_model) { Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van Ha
205
205
  R::Deserialize,
206
206
  ],
207
207
  R::SetValue,
208
- ].extend(P::Debug).(doc, {represented: album_model, binding: artists, doc: doc, options: {}}).must_equal([Artist.new("Diesel Boy"), Artist.new("Van Halen")])
208
+ ].extend(P::Debug).(doc, {represented: album_model, binding: artists, doc: doc, options: {}})).must_equal([Artist.new("Diesel Boy"), Artist.new("Van Halen")])
209
209
 
210
- album_model.artists.must_equal([Artist.new("Diesel Boy"), Artist.new("Van Halen")])
210
+ _(album_model.artists).must_equal([Artist.new("Diesel Boy"), Artist.new("Van Halen")])
211
211
  end
212
212
 
213
213
  # TODO: test with arrays, too, not "only" Pipeline instances.
@@ -215,41 +215,41 @@ let(:album_model) { Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van Ha
215
215
  let(:pipeline) { P[R::GetValue, R::StopOnSkipable, R::StopOnNil] }
216
216
 
217
217
  it "returns Pipeline instance when passing in Pipeline instance" do
218
- P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable).must_be_instance_of(R::Pipeline)
218
+ _(P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable)).must_be_instance_of(R::Pipeline)
219
219
  end
220
220
 
221
221
  it "replaces if exists" do
222
222
  # pipeline.insert!(R::Default, replace: R::StopOnSkipable)
223
- P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable).must_equal P[R::GetValue, R::Default, R::StopOnNil]
224
- pipeline.must_equal P[R::GetValue, R::StopOnSkipable, R::StopOnNil]
223
+ _(P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable)).must_equal P[R::GetValue, R::Default, R::StopOnNil]
224
+ _(pipeline).must_equal P[R::GetValue, R::StopOnSkipable, R::StopOnNil]
225
225
  end
226
226
 
227
227
  it "replaces Function instance" do
228
228
  pipeline = P[R::Prepare, R::StopOnSkipable, R::StopOnNil]
229
- P::Insert.(pipeline, R::Default, replace: R::Prepare).must_equal P[R::Default, R::StopOnSkipable, R::StopOnNil]
230
- pipeline.must_equal P[R::Prepare, R::StopOnSkipable, R::StopOnNil]
229
+ _(P::Insert.(pipeline, R::Default, replace: R::Prepare)).must_equal P[R::Default, R::StopOnSkipable, R::StopOnNil]
230
+ _(pipeline).must_equal P[R::Prepare, R::StopOnSkipable, R::StopOnNil]
231
231
  end
232
232
 
233
233
  it "does not replace when not existing" do
234
234
  P::Insert.(pipeline, R::Default, replace: R::Prepare)
235
- pipeline.must_equal P[R::GetValue, R::StopOnSkipable, R::StopOnNil]
235
+ _(pipeline).must_equal P[R::GetValue, R::StopOnSkipable, R::StopOnNil]
236
236
  end
237
237
 
238
238
  it "applies on nested Collect" do
239
239
  pipeline = P[R::GetValue, R::Collect[R::GetValue, R::StopOnSkipable], R::StopOnNil]
240
240
 
241
- P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable).extend(P::Debug).inspect.must_equal "Pipeline[GetValue, Collect[GetValue, Default], StopOnNil]"
242
- pipeline.must_equal P[R::GetValue, R::Collect[R::GetValue, R::StopOnSkipable], R::StopOnNil]
241
+ _(P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable).extend(P::Debug).inspect).must_equal "Pipeline[GetValue, Collect[GetValue, Default], StopOnNil]"
242
+ _(pipeline).must_equal P[R::GetValue, R::Collect[R::GetValue, R::StopOnSkipable], R::StopOnNil]
243
243
 
244
244
 
245
- P::Insert.(pipeline, R::Default, replace: R::StopOnNil).extend(P::Debug).inspect.must_equal "Pipeline[GetValue, Collect[GetValue, StopOnSkipable], Default]"
245
+ _(P::Insert.(pipeline, R::Default, replace: R::StopOnNil).extend(P::Debug).inspect).must_equal "Pipeline[GetValue, Collect[GetValue, StopOnSkipable], Default]"
246
246
  end
247
247
 
248
248
  it "applies on nested Collect with Function::CreateObject" do
249
249
  pipeline = P[R::GetValue, R::Collect[R::GetValue, R::CreateObject], R::StopOnNil]
250
250
 
251
- P::Insert.(pipeline, R::Default, replace: R::CreateObject).extend(P::Debug).inspect.must_equal "Pipeline[GetValue, Collect[GetValue, Default], StopOnNil]"
252
- pipeline.must_equal P[R::GetValue, R::Collect[R::GetValue, R::CreateObject], R::StopOnNil]
251
+ _(P::Insert.(pipeline, R::Default, replace: R::CreateObject).extend(P::Debug).inspect).must_equal "Pipeline[GetValue, Collect[GetValue, Default], StopOnNil]"
252
+ _(pipeline).must_equal P[R::GetValue, R::Collect[R::GetValue, R::CreateObject], R::StopOnNil]
253
253
  end
254
254
  end
255
255
 
@@ -257,8 +257,8 @@ let(:album_model) { Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van Ha
257
257
  let(:pipeline) { P[R::GetValue, R::StopOnNil] }
258
258
 
259
259
  it do
260
- P::Insert.(pipeline, R::GetValue, delete: true).extend(P::Debug).inspect.must_equal "Pipeline[StopOnNil]"
261
- pipeline.extend(P::Debug).inspect.must_equal "Pipeline[GetValue, StopOnNil]"
260
+ _(P::Insert.(pipeline, R::GetValue, delete: true).extend(P::Debug).inspect).must_equal "Pipeline[StopOnNil]"
261
+ _(pipeline.extend(P::Debug).inspect).must_equal "Pipeline[GetValue, StopOnNil]"
262
262
  end
263
263
  end
264
264
 
@@ -266,8 +266,8 @@ let(:album_model) { Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van Ha
266
266
  let(:pipeline) { P[R::GetValue, R::Collect[R::GetValue, R::StopOnSkipable], R::StopOnNil] }
267
267
 
268
268
  it do
269
- P::Insert.(pipeline, R::GetValue, delete: true).extend(P::Debug).inspect.must_equal "Pipeline[Collect[StopOnSkipable], StopOnNil]"
270
- pipeline.extend(P::Debug).inspect.must_equal "Pipeline[GetValue, Collect[GetValue, StopOnSkipable], StopOnNil]"
269
+ _(P::Insert.(pipeline, R::GetValue, delete: true).extend(P::Debug).inspect).must_equal "Pipeline[Collect[StopOnSkipable], StopOnNil]"
270
+ _(pipeline.extend(P::Debug).inspect).must_equal "Pipeline[GetValue, Collect[GetValue, StopOnSkipable], StopOnNil]"
271
271
  end
272
272
  end
273
273
  end
@@ -20,7 +20,7 @@ class PopulatorTest < Minitest::Spec
20
20
 
21
21
  it do
22
22
  album.extend(representer).from_hash("songs"=>[{"id"=>1}, {"id"=>2}], "artist"=>{"name"=>"Waste"})
23
- album.inspect.must_equal "#<struct PopulatorTest::Album songs=[#<struct PopulatorTest::Song id=1>, #<struct PopulatorTest::Song id=2>], artist=#<struct PopulatorTest::Artist name=\"Waste\">>"
23
+ _(album.inspect).must_equal "#<struct PopulatorTest::Album songs=[#<struct PopulatorTest::Song id=1>, #<struct PopulatorTest::Song id=2>], artist=#<struct PopulatorTest::Artist name=\"Waste\">>"
24
24
  end
25
25
  end
26
26
 
@@ -37,7 +37,7 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
37
37
  end
38
38
  end
39
39
 
40
- Composer = Struct.new(:song)
40
+ Composer = Class.new
41
41
  Composer.class_eval do
42
42
  def song=(v)
43
43
  @song = v
@@ -60,17 +60,17 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
60
60
  it "finds by :id and creates new without :id" do
61
61
  album.from_hash({"song"=>{"id" => 1, "title"=>"Resist Stance"}})
62
62
 
63
- album.song.title.must_equal "Resist Stance" # note how title is updated from "Resist Stan"
64
- album.song.id.must_equal 1
65
- album.song.uid.must_equal "abcd" # not changed via populator, indicating this is a formerly "persisted" object.
63
+ _(album.song.title).must_equal "Resist Stance" # note how title is updated from "Resist Stan"
64
+ _(album.song.id).must_equal 1
65
+ _(album.song.uid).must_equal "abcd" # not changed via populator, indicating this is a formerly "persisted" object.
66
66
  end
67
67
 
68
68
  it "creates new without :id" do
69
69
  album.from_hash({"song"=>{"title"=>"Lower"}})
70
70
 
71
- album.song.title.must_equal "Lower"
72
- album.song.id.must_be_nil
73
- album.song.uid.must_be_nil
71
+ _(album.song.title).must_equal "Lower"
72
+ _(album.song.id).must_be_nil
73
+ _(album.song.uid).must_be_nil
74
74
  end
75
75
  end
76
76
 
@@ -90,16 +90,16 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
90
90
  {"title"=>"Suffer"}
91
91
  ]})
92
92
 
93
- album.songs[0].title.must_equal "Resist Stance" # note how title is updated from "Resist Stan"
94
- album.songs[0].id.must_equal 1
95
- album.songs[0].uid.must_equal "abcd" # not changed via populator, indicating this is a formerly "persisted" object.
93
+ _(album.songs[0].title).must_equal "Resist Stance" # note how title is updated from "Resist Stan"
94
+ _(album.songs[0].id).must_equal 1
95
+ _(album.songs[0].uid).must_equal "abcd" # not changed via populator, indicating this is a formerly "persisted" object.
96
96
 
97
- album.songs[1].title.must_equal "Suffer"
98
- album.songs[1].id.must_be_nil
99
- album.songs[1].uid.must_be_nil
97
+ _(album.songs[1].title).must_equal "Suffer"
98
+ _(album.songs[1].id).must_be_nil
99
+ _(album.songs[1].uid).must_be_nil
100
100
  end
101
101
 
102
102
  # TODO: test with existing collection
103
103
  end
104
104
 
105
- end
105
+ end
data/test/prepare_test.rb CHANGED
@@ -28,7 +28,7 @@ class PrepareTest < BaseTest
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
 
@@ -60,7 +60,7 @@ class PrepareTest < BaseTest
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