mno-enterprise-core 3.0.3 → 3.0.4
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/lib/her_extension/middleware/mnoe_raise_error.rb +21 -0
- data/lib/her_extension/model/relation.rb +3 -0
- data/lib/mno_enterprise/core.rb +4 -0
- data/lib/mno_enterprise/testing_support/mno_enterprise_api_test_helper.rb +2 -1
- data/lib/mno_enterprise/version.rb +1 -1
- data/spec/lib/her_extension/model/relation_spec.rb +14 -0
- data/spec/models/mno_enterprise/base_resource_spec.rb +22 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 813c8e1d92349154521dc8890567c5d781cfa6c6
|
4
|
+
data.tar.gz: 193b99609bab56ce9e15352ca4b4bd4545785683
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 506c85a6be60f669dd1e757f9fc867f8bdd19824b1140434ffb2221ecbe89ff3744c2e37bb2691551d3451d71d1678e1c0a149c07a2530af7e801f2c872f53b8
|
7
|
+
data.tar.gz: a5e71645e53acc694ebc7fde9aa497101c449a5e35704b693c1c61c6147db6c586008652183ae574792107da2d5806431b3252ef655408a9eb9248ddaaa4d6a2
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Her
|
2
|
+
module Middleware
|
3
|
+
# This middleware will raise errors based on the response status
|
4
|
+
# Same as Faraday::Response::RaiseError, except it will catch specific
|
5
|
+
# errors codes rather than everything in 400..600
|
6
|
+
class MnoeRaiseError < Faraday::Response::RaiseError
|
7
|
+
def on_complete(env)
|
8
|
+
case env[:status]
|
9
|
+
when 407
|
10
|
+
# mimic the behavior that we get with proxy requests with HTTPS
|
11
|
+
raise Faraday::Error::ConnectionFailed,
|
12
|
+
%(407 "Proxy Authentication Required ")
|
13
|
+
when 502..504
|
14
|
+
raise Faraday::Error::ConnectionFailed, response_values(env)
|
15
|
+
when 401, 500
|
16
|
+
raise Faraday::Error::ClientError, response_values(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -26,6 +26,9 @@ module Her
|
|
26
26
|
# Use filter instead of raw parameters
|
27
27
|
def where(params = {})
|
28
28
|
return self if !params || params.empty?
|
29
|
+
# If a value is an empty array, it'll be excluded when calling params.to_query, so convert it to nil instead
|
30
|
+
params.each { |k, v| params[k] = v.presence if v.is_a?(Array) }
|
31
|
+
|
29
32
|
self.params[:filter] ||= {}
|
30
33
|
self.params[:filter].merge!(params)
|
31
34
|
self
|
data/lib/mno_enterprise/core.rb
CHANGED
@@ -18,6 +18,7 @@ require "her_extension/model/associations/association"
|
|
18
18
|
require "her_extension/model/associations/association_proxy"
|
19
19
|
require "her_extension/model/associations/has_many_association"
|
20
20
|
require "her_extension/middleware/mnoe_api_v1_parse_json"
|
21
|
+
require "her_extension/middleware/mnoe_raise_error"
|
21
22
|
require "faraday_middleware"
|
22
23
|
require "mno_enterprise/engine"
|
23
24
|
|
@@ -292,6 +293,9 @@ module MnoEnterprise
|
|
292
293
|
|
293
294
|
# Adapter
|
294
295
|
c.use Faraday::Adapter::NetHttpNoProxy
|
296
|
+
|
297
|
+
# Error Handling
|
298
|
+
c.use Her::Middleware::MnoeRaiseError
|
295
299
|
end
|
296
300
|
end
|
297
301
|
end
|
@@ -124,7 +124,8 @@ module MnoEnterpriseApiTestHelper
|
|
124
124
|
|
125
125
|
# Response
|
126
126
|
c.use Her::Middleware::MnoeApiV1ParseJson
|
127
|
-
|
127
|
+
c.use Her::Middleware::MnoeRaiseError
|
128
|
+
|
128
129
|
# Add stubs on the test adapter
|
129
130
|
c.use MnoeFaradayTestAdapter do |receiver|
|
130
131
|
@_stub_list.each do |key,stub|
|
@@ -3,5 +3,19 @@ require 'rails_helper'
|
|
3
3
|
module MnoEnterprise
|
4
4
|
RSpec.describe Her::Model::Relation do
|
5
5
|
pending "add specs for Her::Model::Relation monkey patch: #{__FILE__}"
|
6
|
+
|
7
|
+
let(:dummy_class) { Class.new { include Her::Model } }
|
8
|
+
|
9
|
+
describe '.where' do
|
10
|
+
it 'adds the filter to params[:filter]' do
|
11
|
+
rel = Her::Model::Relation.new(dummy_class).where('uid.in' => [1, 2], 'foo' => 'bar')
|
12
|
+
expect(rel.params[:filter]).to eq('uid.in' => [1, 2], 'foo' => 'bar')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'replaces empty array values with nil' do
|
16
|
+
rel = Her::Model::Relation.new(dummy_class).where('id.in' => [])
|
17
|
+
expect(rel.params[:filter]).to eq('id.in' => nil)
|
18
|
+
end
|
19
|
+
end
|
6
20
|
end
|
7
21
|
end
|
@@ -2,6 +2,28 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
module MnoEnterprise
|
4
4
|
RSpec.describe BaseResource, type: :model do
|
5
|
+
describe 'Error Handling' do
|
6
|
+
class Test < BaseResource; end
|
7
|
+
|
8
|
+
context 'Connection Errors' do
|
9
|
+
((502..504).to_a<<407).each do |code|
|
10
|
+
it "handles #{code} error" do
|
11
|
+
api_stub_for(get: "/tests/1", code: code)
|
12
|
+
expect { Test.find(1) }.to raise_error(Faraday::ConnectionFailed)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'Server Errors' do
|
18
|
+
[401, 500].each do |code|
|
19
|
+
it "handles #{code} error" do
|
20
|
+
api_stub_for(get: "/tests/1", code: code)
|
21
|
+
expect { Test.find(1) }.to raise_error(Faraday::Error::ClientError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
5
27
|
describe '#cache_key' do
|
6
28
|
context 'for existing record' do
|
7
29
|
let(:user) { build(:user) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mno-enterprise-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Lachaume
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -445,6 +445,7 @@ files:
|
|
445
445
|
- lib/generators/mno_enterprise/templates/scripts/upstart/app.conf
|
446
446
|
- lib/her_extension/her_orm_adapter.rb
|
447
447
|
- lib/her_extension/middleware/mnoe_api_v1_parse_json.rb
|
448
|
+
- lib/her_extension/middleware/mnoe_raise_error.rb
|
448
449
|
- lib/her_extension/model/associations/association.rb
|
449
450
|
- lib/her_extension/model/associations/association_proxy.rb
|
450
451
|
- lib/her_extension/model/associations/has_many_association.rb
|