lhs 14.3.0 → 14.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6435e1ce72c8bd918fc9a4b1f5fde544c47ba90
4
- data.tar.gz: f12a4d30361c30793c3a79b182be4acf9bd213f2
3
+ metadata.gz: 592b02ea75646240c5b91bedd2c780898ed87a4b
4
+ data.tar.gz: b91803f278dbdc05c0b1c5405a75d7daa3191116
5
5
  SHA512:
6
- metadata.gz: c40a3b2b6d1f0942837fae1e2e0ee44794708b51a4927e4b52c8d0771f05f442ebf8313d0658053cb8ee7114f23ffaf8c6f0cb780d44da1e5e6bea271c7b46cb
7
- data.tar.gz: ab234e491cf9e16141610dc9f3d8bda6423757b96daf2ba992b68f91e972d053409adcf3cb15b90a15a41b6f7cfe8ea0eb0149b9f2cb4fad25b6ecc138ef9720
6
+ metadata.gz: 61c954708c2abf0147112c0d34ec044ef0f9dd4e53f75b26db3a26f430b138ff203127e1dc49a45066fe02c1cce9806a6b0dab7338fc207fc8b87547890aa29a
7
+ data.tar.gz: 088c03a54f417a2844bc6a85e318e42ea0d2a12540cc3745a2c1c20940448848c2760413eb180a5b8c0154b829a737eb76a04ab4296036c45a1cabad487039ce
data/README.md CHANGED
@@ -760,7 +760,7 @@ or with parameters:
760
760
 
761
761
  In order to validate LHS::Records before persisting them, you can use the `valid?` (`validate` alias) method.
762
762
 
763
- The specific endpoint has to support validations without peristance. An endpoint has to be enabled (opt-in) for validations in the service configuration.
763
+ The specific endpoint has to support validations without persistance. An endpoint has to be enabled (opt-in) for validations in the service configuration.
764
764
 
765
765
  ```ruby
766
766
  class User < LHS::Record
@@ -861,6 +861,33 @@ lhs.errors.fallback_message
861
861
  ### Know issue with `ActiveModel::Validations`
862
862
  If you are using `ActiveModel::Validations` and add errors to the LHS::Record instance - as described above - then those errors will be overwritten by the errors from `ActiveModel::Validations` when using `save` or `valid?`. [Open issue](https://github.com/local-ch/lhs/issues/159)
863
863
 
864
+ ### Blocking errors, original "errors"
865
+
866
+ The fact that records could have errors is not coupled to any response status code.
867
+
868
+ LHS makes errors accessible, if they are present:
869
+
870
+ ```
871
+ {
872
+ company_name: 'localsearch',
873
+ field_errors: [{
874
+ code: 'REQUIRED_PROPERTY_VALUE',
875
+ path: ['place', 'opening_hours']
876
+ }
877
+ }
878
+ ```
879
+
880
+ LHS makes those errors available when accessing `.errors`:
881
+
882
+ ```ruby
883
+ presence = Presence.create(
884
+ place: { href: 'http://storage/places/1' }
885
+ )
886
+
887
+ presence.errors.any? # true
888
+ presence.place.errors.messages[:opening_hours] # ['REQUIRED_PROPERTY_VALUE']
889
+ ```
890
+
864
891
  ### Non blocking validation errors, so called warnings
865
892
 
866
893
  In some cases, you need non blocking meta information about potential problems with the created record, so called warnings.
@@ -14,7 +14,8 @@ class LHS::Proxy
14
14
  end
15
15
 
16
16
  def errors
17
- @errors ||= LHS::Problems::Errors.new(nil, record)
17
+ response = _raw.present? && _raw.is_a?(Hash) && _raw[:field_errors] ? OpenStruct.new(body: _raw.to_json) : nil
18
+ @errors ||= LHS::Problems::Errors.new(response, record)
18
19
  end
19
20
 
20
21
  def warnings
data/lib/lhs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '14.3.0'
2
+ VERSION = '14.3.1'
3
3
  end
@@ -0,0 +1,31 @@
1
+ require 'rails_helper'
2
+
3
+ describe LHS::Item do
4
+
5
+ context 'make errors available' do
6
+
7
+ before(:each) do
8
+ class Presence < LHS::Record
9
+ endpoint 'http://opm/presences'
10
+ end
11
+ end
12
+
13
+ let(:place_href) { 'http://datastore/places/1' }
14
+
15
+ it 'makes errors available no matter the response code' do
16
+ stub_request(:post, "http://opm/presences")
17
+ .to_return(
18
+ status: 200,
19
+ body: {
20
+ place: { href: place_href },
21
+ field_errors: [{
22
+ code: 'REQUIRED_PROPERTY_VALUE',
23
+ path: ['place', 'opening_hours']
24
+ }]
25
+ }.to_json
26
+ )
27
+ presence = Presence.create(place: { href: place_href })
28
+ expect(presence.errors.any?).to be true
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.3.0
4
+ version: 14.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
@@ -321,6 +321,7 @@ files:
321
321
  - spec/dummy/public/500.html
322
322
  - spec/dummy/public/favicon.ico
323
323
  - spec/endpoint/for_url_spec.rb
324
+ - spec/item/access_errors_spec.rb
324
325
  - spec/item/accessors_spec.rb
325
326
  - spec/item/add_error_spec.rb
326
327
  - spec/item/becomes_spec.rb
@@ -499,6 +500,7 @@ test_files:
499
500
  - spec/dummy/public/500.html
500
501
  - spec/dummy/public/favicon.ico
501
502
  - spec/endpoint/for_url_spec.rb
503
+ - spec/item/access_errors_spec.rb
502
504
  - spec/item/accessors_spec.rb
503
505
  - spec/item/add_error_spec.rb
504
506
  - spec/item/becomes_spec.rb