representable 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +17 -0
- data/CHANGES.md +25 -0
- data/Gemfile +4 -12
- data/LICENSE +1 -1
- data/README.md +6 -6
- data/Rakefile +1 -6
- data/TODO +1 -3
- data/TODO-4.0.md +72 -0
- data/lib/representable.rb +19 -25
- data/lib/representable/binding.rb +32 -12
- data/lib/representable/cached.rb +1 -1
- data/lib/representable/coercion.rb +8 -6
- data/lib/representable/config.rb +13 -3
- data/lib/representable/debug.rb +23 -15
- data/lib/representable/declarative.rb +12 -7
- data/lib/representable/decorator.rb +1 -1
- data/lib/representable/definition.rb +7 -3
- data/lib/representable/deserializer.rb +5 -4
- data/lib/representable/for_collection.rb +1 -1
- data/lib/representable/hash.rb +9 -2
- data/lib/representable/hash/allow_symbols.rb +9 -11
- data/lib/representable/hash/binding.rb +1 -0
- data/lib/representable/hash/collection.rb +4 -2
- data/lib/representable/hash_methods.rb +3 -2
- data/lib/representable/insert.rb +1 -1
- data/lib/representable/json.rb +8 -7
- data/lib/representable/json/collection.rb +3 -0
- data/lib/representable/object.rb +1 -1
- data/lib/representable/object/binding.rb +5 -1
- data/lib/representable/option.rb +19 -0
- data/lib/representable/pipeline.rb +3 -2
- data/lib/representable/pipeline_factories.rb +4 -2
- data/lib/representable/populator.rb +1 -1
- data/lib/representable/represent.rb +1 -0
- data/lib/representable/serializer.rb +3 -2
- data/lib/representable/version.rb +1 -1
- data/lib/representable/virtus_coercion.rb +38 -0
- data/lib/representable/xml.rb +12 -10
- data/lib/representable/xml/binding.rb +19 -13
- data/lib/representable/xml/namespace.rb +122 -0
- data/lib/representable/yaml.rb +6 -2
- data/lib/representable/yaml/binding.rb +1 -0
- data/representable.gemspec +8 -9
- data/test/as_test.rb +7 -7
- data/test/binding_test.rb +14 -14
- data/test/cached_test.rb +59 -49
- data/test/class_test.rb +9 -9
- data/test/coercion_test.rb +33 -22
- data/test/config/inherit_test.rb +14 -14
- data/test/config_test.rb +20 -20
- data/test/decorator_scope_test.rb +4 -4
- data/test/decorator_test.rb +33 -20
- data/test/default_test.rb +8 -8
- data/test/defaults_options_test.rb +3 -3
- data/test/definition_test.rb +38 -40
- data/test/{example.rb → examples/example.rb} +0 -1
- data/test/examples/object.rb +1 -5
- data/test/exec_context_test.rb +8 -8
- data/test/features_test.rb +6 -6
- data/test/filter_test.rb +8 -8
- data/test/for_collection_test.rb +10 -10
- data/test/generic_test.rb +13 -13
- data/test/getter_setter_test.rb +5 -5
- data/test/hash_bindings_test.rb +1 -1
- data/test/hash_test.rb +45 -23
- data/test/heritage_test.rb +16 -13
- data/test/if_test.rb +9 -9
- data/test/include_exclude_test.rb +14 -14
- data/test/inherit_test.rb +18 -18
- data/test/inline_test.rb +24 -24
- data/test/instance_test.rb +31 -31
- data/test/is_representable_test.rb +10 -10
- data/test/json_test.rb +29 -7
- data/test/lonely_test.rb +31 -31
- data/test/nested_test.rb +13 -13
- data/test/object_test.rb +9 -9
- data/test/option_test.rb +36 -0
- data/test/parse_pipeline_test.rb +3 -5
- data/test/pipeline_test.rb +50 -50
- data/test/populator_test.rb +18 -18
- data/test/prepare_test.rb +4 -4
- data/test/private_options_test.rb +2 -2
- data/test/reader_writer_test.rb +2 -2
- data/test/render_nil_test.rb +2 -2
- data/test/represent_test.rb +14 -14
- data/test/representable_test.rb +34 -36
- data/test/schema_test.rb +8 -11
- data/test/serialize_deserialize_test.rb +2 -2
- data/test/skip_test.rb +14 -14
- data/test/stringify_hash_test.rb +3 -3
- data/test/test_helper.rb +26 -14
- data/test/uncategorized_test.rb +10 -10
- data/test/user_options_test.rb +4 -4
- data/test/virtus_coercion_test.rb +52 -0
- data/test/wrap_test.rb +19 -19
- data/test/xml_bindings_test.rb +0 -4
- data/test/xml_namespace_test.rb +186 -0
- data/test/xml_test.rb +103 -43
- data/test/yaml_test.rb +51 -26
- metadata +101 -39
- data/.travis.yml +0 -7
- data/lib/representable/TODO.getting_serious +0 -11
- data/lib/representable/autoload.rb +0 -10
- data/test/mongoid_test.rb +0 -31
data/test/config_test.rb
CHANGED
@@ -7,7 +7,7 @@ class ConfigTest < MiniTest::Spec
|
|
7
7
|
|
8
8
|
describe "wrapping" do
|
9
9
|
it "returns false per default" do
|
10
|
-
|
10
|
+
assert_nil subject.wrap_for("Punk", nil)
|
11
11
|
end
|
12
12
|
|
13
13
|
# it "infers a printable class name if set to true" do
|
@@ -23,13 +23,13 @@ class ConfigTest < MiniTest::Spec
|
|
23
23
|
|
24
24
|
describe "#[]" do
|
25
25
|
# does return nil for non-existent
|
26
|
-
it { subject[:hello].
|
26
|
+
it { _(subject[:hello]).must_be_nil }
|
27
27
|
end
|
28
28
|
|
29
29
|
# describe "#[]" do
|
30
30
|
# before { subject.add(:title, {:me => true}) }
|
31
31
|
|
32
|
-
# it { subject[:unknown].
|
32
|
+
# it { subject[:unknown].must_be_nil }
|
33
33
|
# it { subject.get(:title)[:me].must_equal true }
|
34
34
|
# it { subject["title"][:me].must_equal true }
|
35
35
|
# end
|
@@ -44,23 +44,23 @@ class ConfigTest < MiniTest::Spec
|
|
44
44
|
# #add returns Definition.`
|
45
45
|
subject = Representable::Config.new(Representable::Definition).add(:title, {:me => true})
|
46
46
|
|
47
|
-
subject.must_be_kind_of Representable::Definition
|
48
|
-
subject[:me].must_equal true
|
47
|
+
_(subject).must_be_kind_of Representable::Definition
|
48
|
+
_(subject[:me]).must_equal true
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
before { subject.add(:title, {:me => true}) }
|
53
53
|
|
54
54
|
# must be kind of Definition
|
55
|
-
it { subject.size.must_equal 1 }
|
56
|
-
it { subject.get(:title).name.must_equal "title" }
|
57
|
-
it { subject.get(:title)[:me].must_equal true }
|
55
|
+
it { _(subject.size).must_equal 1 }
|
56
|
+
it { _(subject.get(:title).name).must_equal "title" }
|
57
|
+
it { _(subject.get(:title)[:me]).must_equal true }
|
58
58
|
|
59
59
|
# this is actually tested in context in inherit_test.
|
60
60
|
it "overrides former definition" do
|
61
61
|
subject.add(:title, {:peer => Module})
|
62
|
-
subject.get(:title)[:me].
|
63
|
-
subject.get(:title)[:peer].must_equal Module
|
62
|
+
_(subject.get(:title)[:me]).must_be_nil
|
63
|
+
_(subject.get(:title)[:peer]).must_equal Module
|
64
64
|
end
|
65
65
|
|
66
66
|
describe "inherit: true" do
|
@@ -69,8 +69,8 @@ class ConfigTest < MiniTest::Spec
|
|
69
69
|
subject.add(:title, {:peer => Module, :inherit => true})
|
70
70
|
}
|
71
71
|
|
72
|
-
it { subject.get(:title)[:me].must_equal true }
|
73
|
-
it { subject.get(:title)[:peer].must_equal Module }
|
72
|
+
it { _(subject.get(:title)[:me]).must_equal true }
|
73
|
+
it { _(subject.get(:title)[:peer]).must_equal Module }
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -81,10 +81,10 @@ class ConfigTest < MiniTest::Spec
|
|
81
81
|
it do
|
82
82
|
subject.add(:title, {:me => true})
|
83
83
|
subject.add(:genre, {})
|
84
|
-
subject.get(:genre).must_be_kind_of Representable::Definition
|
84
|
+
_(subject.get(:genre)).must_be_kind_of Representable::Definition
|
85
85
|
|
86
86
|
subject.remove(:genre)
|
87
|
-
subject.get(:genre).
|
87
|
+
_(subject.get(:genre)).must_be_nil
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -95,16 +95,16 @@ class ConfigTest < MiniTest::Spec
|
|
95
95
|
it "what" do
|
96
96
|
definitions = []
|
97
97
|
subject.each { |dfn| definitions << dfn }
|
98
|
-
definitions.size.must_equal 1
|
99
|
-
definitions[0][:me].must_equal true
|
98
|
+
_(definitions.size).must_equal 1
|
99
|
+
_(definitions[0][:me]).must_equal true
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
describe "#options" do
|
104
|
-
it { subject.options.must_equal({}) }
|
104
|
+
it { _(subject.options).must_equal({}) }
|
105
105
|
it do
|
106
106
|
subject.options[:namespacing] = true
|
107
|
-
subject.options[:namespacing].must_equal true
|
107
|
+
_(subject.options[:namespacing]).must_equal true
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -115,8 +115,8 @@ class ConfigTest < MiniTest::Spec
|
|
115
115
|
title = subject.add(:title, {})
|
116
116
|
length = subject.add(:length, {})
|
117
117
|
|
118
|
-
subject.get(:title).must_equal title
|
119
|
-
subject.get(:length).must_equal length
|
118
|
+
_(subject.get(:title)).must_equal title
|
119
|
+
_(subject.get(:length)).must_equal length
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
@@ -6,7 +6,7 @@ class DecoratorScopeTest < MiniTest::Spec
|
|
6
6
|
property :title, :getter => lambda { |*| title_from_representer }, :decorator_scope => true
|
7
7
|
end
|
8
8
|
|
9
|
-
let
|
9
|
+
let(:representer_with_method) {
|
10
10
|
Module.new do
|
11
11
|
include Representable::Hash
|
12
12
|
property :title, :decorator_scope => true
|
@@ -15,14 +15,14 @@ class DecoratorScopeTest < MiniTest::Spec
|
|
15
15
|
}
|
16
16
|
|
17
17
|
it "executes lambdas in represented context" do
|
18
|
-
Class.new do
|
18
|
+
_(Class.new do
|
19
19
|
def title_from_representer
|
20
20
|
"Sounds Of Silence"
|
21
21
|
end
|
22
|
-
end.new.extend(representer).to_hash.must_equal({"title"=>"Sounds Of Silence"})
|
22
|
+
end.new.extend(representer).to_hash).must_equal({"title"=>"Sounds Of Silence"})
|
23
23
|
end
|
24
24
|
|
25
25
|
it "executes method in represented context" do
|
26
|
-
Object.new.extend(representer_with_method).to_hash.must_equal({"title"=>"Crystal Planet"})
|
26
|
+
_(Object.new.extend(representer_with_method).to_hash).must_equal({"title"=>"Crystal Planet"})
|
27
27
|
end
|
28
28
|
end
|
data/test/decorator_test.rb
CHANGED
@@ -12,46 +12,59 @@ class DecoratorTest < MiniTest::Spec
|
|
12
12
|
collection :songs, :class => Song, :extend => SongRepresentation
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
class RatingRepresentation < Representable::Decorator
|
16
|
+
include Representable::JSON
|
17
|
+
|
18
|
+
property :system
|
19
|
+
property :value
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:song) { Song.new("Mama, I'm Coming Home") }
|
23
|
+
let(:album) { Album.new([song]) }
|
24
|
+
|
25
|
+
let(:rating) { OpenStruct.new(system: 'MPAA', value: 'R') }
|
17
26
|
|
18
27
|
describe "inheritance" do
|
19
|
-
let
|
28
|
+
let(:inherited_decorator) do
|
20
29
|
Class.new(AlbumRepresentation) do
|
21
30
|
property :best_song
|
22
31
|
end.new(Album.new([song], "Stand Up"))
|
23
32
|
end
|
24
33
|
|
25
|
-
it { inherited_decorator.to_hash.must_equal({"songs"=>[{"name"=>"Mama, I'm Coming Home"}], "best_song"=>"Stand Up"}) }
|
34
|
+
it { _(inherited_decorator.to_hash).must_equal({"songs"=>[{"name"=>"Mama, I'm Coming Home"}], "best_song"=>"Stand Up"}) }
|
26
35
|
end
|
27
36
|
|
28
|
-
let
|
37
|
+
let(:decorator) { AlbumRepresentation.new(album) }
|
38
|
+
|
39
|
+
let(:rating_decorator) { RatingRepresentation.new(rating) }
|
29
40
|
|
30
41
|
it "renders" do
|
31
|
-
decorator.to_hash.must_equal({"songs"=>[{"name"=>"Mama, I'm Coming Home"}]})
|
32
|
-
album.wont_respond_to :to_hash
|
33
|
-
song.wont_respond_to :to_hash # DISCUSS: weak test, how to assert blank slate?
|
42
|
+
_(decorator.to_hash).must_equal({"songs"=>[{"name"=>"Mama, I'm Coming Home"}]})
|
43
|
+
_(album).wont_respond_to :to_hash
|
44
|
+
_(song).wont_respond_to :to_hash # DISCUSS: weak test, how to assert blank slate?
|
34
45
|
# no @representable_attrs in decorated objects
|
35
|
-
song.
|
46
|
+
_(song).wont_be(:instance_variable_defined?, :@representable_attrs)
|
47
|
+
|
48
|
+
_(rating_decorator.to_hash).must_equal({"system" => "MPAA", "value" => "R"})
|
36
49
|
end
|
37
50
|
|
38
51
|
describe "#from_hash" do
|
39
52
|
it "returns represented" do
|
40
|
-
decorator.from_hash({"songs"=>[{"name"=>"Mama, I'm Coming Home"}]}).must_equal album
|
53
|
+
_(decorator.from_hash({"songs"=>[{"name"=>"Mama, I'm Coming Home"}]})).must_equal album
|
41
54
|
end
|
42
55
|
|
43
56
|
it "parses" do
|
44
57
|
decorator.from_hash({"songs"=>[{"name"=>"Atomic Garden"}]})
|
45
|
-
album.songs.first.must_be_kind_of Song
|
46
|
-
album.songs.must_equal [Song.new("Atomic Garden")]
|
47
|
-
album.wont_respond_to :to_hash
|
48
|
-
song.wont_respond_to :to_hash # DISCUSS: weak test, how to assert blank slate?
|
58
|
+
_(album.songs.first).must_be_kind_of Song
|
59
|
+
_(album.songs).must_equal [Song.new("Atomic Garden")]
|
60
|
+
_(album).wont_respond_to :to_hash
|
61
|
+
_(song).wont_respond_to :to_hash # DISCUSS: weak test, how to assert blank slate?
|
49
62
|
end
|
50
63
|
end
|
51
64
|
|
52
65
|
describe "#decorated" do
|
53
66
|
it "is aliased to #represented" do
|
54
|
-
AlbumRepresentation.prepare(album).decorated.must_equal album
|
67
|
+
_(AlbumRepresentation.prepare(album).decorated).must_equal album
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
@@ -67,8 +80,8 @@ class DecoratorTest < MiniTest::Spec
|
|
67
80
|
representer.new(album).from_hash({"songs"=>[{"name"=>"Atomic Garden"}]})
|
68
81
|
|
69
82
|
# no @representable_attrs in decorated objects
|
70
|
-
song.
|
71
|
-
album.
|
83
|
+
_(song).wont_be(:instance_variable_defined?, :@representable_attrs)
|
84
|
+
_(album).wont_be(:instance_variable_defined?, :@representable_attrs)
|
72
85
|
end
|
73
86
|
end
|
74
87
|
end
|
@@ -89,8 +102,8 @@ class InheritanceWithDecoratorTest < MiniTest::Spec
|
|
89
102
|
end
|
90
103
|
|
91
104
|
it do
|
92
|
-
Twin.representer_class.definitions.size.must_equal 0
|
93
|
-
Album.representer_class.definitions.size.must_equal 1
|
94
|
-
Song.representer_class.definitions.size.must_equal 0
|
105
|
+
_(Twin.representer_class.definitions.size).must_equal 0
|
106
|
+
_(Album.representer_class.definitions.size).must_equal 1
|
107
|
+
_(Song.representer_class.definitions.size).must_equal 0
|
95
108
|
end
|
96
109
|
end
|
data/test/default_test.rb
CHANGED
@@ -9,26 +9,26 @@ class DefaultTest < MiniTest::Spec
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#from_hash" do
|
12
|
-
let
|
12
|
+
let(:song) { Song.new.extend(representer) }
|
13
13
|
|
14
|
-
it { song.from_hash({}).must_equal Song.new(nil, "Huber Breeze") }
|
14
|
+
it { _(song.from_hash({})).must_equal Song.new(nil, "Huber Breeze") }
|
15
15
|
# default doesn't apply when empty string.
|
16
|
-
it { song.from_hash({"title"=>""}).must_equal Song.new(nil, "") }
|
17
|
-
it { song.from_hash({"title"=>nil}).must_equal Song.new(nil, nil) }
|
18
|
-
it { song.from_hash({"title"=>"Blindfold"}).must_equal Song.new(nil, "Blindfold") }
|
16
|
+
it { _(song.from_hash({"title"=>""})).must_equal Song.new(nil, "") }
|
17
|
+
it { _(song.from_hash({"title"=>nil})).must_equal Song.new(nil, nil) }
|
18
|
+
it { _(song.from_hash({"title"=>"Blindfold"})).must_equal Song.new(nil, "Blindfold") }
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#to_json" do
|
22
22
|
it "uses :default when not available from object" do
|
23
|
-
Song.new.extend(representer).to_hash.must_equal({"title"=>"Huber Breeze"})
|
23
|
+
_(Song.new.extend(representer).to_hash).must_equal({"title"=>"Huber Breeze"})
|
24
24
|
end
|
25
25
|
|
26
26
|
it "uses value from represented object when present" do
|
27
|
-
Song.new(nil, "After The War").extend(representer).to_hash.must_equal({"title"=>"After The War"})
|
27
|
+
_(Song.new(nil, "After The War").extend(representer).to_hash).must_equal({"title"=>"After The War"})
|
28
28
|
end
|
29
29
|
|
30
30
|
it "uses value from represented object when emtpy string" do
|
31
|
-
Song.new(nil, "").extend(representer).to_hash.must_equal({"title"=>""})
|
31
|
+
_(Song.new(nil, "").extend(representer).to_hash).must_equal({"title"=>""})
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class DefaultsOptionsTest < BaseTest
|
4
|
-
let
|
5
|
-
let
|
6
|
-
let
|
4
|
+
let(:format) { :hash }
|
5
|
+
let(:song) { Struct.new(:title, :author_name, :song_volume, :description).new("Revolution", "Some author", 20, nil) }
|
6
|
+
let(:prepared) { representer.prepare song }
|
7
7
|
|
8
8
|
describe "hash options combined with dynamic options" do
|
9
9
|
representer! do
|
data/test/definition_test.rb
CHANGED
@@ -6,42 +6,40 @@ class DefinitionTest < MiniTest::Spec
|
|
6
6
|
# TODO: test that we DON'T clone options, that must happen in
|
7
7
|
describe "#initialize" do
|
8
8
|
it do
|
9
|
-
opts = nil
|
10
|
-
|
11
9
|
# new yields the defaultized options HASH.
|
12
10
|
definition = Definition.new(:song, :extend => Module) do |options|
|
13
11
|
options[:awesome] = true
|
14
12
|
options[:parse_filter] << 1
|
15
13
|
|
16
14
|
# default variables
|
17
|
-
options[:as].
|
18
|
-
options[:extend].must_equal Module
|
15
|
+
_(options[:as]).must_be_nil
|
16
|
+
_(options[:extend]).must_equal Module
|
19
17
|
end
|
20
|
-
definition.name.must_equal "song"
|
18
|
+
_(definition.name).must_equal "song"
|
21
19
|
|
22
20
|
#
|
23
|
-
definition[:awesome].must_equal true
|
24
|
-
definition[:parse_filter].must_equal Representable::Pipeline[1]
|
25
|
-
definition[:render_filter].must_equal Representable::Pipeline[]
|
21
|
+
_(definition[:awesome]).must_equal true
|
22
|
+
_(definition[:parse_filter]).must_equal Representable::Pipeline[1]
|
23
|
+
_(definition[:render_filter]).must_equal Representable::Pipeline[]
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
27
|
describe "#[]" do
|
30
|
-
let
|
28
|
+
let(:definition) { Definition.new(:song) }
|
31
29
|
# default is nil.
|
32
|
-
it { definition[:bla].
|
30
|
+
it { _(definition[:bla]).must_be_nil }
|
33
31
|
end
|
34
32
|
|
35
33
|
# merge!
|
36
34
|
describe "#merge!" do
|
37
|
-
let
|
35
|
+
let(:definition) { Definition.new(:song, :whatever => true) }
|
38
36
|
|
39
37
|
# merges new options.
|
40
|
-
it { definition.merge!(:something => true)[:something].must_equal true }
|
38
|
+
it { _(definition.merge!(:something => true)[:something]).must_equal true }
|
41
39
|
# doesn't override original options.
|
42
|
-
it { definition.merge!({:something => true})[:whatever].must_equal true }
|
40
|
+
it { _(definition.merge!({:something => true})[:whatever]).must_equal true }
|
43
41
|
# override original when passed in #merge!.
|
44
|
-
it { definition.merge!({:whatever => false})[:whatever].must_equal false }
|
42
|
+
it { _(definition.merge!({:whatever => false})[:whatever]).must_equal false }
|
45
43
|
|
46
44
|
# with block
|
47
45
|
it do
|
@@ -54,47 +52,47 @@ class DefinitionTest < MiniTest::Spec
|
|
54
52
|
# options[:extend].must_equal Module
|
55
53
|
end
|
56
54
|
|
57
|
-
definition[:awesome].must_equal true
|
58
|
-
definition[:something].must_equal true
|
59
|
-
definition[:render_filter].must_equal Representable::Pipeline[1]
|
60
|
-
definition[:parse_filter].must_equal Representable::Pipeline[]
|
55
|
+
_(definition[:awesome]).must_equal true
|
56
|
+
_(definition[:something]).must_equal true
|
57
|
+
_(definition[:render_filter]).must_equal Representable::Pipeline[1]
|
58
|
+
_(definition[:parse_filter]).must_equal Representable::Pipeline[]
|
61
59
|
end
|
62
60
|
|
63
61
|
describe "with :parse_filter" do
|
64
|
-
let
|
62
|
+
let(:definition) { Definition.new(:title, :parse_filter => 1) }
|
65
63
|
|
66
64
|
# merges :parse_filter and :render_filter.
|
67
65
|
it do
|
68
66
|
merged = definition.merge!(:parse_filter => 2)[:parse_filter]
|
69
67
|
|
70
|
-
merged.must_be_kind_of Representable::Pipeline
|
71
|
-
merged.size.must_equal 2
|
68
|
+
_(merged).must_be_kind_of Representable::Pipeline
|
69
|
+
_(merged.size).must_equal 2
|
72
70
|
end
|
73
71
|
|
74
72
|
# :parse_filter can also be array.
|
75
|
-
it { definition.merge!(:parse_filter => [2, 3])[:parse_filter].size.must_equal 3 }
|
73
|
+
it { _(definition.merge!(:parse_filter => [2, 3])[:parse_filter].size).must_equal 3 }
|
76
74
|
end
|
77
75
|
|
78
76
|
# does not change arguments
|
79
77
|
it do
|
80
78
|
Definition.new(:title).merge!(options = {:whatever => 1})
|
81
|
-
options.must_equal(:whatever => 1)
|
79
|
+
_(options).must_equal(:whatever => 1)
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
85
83
|
|
86
84
|
# delete!
|
87
85
|
describe "#delete!" do
|
88
|
-
let
|
86
|
+
let(:definition) { Definition.new(:song, serialize: "remove me!") }
|
89
87
|
|
90
|
-
before { definition[:serialize].
|
88
|
+
before { _(definition[:serialize].(nil)).must_equal "remove me!" }
|
91
89
|
|
92
|
-
it { definition.delete!(:serialize)[:serialize].
|
90
|
+
it { _(definition.delete!(:serialize)[:serialize]).must_be_nil }
|
93
91
|
end
|
94
92
|
|
95
93
|
# #inspect
|
96
94
|
describe "#inspect" do
|
97
|
-
it { Definition.new(:songs).inspect.must_equal "#<Representable::Definition ==>songs @options={:name=>\"songs\", :parse_filter=>[], :render_filter=>[]}>" }
|
95
|
+
it { _(Definition.new(:songs).inspect).must_equal "#<Representable::Definition ==>songs @options={:name=>\"songs\", :parse_filter=>[], :render_filter=>[]}>" }
|
98
96
|
end
|
99
97
|
|
100
98
|
|
@@ -104,13 +102,13 @@ class DefinitionTest < MiniTest::Spec
|
|
104
102
|
end
|
105
103
|
|
106
104
|
it "responds to #representer_module" do
|
107
|
-
|
105
|
+
assert_nil Representable::Definition.new(:song).representer_module
|
108
106
|
assert_equal Hash, Representable::Definition.new(:song, :extend => Hash).representer_module
|
109
107
|
end
|
110
108
|
|
111
109
|
describe "#typed?" do
|
112
110
|
it "is false per default" do
|
113
|
-
|
111
|
+
refute @def.typed?
|
114
112
|
end
|
115
113
|
|
116
114
|
it "is true when :class is present" do
|
@@ -129,7 +127,7 @@ class DefinitionTest < MiniTest::Spec
|
|
129
127
|
|
130
128
|
describe "#representable?" do
|
131
129
|
it { assert Definition.new(:song, :representable => true).representable? }
|
132
|
-
it { Definition.new(:song, :representable => true, :extend => Object).representable
|
130
|
+
it { _(Definition.new(:song, :representable => true, :extend => Object).representable?).must_equal true }
|
133
131
|
it { refute Definition.new(:song, :representable => false, :extend => Object).representable? }
|
134
132
|
it { assert Definition.new(:song, :extend => Object).representable? }
|
135
133
|
it { refute Definition.new(:song).representable? }
|
@@ -152,16 +150,16 @@ class DefinitionTest < MiniTest::Spec
|
|
152
150
|
it do
|
153
151
|
dfn = Representable::Definition.new(:songs, nested: Module)
|
154
152
|
assert dfn.typed?
|
155
|
-
dfn[:extend].(nil).must_equal Module
|
153
|
+
_(dfn[:extend].(nil)).must_equal Module
|
156
154
|
end
|
157
155
|
end
|
158
156
|
|
159
157
|
|
160
158
|
describe "#clone" do
|
161
|
-
subject { Representable::Definition.new(:title, :volume => 9, :clonable =>
|
159
|
+
subject { Representable::Definition.new(:title, :volume => 9, :clonable => ::Representable::Option(1)) }
|
162
160
|
|
163
|
-
it { subject.clone.must_be_kind_of Representable::Definition }
|
164
|
-
it { subject.clone[:clonable].
|
161
|
+
it { _(subject.clone).must_be_kind_of Representable::Definition }
|
162
|
+
it { _(subject.clone[:clonable].(nil)).must_equal 1 }
|
165
163
|
|
166
164
|
it "clones @options" do
|
167
165
|
@def.merge!(:volume => 9)
|
@@ -177,11 +175,11 @@ class DefinitionTest < MiniTest::Spec
|
|
177
175
|
|
178
176
|
describe "#has_default?" do
|
179
177
|
it "returns false if no :default set" do
|
180
|
-
|
178
|
+
refute Representable::Definition.new(:song).has_default?
|
181
179
|
end
|
182
180
|
|
183
181
|
it "returns true if :default set" do
|
184
|
-
|
182
|
+
assert Representable::Definition.new(:song, :default => nil).has_default?
|
185
183
|
end
|
186
184
|
end
|
187
185
|
|
@@ -192,14 +190,14 @@ class DefinitionTest < MiniTest::Spec
|
|
192
190
|
end
|
193
191
|
|
194
192
|
it "returns false when :binding is not set" do
|
195
|
-
|
193
|
+
refute Representable::Definition.new(:songs)[:binding]
|
196
194
|
end
|
197
195
|
end
|
198
196
|
|
199
197
|
describe "#create_binding" do
|
200
198
|
it "executes the block (without special context)" do
|
201
199
|
definition = Representable::Definition.new(:title, :binding => lambda { |*args| @binding = Representable::Binding.new(*args) })
|
202
|
-
definition.create_binding.must_equal @binding
|
200
|
+
_(definition.create_binding).must_equal @binding
|
203
201
|
end
|
204
202
|
end
|
205
203
|
|
@@ -217,7 +215,7 @@ class DefinitionTest < MiniTest::Spec
|
|
217
215
|
describe ":default => value" do
|
218
216
|
it "responds to #default" do
|
219
217
|
@def = Representable::Definition.new(:song)
|
220
|
-
|
218
|
+
assert_nil @def[:default]
|
221
219
|
end
|
222
220
|
|
223
221
|
it "accepts a default value" do
|
@@ -233,7 +231,7 @@ class DefinitionTest < MiniTest::Spec
|
|
233
231
|
|
234
232
|
it "responds to #hash?" do
|
235
233
|
assert @def.hash?
|
236
|
-
|
234
|
+
refute Representable::Definition.new(:songs).hash?
|
237
235
|
end
|
238
236
|
end
|
239
237
|
|