fun_with_json_api 0.0.8.2 → 0.0.9

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.
@@ -25,26 +25,64 @@ describe FunWithJsonApi::SchemaValidators::CheckAttributes do
25
25
  end
26
26
  end
27
27
 
28
- context 'when the document contains an unsupported attribute' do
29
- before { allow(deserializer).to receive(:attributes).and_return([]) }
28
+ context 'when the document contains an disabled attribute' do
29
+ before do
30
+ deserializer_class = class_double(
31
+ 'FunWithJsonApi::Deserializer',
32
+ attribute_names: %i(foobar)
33
+ )
34
+ allow(deserializer).to receive(:class).and_return(deserializer_class)
35
+ allow(deserializer).to receive(:attributes).and_return([])
36
+ end
30
37
 
31
38
  it 'raises a UnknownAttribute error' do
32
39
  expect do
33
40
  subject
34
41
  end.to raise_error(FunWithJsonApi::Exceptions::UnknownAttribute) do |e|
42
+ expect(e.http_status).to eq 403
35
43
  expect(e.payload.size).to eq 1
36
44
 
37
45
  payload = e.payload.first
38
46
  expect(payload.code).to eq 'unknown_attribute'
39
47
  expect(payload.pointer).to eq '/data/attributes/foobar'
40
48
  expect(payload.title).to eq(
41
- 'Request json_api attribute is unsupported by the current endpoint'
49
+ 'Request json_api attribute is not recognised by the current endpoint'
42
50
  )
43
51
  expect(payload.detail).to eq(
44
52
  "The provided attribute 'foobar' can not be assigned to a 'examples' resource"\
45
53
  ' from the current endpoint'
46
54
  )
47
- expect(payload.status).to eq '422'
55
+ expect(payload.status).to eq '403'
56
+ end
57
+ end
58
+ end
59
+
60
+ context 'when the document contains an unknown attribute' do
61
+ before do
62
+ deserializer_class = class_double(
63
+ 'FunWithJsonApi::Deserializer',
64
+ attribute_names: %i(blargh)
65
+ )
66
+ allow(deserializer).to receive(:class).and_return(deserializer_class)
67
+ allow(deserializer).to receive(:attributes).and_return([])
68
+ end
69
+
70
+ it 'raises a UnknownAttribute error' do
71
+ expect do
72
+ subject
73
+ end.to raise_error(FunWithJsonApi::Exceptions::UnknownAttribute) do |e|
74
+ expect(e.payload.size).to eq 1
75
+
76
+ payload = e.payload.first
77
+ expect(payload.code).to eq 'unknown_attribute'
78
+ expect(payload.pointer).to eq '/data/attributes/foobar'
79
+ expect(payload.title).to eq(
80
+ 'Request json_api attribute is not recognised by the current endpoint'
81
+ )
82
+ expect(payload.detail).to eq(
83
+ "The provided attribute 'foobar' can not be assigned to a 'examples' resource"
84
+ )
85
+ expect(payload.status).to eq '400'
48
86
  end
49
87
  end
50
88
  end
@@ -140,26 +140,66 @@ describe FunWithJsonApi::SchemaValidators::CheckRelationships do
140
140
  it { is_expected.to eq true }
141
141
  end
142
142
 
143
- context 'when the document contains an unsupported relationships' do
144
- before { allow(deserializer).to receive(:relationships).and_return([]) }
143
+ context 'when the document contains an excluded relationship' do
144
+ before do
145
+ deserializer_class = class_double(
146
+ 'FunWithJsonApi::Deserializer',
147
+ relationship_names: %i(foobar)
148
+ )
149
+ allow(deserializer).to receive(:class).and_return(deserializer_class)
150
+ allow(deserializer).to receive(:relationships).and_return([])
151
+ end
145
152
 
146
153
  it 'raises a UnknownRelationship error' do
147
154
  expect do
148
155
  subject
149
156
  end.to raise_error(FunWithJsonApi::Exceptions::UnknownRelationship) do |e|
157
+ # expect(e.http_status).to eq 403
150
158
  expect(e.payload.size).to eq 1
151
159
 
152
160
  payload = e.payload.first
153
161
  expect(payload.code).to eq 'unknown_relationship'
154
162
  expect(payload.pointer).to eq '/data/relationships/foobar'
155
163
  expect(payload.title).to eq(
156
- 'Request json_api relationship is unsupported by the current endpoint'
164
+ 'Request json_api relationship is not recognised by the current endpoint'
157
165
  )
158
166
  expect(payload.detail).to eq(
159
167
  "The provided relationship 'foobar' can not be assigned to a 'examples' resource"\
160
168
  ' from the current endpoint'
161
169
  )
162
- expect(payload.status).to eq '422'
170
+ expect(payload.status).to eq '403'
171
+ end
172
+ end
173
+ end
174
+
175
+ context 'when the document contains an unknown relationship' do
176
+ before do
177
+ deserializer_class = class_double(
178
+ 'FunWithJsonApi::Deserializer',
179
+ relationship_names: %i(blargh)
180
+ )
181
+ allow(deserializer).to receive(:class).and_return(deserializer_class)
182
+ allow(deserializer).to receive(:relationships).and_return([])
183
+ end
184
+
185
+ it 'raises a UnknownRelationship error' do
186
+ expect do
187
+ subject
188
+ end.to raise_error(FunWithJsonApi::Exceptions::UnknownRelationship) do |e|
189
+ expect(e.http_status).to eq 400
190
+ expect(e.payload.size).to eq 1
191
+
192
+ payload = e.payload.first
193
+ expect(payload.code).to eq 'unknown_relationship'
194
+ expect(payload.pointer).to eq '/data/relationships/foobar'
195
+ expect(payload.title).to eq(
196
+ 'Request json_api relationship is not recognised by the current endpoint'
197
+ )
198
+ expect(payload.detail).to eq(
199
+ "The provided relationship 'foobar' can not be directly assigned to a 'examples'"\
200
+ ' resource'
201
+ )
202
+ expect(payload.status).to eq '400'
163
203
  end
164
204
  end
165
205
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fun_with_json_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8.2
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Morrall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-04 00:00:00.000000000 Z
11
+ date: 2016-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -194,6 +194,7 @@ files:
194
194
  - lib/fun_with_json_api/schema_validators/check_collection_is_authorized.rb
195
195
  - lib/fun_with_json_api/schema_validators/check_document_id_matches_resource.rb
196
196
  - lib/fun_with_json_api/schema_validators/check_document_type_matches_resource.rb
197
+ - lib/fun_with_json_api/schema_validators/check_relationship_names.rb
197
198
  - lib/fun_with_json_api/schema_validators/check_relationships.rb
198
199
  - lib/fun_with_json_api/schema_validators/check_resource_is_authorized.rb
199
200
  - lib/fun_with_json_api/version.rb