api-resource 0.7.6 → 0.7.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff13e586ba5115068b6d745225fedff154edf75e
4
- data.tar.gz: b0faf9a94735afa8c7ad76808624bc9264fc6105
3
+ metadata.gz: 64acbe85774b705bfa7eb2b9f8c9b451371b586d
4
+ data.tar.gz: ac068136f63a55363e166d676161f073ecff6d6e
5
5
  SHA512:
6
- metadata.gz: f18923f4597e79b3b5afdc67ee9722214344d33b2ff3b31b1de15b6443556ff14333e03c0ae076601378cc730f917ffdd34602fd9ad5652c9e089a35d71e1be8
7
- data.tar.gz: 125fa114e774163151d071cde9b7d3bb01f844fbf48659fdf355a40342d84102396c16b5e0802ee28f77f4cfdbccd755f7bf421afb92545d691965090c694cb1
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, 'Error executing request'
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
@@ -1,3 +1,3 @@
1
1
  module ApiResource
2
- VERSION = '0.7.6'
2
+ VERSION = '0.7.7'
3
3
  end
@@ -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.6
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-01 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple-hmac