fun_with_json_api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -1
  3. data/config/locales/fun_with_json_api.en.yml +29 -2
  4. data/lib/fun_with_json_api.rb +30 -2
  5. data/lib/fun_with_json_api/action_controller_extensions/serialization.rb +18 -0
  6. data/lib/fun_with_json_api/attribute.rb +3 -3
  7. data/lib/fun_with_json_api/attributes/relationship.rb +37 -23
  8. data/lib/fun_with_json_api/attributes/relationship_collection.rb +55 -38
  9. data/lib/fun_with_json_api/attributes/string_attribute.rb +12 -1
  10. data/lib/fun_with_json_api/attributes/uuid_v4_attribute.rb +27 -0
  11. data/lib/fun_with_json_api/controller_methods.rb +1 -1
  12. data/lib/fun_with_json_api/deserializer.rb +61 -8
  13. data/lib/fun_with_json_api/deserializer_class_methods.rb +37 -7
  14. data/lib/fun_with_json_api/exceptions/illegal_client_generated_identifier.rb +17 -0
  15. data/lib/fun_with_json_api/exceptions/invalid_client_generated_identifier.rb +17 -0
  16. data/lib/fun_with_json_api/exceptions/invalid_document_identifier.rb +17 -0
  17. data/lib/fun_with_json_api/exceptions/invalid_document_type.rb +20 -0
  18. data/lib/fun_with_json_api/exceptions/invalid_relationship.rb +5 -3
  19. data/lib/fun_with_json_api/exceptions/invalid_relationship_type.rb +17 -0
  20. data/lib/fun_with_json_api/exceptions/missing_resource.rb +15 -0
  21. data/lib/fun_with_json_api/exceptions/unknown_attribute.rb +15 -0
  22. data/lib/fun_with_json_api/exceptions/unknown_relationship.rb +15 -0
  23. data/lib/fun_with_json_api/find_collection_from_document.rb +124 -0
  24. data/lib/fun_with_json_api/find_resource_from_document.rb +112 -0
  25. data/lib/fun_with_json_api/pre_deserializer.rb +1 -0
  26. data/lib/fun_with_json_api/railtie.rb +30 -1
  27. data/lib/fun_with_json_api/schema_validator.rb +47 -0
  28. data/lib/fun_with_json_api/schema_validators/check_attributes.rb +52 -0
  29. data/lib/fun_with_json_api/schema_validators/check_document_id_matches_resource.rb +96 -0
  30. data/lib/fun_with_json_api/schema_validators/check_document_type_matches_resource.rb +40 -0
  31. data/lib/fun_with_json_api/schema_validators/check_relationships.rb +127 -0
  32. data/lib/fun_with_json_api/version.rb +1 -1
  33. data/spec/dummy/log/test.log +172695 -0
  34. data/spec/fixtures/active_record.rb +6 -0
  35. data/spec/fun_with_json_api/controller_methods_spec.rb +8 -3
  36. data/spec/fun_with_json_api/deserializer_class_methods_spec.rb +14 -6
  37. data/spec/fun_with_json_api/deserializer_spec.rb +155 -40
  38. data/spec/fun_with_json_api/exception_spec.rb +9 -9
  39. data/spec/fun_with_json_api/find_collection_from_document_spec.rb +203 -0
  40. data/spec/fun_with_json_api/find_resource_from_document_spec.rb +100 -0
  41. data/spec/fun_with_json_api/pre_deserializer_spec.rb +26 -26
  42. data/spec/fun_with_json_api/railtie_spec.rb +88 -0
  43. data/spec/fun_with_json_api/schema_validator_spec.rb +94 -0
  44. data/spec/fun_with_json_api/schema_validators/check_attributes_spec.rb +52 -0
  45. data/spec/fun_with_json_api/schema_validators/check_document_id_matches_resource_spec.rb +115 -0
  46. data/spec/fun_with_json_api/schema_validators/check_document_type_matches_resource_spec.rb +30 -0
  47. data/spec/fun_with_json_api/schema_validators/check_relationships_spec.rb +150 -0
  48. data/spec/fun_with_json_api_spec.rb +148 -4
  49. metadata +49 -4
  50. data/spec/example_spec.rb +0 -64
@@ -54,6 +54,12 @@ module ARModels
54
54
  belongs_to :author, -> { AuthorDeserializer }
55
55
  end
56
56
 
57
+ class AuthorSerializer < ActiveModel::Serializer
58
+ type 'person'
59
+ attribute :name
60
+ has_many :posts
61
+ end
62
+
57
63
  class AuthorDeserializer < FunWithJsonApi::Deserializer
58
64
  type 'person'
59
65
  resource_class Author
@@ -4,7 +4,9 @@ describe FunWithJsonApi::ControllerMethods, type: :controller do
4
4
  describe '#render_fun_with_json_api_exception' do
5
5
  context 'with a controller that raises an exception' do
6
6
  controller do
7
+ # rubocop:disable RSpec/DescribedClass
7
8
  include FunWithJsonApi::ControllerMethods
9
+ # rubocop:enable RSpec/DescribedClass
8
10
 
9
11
  rescue_from FunWithJsonApi::Exception, with: :render_fun_with_json_api_exception
10
12
 
@@ -35,9 +37,10 @@ describe FunWithJsonApi::ControllerMethods, type: :controller do
35
37
  it 'returns a json api error status' do
36
38
  get :index
37
39
  expect(response.status).to eq 403
40
+ expect(response.content_type).to eq 'application/vnd.api+json'
38
41
  end
39
42
 
40
- it 'renders the exception payload as a json api errors response ' do
43
+ it 'renders the exception payload as a json api errors response' do
41
44
  get :index
