spyke 5.1.0 → 5.2.0

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: 5862d16d060c727c750f6ef6fa7f785d729747f5
4
- data.tar.gz: '09585cb44ae03a6fda4c919d04ec24175dc55392'
3
+ metadata.gz: 9124e2e536f848aee4a144556f24e0ccad5515e5
4
+ data.tar.gz: c1f33a42164811126c79b044b54265de252ddade
5
5
  SHA512:
6
- metadata.gz: 3fba59829a12e29b2b8290f8aaa6a75fff77ecd274c11a32a46e60797d61f4fcfd08ff24cb9b36083f6c248367778e8668613e69289b7d89b22b98c32d19b3eb
7
- data.tar.gz: b4ff64f835373b9bb7eaeda69d3d67e29ead1926dbf4fecbdd745f0a2409164d1d5ebb3778ac9d9dee6bf907ea2981a1863bf7d0aa1841ff13cf99cb54747f76
6
+ metadata.gz: 7f34c8c2f7b875e742ea9ed51b28d2518af3f62561978683374ea7956082403bd980b54aa176adb6dbb43b97c11c3e23599120d49b540ea9096395ad70c545b9
7
+ data.tar.gz: b087f095780cbd94b6d7a620eb8ef87a589978837130dd9d3471292ea65285f8609996ff199885a67d44ceda15fc9c2070b3679efcb6505921bcca580fdf4942
data/lib/spyke/http.rb CHANGED
@@ -3,6 +3,7 @@ require 'faraday_middleware'
3
3
  require 'spyke/config'
4
4
  require 'spyke/path'
5
5
  require 'spyke/result'
6
+ require 'spyke/normalized_validation_error'
6
7
 
7
8
  module Spyke
8
9
  module Http
@@ -102,9 +103,9 @@ module Spyke
102
103
 
103
104
  def add_errors_to_model(errors_hash)
104
105
  errors_hash.each do |field, field_errors|
105
- field_errors.each do |attributes|
106
- error_name = attributes.delete(:error).to_sym
107
- errors.add(field.to_sym, error_name, attributes.symbolize_keys)
106
+ field_errors.each do |error_attributes|
107
+ error = NormalizedValidationError.new(error_attributes)
108
+ errors.add(field.to_sym, error.message, error.options)
108
109
  end
109
110
  end
110
111
  end
@@ -0,0 +1,27 @@
1
+ module Spyke
2
+ class NormalizedValidationError
3
+ ERROR_KEY = :error
4
+
5
+ def initialize(attributes)
6
+ @attributes = attributes
7
+ end
8
+
9
+ def message
10
+ case @attributes
11
+ when String
12
+ @attributes
13
+ when Hash
14
+ @attributes[ERROR_KEY].to_sym
15
+ end
16
+ end
17
+
18
+ def options
19
+ case @attributes
20
+ when String
21
+ {}
22
+ when Hash
23
+ @attributes.except(ERROR_KEY).symbolize_keys
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/spyke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '5.1.0'
2
+ VERSION = '5.2.0'
3
3
  end
data/test/orm_test.rb CHANGED
@@ -93,6 +93,16 @@ module Spyke
93
93
  assert_requested endpoint
94
94
  end
95
95
 
96
+ def test_create_with_server_returning_string_validation_errors
97
+ endpoint = stub_request(:put, 'http://sushi.com/recipes/1').to_return_json(id: 'write_error:400', errors: { title: ["is too short"], groups: ["can't be blank"] })
98
+
99
+ recipe = Recipe.create(id: 1, title: 'sus')
100
+
101
+ assert_equal 'sus', recipe.title
102
+ assert_equal ['Title is too short', "Groups can't be blank"], recipe.errors.full_messages
103
+ assert_requested endpoint
104
+ end
105
+
96
106
  def test_find_using_custom_uri_template
97
107
  endpoint = stub_request(:get, 'http://sushi.com/images/photos/1').to_return_json(result: { id: 1 })
98
108
  Photo.find(1)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spyke
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-09 00:00:00.000000000 Z
11
+ date: 2017-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -275,6 +275,7 @@ files:
275
275
  - lib/spyke/instrumentation.rb
276
276
  - lib/spyke/instrumentation/controller_runtime.rb
277
277
  - lib/spyke/instrumentation/log_subscriber.rb
278
+ - lib/spyke/normalized_validation_error.rb
278
279
  - lib/spyke/orm.rb
279
280
  - lib/spyke/path.rb
280
281
  - lib/spyke/relation.rb