fun_with_json_api 0.0.10 → 0.0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/locales/fun_with_json_api.en.yml +1 -1
- data/lib/fun_with_json_api/exceptions/invalid_resource.rb +3 -3
- data/lib/fun_with_json_api/exceptions/unauthorized_resource.rb +1 -1
- data/lib/fun_with_json_api/schema_validators/check_collection_is_authorized.rb +1 -1
- data/lib/fun_with_json_api/schema_validators/check_resource_is_authorized.rb +1 -1
- data/lib/fun_with_json_api/version.rb +1 -1
- data/spec/dummy/log/test.log +5687 -0
- data/spec/fun_with_json_api/collection_manager_spec.rb +28 -28
- data/spec/fun_with_json_api/deserializer_spec.rb +2 -2
- data/spec/fun_with_json_api/find_collection_from_document_spec.rb +4 -4
- data/spec/fun_with_json_api/find_resource_from_document_spec.rb +2 -2
- data/spec/fun_with_json_api_spec.rb +2 -2
- metadata +1 -1
@@ -31,7 +31,7 @@ describe FunWithJsonApi::CollectionManager do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
context 'when `insert_record` returns false for an item' do
|
34
|
-
it 'raises a FunWithJsonApi::Exceptions::
|
34
|
+
it 'raises a FunWithJsonApi::Exceptions::UnauthorizedResource with a payload' do
|
35
35
|
collection = [
|
36
36
|
double('collection_a', success?: true),
|
37
37
|
double('collection_b', success?: false)
|
@@ -44,15 +44,15 @@ describe FunWithJsonApi::CollectionManager do
|
|
44
44
|
|
45
45
|
expect do
|
46
46
|
instance.insert_records(collection, ->(index) { "Record '#{index}' is invalid" })
|
47
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
47
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
48
48
|
expect(e.payload.size).to eq 1
|
49
49
|
|
50
50
|
payload = e.payload.first
|
51
|
-
expect(payload.code).to eq '
|
51
|
+
expect(payload.code).to eq 'unauthorized_resource'
|
52
52
|
expect(payload.title).to eq 'Unable to update the relationship with this resource'
|
53
53
|
expect(payload.detail).to eq "Record 'id_b' is invalid"
|
54
54
|
expect(payload.pointer).to eq '/data/1'
|
55
|
-
expect(payload.status).to eq '
|
55
|
+
expect(payload.status).to eq '403'
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -97,7 +97,7 @@ describe FunWithJsonApi::CollectionManager do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
context 'when `remove_record` returns false for an item' do
|
100
|
-
it 'raises a FunWithJsonApi::Exceptions::
|
100
|
+
it 'raises a FunWithJsonApi::Exceptions::UnauthorizedResource with a payload' do
|
101
101
|
collection = [
|
102
102
|
double('collection_a', success?: true),
|
103
103
|
double('collection_b', success?: false)
|
@@ -110,15 +110,15 @@ describe FunWithJsonApi::CollectionManager do
|
|
110
110
|
|
111
111
|
expect do
|
112
112
|
instance.remove_records(collection, ->(index) { "Record '#{index}' is bad!" })
|
113
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
113
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
114
114
|
expect(e.payload.size).to eq 1
|
115
115
|
|
116
116
|
payload = e.payload.first
|
117
|
-
expect(payload.code).to eq '
|
117
|
+
expect(payload.code).to eq 'unauthorized_resource'
|
118
118
|
expect(payload.title).to eq 'Unable to update the relationship with this resource'
|
119
119
|
expect(payload.detail).to eq "Record 'id_b' is bad!"
|
120
120
|
expect(payload.pointer).to eq '/data/1'
|
121
|
-
expect(payload.status).to eq '
|
121
|
+
expect(payload.status).to eq '403'
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
@@ -178,25 +178,25 @@ describe FunWithJsonApi::CollectionManager do
|
|
178
178
|
|
179
179
|
context 'with a invalid resource at an index' do
|
180
180
|
let(:resource_index) { '42' }
|
181
|
-
let(:invalid_resource) { double('
|
181
|
+
let(:invalid_resource) { double('unauthorized_resource', id_value: 'id_1') }
|
182
182
|
|
183
183
|
context 'with a reason message as a string' do
|
184
184
|
let(:reason_message) { Faker::Lorem.sentence }
|
185
185
|
|
186
|
-
it 'raises a
|
186
|
+
it 'raises a UnauthorizedResource exception with the reason message as a detail' do
|
187
187
|
expect do
|
188
188
|
instance.send :raise_invalid_resource_exception,
|
189
189
|
{ 42 => invalid_resource },
|
190
190
|
reason_message
|
191
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
191
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
192
192
|
expect(e.payload.size).to eq 1
|
193
193
|
|
194
194
|
payload = e.payload.first
|
195
|
-
expect(payload.code).to eq '
|
195
|
+
expect(payload.code).to eq 'unauthorized_resource'
|
196
196
|
expect(payload.title).to eq 'Unable to update the relationship with this resource'
|
197
197
|
expect(payload.detail).to eq reason_message
|
198
198
|
expect(payload.pointer).to eq '/data/42'
|
199
|
-
expect(payload.status).to eq '
|
199
|
+
expect(payload.status).to eq '403'
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
@@ -204,39 +204,39 @@ describe FunWithJsonApi::CollectionManager do
|
|
204
204
|
context 'with a reason message as a callable' do
|
205
205
|
let(:reason_message) { Faker::Lorem.sentence }
|
206
206
|
|
207
|
-
it 'raises a
|
207
|
+
it 'raises a UnauthorizedResource exception by invoking call with the resource index' do
|
208
208
|
expect do
|
209
209
|
instance.send :raise_invalid_resource_exception,
|
210
210
|
{ 42 => invalid_resource },
|
211
211
|
->(index) { "#{index}-#{reason_message}" }
|
212
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
212
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
213
213
|
expect(e.payload.size).to eq 1
|
214
214
|
|
215
215
|
payload = e.payload.first
|
216
|
-
expect(payload.code).to eq '
|
216
|
+
expect(payload.code).to eq 'unauthorized_resource'
|
217
217
|
expect(payload.title).to eq 'Unable to update the relationship with this resource'
|
218
218
|
expect(payload.detail).to eq "id_1-#{reason_message}"
|
219
219
|
expect(payload.pointer).to eq '/data/42'
|
220
|
-
expect(payload.status).to eq '
|
220
|
+
expect(payload.status).to eq '403'
|
221
221
|
end
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
225
225
|
context 'with a nil reason message' do
|
226
|
-
it 'raises a
|
226
|
+
it 'raises a UnauthorizedResource exception with a default reason message' do
|
227
227
|
expect do
|
228
228
|
instance.send :raise_invalid_resource_exception, { 42 => invalid_resource }, nil
|
229
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
229
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
230
230
|
expect(e.payload.size).to eq 1
|
231
231
|
|
232
232
|
payload = e.payload.first
|
233
|
-
expect(payload.code).to eq '
|
233
|
+
expect(payload.code).to eq 'unauthorized_resource'
|
234
234
|
expect(payload.title).to eq 'Unable to update the relationship with this resource'
|
235
235
|
expect(payload.detail).to eq(
|
236
|
-
"Unable to
|
236
|
+
"Unable to assign the requested 'examples' (id_1) to the current resource"
|
237
237
|
)
|
238
238
|
expect(payload.pointer).to eq '/data/42'
|
239
|
-
expect(payload.status).to eq '
|
239
|
+
expect(payload.status).to eq '403'
|
240
240
|
end
|
241
241
|
end
|
242
242
|
end
|
@@ -253,25 +253,25 @@ describe FunWithJsonApi::CollectionManager do
|
|
253
253
|
context 'with a reason message as a string' do
|
254
254
|
let(:reason_message) { Faker::Lorem.sentence }
|
255
255
|
|
256
|
-
it 'raises a
|
256
|
+
it 'raises a UnauthorizedResource exception with a payload for each index' do
|
257
257
|
expect do
|
258
258
|
instance.send :raise_invalid_resource_exception, resource_hash, reason_message
|
259
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
259
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
260
260
|
expect(e.payload.size).to eq 2
|
261
261
|
|
262
262
|
payload = e.payload.first
|
263
|
-
expect(payload.code).to eq '
|
263
|
+
expect(payload.code).to eq 'unauthorized_resource'
|
264
264
|
expect(payload.title).to eq 'Unable to update the relationship with this resource'
|
265
265
|
expect(payload.detail).to eq reason_message
|
266
266
|
expect(payload.pointer).to eq '/data/1'
|
267
|
-
expect(payload.status).to eq '
|
267
|
+
expect(payload.status).to eq '403'
|
268
268
|
|
269
269
|
payload = e.payload.second
|
270
|
-
expect(payload.code).to eq '
|
270
|
+
expect(payload.code).to eq 'unauthorized_resource'
|
271
271
|
expect(payload.title).to eq 'Unable to update the relationship with this resource'
|
272
272
|
expect(payload.detail).to eq reason_message
|
273
273
|
expect(payload.pointer).to eq '/data/3'
|
274
|
-
expect(payload.status).to eq '
|
274
|
+
expect(payload.status).to eq '403'
|
275
275
|
end
|
276
276
|
end
|
277
277
|
end
|
@@ -526,10 +526,10 @@ describe FunWithJsonApi::Deserializer do
|
|
526
526
|
)
|
527
527
|
end
|
528
528
|
|
529
|
-
it 'raises a
|
529
|
+
it 'raises a UnauthorizedResource when unable to find a single resource' do
|
530
530
|
expect do
|
531
531
|
deserializer.parse_example_ids %w(foobar blargh)
|
532
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
532
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
533
533
|
expect(e.payload.size).to eq 1
|
534
534
|
|
535
535
|
payload = e.payload.first
|
@@ -38,10 +38,10 @@ describe FunWithJsonApi::FindCollectionFromDocument do
|
|
38
38
|
allow(deserializer).to receive(:resource_authorizer).and_return(resource_authorizer)
|
39
39
|
end
|
40
40
|
|
41
|
-
it 'raises a
|
41
|
+
it 'raises a UnauthorizedResource error' do
|
42
42
|
expect do
|
43
43
|
subject
|
44
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
44
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
45
45
|
expect(e.payload.size).to eq 1
|
46
46
|
|
47
47
|
payload = e.payload.first
|
@@ -129,10 +129,10 @@ describe FunWithJsonApi::FindCollectionFromDocument do
|
|
129
129
|
allow(deserializer).to receive(:resource_authorizer).and_return(resource_authorizer)
|
130
130
|
end
|
131
131
|
|
132
|
-
it 'raises a
|
132
|
+
it 'raises a UnauthorizedResource error' do
|
133
133
|
expect do
|
134
134
|
subject
|
135
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
135
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
136
136
|
expect(e.payload.size).to eq 2
|
137
137
|
|
138
138
|
payload = e.payload.first
|
@@ -38,10 +38,10 @@ describe FunWithJsonApi::FindResourceFromDocument do
|
|
38
38
|
allow(deserializer).to receive(:resource_authorizer).and_return(resource_authorizer)
|
39
39
|
end
|
40
40
|
|
41
|
-
it 'raises a
|
41
|
+
it 'raises a UnauthorizedResource error' do
|
42
42
|
expect do
|
43
43
|
subject
|
44
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
44
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
45
45
|
expect(e.payload.size).to eq 1
|
46
46
|
|
47
47
|
payload = e.payload.first
|
@@ -151,7 +151,7 @@ describe FunWithJsonApi do
|
|
151
151
|
post,
|
152
152
|
author: { resource_authorizer: ->(author) { author.id != 9 } }
|
153
153
|
)
|
154
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
154
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
155
155
|
expect(e.payload.size).to eq 1
|
156
156
|
expect(e.payload.first.pointer).to eq '/data/relationships/author'
|
157
157
|
end
|
@@ -191,7 +191,7 @@ describe FunWithJsonApi do
|
|
191
191
|
post,
|
192
192
|
comments: { resource_authorizer: ->(comment) { comment.contents == 'Foobar' } }
|
193
193
|
)
|
194
|
-
end.to raise_error(FunWithJsonApi::Exceptions::
|
194
|
+
end.to raise_error(FunWithJsonApi::Exceptions::UnauthorizedResource) do |e|
|
195
195
|
expect(e.payload.size).to eq 1
|
196
196
|
expect(e.payload.first.pointer).to eq '/data/relationships/comments/data/0'
|
197
197
|
end
|