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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c18e797eac0b3abed6b8e813fe02868e26b75ae6a83067502adcc4b4b4176cf
4
- data.tar.gz: a3825baa81a2d24a925a820968580bd2006c3e64500de45feec106b17090e325
3
+ metadata.gz: 151804a96a34d4c2703b0c94482ae3abdee035bc086110b5a4867e1deb84be30
4
+ data.tar.gz: 7c3324df0c3e5e253d8994ee0e2d99fab7c1ea42fba891723027eb51479319db
5
5
  SHA512:
6
- metadata.gz: ce0d4f99f72aaad7ff0242026c5fe0efef7442f7dd44f7b44b1bb7e9947115cc8049d24c1977b418140155f66091d070f8c3a983164047f105d4b5a4995a9e2e
7
- data.tar.gz: 58054596b40e2453e1790b3c74c56450b5a0d020bf7ad5d10fe61da68d1e791872e79fa0fa2990d713cf05e9da7055fb700437df5e2063530170ad26d9d210f3
6
+ metadata.gz: 9b7e893131d386a13c898cedac5e880bf9d6e2a31481b9c7af1dd41926f65385c3c667a9556ec8b349b72648a03be4c9ce8ff3f393bfe94f4c9d2b2b33bb6d5e
7
+ data.tar.gz: 910c4e6830b622c404eb9c614b4497eb69e20192f22315fc9d6ab89460fa7602396077ddfe5f000789dd609d4f69a6e126afa4a56bccba2bf8bbc2b06272e685
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.1
4
+
5
+ * Fix issues with resources errors if response payload differs from the expected `field => [messages]`, such as `field => message` or `[messages]`.
6
+
3
7
  ## 1.2.0
4
8
 
5
9
  * Add Rails 5.2 compatibility
@@ -68,8 +68,15 @@ module Acfs
68
68
  def initialize(opts = {})
69
69
  @errors = opts.delete :errors
70
70
  @resource = opts.delete :resource
71
- opts[:message] ||= @errors.map {|k, v| "#{k}: #{v.join ', '}" }.join ', ' if @errors.is_a? Hash
72
- opts[:message] ||= @errors.join ', ' if @errors.is_a? Array
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
- (errors || []).each do |field, errs|
16
- errs.each do |err|
17
- self.errors.add field.to_sym, err
18
- remote_errors.add field.to_sym, err
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
@@ -2,7 +2,7 @@ module Acfs
2
2
  module VERSION
3
3
  MAJOR = 1
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STAGE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
@@ -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, with: {}, return: {errors: {name: ['can\'t be blank']}}, raise: 422
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
- its(:errors) { expect(subject.errors.to_hash).to eq(name: ['can\'t be blank']) }
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.0
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-04-25 00:00:00.000000000 Z
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.3
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.