api-model 2.4.0 → 2.4.1
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/Gemfile.lock +1 -1
- data/api-model.gemspec +1 -1
- data/lib/api_model/instance_methods.rb +4 -3
- data/lib/api_model/response.rb +1 -1
- data/spec/api-model/api_model_spec.rb +7 -0
- data/spec/support/fixtures/posts.yml +29 -0
- 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: 2824a025d53804254f083f5def2121ea04c9ca02
|
4
|
+
data.tar.gz: a0b7b7a237529233ebd6f325e7727ffcab36605c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c048dc626f37626351951594c90d25b58f4e113fbf07dd1ab129c27b1f0afe6f9da00e0cc8b5a121aa18e9b83fe7ef4c3938dc36cfe7b16f74a7f02cbff1e03
|
7
|
+
data.tar.gz: 8811f67f0e7e36663090b86257bf80c84fea21f62c9582c4dee36e851e8e322db1484a7d6e2d4f43d13d0460d66909e842d37f32f3af5a959ba37a8a06187ff1
|
data/Gemfile.lock
CHANGED
data/api-model.gemspec
CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "api-model"
|
5
|
-
s.version = "2.4.
|
5
|
+
s.version = "2.4.1"
|
6
6
|
s.authors = ["Damien Timewell", "Erik Rothoff Andersson"]
|
7
7
|
s.email = ["mail@damientimewell.com", "erik.rothoff@gmail.com"]
|
8
8
|
s.licenses = ['MIT']
|
@@ -68,15 +68,16 @@ module ApiModel
|
|
68
68
|
run_callbacks :save do
|
69
69
|
response = self.class.call_api_with_json request_method, path, body, options.reverse_merge(builder: ApiModel::Builder::Hash.new)
|
70
70
|
response_success = response.http_response.api_call.success?
|
71
|
+
error_messages = response.fetch_from_body(errors_root)
|
72
|
+
|
73
|
+
set_errors_from_hash error_messages if error_messages.present?
|
71
74
|
|
72
75
|
if response_success
|
73
76
|
run_callbacks :successful_save do
|
74
77
|
update_attributes response.response_build_hash
|
75
78
|
end
|
76
79
|
else
|
77
|
-
run_callbacks :unsuccessful_save
|
78
|
-
set_errors_from_hash response.fetch_from_body(errors_root)
|
79
|
-
end
|
80
|
+
run_callbacks :unsuccessful_save
|
80
81
|
end
|
81
82
|
|
82
83
|
response_success
|
data/lib/api_model/response.rb
CHANGED
@@ -256,6 +256,13 @@ describe ApiModel do
|
|
256
256
|
blog_post.errors[:name].should eq ["Cannot be blank"]
|
257
257
|
end
|
258
258
|
|
259
|
+
it 'should set errors on the instance even if the request was sucessful' do
|
260
|
+
expect {
|
261
|
+
VCR.use_cassette('posts') { blog_post.save "/post/200_with_errors", name: "" }
|
262
|
+
}.to change{ blog_post.errors.size }.from(0).to(1)
|
263
|
+
blog_post.errors[:name].should eq ["Cannot be blank"]
|
264
|
+
end
|
265
|
+
|
259
266
|
it 'should be possible to change the error root when making the save call' do
|
260
267
|
expect {
|
261
268
|
VCR.use_cassette('posts') { blog_post.save "/post/with_nested_errors", {name: ""}, json_errors_root: "result.errors" }
|
@@ -280,4 +280,33 @@ http_interactions:
|
|
280
280
|
http_version:
|
281
281
|
recorded_at: Thu, 28 Nov 2013 16:02:20 GMT
|
282
282
|
|
283
|
+
- request:
|
284
|
+
method: put
|
285
|
+
uri: http://api-model-specs.com/post/200_with_errors
|
286
|
+
headers:
|
287
|
+
User-Agent:
|
288
|
+
- Typhoeus - https://github.com/typhoeus/typhoeus
|
289
|
+
body:
|
290
|
+
string: "{\"name\":\"\"}"
|
291
|
+
response:
|
292
|
+
status:
|
293
|
+
code: 200
|
294
|
+
message: OK
|
295
|
+
headers:
|
296
|
+
Server:
|
297
|
+
- nginx/1.4.1
|
298
|
+
Date:
|
299
|
+
- Thu, 28 Nov 2013 16:02:56 GMT
|
300
|
+
Content-Type:
|
301
|
+
- text/plain; charset=utf-8
|
302
|
+
Content-Length:
|
303
|
+
- '248'
|
304
|
+
Connection:
|
305
|
+
- keep-alive
|
306
|
+
body:
|
307
|
+
encoding: UTF-8
|
308
|
+
string: "{\"errors\":{\"name\":\"Cannot be blank\"}}"
|
309
|
+
http_version:
|
310
|
+
recorded_at: Thu, 28 Nov 2013 16:02:20 GMT
|
311
|
+
|
283
312
|
recorded_with: VCR 2.8.0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Timewell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|