yaks-html 0.6.0.alpha → 0.6.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -525
- data/Rakefile +1 -41
- data/{yaks-html/lib → lib}/yaks-html.rb +0 -0
- data/{yaks-html/lib → lib}/yaks/format/html.rb +0 -0
- data/{yaks-html/lib → lib}/yaks/format/template.html +0 -0
- data/{yaks-html/spec → spec}/spec_helper.rb +0 -0
- data/{yaks-html/yaks-html.gemspec → yaks-html.gemspec} +1 -1
- metadata +11 -108
- data/.gitignore +0 -7
- data/.travis.yml +0 -36
- data/ADDING_FORMATS.md +0 -13
- data/CHANGELOG.md +0 -149
- data/Gemfile +0 -4
- data/IDENTIFIERS.md +0 -113
- data/LICENSE +0 -7
- data/bench/bench.rb +0 -16
- data/bench/bench_1000.rb +0 -60
- data/notes.org +0 -72
- data/shaved_yak.gif +0 -0
- data/yaks-html/README.md +0 -3
- data/yaks/README.md +0 -526
- data/yaks/lib/yaks.rb +0 -62
- data/yaks/lib/yaks/breaking_changes.rb +0 -49
- data/yaks/lib/yaks/collection_mapper.rb +0 -52
- data/yaks/lib/yaks/collection_resource.rb +0 -73
- data/yaks/lib/yaks/config.rb +0 -65
- data/yaks/lib/yaks/config/dsl.rb +0 -165
- data/yaks/lib/yaks/default_policy.rb +0 -100
- data/yaks/lib/yaks/format.rb +0 -87
- data/yaks/lib/yaks/format/collection_json.rb +0 -42
- data/yaks/lib/yaks/format/hal.rb +0 -82
- data/yaks/lib/yaks/format/json_api.rb +0 -86
- data/yaks/lib/yaks/fp.rb +0 -26
- data/yaks/lib/yaks/fp/callable.rb +0 -9
- data/yaks/lib/yaks/fp/hash_updatable.rb +0 -19
- data/yaks/lib/yaks/fp/updatable.rb +0 -17
- data/yaks/lib/yaks/mapper.rb +0 -75
- data/yaks/lib/yaks/mapper/association.rb +0 -43
- data/yaks/lib/yaks/mapper/association_mapper.rb +0 -42
- data/yaks/lib/yaks/mapper/attribute.rb +0 -17
- data/yaks/lib/yaks/mapper/class_methods.rb +0 -37
- data/yaks/lib/yaks/mapper/config.rb +0 -44
- data/yaks/lib/yaks/mapper/has_many.rb +0 -29
- data/yaks/lib/yaks/mapper/has_one.rb +0 -15
- data/yaks/lib/yaks/mapper/link.rb +0 -91
- data/yaks/lib/yaks/null_resource.rb +0 -40
- data/yaks/lib/yaks/primitivize.rb +0 -45
- data/yaks/lib/yaks/resource.rb +0 -51
- data/yaks/lib/yaks/resource/link.rb +0 -21
- data/yaks/lib/yaks/runner.rb +0 -101
- data/yaks/lib/yaks/util.rb +0 -56
- data/yaks/lib/yaks/version.rb +0 -3
- data/yaks/spec/acceptance/acceptance_spec.rb +0 -48
- data/yaks/spec/acceptance/json_shared_examples.rb +0 -8
- data/yaks/spec/acceptance/models.rb +0 -48
- data/yaks/spec/fixture_helpers.rb +0 -14
- data/yaks/spec/integration/map_to_resource_spec.rb +0 -28
- data/yaks/spec/json/confucius.collection.json +0 -28
- data/yaks/spec/json/confucius.hal.json +0 -59
- data/yaks/spec/json/confucius.json_api.json +0 -51
- data/yaks/spec/json/john.hal.json +0 -29
- data/yaks/spec/json/plant_collection.collection.json +0 -32
- data/yaks/spec/json/plant_collection.hal.json +0 -34
- data/yaks/spec/json/youtypeitwepostit.collection.json +0 -45
- data/yaks/spec/spec_helper.rb +0 -30
- data/yaks/spec/support/classes_for_policy_testing.rb +0 -36
- data/yaks/spec/support/deep_eql.rb +0 -123
- data/yaks/spec/support/fixtures.rb +0 -6
- data/yaks/spec/support/friends_mapper.rb +0 -29
- data/yaks/spec/support/models.rb +0 -23
- data/yaks/spec/support/pet_mapper.rb +0 -3
- data/yaks/spec/support/pet_peeve_mapper.rb +0 -3
- data/yaks/spec/support/shared_contexts.rb +0 -57
- data/yaks/spec/support/youtypeit_models_mappers.rb +0 -20
- data/yaks/spec/unit/yaks/collection_mapper_spec.rb +0 -165
- data/yaks/spec/unit/yaks/collection_resource_spec.rb +0 -77
- data/yaks/spec/unit/yaks/config/dsl_spec.rb +0 -87
- data/yaks/spec/unit/yaks/config_spec.rb +0 -74
- data/yaks/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +0 -80
- data/yaks/spec/unit/yaks/default_policy_spec.rb +0 -70
- data/yaks/spec/unit/yaks/format/collection_json_spec.rb +0 -41
- data/yaks/spec/unit/yaks/format/hal_spec.rb +0 -44
- data/yaks/spec/unit/yaks/format/json_api_spec.rb +0 -42
- data/yaks/spec/unit/yaks/format_spec.rb +0 -37
- data/yaks/spec/unit/yaks/fp/callable_spec.rb +0 -13
- data/yaks/spec/unit/yaks/fp/hash_updatable_spec.rb +0 -22
- data/yaks/spec/unit/yaks/fp/updatable_spec.rb +0 -22
- data/yaks/spec/unit/yaks/fp_spec.rb +0 -31
- data/yaks/spec/unit/yaks/mapper/association_mapper_spec.rb +0 -60
- data/yaks/spec/unit/yaks/mapper/association_spec.rb +0 -135
- data/yaks/spec/unit/yaks/mapper/attribute_spec.rb +0 -20
- data/yaks/spec/unit/yaks/mapper/class_methods_spec.rb +0 -67
- data/yaks/spec/unit/yaks/mapper/config_spec.rb +0 -166
- data/yaks/spec/unit/yaks/mapper/has_many_spec.rb +0 -89
- data/yaks/spec/unit/yaks/mapper/has_one_spec.rb +0 -51
- data/yaks/spec/unit/yaks/mapper/link_spec.rb +0 -196
- data/yaks/spec/unit/yaks/mapper_spec.rb +0 -303
- data/yaks/spec/unit/yaks/null_resource_spec.rb +0 -32
- data/yaks/spec/unit/yaks/primitivize_spec.rb +0 -77
- data/yaks/spec/unit/yaks/resource/link_spec.rb +0 -20
- data/yaks/spec/unit/yaks/resource_spec.rb +0 -108
- data/yaks/spec/unit/yaks/runner_spec.rb +0 -260
- data/yaks/spec/unit/yaks/util_spec.rb +0 -49
- data/yaks/spec/yaml/confucius.yaml +0 -28
- data/yaks/spec/yaml/youtypeitwepostit.yaml +0 -9
- data/yaks/yaks.gemspec +0 -41
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::FP do
|
4
|
-
include described_class
|
5
|
-
|
6
|
-
describe '#curry_method' do
|
7
|
-
def method_3args(a,b,c)
|
8
|
-
"#{a}-#{b}-#{c}"
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should curry the method' do
|
12
|
-
expect(curry_method(:method_3args).(1).(2,3)).to eql "1-2-3"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#send_with_args' do
|
17
|
-
it 'should bind the arguments' do
|
18
|
-
expect(send_with_args(:+, 'foo').('bar')).to eql 'barfoo'
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should bind the block' do
|
22
|
-
expect(send_with_args(:map) {|x| x.upcase }.(['bar'])).to eql ['BAR']
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '#identity_function' do
|
27
|
-
it 'should return whatever you pass it' do
|
28
|
-
expect(identity_function.(:foo)).to equal :foo
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::Mapper::AssociationMapper do
|
4
|
-
include_context 'yaks context'
|
5
|
-
|
6
|
-
subject(:association_mapper) { described_class.new(parent_mapper, association, yaks_context) }
|
7
|
-
|
8
|
-
let(:parent_mapper_class) { Yaks::Mapper }
|
9
|
-
let(:parent_mapper) { parent_mapper_class.new(yaks_context) }
|
10
|
-
|
11
|
-
fake(:association) { Yaks::Mapper::Association }
|
12
|
-
|
13
|
-
its(:policy) { should be policy }
|
14
|
-
|
15
|
-
let(:mapper_stack) { [:bottom_mapper] }
|
16
|
-
|
17
|
-
describe '#call' do
|
18
|
-
context 'when the association should be rendered as link' do
|
19
|
-
before do
|
20
|
-
stub(association).render_as_link?(parent_mapper) { true }
|
21
|
-
stub(association).map_rel(policy) { 'rels:the_rel' }
|
22
|
-
stub(association).href { 'http://this/is_where_the_associated_thing_can_be_found' }
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should render a link' do
|
26
|
-
expect(association_mapper.call(Yaks::Resource.new)).to eql Yaks::Resource.new(
|
27
|
-
links: [
|
28
|
-
Yaks::Resource::Link.new(
|
29
|
-
'rels:the_rel',
|
30
|
-
'http://this/is_where_the_associated_thing_can_be_found', {}
|
31
|
-
)
|
32
|
-
]
|
33
|
-
)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when the association should be rendered as a subresource' do
|
38
|
-
before do
|
39
|
-
stub(association).render_as_link?(parent_mapper) { false }
|
40
|
-
stub(association).map_rel(policy) { 'rels:the_rel' }
|
41
|
-
stub(association).name { :the_name }
|
42
|
-
stub(association).map_resource(:the_object, association_mapper.context) { :the_resource }
|
43
|
-
|
44
|
-
stub(parent_mapper).load_association(:the_name) { :the_object }
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should render a link' do
|
48
|
-
expect(association_mapper.call(Yaks::Resource.new)).to eql Yaks::Resource.new(
|
49
|
-
subresources: {
|
50
|
-
'rels:the_rel' => :the_resource
|
51
|
-
}
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should add the mapper to the mapper_stack' do
|
56
|
-
expect(association_mapper.context[:mapper_stack]).to eql [:bottom_mapper, parent_mapper]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,135 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::Mapper::Association do
|
4
|
-
include_context 'yaks context'
|
5
|
-
|
6
|
-
subject(:association) do
|
7
|
-
described_class.new(
|
8
|
-
name: name,
|
9
|
-
mapper: mapper,
|
10
|
-
rel: rel,
|
11
|
-
href: href,
|
12
|
-
link_if: link_if
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:name) { :shoes }
|
17
|
-
let(:mapper) { Yaks::Mapper }
|
18
|
-
let(:rel) { Yaks::Undefined }
|
19
|
-
let(:href) { Yaks::Undefined }
|
20
|
-
let(:link_if) { Yaks::Undefined }
|
21
|
-
|
22
|
-
its(:name) { should equal :shoes }
|
23
|
-
its(:child_mapper) { should equal Yaks::Mapper }
|
24
|
-
|
25
|
-
context 'with a minimal constructor' do
|
26
|
-
subject(:association) { described_class.new(name: :foo) }
|
27
|
-
|
28
|
-
its(:name) { should be :foo }
|
29
|
-
its(:child_mapper) { should be Yaks::Undefined }
|
30
|
-
its(:rel) { should be Yaks::Undefined }
|
31
|
-
its(:href) { should be Yaks::Undefined }
|
32
|
-
its(:link_if) { should be Yaks::Undefined }
|
33
|
-
end
|
34
|
-
|
35
|
-
let(:parent_mapper_class) { Yaks::Mapper }
|
36
|
-
let(:parent_mapper) { parent_mapper_class.new(yaks_context) }
|
37
|
-
|
38
|
-
describe '#add_to_resource' do
|
39
|
-
let(:object) { fake(:shoes => []) }
|
40
|
-
let(:rel) { 'rel:shoes' }
|
41
|
-
before do
|
42
|
-
parent_mapper.call(object)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should delegate to AssociationMapper' do
|
46
|
-
expect(association.add_to_resource(Yaks::Resource.new, parent_mapper, yaks_context)).to eql Yaks::Resource.new(subresources: {'rel:shoes' => nil} )
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '#render_as_link?' do
|
51
|
-
let(:href) { '/foo/{bar}/baz' }
|
52
|
-
let(:link_if) { -> { env.fetch('env_entry') == 123 } }
|
53
|
-
let(:rack_env) { { 'env_entry' => 123 } }
|
54
|
-
|
55
|
-
let(:render_as_link?) { association.render_as_link?(parent_mapper) }
|
56
|
-
|
57
|
-
context 'when evaluating to true' do
|
58
|
-
it 'should resolve :link_if in the context of the mapper' do
|
59
|
-
expect(render_as_link?).to be true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'when evaluating to false' do
|
64
|
-
let(:rack_env) { { 'env_entry' => 0 } }
|
65
|
-
|
66
|
-
it 'should resolve :link_if in the context of the mapper' do
|
67
|
-
expect(render_as_link?).to be false
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'with an Undefined href' do
|
72
|
-
let(:href) { Yaks::Undefined }
|
73
|
-
|
74
|
-
it 'should return falsey' do
|
75
|
-
expect(render_as_link?).to be_falsey
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'with an Undefined link_if' do
|
80
|
-
let(:link_if) { Yaks::Undefined }
|
81
|
-
|
82
|
-
it 'should return falsey' do
|
83
|
-
expect(render_as_link?).to be_falsey
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#map_rel' do
|
89
|
-
let(:association_rel) { association.map_rel(policy) }
|
90
|
-
|
91
|
-
context 'with a rel specified' do
|
92
|
-
let(:rel) { 'http://api.com/rels/shoes' }
|
93
|
-
|
94
|
-
it 'should use the specified rel' do
|
95
|
-
expect(association_rel).to eql 'http://api.com/rels/shoes'
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'without a rel specified' do
|
100
|
-
before do
|
101
|
-
stub(policy).derive_rel_from_association(association) {
|
102
|
-
'http://api.com/rel/derived'
|
103
|
-
}
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should infer a rel based on policy' do
|
107
|
-
expect(association_rel).to eql 'http://api.com/rel/derived'
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe '#resolve_association_mapper' do
|
113
|
-
context 'with a specified mapper' do
|
114
|
-
let(:mapper) { :a_specific_mapper_class }
|
115
|
-
|
116
|
-
it 'should return the mapper' do
|
117
|
-
expect(association.resolve_association_mapper(nil)).to equal :a_specific_mapper_class
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'with the mapper undefined' do
|
122
|
-
let(:mapper) { Yaks::Undefined }
|
123
|
-
|
124
|
-
before do
|
125
|
-
stub(policy).derive_mapper_from_association(association) {
|
126
|
-
:a_derived_mapper_class
|
127
|
-
}
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'should derive a mapper based on policy' do
|
131
|
-
expect(association.resolve_association_mapper(policy)).to equal :a_derived_mapper_class
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::Mapper::Attribute do
|
4
|
-
include_context 'yaks context'
|
5
|
-
|
6
|
-
subject(:attribute) { described_class.new(:the_name) }
|
7
|
-
fake(:mapper)
|
8
|
-
|
9
|
-
its(:name) { should be :the_name }
|
10
|
-
|
11
|
-
before do
|
12
|
-
stub(mapper).load_attribute(:the_name) { 123 }
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should add itself to a resource based on a lookup' do
|
16
|
-
expect(attribute.add_to_resource(Yaks::Resource.new, mapper , yaks_context)).to eql(
|
17
|
-
Yaks::Resource.new(attributes: { :the_name => 123 })
|
18
|
-
)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::Mapper::ClassMethods do
|
4
|
-
subject(:mapper_class) do
|
5
|
-
Class.new do
|
6
|
-
extend Yaks::Mapper::ClassMethods
|
7
|
-
attributes :foo, :bar
|
8
|
-
link :some_rel, 'http://some_link'
|
9
|
-
has_one :thing
|
10
|
-
has_many :thingies
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'attributes' do
|
15
|
-
it 'should allow setting them' do
|
16
|
-
expect( mapper_class.attributes ).to eq [
|
17
|
-
Yaks::Mapper::Attribute.new(:foo),
|
18
|
-
Yaks::Mapper::Attribute.new(:bar)
|
19
|
-
]
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'with inheritance' do
|
23
|
-
let(:child_class) do
|
24
|
-
Class.new(mapper_class) do
|
25
|
-
attributes :baz
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
let(:grandchild_class) do
|
30
|
-
Class.new(child_class)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should inherit attributes from the parent' do
|
34
|
-
expect(child_class.attributes).to eq [
|
35
|
-
Yaks::Mapper::Attribute.new(:foo),
|
36
|
-
Yaks::Mapper::Attribute.new(:bar),
|
37
|
-
Yaks::Mapper::Attribute.new(:baz)
|
38
|
-
]
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should create a valid config' do
|
42
|
-
expect(grandchild_class.config).to be_a Yaks::Mapper::Config
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should not alter the parent' do
|
46
|
-
expect(mapper_class.attributes).to eq [
|
47
|
-
Yaks::Mapper::Attribute.new(:foo),
|
48
|
-
Yaks::Mapper::Attribute.new(:bar),
|
49
|
-
]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should register links' do
|
55
|
-
expect(mapper_class.config.links).to eq [
|
56
|
-
Yaks::Mapper::Link.new(:some_rel, 'http://some_link', {})
|
57
|
-
]
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should register associations' do
|
61
|
-
expect(mapper_class.config.associations).to eq [
|
62
|
-
Yaks::Mapper::HasOne.new(name: :thing),
|
63
|
-
Yaks::Mapper::HasMany.new(name: :thingies)
|
64
|
-
]
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
@@ -1,166 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Yaks::Mapper::Config do
|
4
|
-
Undefined = Yaks::Undefined
|
5
|
-
|
6
|
-
subject(:config) { described_class.new(nil, [], [], []) }
|
7
|
-
|
8
|
-
describe '#initialize' do
|
9
|
-
subject(:config) { described_class.new('foo', [:a], [:b], [:c]) }
|
10
|
-
|
11
|
-
its(:type) { should eql 'foo' }
|
12
|
-
its(:attributes) { should eql [:a] }
|
13
|
-
its(:links) { should eql [:b] }
|
14
|
-
its(:associations) { should eql [:c] }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#attributes' do
|
18
|
-
context 'an empty config' do
|
19
|
-
it 'should return an empty attributes list' do
|
20
|
-
expect(config.attributes).to eq []
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should add attributes' do
|
25
|
-
expect(config.attributes(:foo, :bar, :baz).attributes).to eq [
|
26
|
-
Yaks::Mapper::Attribute.new(:foo),
|
27
|
-
Yaks::Mapper::Attribute.new(:bar),
|
28
|
-
Yaks::Mapper::Attribute.new(:baz)
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should be chainable' do
|
33
|
-
expect(
|
34
|
-
config
|
35
|
-
.attributes(:foo, :bar)
|
36
|
-
.attributes(:baz)
|
37
|
-
.attributes
|
38
|
-
).to eq [
|
39
|
-
Yaks::Mapper::Attribute.new(:foo),
|
40
|
-
Yaks::Mapper::Attribute.new(:bar),
|
41
|
-
Yaks::Mapper::Attribute.new(:baz)
|
42
|
-
]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#links' do
|
47
|
-
context 'an empty config' do
|
48
|
-
it 'should have an empty link list' do
|
49
|
-
expect(config.links).to eq []
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'adding links' do
|
54
|
-
let(:config) {
|
55
|
-
subject
|
56
|
-
.link(:self, '/foo/bar/{id}')
|
57
|
-
.link(:profile, '/profile/foo')
|
58
|
-
}
|
59
|
-
|
60
|
-
it 'should have the links in the link list' do
|
61
|
-
expect(config.links).to include Yaks::Mapper::Link.new(:profile, '/profile/foo', {})
|
62
|
-
expect(config.links).to include Yaks::Mapper::Link.new(:self, '/foo/bar/{id}', {})
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe 'links with the same rel' do
|
67
|
-
let(:config) {
|
68
|
-
subject
|
69
|
-
.link(:self, '/foo/self')
|
70
|
-
.link(:self, '/foo/me')
|
71
|
-
}
|
72
|
-
|
73
|
-
it 'should have the links in the defined order' do
|
74
|
-
expect(config.links).to eql [
|
75
|
-
Yaks::Mapper::Link.new(:self, '/foo/self', {}),
|
76
|
-
Yaks::Mapper::Link.new(:self, '/foo/me', {})
|
77
|
-
]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe '#has_one' do
|
83
|
-
context 'with a mapper specified' do
|
84
|
-
let(:config) { subject.has_one :mother, mapper: Yaks::Mapper }
|
85
|
-
|
86
|
-
it 'should have the association configured' do
|
87
|
-
expect(config.associations).to eq [
|
88
|
-
Yaks::Mapper::HasOne.new(name: :mother, mapper: Yaks::Mapper)
|
89
|
-
]
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'with no options' do
|
94
|
-
let(:config) { subject.has_one :mother }
|
95
|
-
|
96
|
-
it 'should have undefined mapper, rel, collection_mapper' do
|
97
|
-
expect(config.associations).to eq [
|
98
|
-
Yaks::Mapper::HasOne.new(name: :mother)
|
99
|
-
]
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'with a rel specified' do
|
104
|
-
let(:config) { subject.has_one :mother, rel: '/api/rels/mother' }
|
105
|
-
|
106
|
-
it 'should have the rel' do
|
107
|
-
expect(config.associations).to eq [
|
108
|
-
Yaks::Mapper::HasOne.new(name: :mother, rel: '/api/rels/mother')
|
109
|
-
]
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe '#has_many' do
|
116
|
-
context 'with a mapper specified' do
|
117
|
-
let(:config) { subject.has_many :shoes, mapper: Yaks::Mapper }
|
118
|
-
|
119
|
-
it 'should have the association configured' do
|
120
|
-
expect(config.associations).to eq [
|
121
|
-
Yaks::Mapper::HasMany.new(name: :shoes, mapper: Yaks::Mapper)
|
122
|
-
]
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'with no options' do
|
127
|
-
let(:config) { subject.has_many :shoes }
|
128
|
-
|
129
|
-
it 'should have undefined mapper, rel, collection_mapper' do
|
130
|
-
expect(config.associations).to eq [
|
131
|
-
Yaks::Mapper::HasMany.new(name: :shoes)
|
132
|
-
]
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context 'with a collection mapper set' do
|
137
|
-
let(:config) { subject.has_many :shoes, collection_mapper: :a_collection_mapper }
|
138
|
-
|
139
|
-
it 'should have the association configured' do
|
140
|
-
expect(config.associations).to eq [
|
141
|
-
Yaks::Mapper::HasMany.new(name: :shoes, collection_mapper: :a_collection_mapper)
|
142
|
-
]
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "#type" do
|
148
|
-
it "should update the type" do
|
149
|
-
config = config().type :shoe
|
150
|
-
expect(config.type).to be :shoe
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context 'multiple associations' do
|
155
|
-
let(:config) {
|
156
|
-
subject
|
157
|
-
.has_many(:shoes)
|
158
|
-
.has_one(:mother)
|
159
|
-
}
|
160
|
-
|
161
|
-
it 'should have them all present' do
|
162
|
-
expect(config.associations).to include Yaks::Mapper::HasOne.new(name: :mother)
|
163
|
-
expect(config.associations).to include Yaks::Mapper::HasMany.new(name: :shoes)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|