api-resource 0.7.6 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api-resource/resource.rb +8 -2
- data/lib/api-resource/version.rb +1 -1
- data/spec/resource_spec.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64acbe85774b705bfa7eb2b9f8c9b451371b586d
|
4
|
+
data.tar.gz: ac068136f63a55363e166d676161f073ecff6d6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5071b7150e0d122cd6326849fe8f149d574b50dec99174d7c8909c85721aaefa21cc0850cd2135220e3ab2256d9a9cd8a0250e633f44d85628706636bbedc3ea
|
7
|
+
data.tar.gz: abccf0ff20ff278fbfb45af0a2a5d74d542d84b16998bbcd0352ea2c89214cbaa0c7ba23a369040ba094dfd5271b45bd4ac79d18e05c85d0cb5bcd21a0ed6f06
|
@@ -11,6 +11,12 @@ require 'active_support/core_ext/module/remove_method'
|
|
11
11
|
module ApiResource
|
12
12
|
|
13
13
|
class ResourceError < StandardError
|
14
|
+
attr_reader :model
|
15
|
+
|
16
|
+
def initialize(model, message)
|
17
|
+
super(message)
|
18
|
+
@model = model
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
22
|
class Resource
|
@@ -202,7 +208,7 @@ module ApiResource
|
|
202
208
|
end
|
203
209
|
|
204
210
|
def submit_resource(path, save_attrs=false, id_attr=nil, method=nil)
|
205
|
-
raise ResourceError unless valid? || method==:delete
|
211
|
+
raise ResourceError.new(self, 'Attempt to submit invalid resource') unless valid? || method==:delete
|
206
212
|
id_attr = id_attr || default_id_attr
|
207
213
|
path = [path]
|
208
214
|
attrs = attributes
|
@@ -219,7 +225,7 @@ module ApiResource
|
|
219
225
|
result = self.class.client(method, attrs, *path)
|
220
226
|
rescue RestClient::ExceptionWithResponse => e
|
221
227
|
result = e.http_body
|
222
|
-
raise ResourceError,
|
228
|
+
raise ResourceError.new(self, "Error executing request #{e.http_code} #{e.http_body}")
|
223
229
|
ensure
|
224
230
|
json = parse_and_check_error(result)
|
225
231
|
self.attributes = json['data'] || json if json && method == :post && save_attrs
|
data/lib/api-resource/version.rb
CHANGED
data/spec/resource_spec.rb
CHANGED
@@ -255,7 +255,9 @@ RSpec.describe ApiResource::Resource do
|
|
255
255
|
it 'sets the returned errors' do
|
256
256
|
expected_value = { errors: { password_confrimation: ["can't be blank"], email: ["can't be blank", 'is invalid'] } }
|
257
257
|
stub = req(:post, '/sign_up', expected_value, 422, sign_up.attributes)
|
258
|
-
expect(proc { sign_up.submit! }).to raise_error(ApiResource::ResourceError)
|
258
|
+
expect(proc { sign_up.submit! }).to raise_error(ApiResource::ResourceError) do |error|
|
259
|
+
expect(error.model).to eq(sign_up)
|
260
|
+
end
|
259
261
|
expect(sign_up.errors.messages).to match(expected_value[:errors])
|
260
262
|
expect(stub).to have_been_requested
|
261
263
|
end
|
@@ -263,7 +265,9 @@ RSpec.describe ApiResource::Resource do
|
|
263
265
|
it 'no request if not valid' do
|
264
266
|
sign_up.name = nil
|
265
267
|
stub = req(:post, '/sign_up', nil, 422)
|
266
|
-
expect(proc { sign_up.submit! }).to raise_error(ApiResource::ResourceError)
|
268
|
+
expect(proc { sign_up.submit! }).to raise_error(ApiResource::ResourceError) do |error|
|
269
|
+
expect(error.model).to eq(sign_up)
|
270
|
+
end
|
267
271
|
expect(sign_up.errors[:name]).to be_truthy
|
268
272
|
expect(stub).to_not have_been_requested
|
269
273
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chaker Nakhli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple-hmac
|