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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bbf841e955ed23fe6c7efbf8f8fe7b05fc35538
4
- data.tar.gz: d331ac41f574be37f783b10ff7c53fe43c592a8f
3
+ metadata.gz: b17c90e65dafbd6cc36a2e8ebfead0e7abee819c
4
+ data.tar.gz: 8ad952d7bebb07cfdb417dd5db4519cac2a80dbc
5
5
  SHA512:
6
- metadata.gz: 3c0a3fee58998e8c51a25c16702a17b20cec97498979863040b2120d51a776e6333733c807e1940105f24e15b987d2d84e50a50c7fbf4846e1aff472b1e840d2
7
- data.tar.gz: 6cb8b54105e3579b76e3ff9d9a26c3d738a85e73eb4ded2a93343a176b3231a99fc88bb7f39cc956faf3375bbc7bf46edd8b51088632ad7eb6cacb3aab8926d1
6
+ metadata.gz: 40d3b01be43d424b9e2b19d7ad029b5e985988bcebcfa324e932836f8d608993f195eb93ee10ed2f77ea95bcab1c15fec3a3bfba7bbd3e8fdc180bd7dff7e16a
7
+ data.tar.gz: b8207ba3f7623a428faa2904c70514b3cc37afbc40a131be76e2c07018cb65f9ed4d364b229db7351fb16ecc899fe8f4df6aef32eb41085bffa1937a3041f1a5
@@ -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
@@ -21,6 +21,10 @@ class LHS::Collection < LHS::Proxy
21
21
  @record = record
22
22
  end
23
23
 
24
+ def to_ary
25
+ map { |item| item }
26
+ end
27
+
24
28
  def each(&_block)
25
29
  raw.each do |item|
26
30
  if item.is_a? Hash
@@ -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
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "11.3.2"
2
+ VERSION = "11.3.3"
3
3
  end
@@ -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
@@ -13,7 +13,7 @@ describe LHS::Item do
13
13
  subject.errors.add(:name, 'This date is invalid')
14
14
  expect(
15
15
  subject.errors.first
16
- ).to eq [:name, 'This date is invalid']
16
+ ).to eq ['name', 'This date is invalid']
17
17
  end
18
18
  end
19
19
  end
@@ -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: ["REQUIRED_PROPERTY_VALUE"], recommended: ["REQUIRED_PROPERTY_VALUE"])
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.2
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-22 00:00:00.000000000 Z
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