yaks 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +158 -56
- data/Rakefile +1 -3
- data/ataru_setup.rb +72 -0
- data/find_missing_tests.rb +34 -0
- data/lib/yaks.rb +8 -10
- data/lib/yaks/breaking_changes.rb +4 -6
- data/lib/yaks/builder.rb +1 -1
- data/lib/yaks/changelog.rb +1 -1
- data/lib/yaks/collection_mapper.rb +8 -5
- data/lib/yaks/collection_resource.rb +0 -1
- data/lib/yaks/config.rb +17 -7
- data/lib/yaks/configurable.rb +20 -14
- data/lib/yaks/default_policy.rb +82 -33
- data/lib/yaks/format.rb +7 -3
- data/lib/yaks/format/collection_json.rb +4 -4
- data/lib/yaks/format/hal.rb +1 -2
- data/lib/yaks/format/halo.rb +2 -4
- data/lib/yaks/format/json_api.rb +46 -27
- data/lib/yaks/html5_forms.rb +0 -2
- data/lib/yaks/mapper.rb +5 -5
- data/lib/yaks/mapper/association.rb +7 -7
- data/lib/yaks/mapper/association_mapper.rb +2 -0
- data/lib/yaks/mapper/attribute.rb +10 -4
- data/lib/yaks/mapper/config.rb +2 -2
- data/lib/yaks/mapper/form.rb +4 -10
- data/lib/yaks/mapper/form/config.rb +16 -17
- data/lib/yaks/mapper/form/dynamic_field.rb +1 -1
- data/lib/yaks/mapper/form/field.rb +16 -7
- data/lib/yaks/mapper/form/field/option.rb +5 -4
- data/lib/yaks/mapper/form/fieldset.rb +1 -1
- data/lib/yaks/mapper/form/legend.rb +18 -0
- data/lib/yaks/mapper/has_many.rb +1 -0
- data/lib/yaks/mapper/link.rb +7 -4
- data/lib/yaks/null_resource.rb +4 -5
- data/lib/yaks/pipeline.rb +2 -2
- data/lib/yaks/primitivize.rb +3 -2
- data/lib/yaks/reader/hal.rb +12 -13
- data/lib/yaks/reader/json_api.rb +50 -33
- data/lib/yaks/resource.rb +6 -7
- data/lib/yaks/resource/form.rb +2 -12
- data/lib/yaks/resource/form/field.rb +4 -3
- data/lib/yaks/resource/form/field/option.rb +1 -1
- data/lib/yaks/resource/form/fieldset.rb +1 -1
- data/lib/yaks/resource/form/legend.rb +18 -0
- data/lib/yaks/resource/has_fields.rb +13 -7
- data/lib/yaks/resource/link.rb +1 -1
- data/lib/yaks/runner.rb +5 -2
- data/lib/yaks/serializer.rb +2 -3
- data/lib/yaks/util.rb +7 -8
- data/lib/yaks/version.rb +1 -1
- data/spec/acceptance/acceptance_spec.rb +53 -38
- data/spec/acceptance/json_shared_examples.rb +45 -12
- data/spec/acceptance/models.rb +1 -1
- data/spec/integration/dynamic_form_fields_spec.rb +0 -1
- data/spec/integration/fieldset_spec.rb +18 -20
- data/spec/integration/map_to_resource_spec.rb +6 -6
- data/spec/json/{confucius.collection.json → confucius.collection_json.json} +0 -0
- data/spec/json/confucius.json_api.json +43 -27
- data/spec/json/list_of_quotes.collection_json.json +43 -0
- data/spec/json/list_of_quotes.hal.json +18 -0
- data/spec/json/list_of_quotes.json_api.json +25 -0
- data/spec/json/youtypeitwepostit.collection_json.json +45 -0
- data/spec/spec_helper.rb +4 -3
- data/spec/support/classes_for_policy_testing.rb +38 -14
- data/spec/support/deep_eql.rb +21 -18
- data/spec/support/pet_mapper.rb +2 -0
- data/spec/support/shared_contexts.rb +9 -9
- data/spec/unit/yaks/builder_spec.rb +41 -18
- data/spec/unit/yaks/collection_mapper_spec.rb +22 -19
- data/spec/unit/yaks/collection_resource_spec.rb +16 -8
- data/spec/unit/yaks/config_spec.rb +215 -19
- data/spec/unit/yaks/configurable_spec.rb +66 -7
- data/spec/unit/yaks/default_policy/derive_mapper_from_collection_spec.rb +47 -0
- data/spec/unit/yaks/default_policy/derive_mapper_from_item_spec.rb +114 -0
- data/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +29 -71
- data/spec/unit/yaks/default_policy_spec.rb +4 -5
- data/spec/unit/yaks/format/collection_json_spec.rb +35 -36
- data/spec/unit/yaks/format/hal_spec.rb +3 -3
- data/spec/unit/yaks/format/json_api_spec.rb +109 -68
- data/spec/unit/yaks/format_spec.rb +34 -0
- data/spec/unit/yaks/fp/callable_spec.rb +5 -3
- data/spec/unit/yaks/mapper/association_mapper_spec.rb +22 -4
- data/spec/unit/yaks/mapper/association_spec.rb +23 -11
- data/spec/unit/yaks/mapper/attribute_spec.rb +46 -7
- data/spec/unit/yaks/mapper/config_spec.rb +2 -3
- data/spec/unit/yaks/mapper/form/config_spec.rb +95 -0
- data/spec/unit/yaks/mapper/form/dynamic_field_spec.rb +30 -0
- data/spec/unit/yaks/mapper/form/field/option_spec.rb +48 -4
- data/spec/unit/yaks/mapper/form/field_spec.rb +43 -2
- data/spec/unit/yaks/mapper/form/fieldset_spec.rb +67 -8
- data/spec/unit/yaks/mapper/form/legend_spec.rb +52 -0
- data/spec/unit/yaks/mapper/form_spec.rb +84 -23
- data/spec/unit/yaks/mapper/has_many_spec.rb +39 -36
- data/spec/unit/yaks/mapper/has_one_spec.rb +28 -20
- data/spec/unit/yaks/mapper/link_spec.rb +68 -16
- data/spec/unit/yaks/mapper_spec.rb +118 -30
- data/spec/unit/yaks/null_resource_spec.rb +83 -52
- data/spec/unit/yaks/pipeline_spec.rb +101 -74
- data/spec/unit/yaks/primitivize_spec.rb +25 -6
- data/spec/unit/yaks/resource/form/field_spec.rb +5 -5
- data/spec/unit/yaks/resource/form/fieldset_spec.rb +7 -0
- data/spec/unit/yaks/resource/form/legend_spec.rb +8 -0
- data/spec/unit/yaks/resource/form_spec.rb +17 -37
- data/spec/unit/yaks/resource/has_fields_spec.rb +44 -3
- data/spec/unit/yaks/resource/link_spec.rb +11 -6
- data/spec/unit/yaks/resource_spec.rb +87 -98
- data/spec/unit/yaks/runner_spec.rb +112 -28
- data/spec/unit/yaks/serializer_spec.rb +1 -1
- data/spec/unit/yaks/util_spec.rb +30 -10
- data/spec/yaml/list_of_quotes.yaml +13 -0
- data/yaks.gemspec +21 -13
- metadata +129 -41
- data/lib/yaks/attributes.rb +0 -86
- data/lib/yaks/fp.rb +0 -26
- data/lib/yaks/identifier/link_relation.rb +0 -17
- data/resources/iana-link-relations.csv +0 -152
- data/spec/json/youtypeitwepostit.collection.json +0 -45
- data/spec/unit/yaks/attributes_spec.rb +0 -178
- data/spec/unit/yaks/fp_spec.rb +0 -29
@@ -9,7 +9,7 @@ RSpec.describe Yaks::Format::Hal do
|
|
9
9
|
|
10
10
|
context 'with multiple links on the same rel' do
|
11
11
|
let(:format) {
|
12
|
-
described_class.new(:
|
12
|
+
described_class.new(plural_links: 'my_plural_rel')
|
13
13
|
}
|
14
14
|
|
15
15
|
let(:resource) {
|
@@ -32,8 +32,8 @@ RSpec.describe Yaks::Format::Hal do
|
|
32
32
|
'bar' => 'barval',
|
33
33
|
'_links' => {
|
34
34
|
"my_plural_rel" => [
|
35
|
-
{"href"=>"the_uri1"},
|
36
|
-
{"href"=>"the_uri2"}
|
35
|
+
{"href" => "the_uri1"},
|
36
|
+
{"href" => "the_uri2"}
|
37
37
|
]
|
38
38
|
}
|
39
39
|
)
|
@@ -5,126 +5,167 @@ RSpec.describe Yaks::Format::JsonAPI do
|
|
5
5
|
context 'with no subresources' do
|
6
6
|
let(:resource) { Yaks::Resource.new(type: 'wizard', attributes: {foo: :bar}) }
|
7
7
|
|
8
|
-
it 'should not include
|
8
|
+
it 'should not include an "included" key' do
|
9
9
|
expect(format.call(resource)).to eql(
|
10
|
-
|
10
|
+
data: {type: 'wizards', attributes: {foo: :bar}}
|
11
11
|
)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context 'with
|
15
|
+
context 'collection with metadata' do
|
16
16
|
let(:resource) {
|
17
|
-
Yaks::
|
17
|
+
Yaks::CollectionResource.new(
|
18
18
|
type: 'wizard',
|
19
|
-
attributes: {
|
20
|
-
|
21
|
-
},
|
22
|
-
links: [
|
23
|
-
Yaks::Resource::Link.new(rel: :self, uri: '/the/self/link')
|
24
|
-
]
|
19
|
+
members: [Yaks::Resource.new(type: 'wizard', attributes: {foo: :bar})],
|
20
|
+
attributes: {meta: {page: {limit: 20, offset: 0, count: 25}}}
|
25
21
|
)
|
26
22
|
}
|
27
23
|
|
28
|
-
|
29
|
-
it 'should give preference to the href attribute' do
|
24
|
+
it 'should include the "meta" key' do
|
30
25
|
expect(format.call(resource)).to eql(
|
31
|
-
{
|
32
|
-
|
33
|
-
type: :wizards,
|
34
|
-
href: '/the/href'
|
35
|
-
}
|
36
|
-
]
|
37
|
-
}
|
26
|
+
meta: {page: {limit: 20, offset: 0, count: 25}},
|
27
|
+
data: [{type: 'wizards', attributes: {foo: :bar}}]
|
38
28
|
)
|
39
29
|
end
|
40
30
|
end
|
41
31
|
|
42
|
-
context 'with
|
32
|
+
context 'with links and subresources' do
|
43
33
|
let(:resource) {
|
44
34
|
Yaks::Resource.new(
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
35
|
+
type: 'wizard',
|
36
|
+
subresources: [
|
37
|
+
Yaks::Resource.new(rels: ['rel:favourite_spell'], type: 'spell', attributes: {id: 1}),
|
38
|
+
],
|
39
|
+
links: [
|
40
|
+
Yaks::Resource::Link.new(rel: :self, uri: '/the/self/link'),
|
41
|
+
Yaks::Resource::Link.new(rel: :profile, uri: '/the/profile/link'),
|
42
|
+
]
|
49
43
|
)
|
50
44
|
}
|
51
|
-
|
45
|
+
|
46
|
+
it 'should include the links in the "links" key' do
|
52
47
|
expect(format.call(resource)).to eql(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
48
|
+
data: {
|
49
|
+
type: 'wizards',
|
50
|
+
links: {
|
51
|
+
self: "/the/self/link",
|
52
|
+
profile: "/the/profile/link",
|
53
|
+
'favourite_spell' => {linkage: {type: "spells", id: "1"}},
|
54
|
+
}
|
55
|
+
},
|
56
|
+
included: [{type: 'spells', id: "1"}]
|
60
57
|
)
|
61
|
-
|
62
58
|
end
|
63
59
|
end
|
64
60
|
|
65
61
|
context 'with subresources' do
|
66
62
|
let(:resource) {
|
67
63
|
Yaks::Resource.new(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
type: 'wizard',
|
65
|
+
subresources: [
|
66
|
+
Yaks::Resource.new(rels: ['rel:favourite_spell'], type: 'spell', attributes: {id: 777, name: 'Lucky Sevens'})
|
67
|
+
]
|
72
68
|
)
|
73
69
|
}
|
74
|
-
|
70
|
+
|
71
|
+
it 'should include subresource links and included' do
|
75
72
|
expect(format.call(resource)).to eql(
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
}
|
82
|
-
],
|
83
|
-
linked: [{type: :spells, id: 777, name: 'Lucky Sevens'}]
|
84
|
-
}
|
73
|
+
data: {
|
74
|
+
type: 'wizards',
|
75
|
+
links: {'favourite_spell' => {linkage: {type: 'spells', id: "777"}}}
|
76
|
+
},
|
77
|
+
included: [{type: 'spells', id: "777", attributes: {name: 'Lucky Sevens'}}]
|
85
78
|
)
|
86
79
|
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'with duplicate subresources' do
|
83
|
+
let(:resource) {
|
84
|
+
Yaks::CollectionResource.new(
|
85
|
+
type: 'wizard',
|
86
|
+
members: [
|
87
|
+
Yaks::Resource.new(type: 'wizard', attributes: {id: 7}, subresources: [
|
88
|
+
Yaks::Resource.new(type: 'spell', attributes: {id: 1}, rels: ['rel:favourite_spell']),
|
89
|
+
]),
|
90
|
+
Yaks::Resource.new(type: 'wizard', attributes: {id: 3}, subresources: [
|
91
|
+
Yaks::Resource.new(type: 'spell', attributes: {id: 1}, rels: ['rel:favourite_spell']),
|
92
|
+
]),
|
93
|
+
Yaks::Resource.new(type: 'wizard', attributes: {id: 2}, subresources: [
|
94
|
+
Yaks::Resource.new(type: 'spell', attributes: {id: 12}, rels: ['rel:favourite_spell']),
|
95
|
+
]),
|
96
|
+
Yaks::Resource.new(type: 'wizard', attributes: {id: 9}, subresources: [
|
97
|
+
Yaks::Resource.new(type: 'wand', attributes: {id: 1}, rels: ['rel:wand']),
|
98
|
+
]),
|
99
|
+
],
|
100
|
+
)
|
101
|
+
}
|
87
102
|
|
103
|
+
it 'should include the each subresource only once' do
|
104
|
+
expect(format.call(resource)).to eql(
|
105
|
+
data: [
|
106
|
+
{type: 'wizards', id: '7', links: {'favourite_spell' => {linkage: {type: 'spells', id: '1'}}}},
|
107
|
+
{type: 'wizards', id: '3', links: {'favourite_spell' => {linkage: {type: 'spells', id: '1'}}}},
|
108
|
+
{type: 'wizards', id: '2', links: {'favourite_spell' => {linkage: {type: 'spells', id: '12'}}}},
|
109
|
+
{type: 'wizards', id: '9', links: {'wand' => {linkage: {type: 'wands', id: '1'}}}},
|
110
|
+
],
|
111
|
+
included: [
|
112
|
+
{type: 'spells', id: '1'},
|
113
|
+
{type: 'spells', id: '12'},
|
114
|
+
{type: 'wands', id: '1'},
|
115
|
+
]
|
116
|
+
)
|
117
|
+
end
|
88
118
|
end
|
89
119
|
|
90
120
|
context 'with null subresources' do
|
91
121
|
let(:resource) {
|
92
122
|
Yaks::Resource.new(
|
93
|
-
|
94
|
-
|
95
|
-
Yaks::NullResource.new
|
96
|
-
]
|
123
|
+
type: 'wizard',
|
124
|
+
subresources: [Yaks::NullResource.new]
|
97
125
|
)
|
98
126
|
}
|
99
|
-
|
127
|
+
|
128
|
+
it 'should not include subresource links' do
|
100
129
|
expect(format.call(resource)).to eql(
|
101
|
-
|
102
|
-
{
|
103
|
-
type: :wizards,
|
104
|
-
}
|
105
|
-
]
|
106
|
-
}
|
130
|
+
data: {type: 'wizards'}
|
107
131
|
)
|
108
132
|
end
|
109
133
|
end
|
110
134
|
|
111
|
-
context 'with no subresources or links' do
|
135
|
+
context 'with no subresources or subresource links' do
|
112
136
|
let(:resource) {
|
113
137
|
Yaks::Resource.new(
|
114
|
-
|
115
|
-
|
138
|
+
type: 'wizard',
|
139
|
+
subresources: []
|
116
140
|
)
|
117
141
|
}
|
118
|
-
|
142
|
+
|
143
|
+
it 'should not include subresource links' do
|
119
144
|
expect(format.call(resource)).to eql(
|
120
|
-
|
121
|
-
{
|
122
|
-
type: :wizards
|
123
|
-
}
|
124
|
-
]
|
125
|
-
}
|
145
|
+
data: {type: 'wizards'}
|
126
146
|
)
|
127
147
|
end
|
128
148
|
end
|
129
149
|
|
150
|
+
context 'with links as collection' do
|
151
|
+
let(:resource) {
|
152
|
+
Yaks::CollectionResource.new(
|
153
|
+
type: 'wizard',
|
154
|
+
links: [
|
155
|
+
Yaks::Resource::Link.new(rel: :prev, uri: '/prev/page/link'),
|
156
|
+
Yaks::Resource::Link.new(rel: :next, uri: '/next/page/link'),
|
157
|
+
]
|
158
|
+
)
|
159
|
+
}
|
160
|
+
|
161
|
+
it 'should include links' do
|
162
|
+
expect(format.call(resource)).to eql(
|
163
|
+
data: [],
|
164
|
+
links: {
|
165
|
+
prev: '/prev/page/link',
|
166
|
+
next: '/next/page/link',
|
167
|
+
}
|
168
|
+
)
|
169
|
+
end
|
170
|
+
end
|
130
171
|
end
|
@@ -28,4 +28,38 @@ RSpec.describe Yaks::Format do
|
|
28
28
|
expect(Yaks::Format.media_types.values_at(:collection_json, :hal, :json_api)).to eql(["application/vnd.collection+json", "application/hal+json", "application/vnd.api+json"])
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
let(:init_opts) { Hash.new }
|
33
|
+
subject(:format) { Yaks::Format.new(init_opts) }
|
34
|
+
|
35
|
+
describe "#initialize" do
|
36
|
+
it 'should set options' do
|
37
|
+
expect(format.send(:options)).to equal init_opts
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should default to an empty hash' do
|
41
|
+
expect(Yaks::Format.new.send(:options)).to eql({})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#call" do
|
46
|
+
it 'should set the environment' do
|
47
|
+
format.call(nil, foo: 1)
|
48
|
+
expect(format.env).to eql(foo: 1)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should default to an empty environment' do
|
52
|
+
format.call(:foo)
|
53
|
+
expect(format.env).to eql({})
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should delegate to #serialize_resource' do
|
57
|
+
stub(format).serialize_resource(:foo) {|_r| :bar}
|
58
|
+
expect(format.call(:foo)).to equal :bar
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#serialize_resource' do
|
63
|
+
specify { expect(format.serialize_resource(:foo)).to be_nil }
|
64
|
+
end
|
31
65
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
-
RSpec.describe Yaks::FP::Callable do
|
1
|
+
RSpec.describe Yaks::FP::Callable, "#to_proc" do
|
2
2
|
it 'should delegate to_proc to method(:call)' do
|
3
3
|
obj = Class.new do
|
4
4
|
include Yaks::FP::Callable
|
5
5
|
|
6
|
-
def call(x)
|
6
|
+
def call(x)
|
7
|
+
x * x
|
8
|
+
end
|
7
9
|
end.new
|
8
10
|
|
9
|
-
expect([1,2,3].map(&obj)).to eql [1,4,9]
|
11
|
+
expect([1, 2, 3].map(&obj)).to eql [1, 4, 9]
|
10
12
|
end
|
11
13
|
end
|
@@ -1,16 +1,34 @@
|
|
1
1
|
RSpec.describe Yaks::Mapper::AssociationMapper do
|
2
2
|
include_context 'yaks context'
|
3
3
|
|
4
|
-
subject(:association_mapper) {
|
4
|
+
subject(:association_mapper) {
|
5
|
+
described_class.new(parent_mapper, association, yaks_context)
|
6
|
+
}
|
5
7
|
|
6
8
|
let(:parent_mapper_class) { Yaks::Mapper }
|
7
|
-
let(:parent_mapper)
|
9
|
+
let(:parent_mapper) { parent_mapper_class.new(yaks_context) }
|
10
|
+
let(:mapper_stack) { [:bottom_mapper] }
|
8
11
|
|
9
12
|
fake(:association) { Yaks::Mapper::Association }
|
10
13
|
|
11
|
-
|
14
|
+
describe "#policy" do
|
15
|
+
its(:policy) { should be policy }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#initialize" do
|
19
|
+
its(:parent_mapper) { should equal parent_mapper }
|
20
|
+
its(:association) { should equal association }
|
12
21
|
|
13
|
-
|
22
|
+
it "should add the parent mapper to the mapper stack" do
|
23
|
+
expect(association_mapper.context[:mapper_stack])
|
24
|
+
.to eql [:bottom_mapper, parent_mapper]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should set the rel based on the association" do
|
28
|
+
stub(association).map_rel(policy) { '/association/rel' }
|
29
|
+
expect(association_mapper.rel).to eql '/association/rel'
|
30
|
+
end
|
31
|
+
end
|
14
32
|
|
15
33
|
describe '#call' do
|
16
34
|
context 'when the association should be rendered as link' do
|
@@ -1,8 +1,15 @@
|
|
1
1
|
RSpec.describe Yaks::Mapper::Association do
|
2
2
|
include_context 'yaks context'
|
3
3
|
|
4
|
+
let(:association_class) {
|
5
|
+
Class.new(described_class) do
|
6
|
+
def map_resource(_object, _context)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
}
|
10
|
+
|
4
11
|
subject(:association) do
|
5
|
-
|
12
|
+
association_class.new(
|
6
13
|
name: name,
|
7
14
|
item_mapper: mapper,
|
8
15
|
rel: rel,
|
@@ -23,7 +30,7 @@ RSpec.describe Yaks::Mapper::Association do
|
|
23
30
|
its(:item_mapper) { should equal Yaks::Mapper }
|
24
31
|
|
25
32
|
context 'with a minimal constructor' do
|
26
|
-
subject(:association) {
|
33
|
+
subject(:association) { association_class.new(name: :foo) }
|
27
34
|
|
28
35
|
its(:name) { should be :foo }
|
29
36
|
its(:item_mapper) { should be Yaks::Undefined }
|
@@ -36,7 +43,7 @@ RSpec.describe Yaks::Mapper::Association do
|
|
36
43
|
let(:parent_mapper) { parent_mapper_class.new(yaks_context) }
|
37
44
|
|
38
45
|
describe '#add_to_resource' do
|
39
|
-
let(:object) { fake(:
|
46
|
+
let(:object) { fake(shoes: []) }
|
40
47
|
let(:rel) { 'rel:shoes' }
|
41
48
|
|
42
49
|
before do
|
@@ -56,6 +63,12 @@ RSpec.describe Yaks::Mapper::Association do
|
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|
66
|
+
context 'without a condition' do
|
67
|
+
it 'should add the association' do
|
68
|
+
expect(association.add_to_resource(Yaks::Resource.new, parent_mapper, yaks_context).subresources.length).to be 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
59
72
|
context 'with a falsey condition' do
|
60
73
|
let(:if) { ->{ false } }
|
61
74
|
|
@@ -63,13 +76,12 @@ RSpec.describe Yaks::Mapper::Association do
|
|
63
76
|
expect(association.add_to_resource(Yaks::Resource.new, parent_mapper, yaks_context).subresources.length).to be 0
|
64
77
|
end
|
65
78
|
end
|
66
|
-
|
67
79
|
end
|
68
80
|
|
69
81
|
describe '#render_as_link?' do
|
70
82
|
let(:href) { '/foo/{bar}/baz' }
|
71
83
|
let(:link_if) { -> { env.fetch('env_entry') == 123 } }
|
72
|
-
let(:rack_env) { {
|
84
|
+
let(:rack_env) { {'env_entry' => 123} }
|
73
85
|
|
74
86
|
let(:render_as_link?) { association.render_as_link?(parent_mapper) }
|
75
87
|
|
@@ -80,7 +92,7 @@ RSpec.describe Yaks::Mapper::Association do
|
|
80
92
|
end
|
81
93
|
|
82
94
|
context 'when evaluating to false' do
|
83
|
-
let(:rack_env) { {
|
95
|
+
let(:rack_env) { {'env_entry' => 0} }
|
84
96
|
|
85
97
|
it 'should resolve :link_if in the context of the mapper' do
|
86
98
|
expect(render_as_link?).to be false
|
@@ -154,24 +166,24 @@ RSpec.describe Yaks::Mapper::Association do
|
|
154
166
|
|
155
167
|
describe '.create' do
|
156
168
|
it 'should take a name' do
|
157
|
-
expect(
|
169
|
+
expect(association_class.create(:foo).name).to be :foo
|
158
170
|
end
|
159
171
|
|
160
172
|
it 'should optionally take a mapper' do
|
161
|
-
expect(
|
173
|
+
expect(association_class.create(:foo, mapper: :bar).item_mapper).to be :bar
|
162
174
|
end
|
163
175
|
|
164
176
|
it 'should take other options' do
|
165
|
-
expect(
|
177
|
+
expect(association_class.create(:foo, mapper: :bar, href: 'xxx').href).to eql 'xxx'
|
166
178
|
end
|
167
179
|
|
168
180
|
it 'should respect attribute defaults' do
|
169
|
-
expect(
|
181
|
+
expect(association_class.create(:foo, href: 'xxx').item_mapper).to be Yaks::Undefined
|
170
182
|
end
|
171
183
|
|
172
184
|
it 'should not munge the options hash' do
|
173
185
|
opts = {mapper: :foo}
|
174
|
-
|
186
|
+
association_class.create(:foo, opts)
|
175
187
|
expect(opts).to eql(mapper: :foo)
|
176
188
|
end
|
177
189
|
end
|