spyke 5.1.0 → 5.2.0
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/lib/spyke/http.rb +4 -3
- data/lib/spyke/normalized_validation_error.rb +27 -0
- data/lib/spyke/version.rb +1 -1
- data/test/orm_test.rb +10 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9124e2e536f848aee4a144556f24e0ccad5515e5
|
4
|
+
data.tar.gz: c1f33a42164811126c79b044b54265de252ddade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 |
|
106
|
-
|
107
|
-
errors.add(field.to_sym,
|
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
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.
|
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
|
+
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
|