representable 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +17 -0
  3. data/CHANGES.md +25 -0
  4. data/Gemfile +4 -12
  5. data/LICENSE +1 -1
  6. data/README.md +6 -6
  7. data/Rakefile +1 -6
  8. data/TODO +1 -3
  9. data/TODO-4.0.md +72 -0
  10. data/lib/representable.rb +19 -25
  11. data/lib/representable/binding.rb +32 -12
  12. data/lib/representable/cached.rb +1 -1
  13. data/lib/representable/coercion.rb +8 -6
  14. data/lib/representable/config.rb +13 -3
  15. data/lib/representable/debug.rb +23 -15
  16. data/lib/representable/declarative.rb +12 -7
  17. data/lib/representable/decorator.rb +1 -1
  18. data/lib/representable/definition.rb +7 -3
  19. data/lib/representable/deserializer.rb +5 -4
  20. data/lib/representable/for_collection.rb +1 -1
  21. data/lib/representable/hash.rb +9 -2
  22. data/lib/representable/hash/allow_symbols.rb +9 -11
  23. data/lib/representable/hash/binding.rb +1 -0
  24. data/lib/representable/hash/collection.rb +4 -2
  25. data/lib/representable/hash_methods.rb +3 -2
  26. data/lib/representable/insert.rb +1 -1
  27. data/lib/representable/json.rb +8 -7
  28. data/lib/representable/json/collection.rb +3 -0
  29. data/lib/representable/object.rb +1 -1
  30. data/lib/representable/object/binding.rb +5 -1
  31. data/lib/representable/option.rb +19 -0
  32. data/lib/representable/pipeline.rb +3 -2
  33. data/lib/representable/pipeline_factories.rb +4 -2
  34. data/lib/representable/populator.rb +1 -1
  35. data/lib/representable/represent.rb +1 -0
  36. data/lib/representable/serializer.rb +3 -2
  37. data/lib/representable/version.rb +1 -1
  38. data/lib/representable/virtus_coercion.rb +38 -0
  39. data/lib/representable/xml.rb +12 -10
  40. data/lib/representable/xml/binding.rb +19 -13
  41. data/lib/representable/xml/namespace.rb +122 -0
  42. data/lib/representable/yaml.rb +6 -2
  43. data/lib/representable/yaml/binding.rb +1 -0
  44. data/representable.gemspec +8 -9
  45. data/test/as_test.rb +7 -7
  46. data/test/binding_test.rb +14 -14
  47. data/test/cached_test.rb +59 -49
  48. data/test/class_test.rb +9 -9
  49. data/test/coercion_test.rb +33 -22
  50. data/test/config/inherit_test.rb +14 -14
  51. data/test/config_test.rb +20 -20
  52. data/test/decorator_scope_test.rb +4 -4
  53. data/test/decorator_test.rb +33 -20
  54. data/test/default_test.rb +8 -8
  55. data/test/defaults_options_test.rb +3 -3
  56. data/test/definition_test.rb +38 -40
  57. data/test/{example.rb → examples/example.rb} +0 -1
  58. data/test/examples/object.rb +1 -5
  59. data/test/exec_context_test.rb +8 -8
  60. data/test/features_test.rb +6 -6
  61. data/test/filter_test.rb +8 -8
  62. data/test/for_collection_test.rb +10 -10
  63. data/test/generic_test.rb +13 -13
  64. data/test/getter_setter_test.rb +5 -5
  65. data/test/hash_bindings_test.rb +1 -1
  66. data/test/hash_test.rb +45 -23
  67. data/test/heritage_test.rb +16 -13
  68. data/test/if_test.rb +9 -9
  69. data/test/include_exclude_test.rb +14 -14
  70. data/test/inherit_test.rb +18 -18
  71. data/test/inline_test.rb +24 -24
  72. data/test/instance_test.rb +31 -31
  73. data/test/is_representable_test.rb +10 -10
  74. data/test/json_test.rb +29 -7
  75. data/test/lonely_test.rb +31 -31
  76. data/test/nested_test.rb +13 -13
  77. data/test/object_test.rb +9 -9
  78. data/test/option_test.rb +36 -0
  79. data/test/parse_pipeline_test.rb +3 -5
  80. data/test/pipeline_test.rb +50 -50
  81. data/test/populator_test.rb +18 -18
  82. data/test/prepare_test.rb +4 -4
  83. data/test/private_options_test.rb +2 -2
  84. data/test/reader_writer_test.rb +2 -2
  85. data/test/render_nil_test.rb +2 -2
  86. data/test/represent_test.rb +14 -14
  87. data/test/representable_test.rb +34 -36
  88. data/test/schema_test.rb +8 -11
  89. data/test/serialize_deserialize_test.rb +2 -2
  90. data/test/skip_test.rb +14 -14
  91. data/test/stringify_hash_test.rb +3 -3
  92. data/test/test_helper.rb +26 -14
  93. data/test/uncategorized_test.rb +10 -10
  94. data/test/user_options_test.rb +4 -4
  95. data/test/virtus_coercion_test.rb +52 -0
  96. data/test/wrap_test.rb +19 -19
  97. data/test/xml_bindings_test.rb +0 -4
  98. data/test/xml_namespace_test.rb +186 -0
  99. data/test/xml_test.rb +103 -43
  100. data/test/yaml_test.rb +51 -26
  101. metadata +101 -39
  102. data/.travis.yml +0 -7
  103. data/lib/representable/TODO.getting_serious +0 -11
  104. data/lib/representable/autoload.rb +0 -10
  105. data/test/mongoid_test.rb +0 -31
@@ -22,7 +22,7 @@ class InstanceTest < BaseTest
22
22
  end
23
23
 
24
24
  song = OpenStruct.new.extend(representer).from_hash({"title" => object})
25
- song.title.must_equal object
25
+ _(song.title).must_equal object
26
26
  end
27
27
  end
28
28
 
@@ -36,11 +36,11 @@ class InstanceTest < BaseTest
36
36
  :extend => song_representer
37
37
  end
38
38
 
39
- it( "xxx") { OpenStruct.new(:song => Song.new(1, "The Answer Is Still No")).extend(representer).
40
- from_hash("song" => {"id" => 1}).song.must_equal Song.new(1, "The Answer Is Still No") }
39
+ it( "xxx") { _(OpenStruct.new(:song => Song.new(1, "The Answer Is Still No")).extend(representer).
40
+ from_hash("song" => {"id" => 1}).song).must_equal Song.new(1, "The Answer Is Still No") }
41
41
 
42
- it { OpenStruct.new(:song => Song.new(1, "The Answer Is Still No")).extend(representer).
43
- from_hash("song" => {"id" => 2}).song.must_equal Song.new(2, "Invincible") }
42
+ it { _(OpenStruct.new(:song => Song.new(1, "The Answer Is Still No")).extend(representer).
43
+ from_hash("song" => {"id" => 2}).song).must_equal Song.new(2, "Invincible") }
44
44
  end
45
45
 
46
46
 
@@ -55,13 +55,13 @@ class InstanceTest < BaseTest
55
55
  end
56
56
 
