yaks 0.7.7 → 0.8.0.alpha

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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/Rakefile +1 -1
  4. data/lib/yaks/attributes.rb +17 -11
  5. data/lib/yaks/builder.rb +43 -0
  6. data/lib/yaks/changelog.rb +2 -2
  7. data/lib/yaks/collection_mapper.rb +0 -2
  8. data/lib/yaks/config.rb +52 -32
  9. data/lib/yaks/configurable.rb +43 -14
  10. data/lib/yaks/errors.rb +1 -0
  11. data/lib/yaks/format/collection_json.rb +37 -5
  12. data/lib/yaks/format/hal.rb +8 -2
  13. data/lib/yaks/format/halo.rb +16 -9
  14. data/lib/yaks/format/json_api.rb +21 -2
  15. data/lib/yaks/format.rb +21 -15
  16. data/lib/yaks/html5_forms.rb +3 -2
  17. data/lib/yaks/identifier/link_relation.rb +17 -0
  18. data/lib/yaks/mapper/attribute.rb +2 -2
  19. data/lib/yaks/mapper/config.rb +1 -15
  20. data/lib/yaks/mapper/form/config.rb +21 -0
  21. data/lib/yaks/mapper/form/field/option.rb +20 -0
  22. data/lib/yaks/mapper/form/field.rb +13 -26
  23. data/lib/yaks/mapper/form/fieldset.rb +43 -0
  24. data/lib/yaks/mapper/form.rb +41 -16
  25. data/lib/yaks/mapper/link.rb +9 -7
  26. data/lib/yaks/mapper.rb +15 -7
  27. data/lib/yaks/null_resource.rb +2 -1
  28. data/lib/yaks/pipeline.rb +42 -0
  29. data/lib/yaks/primitivize.rb +0 -1
  30. data/lib/yaks/reader/hal.rb +63 -0
  31. data/lib/yaks/resource/form/field.rb +19 -0
  32. data/lib/yaks/resource/form/fieldset.rb +13 -0
  33. data/lib/yaks/resource/form.rb +6 -10
  34. data/lib/yaks/resource.rb +19 -2
  35. data/lib/yaks/runner.rb +13 -38
  36. data/lib/yaks/serializer.rb +34 -1
  37. data/lib/yaks/util.rb +8 -2
  38. data/lib/yaks/version.rb +1 -1
  39. data/lib/yaks.rb +37 -10
  40. data/resources/iana-link-relations.csv +152 -0
  41. data/spec/acceptance/acceptance_spec.rb +4 -3
  42. data/spec/acceptance/json_shared_examples.rb +11 -0
  43. data/spec/acceptance/models.rb +1 -1
  44. data/spec/integration/dynamic_form_fields_spec.rb +36 -0
  45. data/spec/integration/fieldset_spec.rb +62 -0
  46. data/spec/integration/map_to_resource_spec.rb +0 -2
  47. data/spec/json/confucius.halo.json +0 -1
  48. data/spec/sanity_spec.rb +0 -2
  49. data/spec/spec_helper.rb +3 -3
  50. data/spec/unit/yaks/attributes_spec.rb +3 -5
  51. data/spec/unit/yaks/{stateful_builder_spec.rb → builder_spec.rb} +8 -10
  52. data/spec/unit/yaks/collection_mapper_spec.rb +0 -2
  53. data/spec/unit/yaks/collection_resource_spec.rb +0 -2
  54. data/spec/unit/yaks/config_spec.rb +9 -15
  55. data/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +0 -2
  56. data/spec/unit/yaks/default_policy_spec.rb +0 -2
  57. data/spec/unit/yaks/format/collection_json_spec.rb +195 -3
  58. data/spec/unit/yaks/format/hal_spec.rb +0 -2
  59. data/spec/unit/yaks/format/halo_spec.rb +0 -1
  60. data/spec/unit/yaks/format/html_spec.rb +0 -2
  61. data/spec/unit/yaks/format/json_api_spec.rb +0 -2
  62. data/spec/unit/yaks/format_spec.rb +4 -6
  63. data/spec/unit/yaks/fp/callable_spec.rb +0 -2
  64. data/spec/unit/yaks/fp_spec.rb +0 -2
  65. data/spec/unit/yaks/mapper/association_mapper_spec.rb +0 -2
  66. data/spec/unit/yaks/mapper/association_spec.rb +0 -2
  67. data/spec/unit/yaks/mapper/attribute_spec.rb +0 -2
  68. data/spec/unit/yaks/mapper/config_spec.rb +6 -167
  69. data/spec/unit/yaks/mapper/form/field_spec.rb +0 -2
  70. data/spec/unit/yaks/mapper/form_spec.rb +2 -26
  71. data/spec/unit/yaks/mapper/has_many_spec.rb +0 -2
  72. data/spec/unit/yaks/mapper/has_one_spec.rb +0 -2
  73. data/spec/unit/yaks/mapper/link_spec.rb +13 -2
  74. data/spec/unit/yaks/mapper_spec.rb +2 -10
  75. data/spec/unit/yaks/null_resource_spec.rb +2 -4
  76. data/spec/unit/yaks/pipeline_spec.rb +140 -0
  77. data/spec/unit/yaks/primitivize_spec.rb +0 -2
  78. data/spec/unit/yaks/resource/link_spec.rb +0 -2
  79. data/spec/unit/yaks/resource_spec.rb +2 -4
  80. data/spec/unit/yaks/runner_spec.rb +52 -92
  81. data/spec/unit/yaks/serializer_spec.rb +0 -2
  82. data/spec/unit/yaks/util_spec.rb +12 -2
  83. metadata +58 -23
  84. data/lib/yaks/config/dsl.rb +0 -174
  85. data/lib/yaks/mapper/class_methods.rb +0 -47
  86. data/lib/yaks/stateful_builder.rb +0 -63
  87. data/spec/unit/yaks/config/dsl_spec.rb +0 -92
  88. data/spec/unit/yaks/configurable_spec.rb +0 -55
  89. data/spec/unit/yaks/mapper/class_methods_spec.rb +0 -83
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Format::CollectionJson do
4
2
  context 'with the plant collection resource' do
