json-crud-api 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6729e49ff86fc11ee1d2983ad50f51882271dc17
4
- data.tar.gz: 635e5569006dfa942d6f1b1e090f1326e085f19c
3
+ metadata.gz: 0423b4c02c64dcc84ecb43145267e8ad6b157716
4
+ data.tar.gz: 18b29475bb8fe29e75c6d9ac97e78a46643087b2
5
5
  SHA512:
6
- metadata.gz: b64f144c33f2ef911b0e84752d1dfb2e09edd28a890cf49052c5dd54bd060c57b299863ab3f959cf119d65d2e27e11485cb40ed13afc3d07638cd0e28c922e52
7
- data.tar.gz: 5a489916c393614074d6941038167691a49335566fbae2aba9c884f443219c6fe88e1fc2279d8fdc510c3a369662d9594bf12b43a9a1be92d2adf0375fc92b9f
6
+ metadata.gz: 73526f31ac42f5986f80754daad727b0d9fc5c1c8bcc43f36f22445282613388cef0e45f69953486919d55b4b6208f9d629251dc20f276681dd2c19c222f8c27
7
+ data.tar.gz: 2dc288144b95ccc849b14a51818ed8eccdf1dc298e51b37c70eea2f28da9375f4c581da9478fc01f54b3d0640303810e4f779c528cadd0c057139a40ada91349
@@ -33,7 +33,11 @@ module JsonCrudApi
33
33
  end
34
34
 
35
35
  not_found do
36
- fail_not_found
36
+ add_error 'NOT_FOUND','The resource cannot be found.'
37
+ halt status, JSON.fast_generate({
38
+ :success => false,
39
+ :errors => @errors
40
+ })
37
41
  end
38
42
 
39
43
  error do
@@ -5,7 +5,7 @@ module JsonCrudApi
5
5
  def crud_get_all(key)
6
6
  service = settings.services[key]
7
7
  presenter = settings.presenters[key]
8
- return fail_unauthorized unless service.user_authorized_for? :get_all
8
+ return fail_forbidden unless service.user_authorized_for? :get_all
9
9
  entities = service.get_all
10
10
  return fail_not_found if entities.nil?
11
11
 
@@ -15,7 +15,7 @@ module JsonCrudApi
15
15
  def crud_get(key)
16
16
  service = settings.services[key]
17
17
  presenter = settings.presenters[key]
18
- return fail_unauthorized unless service.user_authorized_for? :get
18
+ return fail_forbidden unless service.user_authorized_for? :get
19
19
  entity = service.get(params["id"])
20
20
  return fail_not_found if entity.nil?
21
21
 
@@ -25,7 +25,7 @@ module JsonCrudApi
25
25
  def crud_post(key)
26
26
  service = settings.services[key]
27
27
  presenter = settings.presenters[key]
28
- return fail_unauthorized unless service.user_authorized_for? :create
28
+ return fail_forbidden unless service.user_authorized_for? :create
29
29
  post_data = presenter.parse @payload, :post
30
30
  return fail_with_errors unless service.valid_for? post_data, :create, self
31
31
  entity = service.create post_data
@@ -35,7 +35,7 @@ module JsonCrudApi
35
35
  def crud_put(key)
36
36
  service = settings.services[key]
37
37
  presenter = settings.presenters[key]
38
- return fail_unauthorized unless service.user_authorized_for? :update
38
+ return fail_forbidden unless service.user_authorized_for? :update
39
39
  put_data = presenter.parse @payload, :put
40
40
  return fail_with_errors unless service.valid_for? put_data, :update, self
41
41
  return fail_not_found unless service.update params["id"], put_data
@@ -46,7 +46,7 @@ module JsonCrudApi
46
46
  def crud_delete(key)
47
47
  service = settings.services[key]
48
48
  presenter = settings.presenters[key]
49
- return fail_unauthorized unless service.user_authorized_for? :delete
49
+ return fail_forbidden unless service.user_authorized_for? :delete
50
50
  return fail_not_found unless service.delete params["id"]
51
51
  204
52
52
  end
@@ -31,7 +31,7 @@ module JsonCrudApi
31
31
  end
32
32
 
33
33
  def fail_not_found
34
- fail_with_error 404, 'NOT_FOUND','The resource cannot be found.'
34
+ fail_with_errors 404
35
35
  end
36
36
 
37
37
  def fail_unauthorized
@@ -42,13 +42,13 @@ describe JsonCrudApi::AuthClient do
42
42
  expect(@test.send(:crud_get_all,'thekey')).to eq '{"test_output":1}'
43
43
  end
44
44
 
