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.
@@ -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::InvalidResource with a payload for each item' do
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::InvalidResource) do |e|
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 'invalid_resource'
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 '422'
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::InvalidResource with a payload for each item' do
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::InvalidResource) do |e|
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 'invalid_resource'
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 '422'
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('invalid_resource', id_value: 'id_1') }
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 InvalidResource exception with the reason message as a detail' do
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::InvalidResource) do |e|
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 'invalid_resource'
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 '422'
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 InvalidResource exception by invoking call with the resource index' do
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::InvalidResource) do |e|
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 'invalid_resource'
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 '422'
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 InvalidResource exception with a default reason message' do
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::InvalidResource) do |e|
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 'invalid_resource'
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 update relationship with 'examples' resource: 'id_1'"
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 '422'
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 InvalidResource exception with a payload for each index' do
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::InvalidResource) do |e|
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 'invalid_resource'
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 '422'
267
+ expect(payload.status).to eq '403'
268
268
 
269
269
  payload = e.payload.second
270
- expect(payload.code).to eq 'invalid_resource'
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 '422'
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 UnauthorisedResource when unable to find a single resource' do
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::UnauthorisedResource) do |e|
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 UnauthorisedResource error' do
41
+ it 'raises a UnauthorizedResource error' do
42
42
  expect do
43
43
  subject
44
- end.to raise_error(FunWithJsonApi::Exceptions::UnauthorisedResource) do |e|
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 UnauthorisedResource error' do
132
+ it 'raises a UnauthorizedResource error' do
133
133
  expect do
134
134
  subject
135
- end.to raise_error(FunWithJsonApi::Exceptions::UnauthorisedResource) do |e|
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 UnauthorisedResource error' do
41
+ it 'raises a UnauthorizedResource error' do
42
42
  expect do
43
43
  subject
44
- end.to raise_error(FunWithJsonApi::Exceptions::UnauthorisedResource) do |e|
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::UnauthorisedResource) do |e|
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::UnauthorisedResource) do |e|
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fun_with_json_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Morrall