json-crud-api 0.0.10 → 0.0.11
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.
- checksums.yaml +4 -4
- data/lib/json-crud-api/api.rb +5 -1
- data/lib/json-crud-api/crud.rb +5 -5
- data/lib/json-crud-api/json_errors.rb +1 -1
- data/spec/unit/crud_spec.rb +10 -10
- data/spec/unit/json_errors_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0423b4c02c64dcc84ecb43145267e8ad6b157716
|
4
|
+
data.tar.gz: 18b29475bb8fe29e75c6d9ac97e78a46643087b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73526f31ac42f5986f80754daad727b0d9fc5c1c8bcc43f36f22445282613388cef0e45f69953486919d55b4b6208f9d629251dc20f276681dd2c19c222f8c27
|
7
|
+
data.tar.gz: 2dc288144b95ccc849b14a51818ed8eccdf1dc298e51b37c70eea2f28da9375f4c581da9478fc01f54b3d0640303810e4f779c528cadd0c057139a40ada91349
|
data/lib/json-crud-api/api.rb
CHANGED
data/lib/json-crud-api/crud.rb
CHANGED
@@ -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
|
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
|
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
|
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
|
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
|
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
|
data/spec/unit/crud_spec.rb
CHANGED
@@ -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
|
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(:
|
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
|
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(:
|
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
|
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(:
|
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
|
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(:
|
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
|
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(:
|
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(:
|
102
|
+
expect(@test).to receive(:fail_with_errors).with(404)
|
103
103
|
@test.fail_not_found
|
104
104
|
end
|
105
105
|
end
|