5
3
  include_context 'plant collection resource'
@@ -9,7 +7,110 @@ RSpec.describe Yaks::Format::CollectionJson do
9
7
  it { should deep_eql(load_json_fixture('plant_collection.collection')) }
10
8
  end
11
9
 
12
- context 'link' do
10
+ context '#links?' do
11
+ context 'when resource is not a collection' do
12
+ let(:resource) {
13
+ Yaks::Resource.new(
14
+ attributes: {foo: 'fooval', bar: 'barval'},
15
+ links: [Yaks::Resource::Link.new(rel: 'the_rel', uri: 'the_uri')]
16
+ )
17
+ }
18
+
19
+ let(:cj) { Yaks::Format::CollectionJson.new(resource) }
20
+
21
+ it 'should return false' do
22
+ expect(cj.links?(resource)).to eq false
23
+ end
24
+ end
25
+
26
+ context 'when resource is a collection' do
27
+ let(:cj) { Yaks::Format::CollectionJson.new(resource) }
28
+
29
+ context 'and has links' do
30
+ let(:resource) {
31
+ Yaks::CollectionResource.new(
32
+ links: [Yaks::Resource::Link.new(rel: 'the_rel', uri: 'the_uri')]
33
+ )
34
+ }
35
+
36
+ it 'should return true' do
37
+ expect(cj.links?(resource)).to eq true
38
+ end
39
+ end
40
+
41
+ context 'and has no links' do
42
+ let(:resource) {
43
+ Yaks::CollectionResource.new(
44
+ links: []
45
+ )
46
+ }
47
+
48
+ it 'should return false' do
49
+ expect(cj.links?(resource)).to eq false
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ context '#queries?' do
56
+ let(:resource) {
57
+ Yaks::Resource.new(
58
+ attributes: {foo: 'fooval', bar: 'barval'},
59
+ forms: [Yaks::Resource::Form.new(full_args)]
60
+ )
61
+ }
62
+
63
+ subject {
64
+ Yaks::Primitivize.create.call(described_class.new.call(resource))
65
+ }
66
+
67
+ context 'when resource has GET forms' do
68
+ context 'and form has an action' do
69
+ let(:full_args) {
70
+ {
71
+ name: :search,
72
+ method: 'GET',
73
+ action: '/foo'
74
+ }
75
+ }
76
+
77
+ it 'should return true' do
78
+ cj = Yaks::Format::CollectionJson.new(resource)
79
+ expect(cj.queries?(resource)).to eq true
80
+ end
81
+ end
82
+
83
+ context 'and form has no action' do
84
+ let(:full_args) {
85
+ {
86
+ name: :search,
87
+ method: 'GET'
88
+ }
89
+ }
90
+
91
+ it 'should return false' do
92
+ cj = Yaks::Format::CollectionJson.new(resource)
93
+ expect(cj.queries?(resource)).to eq false
94
+ end
95
+ end
96
+ end
97
+
98
+ context 'when resource has not GET forms' do
99
+ let(:full_args) {
100
+ {
101
+ name: :search,
102
+ method: 'POST'
103
+ }
104
+ }
105
+
106
+ it 'should return false' do
107
+ cj = Yaks::Format::CollectionJson.new(resource)
108
+ expect(cj.queries?(resource)).to eq false
109
+ end
110
+ end
111
+ end
112
+
113
+ context 'serialize_links' do
13
114
  context 'without title' do
