json-crud-api 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json-crud-api/crud.rb +2 -2
- data/spec/unit/crud_spec.rb +7 -7
- 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: 6729e49ff86fc11ee1d2983ad50f51882271dc17
|
4
|
+
data.tar.gz: 635e5569006dfa942d6f1b1e090f1326e085f19c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b64f144c33f2ef911b0e84752d1dfb2e09edd28a890cf49052c5dd54bd060c57b299863ab3f959cf119d65d2e27e11485cb40ed13afc3d07638cd0e28c922e52
|
7
|
+
data.tar.gz: 5a489916c393614074d6941038167691a49335566fbae2aba9c884f443219c6fe88e1fc2279d8fdc510c3a369662d9594bf12b43a9a1be92d2adf0375fc92b9f
|
data/lib/json-crud-api/crud.rb
CHANGED
@@ -27,7 +27,7 @@ module JsonCrudApi
|
|
27
27
|
presenter = settings.presenters[key]
|
28
28
|
return fail_unauthorized unless service.user_authorized_for? :create
|
29
29
|
post_data = presenter.parse @payload, :post
|
30
|
-
return fail_with_errors unless service.
|
30
|
+
return fail_with_errors unless service.valid_for? post_data, :create, self
|
31
31
|
entity = service.create post_data
|
32
32
|
JSON.fast_generate presenter.render(entity, :post)
|
33
33
|
end
|
@@ -37,7 +37,7 @@ module JsonCrudApi
|
|
37
37
|
presenter = settings.presenters[key]
|
38
38
|
return fail_unauthorized unless service.user_authorized_for? :update
|
39
39
|
put_data = presenter.parse @payload, :put
|
40
|
-
return fail_with_errors unless service.
|
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
|
42
42
|
entity = service.get params["id"]
|
43
43
|
JSON.fast_generate presenter.render(entity, :put)
|
data/spec/unit/crud_spec.rb
CHANGED
@@ -143,7 +143,7 @@ describe JsonCrudApi::AuthClient do
|
|
143
143
|
expect(@test.test_settings.presenters).to receive(:[]).with('thekey').and_return(@presenter)
|
144
144
|
|
145
145
|
expect(@service).to receive(:user_authorized_for?).with(:create).and_return(true)
|
146
|
-
expect(@service).to receive(:
|
146
|
+
expect(@service).to receive(:valid_for?).with({ :test_output => 12398}, :create, @test).and_return(true)
|
147
147
|
expect(@service).to receive(:create).with({ :test_output => 12398}).and_return({ :test_output => 77234})
|
148
148
|
|
149
149
|
expect(@presenter).to receive(:parse).with(@test.payload, :post).and_return({ :test_output => 12398})
|
@@ -152,12 +152,12 @@ describe JsonCrudApi::AuthClient do
|
|
152
152
|
expect(@test.send(:crud_post,'thekey')).to eq '{"test_output":12313}'
|
153
153
|
end
|
154
154
|
|
155
|
-
it 'should fail with 422 if service
|
155
|
+
it 'should fail with 422 if service valid_for? fails' do
|
156
156
|
expect(@test.test_settings.services).to receive(:[]).with('thekey').and_return(@service)
|
157
157
|
expect(@test.test_settings.presenters).to receive(:[]).with('thekey').and_return(@presenter)
|
158
158
|
|
159
159
|
expect(@service).to receive(:user_authorized_for?).with(:create).and_return(true)
|
160
|
-
expect(@service).to receive(:
|
160
|
+
expect(@service).to receive(:valid_for?).with({ :test_output => 12398}, :create, @test).and_return(false)
|
161
161
|
|
162
162
|
expect(@presenter).to receive(:parse).with(@test.payload, :post).and_return({ :test_output => 12398})
|
163
163
|
|
@@ -203,7 +203,7 @@ describe JsonCrudApi::AuthClient do
|
|
203
203
|
|
204
204
|
expect(@service).to receive(:user_authorized_for?).with(:update).and_return(true)
|
205
205
|
expect(@presenter).to receive(:parse).with(@test.payload, :put).and_return({ :test_output => 12398})
|
206
|
-
expect(@service).to receive(:
|
206
|
+
expect(@service).to receive(:valid_for?).with({ :test_output => 12398},:update,@test).and_return(true)
|
207
207
|
expect(@service).to receive(:update).with(7345, { :test_output => 12398}).and_return(true)
|
208
208
|
expect(@service).to receive(:get).with(7345).and_return({ :test_output => 77234})
|
209
209
|
|
@@ -212,13 +212,13 @@ describe JsonCrudApi::AuthClient do
|
|
212
212
|
expect(@test.send(:crud_put,'thekey')).to eq '{"test_output":12313}'
|
213
213
|
end
|
214
214
|
|
215
|
-
it 'should fail_with_errors if service
|
215
|
+
it 'should fail_with_errors if service valid_for? fails' do
|
216
216
|
expect(@test.test_settings.services).to receive(:[]).with('thekey').and_return(@service)
|
217
217
|
expect(@test.test_settings.presenters).to receive(:[]).with('thekey').and_return(@presenter)
|
218
218
|
|
219
219
|
expect(@service).to receive(:user_authorized_for?).with(:update).and_return(true)
|
220
220
|
expect(@presenter).to receive(:parse).with(@test.payload, :put).and_return({ :test_output => 12398})
|
221
|
-
expect(@service).to receive(:
|
221
|
+
expect(@service).to receive(:valid_for?).with({ :test_output => 12398},:update,@test).and_return(false)
|
222
222
|
expect(@presenter).not_to receive(:render)
|
223
223
|
|
224
224
|
expect(@test).to receive(:fail_with_errors)
|
@@ -231,7 +231,7 @@ describe JsonCrudApi::AuthClient do
|
|
231
231
|
expect(@test.test_settings.presenters).to receive(:[]).with('thekey').and_return(@presenter)
|
232
232
|
|
233
233
|
expect(@service).to receive(:user_authorized_for?).with(:update).and_return(true)
|
234
|
-
expect(@service).to receive(:
|
234
|
+
expect(@service).to receive(:valid_for?).with({ :test_output => 12398},:update,@test).and_return(true)
|
235
235
|
expect(@service).to receive(:update).with(7345, { :test_output => 12398}).and_return(false)
|
236
236
|
|
237
237
|
expect(@test).to receive(:fail_not_found)
|