45
- it 'should fail_unauthorized if not authorized for get_all' do
45
+ it 'should fail_forbidden if not authorized for get_all' do
46
46
  expect(@test.test_settings.services).to receive(:[]).with('thekey').and_return(@service)
47
47
  expect(@test.test_settings.presenters).to receive(:[]).with('thekey').and_return(@presenter)
48
48
 
49
49
  expect(@service).to receive(:user_authorized_for?).with(:get_all).and_return(false)
50
50
 
51
- expect(@test).to receive(:fail_unauthorized)
51
+ expect(@test).to receive(:fail_forbidden)
52
52
 
53
53
  expect(@service).not_to receive(:get_all)
54
54
  expect(@presenter).not_to receive(:render)
@@ -96,13 +96,13 @@ describe JsonCrudApi::AuthClient do
96
96
  expect(@test.send(:crud_get,'thekey')).to eq '{"test_output":56}'
97
97
  end
98
98
 
99
- it 'should fail_unauthorized if not authorized for get' do
99
+ it 'should fail_forbidden if not authorized for get' do
100
100
  expect(@test.test_settings.services).to receive(:[]).with('thekey').and_return(@service)
101
101
  expect(@test.test_settings.presenters).to receive(:[]).with('thekey').and_return(@presenter)
102
102
 
103
103
  expect(@service).to receive(:user_authorized_for?).with(:get).and_return(false)
104
104
 
105
- expect(@test).to receive(:fail_unauthorized)
105
+ expect(@test).to receive(:fail_forbidden)
106
106
 
107
107
  expect(@service).not_to receive(:get)
108
108
  expect(@presenter).not_to receive(:render)
@@ -169,13 +169,13 @@ describe JsonCrudApi::AuthClient do
169
169
  @test.send(:crud_post,'thekey')
170
170
  end
171
171
 
172
- it 'should fail_unauthorized if not authorized for create' do
172
+ it 'should fail_forbidden if not authorized for create' do
173
173
  expect(@test.test_settings.services).to receive(:[]).with('thekey').and_return(@service)
174
174
  expect(@test.test_settings.presenters).to receive(:[]).with('thekey').and_return(@presenter)
175
175
 
176
176
  expect(@service).to receive(:user_authorized_for?).with(:create).and_return(false)
177
177
 
178
- expect(@test).to receive(:fail_unauthorized)
178
+ expect(@test).to receive(:fail_forbidden)
179
179
 
180
180
  expect(@service).not_to receive(:create)
181
181
  expect(@presenter).not_to receive(:render)
@@ -242,13 +242,13 @@ describe JsonCrudApi::AuthClient do
242
242
  @test.send(:crud_put,'thekey')
243
243
  end
244
244
 
245
- it 'should fail_unauthorized if not authorized for update' do
245
+ it 'should fail_forbidden if not authorized for update' do
246
246
  expect(@test.test_settings.services).to receive(:[]).with('thekey').and_return(@service)
247
247
  expect(@test.test_settings.presenters).to receive(:[]).with('thekey').and_return(@presenter)
248
248
 
249
249
  expect(@service).to receive(:user_authorized_for?).with(:update).and_return(false)
250
250
 
251
- expect(@test).to receive(:fail_unauthorized)
251
+ expect(@test).to receive(:fail_forbidden)
252
252
 
253
253
  expect(@service).not_to receive(:update)
254
254
  expect(@service).not_to receive(:get)
@@ -280,13 +280,13 @@ describe JsonCrudApi::AuthClient do
280
280
  expect(@test.send(:crud_delete,'thekey')).to eq 204
281
281
  end
282
282
 
283
- it 'should fail_unauthorized if not authorized for delete' do
283
+ it 'should fail_forbidden if not authorized for delete' do
284
284
  expect(@test.test_settings.services).to receive(:[]).with('thekey').and_return(@service)
285
285
  expect(@test.test_settings.presenters).to receive(:[]).with('thekey').and_return(@presenter)
286
286
 
287
287
  expect(@service).to receive(:user_authorized_for?).with(:delete).and_return(false)
288
288
 
289
- expect(@test).to receive(:fail_unauthorized)
289
+ expect(@test).to receive(:fail_forbidden)
290
290
 
291
291
  expect(@service).not_to receive(:delete)
292
292
 
@@ -99,7 +99,7 @@ describe JsonCrudApi::JsonErrors do
99
99
 
100
100
  describe '#fail_not_found' do
101
101
  it 'should call fail_not_found with 404 and message' do
102
- expect(@test).to receive(:fail_with_error).with(404, 'NOT_FOUND','The resource cannot be found.')
102
+ expect(@test).to receive(:fail_with_errors).with(404)
103
103
  @test.fail_not_found
104
104
  end
105
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-crud-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Cully