14
115
  let(:resource) {
15
116
  Yaks::Resource.new(
@@ -70,4 +171,95 @@ RSpec.describe Yaks::Format::CollectionJson do
70
171
  end
71
172
  end
72
173
  end
174
+
175
+ context 'serialize_queries' do
176
+ let(:resource) {
177
+ Yaks::Resource.new(
178
+ attributes: {foo: 'fooval', bar: 'barval'},
179
+ forms: [
180
+ Yaks::Resource::Form.new(full_args),
181
+ Yaks::Resource::Form.new(name: :no_render, action: '/foo', method: 'POST')
182
+ ]
183
+ )
184
+ }
185
+
186
+ subject {
187
+ Yaks::Primitivize.create.call(described_class.new.call(resource))
188
+ }
189
+
190
+ context 'when form method is GET' do
191
+ context "form uses only required fields" do
192
+ let(:full_args) {
193
+ {
194
+ name: :search,
195
+ action: '/foo',
196
+ method: 'GET'
197
+ }
198
+ }
199
+
200
+ it 'should render the queries array' do
201
+ should deep_eql(
202
+ "collection" => {
203
+ "version" => "1.0",
204
+ "items" => [
205
+ {
206
+ "data" => [
207
+ { "name"=>"foo", "value"=>"fooval" },
208
+ { "name"=>"bar", "value"=>"barval" }
209
+ ]
210
+ }
211
+ ],
212
+ "queries" => [
213
+ { "href"=>"/foo", "rel"=>"search" }
214
+ ]
215
+ }
216
+ )
217
+ end
218
+ end
219
+
220
+ context "form uses optional fields" do
221
+ let(:fields) {
222
+ [
223
+ Yaks::Resource::Form::Field.new(name: 'foo'),
224
+ Yaks::Resource::Form::Field.new(name: 'bar', label: 'My Bar Field')
225
+ ]
226
+ }
227
+
228
+ let(:full_args) {
229
+ {
230
+ name: :search,
231
+ action: '/foo',
232
+ method: 'GET',
233
+ title: 'My query prompt',
234
+ fields: fields
235
+ }
236
+ }
237
+
238
+ it 'should render the queries array with optional fields' do
239
+ should deep_eql(
240
+ "collection" => {
241
+ "version" => "1.0",
242
+ "items" => [
243
+ {
244
+ "data" => [
245
+ { "name"=>"foo", "value"=>"fooval" },
246
+ { "name"=>"bar", "value"=>"barval" }
247
+ ]
248
+ }
249
+ ],
250
+ "queries" => [
251
+ { "href"=>"/foo", "rel"=>"search", "prompt"=>"My query prompt",
252
+ "data"=>
253
+ [
254
+ { "name"=>"foo", "value"=>"" },
255
+ { "name"=>"bar", "value"=>"", "prompt"=>"My Bar Field" }
256
+ ]
257
+ }
258
+ ]
259
+ }
260
+ )
261
+ end
262
+ end
263
+ end
264
+ end
73
265
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Format::Hal do
4
2
  context 'with the plant collection resource' do
5
3
  include_context 'plant collection resource'
@@ -1,3 +1,2 @@
1
-
2
1
  RSpec.describe Yaks::Format::Halo do
3
2
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  # RSpec.describe Yaks::Format::HTML do
4
2
 
5
3
  # end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  # Mainly tested through the acceptance tests, here covering a few specific edge cases
4
2
  RSpec.describe Yaks::Format::JsonAPI do
5
3
  let(:format) { Yaks::Format::JsonAPI.new }
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Format do
4
2
  describe '.by_name' do
5
3
  specify do
@@ -10,9 +8,9 @@ RSpec.describe Yaks::Format do
10
8
  end
11
9
  end
12
10
 
13
- describe '.by_mime_type' do
11
+ describe '.by_media_type' do
14
12
  specify do
15
- expect(Yaks::Format.by_mime_type('application/hal+json')).to eql Yaks::Format::Hal
13
+ expect(Yaks::Format.by_media_type('application/hal+json')).to eql Yaks::Format::Hal
16
14
  end
17
15
  end
18
16
 
@@ -25,9 +23,9 @@ RSpec.describe Yaks::Format do
25
23
  end
26
24
  end
27
25
 
28
- describe '.mime_types' do
26
+ describe '.media_types' do
29
27
  specify do
30
- expect(Yaks::Format.mime_types.values_at(:collection_json, :hal, :json_api)).to eql(["application/vnd.collection+json", "application/hal+json", "application/vnd.api+json"])
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"])
31
29
  end
32
30
  end
33
31
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::FP::Callable do
4
2
  it 'should delegate to_proc to method(:call)' do
5
3
  obj = Class.new do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::FP do
4
2
  include described_class
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Mapper::AssociationMapper do
4
2
  include_context 'yaks context'
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Mapper::Association do
4
2
  include_context 'yaks context'
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Mapper::Attribute do
4
2
  include_context 'yaks context'
5
3
 
@@ -1,174 +1,13 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Mapper::Config do
4
- Undefined = Yaks::Undefined
5
-
6
- subject(:config) { described_class.new }
7
-
8
- describe '#initialize' do
9
- subject(:config) do
10
- described_class.new(
11
- type: 'foo',
12
- attributes: [:a],
13
- links: [:b],
14
- associations: [:c]
15
- )
16
- end
17
-
18
-
19
- its(:type) { should eql 'foo' }
20
- its(:attributes) { should eql [:a] }
21
- its(:links) { should eql [:b] }
22
- its(:associations) { should eql [:c] }
23
- end
24
-
25
- describe '#attributes' do
26
- context 'an empty config' do
27
- it 'should return an empty attributes list' do
28
- expect(config.attributes).to eq []
29
- end
30
- end
31
2
 
3
+ describe '#add_attributes' do
32
4
  it 'should add attributes' do
33
- expect(config.attributes(:foo, :bar, :baz).attributes).to eq [
34
- Yaks::Mapper::Attribute.new(:foo),
35
- Yaks::Mapper::Attribute.new(:bar),
36
- Yaks::Mapper::Attribute.new(:baz)
37
- ]
38
- end
39
-
40
- it 'should be chainable' do
41
- expect(
42
- config
43
- .attributes(:foo, :bar)
44
- .attributes(:baz)
45
- .attributes
46
- ).to eq [
47
- Yaks::Mapper::Attribute.new(:foo),
48
- Yaks::Mapper::Attribute.new(:bar),
49
- Yaks::Mapper::Attribute.new(:baz)
50
- ]
51
- end
52
- end
53
-
54
- describe '#links' do
55
- context 'an empty config' do
56
- it 'should have an empty link list' do
57
- expect(config.links).to eq []
58
- end
59
- end
60
-
61
- describe 'adding links' do
62
- let(:config) {
63
- subject
64
- .link(:self, '/foo/bar/{id}')
65
- .link(:profile, '/profile/foo')
66
- }
67
-
68
- it 'should have the links in the link list' do
69
- expect(config.links).to include Yaks::Mapper::Link.new(rel: :profile, template: '/profile/foo')
70
- expect(config.links).to include Yaks::Mapper::Link.new(rel: :self, template: '/foo/bar/{id}')
71
- end
72
- end
73
-
74
- describe 'links with the same rel' do
75
- let(:config) {
76
- subject
77
- .link(:self, '/foo/self')
78
- .link(:self, '/foo/me')
79
- }
80
-
81
- it 'should have the links in the defined order' do
82
- expect(config.links).to eql [
83
- Yaks::Mapper::Link.new(rel: :self, template: '/foo/self'),
84
- Yaks::Mapper::Link.new(rel: :self, template: '/foo/me')
85
- ]
86
- end
87
- end
88
- end
89
-
90
- describe '#has_one' do
91
- context 'with a mapper specified' do
92
- let(:config) { subject.has_one :mother, mapper: Yaks::Mapper }
93
-
94
- it 'should have the association configured' do
95
- expect(config.associations).to eq [
96
- Yaks::Mapper::HasOne.new(name: :mother, item_mapper: Yaks::Mapper)
97
- ]
98
- end
99
- end
100
-
101
- context 'with no options' do
102
- let(:config) { subject.has_one :mother }
103
-
104
- it 'should have undefined mapper, rel, collection_mapper' do
105
- expect(config.associations).to eq [
106
- Yaks::Mapper::HasOne.new(name: :mother)
107
- ]
108
- end
109
- end
110
-
111
- context 'with a rel specified' do
112
- let(:config) { subject.has_one :mother, rel: '/api/rels/mother' }
113
-
114
- it 'should have the rel' do
115
- expect(config.associations).to eq [
116
- Yaks::Mapper::HasOne.new(name: :mother, rel: '/api/rels/mother')
117
- ]
118
- end
119
-
120
- end
121
- end
122
-
123
- describe '#has_many' do
124
- context 'with a mapper specified' do
125
- let(:config) { subject.has_many :shoes, mapper: Yaks::Mapper }
126
-
127
- it 'should have the association configured' do
128
- expect(config.associations).to eq [
129
- Yaks::Mapper::HasMany.new(name: :shoes, item_mapper: Yaks::Mapper)
130
- ]
131
- end
132
- end
133
-
134
- context 'with no options' do
135
- let(:config) { subject.has_many :shoes }
136
-
137
- it 'should have undefined mapper, rel, collection_mapper' do
138
- expect(config.associations).to eq [
139
- Yaks::Mapper::HasMany.new(name: :shoes)
5
+ expect(subject.add_attributes(:bar).add_attributes(:baz)).to eql described_class.new(
6
+ attributes: [
7
+ Yaks::Mapper::Attribute.new(:bar),
8
+ Yaks::Mapper::Attribute.new(:baz),
140
9
  ]
141
- end
142
- end
143
-
144
- context 'with a collection mapper set' do
145
- let(:config) { subject.has_many :shoes, collection_mapper: :a_collection_mapper }
146
-
147
- it 'should have the association configured' do
148
- expect(config.associations).to eq [
149
- Yaks::Mapper::HasMany.new(name: :shoes, collection_mapper: :a_collection_mapper)
150
- ]
151
- end
152
- end
153
- end
154
-
155
- describe "#type" do
156
- it "should update the type" do
157
- config = config().type :shoe
158
- expect(config.type).to be :shoe
159
- end
160
- end
161
-
162
- context 'multiple associations' do
163
- let(:config) {
164
- subject
165
- .has_many(:shoes)
166
- .has_one(:mother)
167
- }
168
-
169
- it 'should have them all present' do
170
- expect(config.associations).to include Yaks::Mapper::HasOne.new(name: :mother)
171
- expect(config.associations).to include Yaks::Mapper::HasMany.new(name: :shoes)
10
+ )
172
11
  end
173
12
  end
174
13
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Mapper::Form::Field do
4
2
  include_context 'yaks context'
5
3
 
@@ -1,7 +1,5 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Mapper::Form do
4
- let(:form) { described_class.new( full_args ) }
2
+ let(:form) { described_class.create( full_args ) }
5
3
  let(:name) { :the_name }
6
4
  let(:full_args) { {name: name}.merge(args) }
7
5
  let(:args) {
@@ -16,26 +14,14 @@ RSpec.describe Yaks::Mapper::Form do
16
14
  let(:fields) { [] }
17
15
 
18
16
  describe '.create' do
19
- it 'should create an instance, first arg is the name' do
20
-
21
- expect( described_class.create(name, args) ).to eql form
22
- end
23
-
24
17
  it 'should have a name of nil when ommitted' do
25
18
  expect(described_class.create.name).to be_nil
26
19
  end
27
20
  end
28
21
 
29
22
  describe '#add_to_resource' do
30
- let(:resource) { form.add_to_resource(Yaks::Resource.new, Yaks::Mapper.new(nil), nil) }
23
+ let(:resource) { form.new.add_to_resource(Yaks::Resource.new, Yaks::Mapper.new(nil), nil) }
31
24
 
32
- it 'should add a form to the resource' do
33
- expect(resource.forms.length).to be 1
34
- end
35
-
36
- it 'should create a Yaks::Resource::Form with corresponding fields' do
37
- expect(resource.forms.first).to eql Yaks::Resource::Form.new( full_args )
38
- end
39
25
 
40
26
  context 'with fields' do
41
27
  let(:fields) {
@@ -49,16 +35,6 @@ RSpec.describe Yaks::Mapper::Form do
49
35
  ]
50
36
  }
51
37
 
52
- it 'should map to Yaks::Resource::Form::Field instances' do
53
- expect(resource.forms.first.fields).to eql [
54
- Yaks::Resource::Form::Field.new(
55
- name: 'field name',
56
- label: 'field label',
57
- type: 'text',
58
- value: 7
59
- )
60
- ]
61
- end
62
38
  end
63
39
  end
64
40
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Mapper::HasMany do
4
2
  include_context 'yaks context'
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Mapper::HasOne do
4
2
  include_context 'yaks context'
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Mapper::Link do
4
2
  include_context 'yaks context'
5
3
 
@@ -45,6 +43,19 @@ RSpec.describe Yaks::Mapper::Link do
45
43
  end
46
44
  end
47
45
 
46
+ context 'with :replace => true' do
47
+ let(:options) { { remove: true } }
48
+ let(:resource) {
49
+ Yaks::Resource.new.add_link(Yaks::Resource::Link.new(rel: :next, uri: '/api/next'))
50
+ }
51
+
52
+ it 'should remove earlier links of the same rel' do
53
+ expect(link.add_to_resource(resource, mapper, yaks_context)).to eql(
54
+ Yaks::Resource.new
55
+ )
56
+ end
57
+ end
58
+
48
59
  context 'with :replace => true' do
49
60
  let(:options) { { replace: true } }
50
61
  let(:resource) {
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Mapper do
4
2
  include_context 'yaks context'
5
3
 
@@ -306,19 +304,13 @@ RSpec.describe Yaks::Mapper do
306
304
 
307
305
  describe '#map_links' do
308
306
  let(:object) { fake('Link') }
309
- before { mapper.config(mapper.config.append_to(:links, object)) }
307
+ before { mapper_class.config = mapper.config.append_to(:links, object) }
310
308
  it_should_behave_like 'something that can be added to a resource'
311
309
  end
312
310
 
313
311
  describe '#map_subresources' do
314
312
  let(:object) { fake('Association') }
315
- before { mapper.config(mapper.config.append_to(:associations, object)) }
316
- it_should_behave_like 'something that can be added to a resource'
317
- end
318
-
319
- describe '#map_forms' do
320
- let(:object) { fake('Form') }
321
- before { mapper.config(mapper.config.append_to(:forms, object)) }
313
+ before { mapper_class.config = mapper.config.append_to(:associations, object) }
322
314
  it_should_behave_like 'something that can be added to a resource'
323
315
  end
324
316
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::NullResource do
4
2
  subject(:null_resource) { described_class.new }
5
3
 
@@ -33,8 +31,8 @@ RSpec.describe Yaks::NullResource do
33
31
  end
34
32
 
35
33
  it 'should not allow updating attributes' do
36
- expect { null_resource.update_attributes({}) }.to raise_error(
37
- Yaks::UnsupportedOperationError, "Operation update_attributes not supported on Yaks::NullResource"
34
+ expect { null_resource.merge_attributes({}) }.to raise_error(
35
+ Yaks::UnsupportedOperationError, "Operation merge_attributes not supported on Yaks::NullResource"
38
36
  )
39
37
  end
40
38