hoodoo 2.3.0 → 2.4.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 +4 -4
- data/lib/hoodoo/monkey/patch/datadog_traced_amqp.rb +1 -0
- data/lib/hoodoo/presenters/base.rb +1 -1
- data/lib/hoodoo/services/middleware/middleware.rb +2 -2
- data/lib/hoodoo/version.rb +2 -2
- data/spec/presenters/base_spec.rb +18 -0
- data/spec/services/middleware/middleware_spec.rb +139 -13
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28c5549a689e0e841a9c435f0c6a5bfe502f4b592b4bdcec929d0680818e5d3c
|
4
|
+
data.tar.gz: c41b08c154c94b959c674b4c5acf3da3e9174b83fd3ab7b210adcc51aeaa8991
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 271dbaf036afd87732ff3f702fc82b0a1e8abc334531f9b62f2bac266f9b258b65e8fe42c8bc865a70f39e6624e7e15611ed17ca158cc8b59ecd4ef501a8a77a
|
7
|
+
data.tar.gz: f3355e88dabae561eaf7ef72adccb57606f33df0f2593e0ef0963aa7c85c3526831bdc95012bf6a4f0954bd1e9d5fed9f89d0c6aaca69447afffc75df1d1f237
|
@@ -48,6 +48,7 @@ module Hoodoo
|
|
48
48
|
span.span_type = 'alchemy'
|
49
49
|
span.resource = http_message[ 'verb' ]
|
50
50
|
span.set_tag( 'target.path', http_message[ 'path'] )
|
51
|
+
span.set_tag( 'interaction.id', http_message[ 'headers' ][ 'X-Interaction-ID' ] )
|
51
52
|
|
52
53
|
# Add Datadog trace IDs to the HTTP message. For compatibility
|
53
54
|
# with Hoodoo V1 services using a fork of DDTrace, we send both
|
@@ -202,7 +202,7 @@ module Hoodoo
|
|
202
202
|
|
203
203
|
target = self.render( data, uuid, created_at, language, created_by )
|
204
204
|
|
205
|
-
if secured_with.is_a?( ::ActiveRecord::Base )
|
205
|
+
if defined?( ::ActiveRecord ) && secured_with.is_a?( ::ActiveRecord::Base )
|
206
206
|
result_hash = {}
|
207
207
|
extra_scope_map = secured_with.class.secured_with()
|
208
208
|
|
@@ -538,12 +538,12 @@ module Hoodoo; module Services
|
|
538
538
|
# everything else.
|
539
539
|
#
|
540
540
|
custom_path = "/v#{ interface.version }/#{ interface.endpoint }"
|
541
|
-
custom_regexp =
|
541
|
+
custom_regexp = /^\/v#{ interface.version }\/#{ interface.endpoint }(\.|\/|$)(.*)/
|
542
542
|
|
543
543
|
# Same as above, but for the de facto routing.
|
544
544
|
#
|
545
545
|
de_facto_path = self.class.de_facto_path_for( interface.resource, interface.version )
|
546
|
-
de_facto_regexp =
|
546
|
+
de_facto_regexp = /^\/#{ interface.version }\/#{ interface.resource }(\.|\/|$)(.*)/
|
547
547
|
|
548
548
|
Hoodoo::Services::Discovery::ForLocal.new(
|
549
549
|
:resource => interface.resource,
|
data/lib/hoodoo/version.rb
CHANGED
@@ -12,11 +12,11 @@ module Hoodoo
|
|
12
12
|
# The Hoodoo gem version. If this changes, be sure to re-run
|
13
13
|
# <tt>bundle install</tt> or <tt>bundle update</tt>.
|
14
14
|
#
|
15
|
-
VERSION = '2.
|
15
|
+
VERSION = '2.4.0'
|
16
16
|
|
17
17
|
# The Hoodoo gem date. If this changes, be sure to re-run
|
18
18
|
# <tt>bundle install</tt> or <tt>bundle update</tt>.
|
19
19
|
#
|
20
|
-
DATE = '2018-
|
20
|
+
DATE = '2018-03-21'
|
21
21
|
|
22
22
|
end
|
@@ -931,6 +931,24 @@ describe '#schema' do
|
|
931
931
|
})
|
932
932
|
end
|
933
933
|
|
934
|
+
context 'without ActiveRecord' do
|
935
|
+
before :each do
|
936
|
+
@old_ar = ::ActiveRecord
|
937
|
+
Object.send( :remove_const, :ActiveRecord )
|
938
|
+
end
|
939
|
+
|
940
|
+
after :each do
|
941
|
+
Object.send( :const_set, :ActiveRecord, @old_ar )
|
942
|
+
end
|
943
|
+
|
944
|
+
it 'renders' do
|
945
|
+
data = {}
|
946
|
+
expect(TestPresenter5.render_in(@con, data)).to eq({
|
947
|
+
'three' => 'default_three'
|
948
|
+
})
|
949
|
+
end
|
950
|
+
end
|
951
|
+
|
934
952
|
# The "secured_with" option is tested in "secure_spec.rb" as lots of
|
935
953
|
# tricky related setup is done there that would only end up being
|
936
954
|
# coped in here otherwise.
|
@@ -1717,7 +1717,7 @@ class RSpecTestServiceAltStubImplementation < Hoodoo::Services::Implementation
|
|
1717
1717
|
end
|
1718
1718
|
|
1719
1719
|
class RSpecTestServiceAltStubInterface < Hoodoo::Services::Interface
|
1720
|
-
interface :
|
1720
|
+
interface :RSpecTestResourceAlt do
|
1721
1721
|
version 2
|
1722
1722
|
endpoint :rspec_test_service_alt_stub, RSpecTestServiceAltStubImplementation
|
1723
1723
|
end
|
@@ -1744,22 +1744,148 @@ describe Hoodoo::Services::Middleware do
|
|
1744
1744
|
expect(last_response.status).to eq(404)
|
1745
1745
|
end
|
1746
1746
|
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1747
|
+
context 'should route to the V1 endpoint' do
|
1748
|
+
before :each do
|
1749
|
+
expect_any_instance_of(RSpecTestServiceV1StubImplementation).to receive(:list)
|
1750
|
+
end
|
1751
|
+
|
1752
|
+
after :each do
|
1753
|
+
expect(last_response.status).to eq(200)
|
1754
|
+
end
|
1755
|
+
|
1756
|
+
it 'with custom route and no trailing slash' do
|
1757
|
+
get '/v1/rspec_test_service_stub', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1758
|
+
end
|
1759
|
+
|
1760
|
+
it 'with custom route and trailing slash' do
|
1761
|
+
get '/v1/rspec_test_service_stub/', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1762
|
+
end
|
1763
|
+
|
1764
|
+
it 'with de facto route and no trailing slash' do
|
1765
|
+
get '/1/RSpecTestResource', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1766
|
+
end
|
1767
|
+
|
1768
|
+
it 'with de facto route and trailing slash' do
|
1769
|
+
get '/1/RSpecTestResource/', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1770
|
+
end
|
1751
1771
|
end
|
1752
1772
|
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1773
|
+
context 'should route to the V2 endpoint' do
|
1774
|
+
before :each do
|
1775
|
+
expect_any_instance_of(RSpecTestServiceStubImplementation).to receive(:list)
|
1776
|
+
end
|
1777
|
+
|
1778
|
+
after :each do
|
1779
|
+
expect(last_response.status).to eq(200)
|
1780
|
+
end
|
1781
|
+
|
1782
|
+
it 'with custom route and no trailing slash' do
|
1783
|
+
get '/v2/rspec_test_service_stub', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1784
|
+
end
|
1785
|
+
|
1786
|
+
it 'with custom route and trailing slash' do
|
1787
|
+
get '/v2/rspec_test_service_stub/', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1788
|
+
end
|
1789
|
+
|
1790
|
+
it 'with de facto route and no trailing slash' do
|
1791
|
+
get '/2/RSpecTestResource', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1792
|
+
end
|
1793
|
+
|
1794
|
+
it 'with de facto route and trailing slash' do
|
1795
|
+
get '/2/RSpecTestResource/', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1796
|
+
end
|
1757
1797
|
end
|
1758
1798
|
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1799
|
+
context 'should route to the V2 alternative endpoint' do
|
1800
|
+
before :each do
|
1801
|
+
expect_any_instance_of(RSpecTestServiceAltStubImplementation).to receive(:list)
|
1802
|
+
end
|
1803
|
+
|
1804
|
+
it 'with custom route and no trailing slash' do
|
1805
|
+
get '/v2/rspec_test_service_alt_stub', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1806
|
+
end
|
1807
|
+
|
1808
|
+
it 'with custom route and trailing slash' do
|
1809
|
+
get '/v2/rspec_test_service_alt_stub/', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1810
|
+
end
|
1811
|
+
|
1812
|
+
it 'with de facto route and no trailing slash' do
|
1813
|
+
get '/2/RSpecTestResourceAlt', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1814
|
+
end
|
1815
|
+
|
1816
|
+
it 'with de facto route and trailing slash' do
|
1817
|
+
get '/2/RSpecTestResourceAlt/', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1818
|
+
end
|
1819
|
+
end
|
1820
|
+
|
1821
|
+
context 'with trailing route matches' do
|
1822
|
+
context 'should not mis-match' do
|
1823
|
+
it 'custom routes with a junk lead-in' do
|
1824
|
+
expect_any_instance_of(RSpecTestServiceV1StubImplementation).to_not receive(:list)
|
1825
|
+
get '/v1/junk/v1/rspec_test_service_stub/', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1826
|
+
expect(last_response.status).to eq(404)
|
1827
|
+
end
|
1828
|
+
|
1829
|
+
it 'custom routes with a resource match lead-in' do
|
1830
|
+
expect_any_instance_of(RSpecTestServiceAltStubImplementation).to receive(:show)
|
1831
|
+
get '/v2/rspec_test_service_alt_stub/v1/rspec_test_service_stub/', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1832
|
+
expect(last_response.status).to eq(200)
|
1833
|
+
end
|
1834
|
+
|
1835
|
+
it 'de facto routes with a junk lead-in' do
|
1836
|
+
expect_any_instance_of(RSpecTestServiceV1StubImplementation).to_not receive(:list)
|
1837
|
+
get '/1/Junk/1/RSpecTestResource/', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1838
|
+
expect(last_response.status).to eq(404)
|
1839
|
+
end
|
1840
|
+
|
1841
|
+
it 'de facto routes with a resource match lead-in' do
|
1842
|
+
expect_any_instance_of(RSpecTestServiceAltStubImplementation).to receive(:show)
|
1843
|
+
get '/2/RSpecTestResourceAlt/1/RSpecTestResource/', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1844
|
+
expect(last_response.status).to eq(200)
|
1845
|
+
end
|
1846
|
+
end
|
1847
|
+
|
1848
|
+
context 'should pass the remainder as the "ident"' do
|
1849
|
+
after :each do
|
1850
|
+
expect(last_response.status).to eq(200)
|
1851
|
+
end
|
1852
|
+
|
1853
|
+
it 'on custom routes' do
|
1854
|
+
expect_any_instance_of(RSpecTestServiceV1StubImplementation).to receive(:update) do | instance, context |
|
1855
|
+
expect(context.request.ident).to eq('v2')
|
1856
|
+
expect(context.request.uri_path_components).to eq(['v2', 'rspec_test_service_alt_stub'])
|
1857
|
+
end
|
1858
|
+
|
1859
|
+
patch '/v1/rspec_test_service_stub/v2/rspec_test_service_alt_stub', '{}', { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1860
|
+
end
|
1861
|
+
|
1862
|
+
it 'on de facto routes' do
|
1863
|
+
expect_any_instance_of(RSpecTestServiceV1StubImplementation).to receive(:update) do | instance, context |
|
1864
|
+
expect(context.request.ident).to eq('2')
|
1865
|
+
expect(context.request.uri_path_components).to eq(['2', 'RSpecTestResourceAlt'])
|
1866
|
+
end
|
1867
|
+
|
1868
|
+
patch '/1/RSpecTestResource/2/RSpecTestResourceAlt', '{}', { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1869
|
+
end
|
1870
|
+
|
1871
|
+
it 'on mixed routes (1)' do
|
1872
|
+
expect_any_instance_of(RSpecTestServiceV1StubImplementation).to receive(:update) do | instance, context |
|
1873
|
+
expect(context.request.ident).to eq('v2')
|
1874
|
+
expect(context.request.uri_path_components).to eq(['v2', 'rspec_test_service_alt_stub'])
|
1875
|
+
end
|
1876
|
+
|
1877
|
+
patch '/1/RSpecTestResource/v2/rspec_test_service_alt_stub', '{}', { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1878
|
+
end
|
1879
|
+
|
1880
|
+
it 'on mixed routes (2)' do
|
1881
|
+
expect_any_instance_of(RSpecTestServiceV1StubImplementation).to receive(:update) do | instance, context |
|
1882
|
+
expect(context.request.ident).to eq('2')
|
1883
|
+
expect(context.request.uri_path_components).to eq(['2', 'RSpecTestResourceAlt'])
|
1884
|
+
end
|
1885
|
+
|
1886
|
+
patch '/v1/rspec_test_service_stub/2/RSpecTestResourceAlt', '{}', { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
1887
|
+
end
|
1888
|
+
end
|
1763
1889
|
end
|
1764
1890
|
end
|
1765
1891
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoodoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loyalty New Zealand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dalli
|
@@ -184,14 +184,14 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: '0
|
187
|
+
version: '1.0'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: '0
|
194
|
+
version: '1.0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: byebug
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|