acfs 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/acfs/errors.rb +9 -2
- data/lib/acfs/resource/validation.rb +11 -4
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs/resource/validation_spec.rb +20 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 151804a96a34d4c2703b0c94482ae3abdee035bc086110b5a4867e1deb84be30
|
4
|
+
data.tar.gz: 7c3324df0c3e5e253d8994ee0e2d99fab7c1ea42fba891723027eb51479319db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b7e893131d386a13c898cedac5e880bf9d6e2a31481b9c7af1dd41926f65385c3c667a9556ec8b349b72648a03be4c9ce8ff3f393bfe94f4c9d2b2b33bb6d5e
|
7
|
+
data.tar.gz: 910c4e6830b622c404eb9c614b4497eb69e20192f22315fc9d6ab89460fa7602396077ddfe5f000789dd609d4f69a6e126afa4a56bccba2bf8bbc2b06272e685
|
data/CHANGELOG.md
CHANGED
data/lib/acfs/errors.rb
CHANGED
@@ -68,8 +68,15 @@ module Acfs
|
|
68
68
|
def initialize(opts = {})
|
69
69
|
@errors = opts.delete :errors
|
70
70
|
@resource = opts.delete :resource
|
71
|
-
|
72
|
-
|
71
|
+
|
72
|
+
if @errors.is_a?(Hash)
|
73
|
+
opts[:message] ||= @errors.each_pair.map do |k, v|
|
74
|
+
@errors.is_a?(Array) ? "#{k}: #{v.join(', ')}" : "#{k}: #{v}"
|
75
|
+
end.join ', '
|
76
|
+
elsif @errors.is_a?(Array)
|
77
|
+
opts[:message] ||= @errors.join ', '
|
78
|
+
end
|
79
|
+
|
73
80
|
super
|
74
81
|
end
|
75
82
|
end
|
@@ -12,10 +12,17 @@ class Acfs::Resource
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def remote_errors=(errors)
|
15
|
-
(
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
if errors.respond_to?(:each_pair)
|
16
|
+
errors.each_pair do |field, errs|
|
17
|
+
Array(errs).each do |err|
|
18
|
+
self.errors.add field.to_sym, err
|
19
|
+
remote_errors.add field.to_sym, err
|
20
|
+
end
|
21
|
+
end
|
22
|
+
else
|
23
|
+
Array(errors).each do |err|
|
24
|
+
self.errors.add :base, err
|
25
|
+
remote_errors.add :base, err
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
data/lib/acfs/version.rb
CHANGED
@@ -66,14 +66,31 @@ describe Acfs::Resource::Validation do
|
|
66
66
|
after { Acfs::Stub.disable }
|
67
67
|
|
68
68
|
before do
|
69
|
-
Acfs::Stub.resource MyUser, :create,
|
69
|
+
Acfs::Stub.resource MyUser, :create,
|
70
|
+
with: {}, return: {errors: errors}, raise: 422
|
70
71
|
end
|
71
72
|
|
72
73
|
let(:params) { {} }
|
73
74
|
let(:resource) { MyUser.create params }
|
74
|
-
subject { resource }
|
75
|
+
subject { resource.errors.to_hash }
|
76
|
+
|
77
|
+
context 'with `field => [messages]` payload' do
|
78
|
+
let(:errors) { {name: ['cannot be blank']} }
|
79
|
+
|
80
|
+
it { is_expected.to eq(name: ['cannot be blank']) }
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'with `field => message` payload' do
|
84
|
+
let(:errors) { {name: 'cannot be blank'} }
|
75
85
|
|
76
|
-
|
86
|
+
it { is_expected.to eq(name: ['cannot be blank']) }
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'with `[messages]` payload' do
|
90
|
+
let(:errors) { ['cannot be blank'] }
|
91
|
+
|
92
|
+
it { is_expected.to eq(base: ['cannot be blank']) }
|
93
|
+
end
|
77
94
|
end
|
78
95
|
end
|
79
96
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -228,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
228
|
version: '0'
|
229
229
|
requirements: []
|
230
230
|
rubyforge_project:
|
231
|
-
rubygems_version: 2.7.
|
231
|
+
rubygems_version: 2.7.7
|
232
232
|
signing_key:
|
233
233
|
specification_version: 4
|
234
234
|
summary: An abstract API base client for service oriented application.
|