mno-enterprise-core 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- 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: 2db1615a4972df4d796099d38b3e492585349bb6
|
4
|
+
data.tar.gz: cd2d825dc1e24d86fea3b5cde5af1be440341c53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b7605252044117c2c99749f54cf4c8d198063b371ec010a78a45d32b5d89483dca8e540ccb4dadb0f2690e754448ef11c5b9a41e520f16e76b10cfd6db158d3
|
7
|
+
data.tar.gz: aabb872ecfe84d47f813ae1f363cfaa8c1009336268fa028e61068bdb59f6a6abd4fbc80af932caf68828e0377a1a686b3cca4abeba9bbc589b79a79b9f88184
|
@@ -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
|
|
@@ -266,6 +267,9 @@ module MnoEnterprise
|
|
266
267
|
|
267
268
|
# Adapter
|
268
269
|
c.use Faraday::Adapter::NetHttpNoProxy
|
270
|
+
|
271
|
+
# Error Handling
|
272
|
+
c.use Her::Middleware::MnoeRaiseError
|
269
273
|
end
|
270
274
|
end
|
271
275
|
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: 2.0.
|
4
|
+
version: 2.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
|
@@ -313,6 +313,7 @@ files:
|
|
313
313
|
- lib/generators/mno_enterprise/templates/scripts/upstart/app.conf
|
314
314
|
- lib/her_extension/her_orm_adapter.rb
|
315
315
|
- lib/her_extension/middleware/mnoe_api_v1_parse_json.rb
|
316
|
+
- lib/her_extension/middleware/mnoe_raise_error.rb
|
316
317
|
- lib/her_extension/model/associations/association.rb
|
317
318
|
- lib/her_extension/model/associations/association_proxy.rb
|
318
319
|
- lib/her_extension/model/associations/has_many_association.rb
|