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 +4 -4
- data/README.md +16 -10
- data/lib/lhs/concerns/item/validation.rb +1 -1
- data/lib/lhs/errors.rb +5 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/item/errors_spec.rb +16 -0
- data/spec/item/validation_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 728cf6034afb426a4b3fb40dd3a8dcdbffd3d004
|
|
4
|
+
data.tar.gz: 18872dbdb2fe63ea9b4dc1db69fd370f1499fce3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)
|
data/lib/lhs/errors.rb
CHANGED
data/lib/lhs/version.rb
CHANGED
data/spec/item/errors_spec.rb
CHANGED
|
@@ -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
|
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:
|
|
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-
|
|
11
|
+
date: 2017-03-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lhc
|