representable 3.0.3 → 3.0.4
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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/CHANGES.md +5 -0
- data/README.md +1 -1
- data/TODO +1 -3
- data/TODO-4.0.md +72 -0
- data/lib/representable/declarative.rb +3 -3
- data/lib/representable/deserializer.rb +1 -1
- data/lib/representable/serializer.rb +1 -1
- data/lib/representable/version.rb +1 -1
- data/lib/representable/xml.rb +6 -4
- data/lib/representable/xml/binding.rb +19 -12
- data/lib/representable/xml/namespace.rb +122 -0
- data/representable.gemspec +2 -2
- data/test/as_test.rb +2 -2
- data/test/binding_test.rb +7 -7
- data/test/cached_test.rb +13 -13
- data/test/class_test.rb +2 -2
- data/test/coercion_test.rb +1 -1
- data/test/config_test.rb +5 -5
- data/test/decorator_scope_test.rb +1 -1
- data/test/decorator_test.rb +8 -8
- data/test/default_test.rb +1 -1
- data/test/defaults_options_test.rb +3 -3
- data/test/definition_test.rb +9 -11
- data/test/examples/object.rb +1 -5
- data/test/exec_context_test.rb +2 -2
- data/test/features_test.rb +3 -3
- data/test/filter_test.rb +2 -2
- data/test/for_collection_test.rb +8 -8
- data/test/generic_test.rb +11 -11
- data/test/hash_bindings_test.rb +1 -1
- data/test/hash_test.rb +13 -13
- data/test/heritage_test.rb +16 -13
- data/test/if_test.rb +3 -3
- data/test/include_exclude_test.rb +2 -2
- data/test/inherit_test.rb +3 -3
- data/test/inline_test.rb +13 -13
- data/test/instance_test.rb +2 -2
- data/test/json_test.rb +4 -6
- data/test/lonely_test.rb +15 -15
- data/test/nested_test.rb +6 -6
- data/test/object_test.rb +4 -4
- data/test/parse_pipeline_test.rb +0 -2
- data/test/pipeline_test.rb +7 -7
- data/test/populator_test.rb +7 -7
- data/test/prepare_test.rb +2 -2
- data/test/represent_test.rb +10 -10
- data/test/representable_test.rb +7 -7
- data/test/schema_test.rb +3 -6
- data/test/skip_test.rb +6 -6
- data/test/test_helper.rb +16 -6
- data/test/wrap_test.rb +8 -8
- data/test/xml_namespace_test.rb +186 -0
- data/test/xml_test.rb +53 -34
- data/test/yaml_test.rb +11 -11
- metadata +9 -7
- data/lib/representable/TODO.getting_serious +0 -11
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
|
14
|
+
let(:format) { format }
|
15
15
|
|
16
16
|
representer!(:module => mod, :decorator => is_decorator) do
|
17
17
|
nested :label do
|
@@ -27,8 +27,8 @@ class NestedTest < MiniTest::Spec
|
|
27
27
|
# self.representation_wrap = :album if format == :xml
|
28
28
|
end
|
29
29
|
|
30
|
-
let
|
31
|
-
let
|
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
|
@@ -49,7 +49,7 @@ class NestedTest < MiniTest::Spec
|
|
49
49
|
|
50
50
|
|
51
51
|
describe "Decorator ::nested with extend:" do
|
52
|
-
let
|
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
|
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
|
@@ -99,7 +99,7 @@ class NestedTest < MiniTest::Spec
|
|
99
99
|
nested :label, :inherit => true, :as => "Label"
|
100
100
|
end
|
101
101
|
|
102
|
-
let
|
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
105
|
representer.prepare(album).to_hash.must_equal({"Label"=>{"owner"=>"Brett Gurewitz"}})
|
data/test/object_test.rb
CHANGED
@@ -18,8 +18,8 @@ class ObjectTest < MiniTest::Spec
|
|
18
18
|
# TODO: collection
|
19
19
|
end
|
20
20
|
|
21
|
-
let
|
22
|
-
let
|
21
|
+
let(:source) { Song.new("The King Is Dead", Album.new("Ruiner", [Song.new("In Vino Veritas II")])) }
|
22
|
+
let(:target) { Song.new }
|
23
23
|
|
24
24
|
it do
|
25
25
|
representer.prepare(target).from_object(source)
|
@@ -33,8 +33,8 @@ class ObjectTest < MiniTest::Spec
|
|
33
33
|
it do
|
34
34
|
representer.prepare(Song.new("The King Is Dead")).from_object(Song.new)
|
35
35
|
|
36
|
-
target.title.
|
37
|
-
target.album.
|
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
|
data/test/parse_pipeline_test.rb
CHANGED
@@ -45,7 +45,6 @@ class ParsePipelineTest < MiniTest::Spec
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def instance!(*options)
|
48
|
-
puts "@@@@@ #{options.inspect}"
|
49
48
|
Song.new
|
50
49
|
end
|
51
50
|
|
@@ -59,6 +58,5 @@ class ParsePipelineTest < MiniTest::Spec
|
|
59
58
|
album = Album.new
|
60
59
|
Representer.new(album).from_hash({"artist"=>{"email"=>"yo"}, "songs"=>[{"title"=>"Affliction"}, {"title"=>"Dream Beater"}]})
|
61
60
|
album.songs.must_equal([Song.new("Affliction"), Song.new("Dream Beater")])
|
62
|
-
puts album.inspect
|
63
61
|
end
|
64
62
|
end
|
data/test/pipeline_test.rb
CHANGED
@@ -68,7 +68,7 @@ class PipelineTest < MiniTest::Spec
|
|
68
68
|
|
69
69
|
######### scalar property
|
70
70
|
|
71
|
-
let
|
71
|
+
let(:title) {
|
72
72
|
dfn = R::Definition.new(:title)
|
73
73
|
|
74
74
|
R::Hash::Binding.new(dfn)
|
@@ -105,13 +105,13 @@ class PipelineTest < MiniTest::Spec
|
|
105
105
|
property :name
|
106
106
|
end
|
107
107
|
|
108
|
-
let
|
108
|
+
let(:artist) {
|
109
109
|
dfn = R::Definition.new(:artist, extend: ArtistRepresenter, class: Artist)
|
110
110
|
|
111
111
|
R::Hash::Binding.new(dfn)
|
112
112
|
}
|
113
113
|
|
114
|
-
let
|
114
|
+
let(:song_model) { Song.new("Lime Green", Artist.new("Diesel Boy")) }
|
115
115
|
|
116
116
|
it "rendering typed property" do
|
117
117
|
doc = {}
|
@@ -146,7 +146,7 @@ class PipelineTest < MiniTest::Spec
|
|
146
146
|
|
147
147
|
######### collection :ratings
|
148
148
|
|
149
|
-
let
|
149
|
+
let(:ratings) {
|
150
150
|
dfn = R::Definition.new(:ratings, collection: true, skip_render: ->(*) { false })
|
151
151
|
|
152
152
|
R::Hash::Binding::Collection.new(dfn)
|
@@ -167,7 +167,7 @@ class PipelineTest < MiniTest::Spec
|
|
167
167
|
end
|
168
168
|
|
169
169
|
######### collection :songs, extend: SongRepresenter
|
170
|
-
let
|
170
|
+
let(:artists) {
|
171
171
|
dfn = R::Definition.new(:artists, collection: true, extend: ArtistRepresenter, class: Artist)
|
172
172
|
|
173
173
|
R::Hash::Binding::Collection.new(dfn)
|
@@ -188,7 +188,7 @@ class PipelineTest < MiniTest::Spec
|
|
188
188
|
doc.must_equal({"artists"=>[{"name"=>"Diesel Boy"}, {"name"=>"Van Halen"}]})
|
189
189
|
end
|
190
190
|
|
191
|
-
let
|
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"}]}
|
@@ -212,7 +212,7 @@ let (:album_model) { Album.new(nil, [Artist.new("Diesel Boy"), Artist.new("Van H
|
|
212
212
|
|
213
213
|
# TODO: test with arrays, too, not "only" Pipeline instances.
|
214
214
|
describe "#Insert Pipeline[], Function, replace: OldFunction" do
|
215
|
-
let
|
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
218
|
P::Insert.(pipeline, R::Default, replace: R::StopOnSkipable).must_be_instance_of(R::Pipeline)
|
data/test/populator_test.rb
CHANGED
@@ -16,7 +16,7 @@ class PopulatorTest < Minitest::Spec
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
let
|
19
|
+
let(:album) { Album.new([]) }
|
20
20
|
|
21
21
|
it do
|
22
22
|
album.extend(representer).from_hash("songs"=>[{"id"=>1}, {"id"=>2}], "artist"=>{"name"=>"Waste"})
|
@@ -55,7 +55,7 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
let
|
58
|
+
let(:album) { Composer.new.extend(representer).extend(Representable::Debug) }
|
59
59
|
|
60
60
|
it "finds by :id and creates new without :id" do
|
61
61
|
album.from_hash({"song"=>{"id" => 1, "title"=>"Resist Stance"}})
|
@@ -69,8 +69,8 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
|
|
69
69
|
album.from_hash({"song"=>{"title"=>"Lower"}})
|
70
70
|
|
71
71
|
album.song.title.must_equal "Lower"
|
72
|
-
album.song.id.
|
73
|
-
album.song.uid.
|
72
|
+
album.song.id.must_be_nil
|
73
|
+
album.song.uid.must_be_nil
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -82,7 +82,7 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
let
|
85
|
+
let(:album) { Struct.new(:songs).new([]).extend(representer) }
|
86
86
|
|
87
87
|
it "finds by :id and creates new without :id" do
|
88
88
|
album.from_hash({"songs"=>[
|
@@ -95,8 +95,8 @@ class PopulatorFindOrInstantiateTest < Minitest::Spec
|
|
95
95
|
album.songs[0].uid.must_equal "abcd" # not changed via populator, indicating this is a formerly "persisted" object.
|
96
96
|
|
97
97
|
album.songs[1].title.must_equal "Suffer"
|
98
|
-
album.songs[1].id.
|
99
|
-
album.songs[1].uid.
|
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
|
data/test/prepare_test.rb
CHANGED
@@ -24,7 +24,7 @@ class PrepareTest < BaseTest
|
|
24
24
|
:representable => false # don't call #to_hash.
|
25
25
|
end
|
26
26
|
|
27
|
-
let
|
27
|
+
let(:hit) { Struct.new(:song).new(song).extend(representer) }
|
28
28
|
|
29
29
|
it "calls prepare:, nothing else" do
|
30
30
|
# render(hit).must_equal_document(output)
|
@@ -54,7 +54,7 @@ class PrepareTest < BaseTest
|
|
54
54
|
:representable => false # don't call #to_hash.
|
55
55
|
end
|
56
56
|
|
57
|
-
let
|
57
|
+
let(:hit) { Struct.new(:song).new.extend(representer) }
|
58
58
|
|
59
59
|
it "calls prepare:, nothing else" do
|
60
60
|
# render(hit).must_equal_document(output)
|
data/test/represent_test.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class RepresentTest < MiniTest::Spec
|
4
|
-
let
|
5
|
-
let
|
4
|
+
let(:songs) { [song, Song.new("Can't Take Them All")] }
|
5
|
+
let(:song) { Song.new("Days Go By") }
|
6
6
|
|
7
7
|
for_formats(
|
8
8
|
:hash => [Representable::Hash, out=[{"name" => "Days Go By"}, {"name"=>"Can't Take Them All"}], out],
|
@@ -12,9 +12,9 @@ class RepresentTest < MiniTest::Spec
|
|
12
12
|
|
13
13
|
# Representer.represents detects collection.
|
14
14
|
describe "Module#to_/from_#{format}" do
|
15
|
-
let
|
15
|
+
let(:format) { format }
|
16
16
|
|
17
|
-
let
|
17
|
+
let(:representer) {
|
18
18
|
Module.new do
|
19
19
|
include mod
|
20
20
|
property :name
|
@@ -29,8 +29,8 @@ class RepresentTest < MiniTest::Spec
|
|
29
29
|
|
30
30
|
# Decorator.represents detects collection.
|
31
31
|
describe "Decorator#to_/from_#{format}" do
|
32
|
-
let
|
33
|
-
let
|
32
|
+
let(:format) { format }
|
33
|
+
let(:representer) {
|
34
34
|
Class.new(Representable::Decorator) do
|
35
35
|
include mod
|
36
36
|
property :name
|
@@ -53,9 +53,9 @@ class RepresentTest < MiniTest::Spec
|
|
53
53
|
|
54
54
|
# Representer.represents detects singular.
|
55
55
|
describe "Module#to_/from_#{format}" do
|
56
|
-
let
|
56
|
+
let(:format) { format }
|
57
57
|
|
58
|
-
let
|
58
|
+
let(:representer) {
|
59
59
|
Module.new do
|
60
60
|
include mod
|
61
61
|
property :name
|
@@ -71,8 +71,8 @@ class RepresentTest < MiniTest::Spec
|
|
71
71
|
|
72
72
|
# Decorator.represents detects singular.
|
73
73
|
describe "Decorator#to_/from_#{format}" do
|
74
|
-
let
|
75
|
-
let
|
74
|
+
let(:format) { format }
|
75
|
+
let(:representer) {
|
76
76
|
Class.new(Representable::Decorator) do
|
77
77
|
include mod
|
78
78
|
property :name
|
data/test/representable_test.rb
CHANGED
@@ -224,7 +224,7 @@ class RepresentableTest < MiniTest::Spec
|
|
224
224
|
@band = Class.new(Band) { property :name; collection :founders, :writeable => false; attr_accessor :founders }.new
|
225
225
|
@band.from_hash("name" => "Iron Maiden", "groupies" => 2, "founders" => ["Steve Harris"])
|
226
226
|
assert_equal "Iron Maiden", @band.name
|
227
|
-
|
227
|
+
assert_nil @band.founders
|
228
228
|
end
|
229
229
|
|
230
230
|
it "always returns the represented" do
|
@@ -261,7 +261,7 @@ class RepresentableTest < MiniTest::Spec
|
|
261
261
|
|
262
262
|
@band = Band.new.extend(repr)
|
263
263
|
@band.send(config.first, config.last)
|
264
|
-
|
264
|
+
assert_nil @band.name, "Failed in #{format}"
|
265
265
|
end
|
266
266
|
end
|
267
267
|
|
@@ -449,9 +449,9 @@ class RepresentableTest < MiniTest::Spec
|
|
449
449
|
end
|
450
450
|
|
451
451
|
describe ":decorator" do
|
452
|
-
let
|
453
|
-
let
|
454
|
-
let
|
452
|
+
let(:extend_rpr) { Module.new { include Representable::Hash; collection :songs, :extend => SongRepresenter } }
|
453
|
+
let(:decorator_rpr) { Module.new { include Representable::Hash; collection :songs, :decorator => SongRepresenter } }
|
454
|
+
let(:songs) { [Song.new("Bloody Mary")] }
|
455
455
|
|
456
456
|
it "is aliased to :extend" do
|
457
457
|
Album.new(songs).extend(extend_rpr).to_hash.must_equal Album.new(songs).extend(decorator_rpr).to_hash
|
@@ -470,8 +470,8 @@ class RepresentableTest < MiniTest::Spec
|
|
470
470
|
end
|
471
471
|
|
472
472
|
describe "::prepare" do
|
473
|
-
let
|
474
|
-
let
|
473
|
+
let(:song) { Song.new("Still Friends In The End") }
|
474
|
+
let(:album) { Album.new([song]) }
|
475
475
|
|
476
476
|
describe "module including Representable" do
|
477
477
|
it "uses :extend strategy" do
|
data/test/schema_test.rb
CHANGED
@@ -58,7 +58,7 @@ class SchemaTest < MiniTest::Spec
|
|
58
58
|
end
|
59
59
|
|
60
60
|
describe "3-level deep with features" do
|
61
|
-
let
|
61
|
+
let(:label) { OpenStruct.new(:name => "Epitaph", :location => OpenStruct.new(:city => "Sanfran", :name => "DON'T SHOW ME!")) }
|
62
62
|
|
63
63
|
# Module does correctly include features in inlines.
|
64
64
|
it { band.extend(Module).to_hash.must_equal({"label"=>{"name"=>"Epitaph", "location"=>{"city"=>"Sanfran"}}, "genre"=>"Punkrock"}) }
|
@@ -77,8 +77,8 @@ class SchemaTest < MiniTest::Spec
|
|
77
77
|
|
78
78
|
# puts Decorator.representable_attrs[:definitions].inspect
|
79
79
|
|
80
|
-
let
|
81
|
-
let
|
80
|
+
let(:label) { OpenStruct.new(:name => "Fat Wreck", :city => "San Francisco", :employees => [OpenStruct.new(:name => "Mike")], :location => OpenStruct.new(:city => "Sanfran")) }
|
81
|
+
let(:band) { OpenStruct.new(:genre => "Punkrock", :label => label) }
|
82
82
|
|
83
83
|
|
84
84
|
# it { FlatlinersDecorator.new( OpenStruct.new(label: OpenStruct.new) ).
|
@@ -116,9 +116,6 @@ class SchemaTest < MiniTest::Spec
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
require "pp"
|
120
|
-
pp InheritFromDecorator.representable_attrs.get(:label)[:extend].(nil).representable_attrs
|
121
|
-
|
122
119
|
it do
|
123
120
|
InheritFromDecorator.new(band).to_hash.must_equal({"genre"=>"Punkrock", "label"=>{"name"=>"Fat Wreck", "city"=>"San Francisco", "employees"=>[{"name"=>"Mike"}], "location"=>{"city"=>"Sanfran"}}})
|
124
121
|
end
|
data/test/skip_test.rb
CHANGED
@@ -14,7 +14,7 @@ class SkipParseTest < MiniTest::Spec
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
let
|
17
|
+
let(:song) { OpenStruct.new.extend(representer) }
|
18
18
|
|
19
19
|
# do parse.
|
20
20
|
it do
|
@@ -30,7 +30,7 @@ class SkipParseTest < MiniTest::Spec
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# skip parsing.
|
33
|
-
let
|
33
|
+
let(:airplay) { OpenStruct.new(station: "JJJ") }
|
34
34
|
|
35
35
|
it do
|
36
36
|
song.from_hash({
|
@@ -39,8 +39,8 @@ class SkipParseTest < MiniTest::Spec
|
|
39
39
|
"airplays" => [{}, {"station" => "JJJ"}, {}],
|
40
40
|
}, user_options: { skip?: true })
|
41
41
|
|
42
|
-
song.title.
|
43
|
-
song.band.
|
42
|
+
song.title.must_be_nil
|
43
|
+
song.band.must_be_nil
|
44
44
|
song.airplays.must_equal [airplay]
|
45
45
|
end
|
46
46
|
end
|
@@ -59,8 +59,8 @@ class SkipRenderTest < MiniTest::Spec
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
let
|
63
|
-
let
|
62
|
+
let(:song) { OpenStruct.new(title: "Black Night", band: OpenStruct.new(name: "Time Again")).extend(representer) }
|
63
|
+
let(:skip_song) { OpenStruct.new(title: "Time Bomb", band: OpenStruct.new(name: "Rancid")).extend(representer) }
|
64
64
|
|
65
65
|
# do render.
|
66
66
|
it { song.to_hash(user_options: { skip?: true }).must_equal({"title"=>"Black Night", "band"=>{"name"=>"Time Again"}}) }
|
data/test/test_helper.rb
CHANGED
@@ -5,6 +5,14 @@ require 'test_xml/mini_test'
|
|
5
5
|
|
6
6
|
require "representable/debug"
|
7
7
|
|
8
|
+
module MiniTest::Assertions
|
9
|
+
def assert_equal_xml(text, subject)
|
10
|
+
subject.gsub("\n", "").gsub(/(\s\s+)/, "").must_equal(text.gsub("\n", "").gsub(/(\s\s+)/, ""))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
String.infect_an_assertion :assert_equal_xml, :must_xml
|
14
|
+
|
15
|
+
# TODO: delete all that in 4.0:
|
8
16
|
class Album
|
9
17
|
attr_accessor :songs, :best_song
|
10
18
|
def initialize(songs=nil, best_song=nil)
|
@@ -77,7 +85,7 @@ MiniTest::Spec.class_eval do
|
|
77
85
|
end
|
78
86
|
|
79
87
|
def self.representer!(options={}, &block)
|
80
|
-
fmt = options # we need that so the 2nd call to ::let
|
88
|
+
fmt = options # we need that so the 2nd call to ::let(within a ::describe) remembers the right format.
|
81
89
|
|
82
90
|
name = options[:name] || :representer
|
83
91
|
format = options[:module] || Representable::Hash
|
@@ -95,6 +103,8 @@ MiniTest::Spec.class_eval do
|
|
95
103
|
mod
|
96
104
|
end
|
97
105
|
|
106
|
+
undef :inject_representer if method_defined? :inject_representer
|
107
|
+
|
98
108
|
def inject_representer(mod, options)
|
99
109
|
return unless options[:inject]
|
100
110
|
|
@@ -110,7 +120,7 @@ MiniTest::Spec.class_eval do
|
|
110
120
|
def representer_for(modules=[Representable::Hash], &block)
|
111
121
|
Module.new do
|
112
122
|
extend TestMethods
|
113
|
-
include
|
123
|
+
include(*modules)
|
114
124
|
module_exec(&block)
|
115
125
|
end
|
116
126
|
end
|
@@ -121,10 +131,10 @@ MiniTest::Spec.class_eval do
|
|
121
131
|
end
|
122
132
|
|
123
133
|
class BaseTest < MiniTest::Spec
|
124
|
-
let
|
125
|
-
let
|
126
|
-
let
|
127
|
-
let
|
134
|
+
let(:new_album) { OpenStruct.new.extend(representer) }
|
135
|
+
let(:album) { OpenStruct.new(:songs => ["Fuck Armageddon"]).extend(representer) }
|
136
|
+
let(:song) { OpenStruct.new(:title => "Resist Stance") }
|
137
|
+
let(:song_representer) { Module.new do include Representable::Hash; property :title end }
|
128
138
|
|
129
139
|
end
|
130
140
|
|
data/test/wrap_test.rb
CHANGED
@@ -8,10 +8,10 @@ class WrapTest < MiniTest::Spec
|
|
8
8
|
class SoftcoreBand < HardcoreBand
|
9
9
|
end
|
10
10
|
|
11
|
-
let
|
11
|
+
let(:band) { HardcoreBand.new }
|
12
12
|
|
13
13
|
it "returns false per default" do
|
14
|
-
|
14
|
+
assert_nil SoftcoreBand.new.send(:representation_wrap)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "infers a printable class name if set to true" do
|
@@ -32,8 +32,8 @@ class WrapTest < MiniTest::Spec
|
|
32
32
|
) do |format, mod, output, input|
|
33
33
|
|
34
34
|
describe "[#{format}] dynamic wrap" do
|
35
|
-
let
|
36
|
-
let
|
35
|
+
let(:band) { representer.prepare(Struct.new(:name, :genre).new("Blink", "Pop")) }
|
36
|
+
let(:format) { format }
|
37
37
|
|
38
38
|
representer!(:module => mod) do
|
39
39
|
self.representation_wrap = lambda { |args| "#{name}#{args[:number]}" }
|
@@ -65,7 +65,7 @@ class HashDisableWrapTest < MiniTest::Spec
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
let
|
68
|
+
let(:band) { BandDecorator.prepare(Band.new("Social Distortion")) }
|
69
69
|
|
70
70
|
# direct, local api.
|
71
71
|
it do
|
@@ -90,7 +90,7 @@ class HashDisableWrapTest < MiniTest::Spec
|
|
90
90
|
end
|
91
91
|
|
92
92
|
|
93
|
-
let
|
93
|
+
let(:album) { AlbumDecorator.prepare(Album.new(Band.new("Social Distortion", Label.new("Epitaph")))) }
|
94
94
|
|
95
95
|
# band has wrap turned off per property definition, however, label still has wrap.
|
96
96
|
it "renders" do
|
@@ -120,7 +120,7 @@ class XMLDisableWrapTest < MiniTest::Spec
|
|
120
120
|
# end
|
121
121
|
end
|
122
122
|
|
123
|
-
let
|
123
|
+
let(:band) { BandDecorator.prepare(Band.new("Social Distortion")) }
|
124
124
|
|
125
125
|
it do
|
126
126
|
band.to_xml.must_equal_xml "<bands><name>Social Distortion</name></bands>"
|
@@ -137,7 +137,7 @@ class XMLDisableWrapTest < MiniTest::Spec
|
|
137
137
|
end
|
138
138
|
|
139
139
|
|
140
|
-
let
|
140
|
+
let(:album) { AlbumDecorator.prepare(Album.new(Band.new("Social Distortion", Label.new("Epitaph")))) }
|
141
141
|
|
142
142
|
# band has wrap turned of per property definition, however, label still has wrap.
|
143
143
|
it "rendersxx" do
|