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
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
@@ -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