42
45
  expect(JSON.parse(response.body)).to eq(
43
46
  'errors' => [
@@ -74,9 +77,10 @@ describe FunWithJsonApi::ControllerMethods, type: :controller do
74
77
  it 'returns a json api error status' do
75
78
  get :index
76
79
  expect(response.status).to eq 403
80
+ expect(response.content_type).to eq 'application/vnd.api+json'
77
81
  end
78
82
 
79
- it 'renders all exception payload items ' do
83
+ it 'renders all exception payload items' do
80
84
  get :index
81
85
  expect(JSON.parse(response.body)).to eq(
82
86
  'errors' => [
@@ -104,9 +108,10 @@ describe FunWithJsonApi::ControllerMethods, type: :controller do
104
108
  it 'returns a json api error status' do
105
109
  get :index
106
110
  expect(response.status).to eq 422
111
+ expect(response.content_type).to eq 'application/vnd.api+json'
107
112
  end
108
113
 
109
- it 'only renders the non-nil params ' do
114
+ it 'only renders the non-nil params' do
110
115
  get :index
111
116
  expect(JSON.parse(response.body)).to eq(
112
117
  'errors' => [
@@ -2,14 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  describe FunWithJsonApi::DeserializerClassMethods do
4
4
  describe '.belongs_to' do
5
- it 'should add a Relationship attribute' do
5
+ it 'adds a Relationship attribute' do
6
6
  foos_deserializer_class = Class.new(FunWithJsonApi::Deserializer) do
7
7
  attribute :blargh
8
+ has_many :foos, -> { foos_deserializer_class }
8
9
  end
9
10
  deserializer_class = Class.new(FunWithJsonApi::Deserializer) do
10
11
  belongs_to :foo, -> { foos_deserializer_class }
11
12
  end
12
- relationship = deserializer_class.relationships.last
13
+
14
+ deserializer = deserializer_class.create
15
+
16
+ relationship = deserializer.relationships.last
13
17
  expect(relationship).to be_kind_of(FunWithJsonApi::Attributes::Relationship)
14
18
 
15
19
  expect(relationship.name).to eq :foo
@@ -22,14 +26,18 @@ describe FunWithJsonApi::DeserializerClassMethods do
22
26
  end
23
27
 
24
28
  describe '.has_many' do
25
- it 'should add a RelationshipCollection attribute' do
29
+ it 'adds a RelationshipCollection attribute' do
26
30
  foos_deserializer_class = Class.new(FunWithJsonApi::Deserializer) do
27
31
  attribute :blargh
32
+ has_many :foos, -> { foos_deserializer_class }
28
33
  end
29
34
  deserializer_class = Class.new(FunWithJsonApi::Deserializer) do
30
35
  has_many :foos, -> { foos_deserializer_class }
31
36
  end
32
- relationship = deserializer_class.relationships.last
37
+
38
+ deserializer = deserializer_class.create
39
+
40
+ relationship = deserializer.relationships.last
33
41
  expect(relationship).to be_kind_of(FunWithJsonApi::Attributes::RelationshipCollection)
34
42
 
35
43
  expect(relationship.name).to eq :foos
@@ -40,12 +48,12 @@ describe FunWithJsonApi::DeserializerClassMethods do
40
48
  expect(relationship.deserializer.relationships).to eq []
41
49
  end
42
50
 
43
- it 'should not allow pluralized as values' do
51
+ it 'does not allow pluralized "as" values' do
44
52
  foos_deserializer_class = Class.new(FunWithJsonApi::Deserializer)
45
53
  expect do
46
54
  Class.new(FunWithJsonApi::Deserializer) do
47
55
  has_many :foos, -> { foos_deserializer_class }, as: 'foos'
48
- end
56
+ end.relationships
49
57
  end.to raise_error(ArgumentError, 'Use a singular relationship as value: {as: :foo}')
50
58
  end
51
59
  end
@@ -37,40 +37,115 @@ def deserializer_with_attribute(attribute, attribute_options = {})
37
37
  end
38
38
 
39
39
  describe FunWithJsonApi::Deserializer do
40
+ describe '.id_param' do
41
+ context 'with no arguments' do
42
+ it 'sets id_param to id for all new deserializer instances' do
43
+ instance = Class.new(described_class).create
44
+ expect(instance.id_param).to eq :id
45
+ expect(instance.attributes.size).to eq 0
46
+ end
47
+ end
48
+ context 'with a name argument' do
49
+ it 'adds an aliased id attribute for all new deserializer instances' do
50
+ instance = Class.new(described_class) do
51
+ id_param :code
52
+ end.create
53
+ expect(instance.id_param).to eq :code
54
+ expect(instance.attributes.size).to eq 0
55
+ end
56
+ it 'converts the name parameter to a symbol' do
57
+ instance = Class.new(described_class) do
58
+ id_param 'code'
59
+ end.create
60
+ expect(instance.id_param).to eq :code
61
+ expect(instance.attributes.size).to eq 0
62
+ end
63
+ end
64
+ context 'with a format argument' do
65
+ it 'adds an id attribute with format to all new deserializer instances' do
66
+ instance = Class.new(described_class) do
67
+ id_param format: :integer
68
+ end.create
69
+ expect(instance.id_param).to eq :id
70
+ expect(instance.attributes.size).to eq 1
71
+
72
+ attribute = instance.attributes.first
73
+ expect(attribute).to be_kind_of(FunWithJsonApi::Attributes::IntegerAttribute)
74
+ expect(attribute.name).to eq :id
75
+ expect(attribute.as).to eq :id
76
+ end
77
+ end
78
+ context 'with a name and format argument' do
79
+ it 'adds an aliased id attribute with format to all new deserializer instances' do
80
+ instance = Class.new(described_class) do
81
+ id_param :code, format: :uuid_v4
82
+ end.create
83
+ expect(instance.id_param).to eq :code
84
+ expect(instance.attributes.size).to eq 1
85
+
86
+ attribute = instance.attributes.first
87
+ expect(attribute).to be_kind_of(FunWithJsonApi::Attributes::UuidV4Attribute)
88
+ expect(attribute.name).to eq :id
89
+ expect(attribute.as).to eq :code
90
+ end
91
+ end
92
+ end
93
+
40
94
  describe '#parse_{attribute}' do
41
95
  context 'with an alias value' do
42
- it 'should generated an attribute from the alias value' do
96
+ it 'defines a parse method from the alias value' do
43
97
  deserializer = deserializer_with_attribute(:original_key, as: :assigned_key)
44
98
  expect(deserializer.parse_assigned_key('Foo Bar')).to eq 'Foo Bar'
45
- expect(deserializer).to_not respond_to(:original_key)
99
+ expect(deserializer).not_to respond_to(:original_key)
46
100
  end
47
101
  end
48
102
 
49
103
  context 'with no format argument (string)' do
50
- it 'should allow a String value' do
104
+ it 'allows a String value' do
51
105
  deserializer = deserializer_with_attribute(:example)
52
106
  expect(deserializer.parse_example('Foo Bar')).to eq 'Foo Bar'
53
107
  end
54
- it 'should allow a nil value' do
108
+ it 'allows a nil value' do
55
109
  deserializer = deserializer_with_attribute(:example)
56
110
  expect(deserializer.parse_example(nil)).to be nil
57
111
  end
112
+ it 'raises an InvalidAttribute error an for non string value' do
113
+ deserializer = deserializer_with_attribute(:example)
114
+ [1, true, false, [], {}].each do |value|
115
+ expect do
116
+ deserializer.parse_example(value)
117
+ end.to raise_error(FunWithJsonApi::Exceptions::InvalidAttribute) do |e|
118
+ expect(e.payload.size).to eq 1
119
+
120
+ payload = e.payload.first
121
+ expect(payload.status).to eq '400'
122
+ expect(payload.code).to eq 'invalid_attribute'
123
+ expect(payload.title).to eq(
124
+ I18n.t('fun_with_json_api.exceptions.invalid_attribute')
125
+ )
126
+ expect(payload.detail).to eq(
127
+ I18n.t('fun_with_json_api.exceptions.invalid_string_attribute')
128
+ )
129
+ expect(payload.pointer).to eq '/data/attributes/example'
130
+ end
131
+ end
132
+ end
58
133
  end
59
134
 
60
135
  context 'with a boolean format' do
61
- it 'should allow a Boolean.TRUE value' do
136
+ it 'allows a Boolean.TRUE value' do
62
137
  deserializer = deserializer_with_attribute(:example, format: :boolean)
63
138
  expect(deserializer.parse_example(true)).to eq true
64
139
  end
65
- it 'should allow a Boolean.FALSE value' do
140
+ it 'allows a Boolean.FALSE value' do
66
141
  deserializer = deserializer_with_attribute(:example, format: :boolean)
67
142
  expect(deserializer.parse_example(false)).to eq false
68
143
  end
69
- it 'should allow a nil value' do
144
+ it 'allows a nil value' do
70
145
  deserializer = deserializer_with_attribute(:example, format: :boolean)
71
146
  expect(deserializer.parse_example(nil)).to be nil
72
147
  end
73
- it 'should raise an InvalidAttribute for invalid boolean values' do
148
+ it 'raises an InvalidAttribute error an for invalid boolean values' do
74
149
  deserializer = deserializer_with_attribute(:example, format: :boolean)
75
150
  ['true', 'True', 'TRUE', 1, 'false', 'False', 'FALSE', 0].each do |value|
76
151
  expect do
@@ -94,15 +169,15 @@ describe FunWithJsonApi::Deserializer do
94
169
  end
95
170
 
96
171
  context 'with a date format' do
97
- it 'should allow a "YYYY-MM-DD" formatted value' do
172
+ it 'allows a "YYYY-MM-DD" formatted date String' do
98
173
  deserializer = deserializer_with_attribute(:example, format: :date)
99
174
  expect(deserializer.parse_example('2016-03-12')).to eq Date.new(2016, 03, 12)
100
175
  end
101
- it 'should allow a nil value' do
176
+ it 'allows a nil value' do
102
177
  deserializer = deserializer_with_attribute(:example, format: :date)
103
178
  expect(deserializer.parse_example(nil)).to be nil
104
179
  end
105
- it 'should raise an InvalidAttribute for invalid date value' do
180
+ it 'raises an InvalidAttribute error an for invalid date value' do
106
181
  deserializer = deserializer_with_attribute(:example, format: :date)
107
182
  ['2016-12', 'Last Wednesday', 'April'].each do |value|
108
183
  expect do
@@ -126,7 +201,7 @@ describe FunWithJsonApi::Deserializer do
126
201
  end
127
202
 
128
203
  context 'with a datetime format' do
129
- it 'should allow a ISO 8601 formatted values' do
204
+ it 'allows a ISO 8601 formatted values' do
130
205
  deserializer = deserializer_with_attribute(:example, format: :datetime)
131
206
  [
132
207
  '2016-03-11T03:45:40+00:00',
@@ -139,11 +214,11 @@ describe FunWithJsonApi::Deserializer do
139
214
  )
140
215
  end
141
216
  end
142
- it 'should allow a nil value' do
217
+ it 'allows a nil value' do
143
218
  deserializer = deserializer_with_attribute(:example, format: :datetime)
144
219
  expect(deserializer.parse_example(nil)).to be nil
145
220
  end
146
- it 'should raise an InvalidAttribute for invalid date value' do
221
+ it 'raises an InvalidAttribute error an for invalid date value' do
147
222
  deserializer = deserializer_with_attribute(:example, format: :datetime)
148
223
  [
149
224
  'Last Wednesday',
@@ -170,27 +245,27 @@ describe FunWithJsonApi::Deserializer do
170
245
  end
171
246
 
172
247
  context 'with a decimal format' do
173
- it 'should allow integers' do
248
+ it 'allows integers' do
174
249
  deserializer = deserializer_with_attribute(:example, format: :decimal)
175
250
  expect(deserializer.parse_example(12)).to eq BigDecimal.new('12')
176
251
  end
177
- it 'should allow floats' do
252
+ it 'allows floats' do
178
253
  deserializer = deserializer_with_attribute(:example, format: :decimal)
179
254
  expect(deserializer.parse_example(12.34)).to eq BigDecimal.new('12.34')
180
255
  end
181
- it 'should allow integer numbers as strings' do
256
+ it 'allows integer numbers as strings' do
182
257
  deserializer = deserializer_with_attribute(:example, format: :decimal)
183
258
  expect(deserializer.parse_example('12')).to eq BigDecimal.new('12')
184
259
  end
185
- it 'should allow floating point numbers as strings' do
260
+ it 'allows floating point numbers as strings' do
186
261
  deserializer = deserializer_with_attribute(:example, format: :decimal)
187
262
  expect(deserializer.parse_example('12.30')).to eq BigDecimal.new('12.30')
188
263
  end
189
- it 'should allow a nil value' do
264
+ it 'allows a nil value' do
190
265
  deserializer = deserializer_with_attribute(:example, format: :decimal)
191
266
  expect(deserializer.parse_example(nil)).to be nil
192
267
  end
193
- it 'should raise an InvalidAttribute for invalid decimal value' do
268
+ it 'raises an InvalidAttribute error an for invalid decimal value' do
194
269
  deserializer = deserializer_with_attribute(:example, format: :decimal)
195
270
  [
196
271
  'twelve',
@@ -218,23 +293,23 @@ describe FunWithJsonApi::Deserializer do
218
293
  end
219
294
 
220
295
  context 'with a float format' do
221
- it 'should allow floats' do
296
+ it 'allows floats' do
222
297
  deserializer = deserializer_with_attribute(:example, format: :float)
223
298
  expect(deserializer.parse_example(12.34)).to eq 12.34
224
299
  end
225
- it 'should allow float numbers as strings' do
300
+ it 'allows float numbers as strings' do
226
301
  deserializer = deserializer_with_attribute(:example, format: :float)
227
302
  expect(deserializer.parse_example('12.34')).to eq 12.34
228
303
  end
229
- it 'should allow integer numbers as strings' do
304
+ it 'allows integer numbers as strings' do
230
305
  deserializer = deserializer_with_attribute(:example, format: :float)
231
306
  expect(deserializer.parse_example('12')).to eq 12.0
232
307
  end
233
- it 'should allow a nil value' do
308
+ it 'allows a nil value' do
234
309
  deserializer = deserializer_with_attribute(:example, format: :float)
235
310
  expect(deserializer.parse_example(nil)).to be nil
236
311
  end
237
- it 'should raise an InvalidAttribute for invalid float value' do
312
+ it 'raises an InvalidAttribute error an for invalid float value' do
238
313
  deserializer = deserializer_with_attribute(:example, format: :float)
239
314
  [
240
315
  'twelve',
@@ -262,15 +337,15 @@ describe FunWithJsonApi::Deserializer do
262
337
  end
263
338
 
264
339
  context 'with a integer format' do
265
- it 'should allow integer numbers as strings' do
340
+ it 'allows integer numbers as strings' do
266
341
  deserializer = deserializer_with_attribute(:example, format: :integer)
267
342
  expect(deserializer.parse_example('12')).to eq BigDecimal.new('12')
268
343
  end
269
- it 'should allow a nil value' do
344
+ it 'allows a nil value' do
270
345
  deserializer = deserializer_with_attribute(:example, format: :integer)
271
346
  expect(deserializer.parse_example(nil)).to be nil
272
347
  end
273
- it 'should raise an InvalidAttribute for invalid integer value' do
348
+ it 'raises an InvalidAttribute error an for invalid integer value' do
274
349
  deserializer = deserializer_with_attribute(:example, format: :integer)
275
350
  [
276
351
  12.0,
@@ -299,6 +374,46 @@ describe FunWithJsonApi::Deserializer do
299
374
  end
300
375
  end
301
376
 
377
+ context 'with a uuid_v4 format' do
378
+ it 'allows uuid_v4 numbers as strings' do
379
+ deserializer = deserializer_with_attribute(:example, format: :uuid_v4)
380
+ expect(deserializer.parse_example('f47ac10b-58cc-4372-a567-0e02b2c3d479')).to eq(
381
+ 'f47ac10b-58cc-4372-a567-0e02b2c3d479'
382
+ )
383
+ end
384
+ it 'allows a nil value' do
385
+ deserializer = deserializer_with_attribute(:example, format: :uuid_v4)
386
+ expect(deserializer.parse_example(nil)).to be nil
387
+ end
388
+ it 'raises an InvalidAttribute error an for invalid uuid_v4 value' do
389
+ deserializer = deserializer_with_attribute(:example, format: :uuid_v4)
390
+ [
391
+ 'abc',
392
+ 12.0,
393
+ '12.0',
394
+ '6ba7b810-9dad-11d1-80b4-00c04fd430c8', # RFC 4122 version 3
395
+ 'f47ac10b58cc4372a5670e02b2c3d479' # uuid without dashes
396
+ ].each do |value|
397
+ expect do
398
+ deserializer.parse_example(value)
399
+ end.to raise_error(FunWithJsonApi::Exceptions::InvalidAttribute) do |e|
400
+ expect(e.payload.size).to eq 1
401
+
402
+ payload = e.payload.first
403
+ expect(payload.status).to eq '400'
404
+ expect(payload.code).to eq 'invalid_attribute'
405
+ expect(payload.title).to eq(
406
+ I18n.t('fun_with_json_api.exceptions.invalid_attribute')
407
+ )
408
+ expect(payload.detail).to eq(
409
+ I18n.t('fun_with_json_api.exceptions.invalid_uuid_v4_attribute')
410
+ )
411
+ expect(payload.pointer).to eq '/data/attributes/example'
412
+ end
413
+ end
414
+ end
415
+ end
416
+
302
417
  it 'raises an ArgumentError with an unknown format' do
303
418
  expect do
304
419
  deserializer_class_with_attribute(:example, format: :blarg)
@@ -315,14 +430,14 @@ describe FunWithJsonApi::Deserializer do
315
430
  describe '#parse_{relationship}_id' do
316
431
  context 'with a ARModels::Author relationship with a "code" id param' do
317
432
  let(:deserializer) do
318
- author_deserializer_class = Class.new(FunWithJsonApi::Deserializer) do
433
+ author_deserializer_class = Class.new(described_class) do
319
434
  id_param 'code'
320
435
  type 'persons'
321
436
  resource_class ARModels::Author
322
437
  end
323
438
 
324
439
  # Build the Deserializer
325
- Class.new(FunWithJsonApi::Deserializer) do
440
+ Class.new(described_class) do
326
441
  belongs_to :example, author_deserializer_class
327
442
  end.create
328
443
  end
@@ -336,13 +451,13 @@ describe FunWithJsonApi::Deserializer do
336
451
  expect do
337
452
  deserializer.parse_example_id 'foobar'
338
453
  end.to raise_error(FunWithJsonApi::Exceptions::MissingRelationship) do |e|
339
- expect(e.message).to start_with "Couldn't find ARModels::Author where code = \"foobar\": "
454
+ expect(e.message).to eq "Couldn't find ARModels::Author where code = \"foobar\""
340
455
  expect(e.payload.size).to eq 1
341
456
 
342
457
  payload = e.payload.first
343
458
  expect(payload.status).to eq '404'
344
459
  expect(payload.code).to eq 'missing_relationship'
345
- expect(payload.title).to eq I18n.t('fun_with_json_api.exceptions.missing_relationship')
460
+ expect(payload.title).to eq 'Unable to find the requested relationship'
346
461
  expect(payload.pointer).to eq '/data/relationships/example/id'
347
462
  expect(payload.detail).to eq "Unable to find 'persons' with matching id: \"foobar\""
348
463
  end
@@ -368,14 +483,14 @@ describe FunWithJsonApi::Deserializer do
368
483
  describe '#parse_{relationship}_ids' do
369
484
  context 'with a ARModels::Author relationship with a "code" id param' do
370
485
  let(:deserializer) do
371
- author_deserializer_class = Class.new(FunWithJsonApi::Deserializer) do
486
+ author_deserializer_class = Class.new(described_class) do
372
487
  id_param 'code'
373
488
  type 'persons'
374
489
  resource_class ARModels::Author
375
490
  end
376
491
 
377
492
  # Build the Deserializer
378
- Class.new(FunWithJsonApi::Deserializer) do
493
+ Class.new(described_class) do
379
494
  has_many :examples, author_deserializer_class
380
495
  end.create
381
496
  end
@@ -400,8 +515,8 @@ describe FunWithJsonApi::Deserializer do
400
515
  payload = e.payload.first
401
516
  expect(payload.status).to eq '404'
402
517
  expect(payload.code).to eq 'missing_relationship'
403
- expect(payload.title).to eq I18n.t('fun_with_json_api.exceptions.missing_relationship')
404
- expect(payload.pointer).to eq '/data/relationships/examples/id'
518
+ expect(payload.title).to eq 'Unable to find the requested relationship'
519
+ expect(payload.pointer).to eq '/data/relationships/examples/1/id'
405
520
  expect(payload.detail).to eq "Unable to find 'persons' with matching id: \"blargh\""
406
521
  end
407
522
  end
@@ -418,15 +533,15 @@ describe FunWithJsonApi::Deserializer do
418
533
  payload_a = e.payload.first
419
534
  expect(payload_a.status).to eq '404'
420
535
  expect(payload_a.code).to eq 'missing_relationship'
421
- expect(payload_a.title).to eq I18n.t('fun_with_json_api.exceptions.missing_relationship')
422
- expect(payload_a.pointer).to eq '/data/relationships/examples/id'
536
+ expect(payload_a.title).to eq 'Unable to find the requested relationship'
537
+ expect(payload_a.pointer).to eq '/data/relationships/examples/0/id'
423
538
  expect(payload_a.detail).to eq "Unable to find 'persons' with matching id: \"foobar\""
424
539
 
425
540
  payload_b = e.payload.last
426
541
  expect(payload_b.status).to eq '404'
427
542
  expect(payload_b.code).to eq 'missing_relationship'
428
- expect(payload_b.title).to eq I18n.t('fun_with_json_api.exceptions.missing_relationship')
429
- expect(payload_b.pointer).to eq '/data/relationships/examples/id'
543
+ expect(payload_b.title).to eq 'Unable to find the requested relationship'
544
+ expect(payload_b.pointer).to eq '/data/relationships/examples/1/id'
430
545
  expect(payload_b.detail).to eq "Unable to find 'persons' with matching id: \"blargh\""
431
546
  end
432
547
  end