api-model 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f815e2fe813c6ab61d66e7cd060c4684c38b41e
4
- data.tar.gz: 75056c124a3c1bf7772216ddea09f824db7c1a50
3
+ metadata.gz: 2824a025d53804254f083f5def2121ea04c9ca02
4
+ data.tar.gz: a0b7b7a237529233ebd6f325e7727ffcab36605c
5
5
  SHA512:
6
- metadata.gz: cbfbbff8f9dea0f02b804a75d91fb697abadfef39a44e0a9531b053677f0b046b766cc66f4d410074d9bde4fb1947035ddaa33fc21ba150ffdf8022ead0df860
7
- data.tar.gz: 695d60e37fc49ec0861516cacf1aaee650e6aa5ab5f0c3e9faf2f20d65d1a46182b4808084c4b56709219150ea8cbaac0b287596e95fd0dc52ca5833b3b64bf5
6
+ metadata.gz: 6c048dc626f37626351951594c90d25b58f4e113fbf07dd1ab129c27b1f0afe6f9da00e0cc8b5a121aa18e9b83fe7ef4c3938dc36cfe7b16f74a7f02cbff1e03
7
+ data.tar.gz: 8811f67f0e7e36663090b86257bf80c84fea21f62c9582c4dee36e851e8e322db1484a7d6e2d4f43d13d0460d66909e842d37f32f3af5a959ba37a8a06187ff1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-model (2.4.0)
4
+ api-model (2.4.1)
5
5
  activemodel (~> 4.1)
6
6
  activesupport (~> 4.1)
7
7
  hash-pipe (~> 0.0)
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.0"
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 do
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
@@ -87,7 +87,7 @@ module ApiModel
87
87
  # Then calling ++fetch_from_body("foo.bar.baz")++ would return "Hello world"
88
88
  def fetch_from_body(key_reference)
89
89
  key_reference.split(".").inject(response_body) do |hash,key|
90
- hash.fetch(key)
90
+ hash.fetch(key, nil)
91
91
  end
92
92
  end
93
93
 
@@ -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.0
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-03-05 00:00:00.000000000 Z
12
+ date: 2015-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport