lhs 11.3.2 → 11.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhs/collection.rb +1 -1
- data/lib/lhs/concerns/collection/internal_collection.rb +4 -0
- data/lib/lhs/errors/base.rb +2 -2
- data/lib/lhs/version.rb +1 -1
- data/spec/collection/to_ary_spec.rb +34 -0
- data/spec/item/add_error_spec.rb +1 -1
- data/spec/item/errors_spec.rb +8 -0
- data/spec/record/creation_failed_spec.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b17c90e65dafbd6cc36a2e8ebfead0e7abee819c
|
4
|
+
data.tar.gz: 8ad952d7bebb07cfdb417dd5db4519cac2a80dbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40d3b01be43d424b9e2b19d7ad029b5e985988bcebcfa324e932836f8d608993f195eb93ee10ed2f77ea95bcab1c15fec3a3bfba7bbd3e8fdc180bd7dff7e16a
|
7
|
+
data.tar.gz: b8207ba3f7623a428faa2904c70514b3cc37afbc40a131be76e2c07018cb65f9ed4d364b229db7351fb16ecc899fe8f4df6aef32eb41085bffa1937a3041f1a5
|
data/lib/lhs/collection.rb
CHANGED
@@ -7,7 +7,7 @@ class LHS::Collection < LHS::Proxy
|
|
7
7
|
include InternalCollection
|
8
8
|
include Create
|
9
9
|
|
10
|
-
METHOD_NAMES_EXLCUDED_FROM_WRAPPING = %w(to_a map).freeze
|
10
|
+
METHOD_NAMES_EXLCUDED_FROM_WRAPPING = %w(to_a to_ary map).freeze
|
11
11
|
|
12
12
|
delegate :select, :length, :size, to: :_collection
|
13
13
|
delegate :_record, :_raw, to: :_data
|
data/lib/lhs/errors/base.rb
CHANGED
@@ -8,11 +8,11 @@ module LHS::Errors
|
|
8
8
|
def initialize(response = nil, record = nil)
|
9
9
|
@raw = response.body if response
|
10
10
|
@record = record
|
11
|
-
@messages = messages_from_response(response)
|
11
|
+
@messages = messages_from_response(response).with_indifferent_access
|
12
12
|
@message = message_from_response(response)
|
13
13
|
@status_code = response.code if response
|
14
14
|
rescue JSON::ParserError
|
15
|
-
@messages = messages || {}
|
15
|
+
@messages = (messages || {}).with_indifferent_access
|
16
16
|
@message = 'parse error'
|
17
17
|
add_error(@messages, 'body', 'parse error')
|
18
18
|
end
|
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Collection do
|
4
|
+
let(:items) { [{ name: 'Steve' }] }
|
5
|
+
let(:extra) { 'extra' }
|
6
|
+
let(:collection) { Record.where }
|
7
|
+
|
8
|
+
context 'to_ary' do
|
9
|
+
before(:each) do
|
10
|
+
class Record < LHS::Record
|
11
|
+
endpoint 'http://datastore/records`'
|
12
|
+
end
|
13
|
+
stub_request(:get, %r{http://datastore/records})
|
14
|
+
.to_return(body: response_data.to_json)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:response_data) do
|
18
|
+
{
|
19
|
+
items: items,
|
20
|
+
extra: extra,
|
21
|
+
total: 1
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:subject) { collection.to_ary }
|
26
|
+
|
27
|
+
it 'returns an array' do
|
28
|
+
expect(subject).to be
|
29
|
+
expect(subject).to be_kind_of Array
|
30
|
+
expect(subject[0]).to be_kind_of Record
|
31
|
+
expect(subject[0].name).to eq 'Steve'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/item/add_error_spec.rb
CHANGED
data/spec/item/errors_spec.rb
CHANGED
@@ -75,6 +75,14 @@ describe LHS::Item do
|
|
75
75
|
expect(record.errors[:recommended]).to eq ['REQUIRED_PROPERTY_VALUE']
|
76
76
|
end
|
77
77
|
|
78
|
+
it 'allows accessing error messages as a hash with indifferent access' do
|
79
|
+
stub_request(:post, "#{datastore}/feedbacks")
|
80
|
+
.to_return(status: 400, body: error_format_fields.to_json)
|
81
|
+
record.save
|
82
|
+
expect(record.errors.messages[:ratings]).to be
|
83
|
+
expect(record.errors.messages['ratings']).to be
|
84
|
+
end
|
85
|
+
|
78
86
|
it 'parses field errors correctly when creation failed' do
|
79
87
|
stub_request(:post, "#{datastore}/feedbacks")
|
80
88
|
.to_return(status: 400, body: error_format_field_errors.to_json)
|
@@ -40,7 +40,7 @@ describe LHS::Record do
|
|
40
40
|
expect(record.errors.include?(:ratings)).to eq true
|
41
41
|
expect(record.errors.include?(:recommended)).to eq true
|
42
42
|
expect(record.errors[:ratings]).to eq ['REQUIRED_PROPERTY_VALUE']
|
43
|
-
expect(record.errors.messages).to eq(ratings
|
43
|
+
expect(record.errors.messages).to eq('ratings' => ["REQUIRED_PROPERTY_VALUE"], 'recommended' => ["REQUIRED_PROPERTY_VALUE"])
|
44
44
|
expect(record.errors.message).to eq error_message
|
45
45
|
end
|
46
46
|
|
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: 11.3.
|
4
|
+
version: 11.3.3
|
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-06-
|
11
|
+
date: 2017-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -240,6 +240,7 @@ files:
|
|
240
240
|
- spec/collection/meta_data_spec.rb
|
241
241
|
- spec/collection/respond_to_spec.rb
|
242
242
|
- spec/collection/to_a_spec.rb
|
243
|
+
- spec/collection/to_ary_spec.rb
|
243
244
|
- spec/collection/without_object_items_spec.rb
|
244
245
|
- spec/complex/reduce_spec.rb
|
245
246
|
- spec/concerns/record/request_spec.rb
|
@@ -405,6 +406,7 @@ test_files:
|
|
405
406
|
- spec/collection/meta_data_spec.rb
|
406
407
|
- spec/collection/respond_to_spec.rb
|
407
408
|
- spec/collection/to_a_spec.rb
|
409
|
+
- spec/collection/to_ary_spec.rb
|
408
410
|
- spec/collection/without_object_items_spec.rb
|
409
411
|
- spec/complex/reduce_spec.rb
|
410
412
|
- spec/concerns/record/request_spec.rb
|