57
57
  it {
58
- album= Struct.new(:songs).new(songs = [
58
+ album= Struct.new(:songs).new([
59
59
  Song.new(1, "The Answer Is Still No"),
60
60
  Song.new(2, "")])
61
61
 
62
- album.
62
+ _(album.
63
63
  extend(representer).
64
- from_hash("songs" => [{"id" => 2},{"id" => 2, "title"=>"The Answer Is Still No"}]).songs.must_equal [
64
+ from_hash("songs" => [{"id" => 2},{"id" => 2, "title"=>"The Answer Is Still No"}]).songs).must_equal [
65
65
  Song.new(2, "Invincible"), Song.new(2, "The Answer Is Still No")]
66
66
  }
67
67
  end
@@ -71,8 +71,8 @@ class InstanceTest < BaseTest
71
71
  property :song, :instance => lambda { |options| Struct.new(:args, :id).new([options[:fragment], options[:user_options]]) }, :extend => song_representer
72
72
  end
73
73
 
74
- it { OpenStruct.new(:song => Song.new(1, "The Answer Is Still No")).extend(representer).
75
- from_hash({"song" => {"id" => 1}}, user_options: { volume: 1 }).song.args.must_equal([{"id"=>1}, {:volume=>1}]) }
74
+ it { _(OpenStruct.new(:song => Song.new(1, "The Answer Is Still No")).extend(representer).
75
+ from_hash({"song" => {"id" => 1}}, user_options: { volume: 1 }).song.args).must_equal([{"id"=>1}, {:volume=>1}]) }
76
76
  end
77
77
 
78
78
  # TODO: raise and test instance:{nil}
@@ -81,7 +81,7 @@ class InstanceTest < BaseTest
81
81
  # property :song, :instance => lambda { |*| nil }, :extend => song_representer
82
82
  # end
83
83
 
84
- # let (:hit) { hit = OpenStruct.new(:song => song).extend(representer) }
84
+ # let(:hit) { hit = OpenStruct.new(:song => song).extend(representer) }
85
85
 
86
86
  # it "calls #to_hash on song instance, nothing else" do
87
87
  # hit.to_hash.must_equal("song"=>{"title"=>"Resist Stance"})
@@ -117,13 +117,13 @@ class InstanceTest < BaseTest
117
117
  extend(representer).
118
118
  from_hash("songs" => [{"title" => "The Answer Is Still No"}, {"title" => "Invincible"}])
119
119
 
120
- album.songs.must_equal [
120
+ _(album.songs).must_equal [
121
121
  Song.new(1, "The Answer Is Still No"),
122
122
  Song.new(2, "Invincible")]
123
123
 
124
- songs.object_id.must_equal album.songs.object_id
125
- songs[0].object_id.must_equal album.songs[0].object_id
126
- songs[1].object_id.must_equal album.songs[1].object_id
124
+ _(songs.object_id).must_equal album.songs.object_id
125
+ _(songs[0].object_id).must_equal album.songs[0].object_id
126
+ _(songs[1].object_id).must_equal album.songs[1].object_id
127
127
  }
128
128
  end
129
129
 
@@ -146,17 +146,17 @@ class InstanceTest < BaseTest
146
146
  Song.new(1, "The Answer Is Still No"),
147
147
  Song.new(2, "Invncble")])
148
148
 
149
- album.
149
+ _(album.
150
150
  extend(representer).
151
151
  from_hash("songs" => [{"id" => 2, "title" => "Invincible"}]).
152
- songs.must_equal [
152
+ songs).must_equal [
153
153
  Song.new(1, "The Answer Is Still No"),
154
154
  Song.new(2, "Invincible")]
155
155
  # TODO: check elements object_id!
156
156
 
157
- songs.object_id.must_equal album.songs.object_id
158
- songs[0].object_id.must_equal album.songs[0].object_id
159
- songs[1].object_id.must_equal album.songs[1].object_id
157
+ _(songs.object_id).must_equal album.songs.object_id
158
+ _(songs[0].object_id).must_equal album.songs[0].object_id
159
+ _(songs[1].object_id).must_equal album.songs[1].object_id
160
160
  }
161
161
  end
162
162
 
@@ -178,15 +178,15 @@ class InstanceTest < BaseTest
178
178
  album= Struct.new(:songs).new(songs = [
179
179
  Song.new(1, "The Answer Is Still No")])
180
180
 
181
- album.
181
+ _(album.
182
182
  extend(representer).
183
183
  from_hash("songs" => [{"title" => "Invincible"}]).
184
- songs.must_equal [
184
+ songs).must_equal [
185
185
  Song.new(1, "The Answer Is Still No"),
186
186
  Song.new(2, "Invincible")]
187
187
 
188
- songs.object_id.must_equal album.songs.object_id
189
- songs[0].object_id.must_equal album.songs[0].object_id
188
+ _(songs.object_id).must_equal album.songs.object_id
189
+ _(songs[0].object_id).must_equal album.songs[0].object_id
190
190
  }
191
191
  end
192
192
 
@@ -212,15 +212,15 @@ class InstanceTest < BaseTest
212
212
  Song.new(1, "The Answer Is Still No"),
213
213
  Song.new(2, "Invincible")])
214
214
 
215
- album.
215
+ _(album.
216
216
  extend(representer).
217
217
  from_hash("songs" => [{"replace_id"=>2, "id" => 3, "title" => "Soulmate"}]).
218
- songs.must_equal [
218
+ songs).must_equal [
219
219
  Song.new(1, "The Answer Is Still No"),
220
220
  Song.new(3, "Soulmate")]
221
221
 
222
- songs.object_id.must_equal album.songs.object_id
223
- songs[0].object_id.must_equal album.songs[0].object_id
222
+ _(songs.object_id).must_equal album.songs.object_id
223
+ _(songs[0].object_id).must_equal album.songs[0].object_id
224
224
  }
225
225
  end
226
226
 
@@ -235,13 +235,13 @@ class InstanceTest < BaseTest
235
235
  album= Struct.new(:songs).new(songs = [
236
236
  Song.new(1, "The Answer Is Still No")])
237
237
 
238
- album.
238
+ _(album.
239
239
  extend(representer).
240
240
  from_hash("songs" => [{"title" => "Invincible"}]).
241
- songs.must_equal [
241
+ songs).must_equal [
242
242
  Song.new(nil, "Invincible")]
243
243
 
244
- songs.object_id.wont_equal album.songs.object_id
244
+ _(songs.object_id).wont_equal album.songs.object_id
245
245
  }
246
246
  end
247
247
  end
@@ -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
@@ -1,10 +1,34 @@
1
1
  require 'test_helper'
2
+ require 'json'
2
3
 
3
4
  module JsonTest
5
+ class JSONPublicMethodsTest < Minitest::Spec
6
+ #---
7
+ # from_json
8
+ class BandRepresenter < Representable::Decorator
9
+ include Representable::JSON
10
+ property :id
11
+ property :name
12
+ end
13
+
14
+ let(:json) { '{"id":1,"name":"Rancid"}' }
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"] }
18
+
19
+ #---
20
+ # to_json
21
+ let(:band) { Band.new(1, "Rancid") }
22
+
23
+ it { _(BandRepresenter.new(band).to_json).must_equal json }
24
+ it { _(BandRepresenter.new(band).render).must_equal json }
25
+ end
26
+
4
27
  class APITest < MiniTest::Spec
5
28
  Json = Representable::JSON
6
29
  Def = Representable::Definition
7
30
 
31
+
8
32
  describe "JSON module" do
9
33
  before do
10
34
  @Band = Class.new do
@@ -229,9 +253,7 @@ module JsonTest
229
253
  assert_json '{"songName":"22 Acacia Avenue"}', song.to_json
230
254
  end
231
255
  end
232
-
233
- end
234
-
256
+ end
235
257
 
236
258
  class CollectionTest < MiniTest::Spec
237
259
  describe "collection :name" do
@@ -334,20 +356,20 @@ end
334
356
  end
335
357
 
336
358
  it "renders" do
337
- 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"}})
338
360
  end
339
361
 
340
362
  describe "parsing" do
341
363
  subject { OpenStruct.new.extend(representer) }
342
- let (:hsh) { {"7"=>{"name"=>"Contemplation"}} }
364
+ let(:hsh) { {"7"=>{"name"=>"Contemplation"}} }
343
365
 
344
366
  it "parses incoming hash" do
345
- 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")})
346
368
  end
347
369
 
348
370
  it "doesn't modify the incoming hash" do
349
371
  subject.from_hash("songs"=> incoming_hash = hsh.dup)
350
- hsh.must_equal incoming_hash
372
+ _(hsh).must_equal incoming_hash
351
373
  end
352
374
  end
353
375
  end
data/test/lonely_test.rb CHANGED
@@ -12,7 +12,7 @@ class LonelyRepresenterTest < MiniTest::Spec
12
12
  ) do |format, mod, output, input|
13
13
 
14
14
  describe "[#{format}] lonely collection, render-only" do # TODO: introduce :representable option?
15
- let (:format) { format }
15
+ let(:format) { format }
16
16
 
17
17
  representer!(module: mod) do
18
18
  items do
@@ -20,7 +20,7 @@ class LonelyRepresenterTest < MiniTest::Spec
20
20
  end
21
21
  end
22
22
 
23
- let (:album) { [Song.new("Resist Stance"), Song.new("Suffer")].extend(representer) }
23
+ let(:album) { [Song.new("Resist Stance"), Song.new("Suffer")].extend(representer) }
24
24
 
25
25
  it "calls #to_hash on song instances, nothing else" do
26
26
  render(album).must_equal_document(output)
@@ -36,14 +36,14 @@ class LonelyRepresenterTest < MiniTest::Spec
36
36
  property :name
37
37
  end
38
38
 
39
- let (:decorator) { rpr = representer; Class.new(Representable::Decorator) { include Representable::Hash; include rpr } }
39
+ let(:decorator) { rpr = representer; Class.new(Representable::Decorator) { include Representable::Hash; include rpr } }
40
40
 
41
41
  describe "JSON::Collection" do
42
- let (:songs) { [Song.new("Days Go By"), Song.new("Can't Take Them All")] }
43
- let (:json) { "[{\"name\":\"Days Go By\"},{\"name\":\"Can't Take Them All\"}]" }
42
+ let(:songs) { [Song.new("Days Go By"), Song.new("Can't Take Them All")] }
43
+ let(:json) { "[{\"name\":\"Days Go By\"},{\"name\":\"Can't Take Them All\"}]" }
44
44
 
