lhs 9.1.1 → 10.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 580d8981ba9059cb3e1e5a5d598313e167421279
4
- data.tar.gz: 561ba57069262b2c87a825b935b933522daac02f
3
+ metadata.gz: 728cf6034afb426a4b3fb40dd3a8dcdbffd3d004
4
+ data.tar.gz: 18872dbdb2fe63ea9b4dc1db69fd370f1499fce3
5
5
  SHA512:
6
- metadata.gz: 1aaad8a56559f5a27c4fd5b9a82d31732525c8eb11e20d6b5b30b3b3913749caf7bc674bc71fa837c6c7cb9bb032983358f4fe3017e6621b6b8ace5bd04b9b8a
7
- data.tar.gz: 2b298c29b539f34559693c83489809919005f7879a63731c217aecd07df222e9fcfa5646949775b9d0f1f8ee8ed3475fac472bf345f3619b55a506b92efbace4
6
+ metadata.gz: 5d2733b6ee17ed421ab06af04d65c5bfd09f2cdee35f7fbd82bc04ea59152fb9977100b60a6143fa872a90039b589af19b187da48e2d80d5ccf20202278aa8ce
7
+ data.tar.gz: 11e83155ac46883623f321bf12da0357f709fddf3343feb225f2e1af1fadfb4847668f299f921c2a0900ac506c6c1040191f636269c261c3a76ef04acf49927a
data/README.md CHANGED
@@ -309,15 +309,7 @@ end
309
309
  )
310
310
  ```
311
311
 
312
- When creation fails, the object contains errors. It provides them through the `errors` attribute:
313
-
314
- ```ruby
315
- record.errors #<LHS::Errors>
316
- record.errors.include?(:ratings) # true
317
- record.errors[:ratings] # ['REQUIRED_PROPERTY_VALUE']
318
- record.errors.messages # {:ratings=>["REQUIRED_PROPERTY_VALUE"], :recommended=>["REQUIRED_PROPERTY_VALUE"]}
319
- record.errors.message # ratings must be set when review or name or review_title is set | The property value is required; it cannot be null, empty, or blank."
320
- ```
312
+ See [Validation](#Validation) for handling validation errors when creating records.
321
313
 
322
314
  ## Create records through associations (nested resources)
323
315
 
@@ -680,6 +672,12 @@ user = User.build(email: 'im not an email address')
680
672
  unless user.valid?
681
673
  fail(user.errors[:email])
682
674
  end
675
+
676
+ user.errors #<LHS::Errors>
677
+ user.errors.include?(:email) # true
678
+ user.errors[:email] # ['REQUIRED_PROPERTY_VALUE']
679
+ user.errors.messages # {:email=>["REQUIRED_PROPERTY_VALUE"]}
680
+ user.errors.message # email must be set when user is created."
683
681
  ```
684
682
 
685
683
  The parameters passed to the `validates` endpoint option are used to perform the validation:
@@ -691,7 +689,15 @@ The parameters passed to the `validates` endpoint option are used to perform the
691
689
  endpoint ':service/v2/users', validates: { path: 'validate' } # will perform a validation via :service/v2/users/validate
692
690
  ```
693
691
 
694
- ## Custom validation errors
692
+ ### Reset validation errors
693
+
694
+ Clear the error messages. Compatible with [ActiveRecord](https://github.com/rails/rails/blob/6c8cf21584ced73ade45529d11463c74b5a0c58f/activemodel/lib/active_model/errors.rb#L85).
695
+
696
+ ```ruby
697
+ record.errors.clear
698
+ ```
699
+
700
+ ### Custom validation errors
695
701
 
696
702
  In case you want to add custom validation errors to an instance of LHS::Record:
697
703
 
@@ -7,7 +7,7 @@ class LHS::Item < LHS::Proxy
7
7
 
8
8
  def valid?(options = {})
9
9
  options ||= {}
10
- self.errors = nil
10
+ errors.clear
11
11
  endpoint = validation_endpoint
12
12
  raise 'No endpoint found to perform validations! See here: https://github.com/local-ch/lhs#validation' unless endpoint
13
13
  record = LHS::Record.for_url(endpoint.url)
@@ -53,6 +53,11 @@ class LHS::Errors
53
53
  values.flatten.size
54
54
  end
55
55
 
56
+ def clear
57
+ @raw = nil
58
+ @messages.clear
59
+ end
60
+
56
61
  delegate :values, to: :messages
57
62
 
58
63
  delegate :keys, to: :messages
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "9.1.1"
2
+ VERSION = "10.0.0"
3
3
  end
@@ -157,4 +157,20 @@ describe LHS::Item do
157
157
  expect(record.errors['body']).to eq ['parse error']
158
158
  end
159
159
  end
160
+
161
+ describe '#clear' do
162
+ let(:record) { Record.build(name: 'Steve') }
163
+
164
+ before(:each) do
165
+ stub_request(:post, "#{datastore}/feedbacks")
166
+ .to_return(status: 400, body: error_format_fields.to_json)
167
+ end
168
+
169
+ it 'resets all errors' do
170
+ record.save
171
+ expect(record.errors.any?).to eq true
172
+ record.errors.clear
173
+ expect(record.errors.any?).to eq false
174
+ end
175
+ end
160
176
  end
@@ -93,7 +93,7 @@ describe LHS::Item do
93
93
  user.email = 'steve@local.ch'
94
94
  successful_validation
95
95
  expect(user.valid?).to eq true
96
- expect(user.errors).to be_nil
96
+ expect(user.errors.messages).to be_empty
97
97
  end
98
98
  end
99
99
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.1
4
+ version: 10.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-02 00:00:00.000000000 Z
11
+ date: 2017-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc