lhs 1.4.0 → 1.5.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: c4d9308df49f7152059f1d2c5b243073708b3f5c
4
- data.tar.gz: c2cf09d5ff720426922a46f858cbfda21603c899
3
+ metadata.gz: 971b5b5be07447f22d6836f2b753b2cf1a0ed6fe
4
+ data.tar.gz: 758c110834c300f5bfaa83c522b0448c387219c0
5
5
  SHA512:
6
- metadata.gz: 6c6e0edeadc0e459455d358c34fb9f3e66527d8529a868eaca3c630752837eb3f4dd3bc8f205c1b587240039173ea3459d7add01cb374ae7b9662c45f4990105
7
- data.tar.gz: fbfeed8fe2eeb6ba43eec211a1653250a016ec7aa51af4ecd0ae723a399205a2700b37220c82dfc29cf3c807d2e2e3b2b4f8e8730bd3639a7182970b5704ef06
6
+ metadata.gz: 300c01350c020f53b49b775d762a7ad58a242f6a26548b3dedebd5bdde9f66a9e7b5dca28f78a77432aa7e0329be0cb561a45783fb94d0a101a221423768162f
7
+ data.tar.gz: 35a0b20be75b9f31e528a59be968849ed7588f4502c9b426ec44895aa4c4d674deea14dc2baba0f834a52ffdcabad208d0f96b4e8e07e180324f22005988af06
data/lib/lhs/errors.rb CHANGED
@@ -2,11 +2,12 @@
2
2
  class LHS::Errors
3
3
  include Enumerable
4
4
 
5
- attr_reader :messages, :message
5
+ attr_reader :messages, :message, :raw
6
6
 
7
7
  def initialize(response)
8
8
  @messages = messages_from_response(response)
9
9
  @message = message_from_response(response)
10
+ @raw = response.body
10
11
  rescue JSON::ParserError
11
12
  end
12
13
 
data/lib/lhs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -2,19 +2,9 @@ require 'rails_helper'
2
2
 
3
3
  describe LHS::Item do
4
4
 
5
- context 'save failed' do
6
-
7
- let(:datastore) { 'http://local.ch/v2' }
5
+ let(:datastore) { 'http://local.ch/v2' }
8
6
 
9
- before(:each) do
10
- LHC.config.placeholder(:datastore, datastore)
11
- class SomeService < LHS::Service
12
- endpoint ':datastore/:campaign_id/feedbacks'
13
- endpoint ':datastore/feedbacks'
14
- end
15
- end
16
-
17
- let(:error_format_fields) do
7
+ let(:error_format_fields) do
18
8
  {
19
9
  "status" => 400,
20
10
  "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.",
@@ -30,29 +20,39 @@ describe LHS::Item do
30
20
  }
31
21
  end
32
22
 
33
- let(:error_format_field_errors) do
34
- {
35
- "status" => 400,
36
- "message" => "Some data in the request body failed validation. Inspect the field errors for details.",
37
- "field_errors" => [ {
38
- "code" => "UNSUPPORTED_PROPERTY_VALUE",
39
- "path" => [ "gender" ],
40
- "message" => "The property value is unsupported. Supported values are: FEMALE, MALE"
41
- }, {
42
- "code" => "INCOMPLETE_PROPERTY_VALUE",
43
- "path" => [ "gender" ],
44
- "message" => "The property value is incomplete. It misses some data"
45
- }, {
46
- "code" => "INCOMPLETE_PROPERTY_VALUE",
47
- "path" => [ "contract", "entry_id" ],
48
- "message" => "The property value is incomplete. It misses some data"
49
- } ]
50
- }
51
- end
23
+ let(:error_format_field_errors) do
24
+ {
25
+ "status" => 400,
26
+ "message" => "Some data in the request body failed validation. Inspect the field errors for details.",
27
+ "field_errors" => [ {
28
+ "code" => "UNSUPPORTED_PROPERTY_VALUE",
29
+ "path" => [ "gender" ],
30
+ "message" => "The property value is unsupported. Supported values are: FEMALE, MALE"
31
+ }, {
32
+ "code" => "INCOMPLETE_PROPERTY_VALUE",
33
+ "path" => [ "gender" ],
34
+ "message" => "The property value is incomplete. It misses some data"
35
+ }, {
36
+ "code" => "INCOMPLETE_PROPERTY_VALUE",
37
+ "path" => [ "contract", "entry_id" ],
38
+ "message" => "The property value is incomplete. It misses some data"
39
+ } ]
40
+ }
41
+ end
42
+
43
+ before(:each) do
44
+ LHC.config.placeholder(:datastore, datastore)
45
+ class SomeService < LHS::Service
46
+ endpoint ':datastore/:campaign_id/feedbacks'
47
+ endpoint ':datastore/feedbacks'
48
+ end
49
+ end
50
+
51
+ context 'save failed' do
52
52
 
53
53
  it 'parses fields correctly when creation failed' do
54
54
  stub_request(:post, "#{datastore}/feedbacks")
55
- .to_return(status: 400, body: error_format_fields.to_json)
55
+ .to_return(status: 400, body: error_format_fields.to_json)
56
56
  record = SomeService.build
57
57
  record.name = 'Steve'
58
58
  result = record.save
@@ -67,7 +67,7 @@ describe LHS::Item do
67
67
 
68
68
  it 'parses field errors correctly when creation failed' do
69
69
  stub_request(:post, "#{datastore}/feedbacks")
70
- .to_return(status: 400, body: error_format_field_errors.to_json)
70
+ .to_return(status: 400, body: error_format_field_errors.to_json)
71
71
  record = SomeService.build
72
72
  record.name = 'Steve'
73
73
  result = record.save
@@ -79,4 +79,19 @@ describe LHS::Item do
79
79
  expect(record.errors[:"contract.entry_id"]).to eq ['INCOMPLETE_PROPERTY_VALUE']
80
80
  end
81
81
  end
82
+
83
+ context 'raw error data' do
84
+
85
+ it 'provides access to raw error data' do
86
+ stub_request(:post, "#{datastore}/feedbacks")
87
+ .to_return(status: 400, body: error_format_field_errors.to_json)
88
+ record = SomeService.build
89
+ record.save
90
+ expect(record.errors.raw).to be
91
+ json = JSON.parse(record.errors.raw)
92
+ expect(json['status']).to be
93
+ expect(json['message']).to be
94
+ expect(json['field_errors']).to be
95
+ end
96
+ end
82
97
  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: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - local.ch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-27 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -213,9 +213,9 @@ files:
213
213
  - spec/endpoint/for_url_spec.rb
214
214
  - spec/item/delegate_spec.rb
215
215
  - spec/item/destroy_spec.rb
216
+ - spec/item/errors_spec.rb
216
217
  - spec/item/getter_spec.rb
217
218
  - spec/item/respond_to_spec.rb
218
- - spec/item/save_errors_spec.rb
219
219
  - spec/item/save_spec.rb
220
220
  - spec/item/setter_spec.rb
221
221
  - spec/item/update_spec.rb
@@ -325,9 +325,9 @@ test_files:
325
325
  - spec/endpoint/for_url_spec.rb
326
326
  - spec/item/delegate_spec.rb
327
327
  - spec/item/destroy_spec.rb
328
+ - spec/item/errors_spec.rb
328
329
  - spec/item/getter_spec.rb
329
330
  - spec/item/respond_to_spec.rb
330
- - spec/item/save_errors_spec.rb
331
331
  - spec/item/save_spec.rb
332
332
  - spec/item/setter_spec.rb
333
333
  - spec/item/update_spec.rb