45
45
  describe "with contained objects" do
46
- let (:representer) {
46
+ let(:representer) {
47
47
  Module.new do
48
48
  include Representable::JSON::Collection
49
49
  items :class => Song, :extend => SongRepresenter
@@ -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,25 +75,25 @@ 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
83
- let (:representer) {
83
+ let(:representer) {
84
84
  Module.new do
85
85
  include Representable::JSON::Collection
86
86
  end
87
87
  }
88
- let (:songs) { ["Days Go By", "Can't Take Them All"] }
89
- let (:json) { "[\"Days Go By\",\"Can't Take Them All\"]" }
88
+ let(:songs) { ["Days Go By", "Can't Take Them All"] }
89
+ let(:json) { "[\"Days Go By\",\"Can't Take Them All\"]" }
90
90
 
91
91
  it "renders contained items #to_json" do
92
92
  assert_json json, songs.extend(representer).to_json
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,28 +112,28 @@ 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
 
119
119
  describe "JSON::Hash" do # TODO: move to HashTest.
120
120
  describe "with contained objects" do
121
- let (:representer) {
121
+ let(:representer) {
122
122
  Module.new do
123
123
  include Representable::JSON::Hash
124
124
  values :class => Song, :extend => SongRepresenter
125
125
  end
126
126
  }
127
- let (:json) { "{\"one\":{\"name\":\"Days Go By\"},\"two\":{\"name\":\"Can't Take Them All\"}}" }
128
- let (:songs) { {"one" => Song.new("Days Go By"), "two" => Song.new("Can't Take Them All")} }
127
+ let(:json) { "{\"one\":{\"name\":\"Days Go By\"},\"two\":{\"name\":\"Can't Take Them All\"}}" }
128
+ let(:songs) { {"one" => Song.new("Days Go By"), "two" => Song.new("Can't Take Them All")} }
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,23 +171,23 @@ 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
 
179
179
 
180
180
  describe "with scalar" do
181
- let (:representer) {
181
+ let(:representer) {
182
182
  Module.new do
183
183
  include Representable::JSON::Hash
184
184
  end
185
185
  }
186
- let (:json) { %{{"one":1,"two":2}} }
187
- let (:data) { {one: 2, two: 3} }
186
+ let(:json) { %{{"one":1,"two":2}} }
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
@@ -11,7 +11,7 @@ class NestedTest < MiniTest::Spec
11
11
 
12
12
  [false, true].each do |is_decorator|
13
13
  describe "::nested with (inline representer|decorator): #{is_decorator}" do
14
- let (:format) { format }
14
+ let(:format) { format }
15
15
 
16
16
  representer!(:module => mod, :decorator => is_decorator) do
17
17
  nested :label do
@@ -27,29 +27,29 @@ class NestedTest < MiniTest::Spec
27
27
  # self.representation_wrap = :album if format == :xml
28
28
  end
29
29
 
30
- let (:album) { Album.new("Epitaph", "Brett Gurewitz", 19) }
31
- let (:decorator) { representer.prepare(album) }
30
+ let(:album) { Album.new("Epitaph", "Brett Gurewitz", 19) }
31
+ let(:decorator) { representer.prepare(album) }
32
32
 
33
33
  it "renders nested Album-properties in separate section" do
34
34
  render(decorator).must_equal_document output
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
49
49
 
50
50
 
51
51
  describe "Decorator ::nested with extend:" do
52
- let (:format) { format }
52
+ let(:format) { format }
53
53
 
54
54
  representer!(:name => :label_rpr) do
55
55
  include mod
@@ -67,7 +67,7 @@ class NestedTest < MiniTest::Spec
67
67
  self.representation_wrap = :album if format == :xml
68
68
  end
69
69
 
70
- let (:album) { representer.prepare(Album.new("Epitaph", "Brett Gurewitz", 19)) }
70
+ let(:album) { representer.prepare(Album.new("Epitaph", "Brett Gurewitz", 19)) }
71
71
 
72
72
  # TODO: shared example with above.
73
73
  it "renders nested Album-properties in separate section" do
@@ -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
@@ -99,10 +99,10 @@ class NestedTest < MiniTest::Spec
99
99
  nested :label, :inherit => true, :as => "Label"
100
100
  end
101
101
 
102
- let (:album) { representer.prepare(Album.new("Epitaph", "Brett Gurewitz", 19)) }
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