hoodoo 2.12.0 → 2.12.2

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
  SHA256:
3
- metadata.gz: a6cfaed24695383d45ef45ee57241f89f37ef6005247c613014238c59b57f158
4
- data.tar.gz: 0547a5c355d815eaf6709f5023fa9878065f613d43c492fe781d87dbcb40b075
3
+ metadata.gz: 97098d14a63ca3169567bec32d623914a8e04389c0b26a1c513ccfcd3069e101
4
+ data.tar.gz: 0d673e879ca169f1dbcecd0d1c03bba5c8ec138f377abe99fc7aeccb3c39713d
5
5
  SHA512:
6
- metadata.gz: af7cd5e04e9ed36530627d80120a43a3f7e5569fda99969cf23c437edb98e509011cd00a83e720d67027bbfedd09a2b3cdc20cbcfcbd7b6d56dfb1a30152122a
7
- data.tar.gz: a4cc5ef27dfb5ae7d8f3c8ad555fd96101ca0ac6b864055d4b37534a276ffb47856da28c9b7eacbe6fb93b766b9285c164ae338d76ed268998c209dc5b2446a6
6
+ metadata.gz: a626927fcbd049c377698fe423550c78cd2feaf1225a54281e63dcc16cfa61093f7d03fbadfa01ef9739ca6987e6a1737fc0e29460a0734ee01536311479dd27
7
+ data.tar.gz: 056a00f6fb6e7d171a3228d20e931f27e4e95aad9c5813dc91999666e1472b2f379964d87edf34e40adb2bfcb0692bd33fa0db091a6244a25c35b57297abde1e
@@ -56,7 +56,22 @@ module Hoodoo
56
56
 
57
57
  # See Hoodoo::Client::Endpoint#show.
58
58
  #
59
+ # In RESTful HTTP, `GET /resources/#{ident = nil}` gets evaluated
60
+ # as `GET /resources/`, which is of course interpreted as a #list
61
+ # request. Since this is undesirable behaviour, the +ident+ must be
62
+ # populated, and this will return `404 Not Found` if it is not.
63
+ #
59
64
  def show( ident, query_hash = nil )
65
+ if ident.nil?
66
+ data = response_class_for( :show ).new
67
+ data.platform_errors.add_error(
68
+ 'platform.not_found',
69
+ 'reference' => {entity_name: 'nil identifier given on :show action'}
70
+ )
71
+
72
+ return data
73
+ end
74
+
60
75
  d = @description.dup
61
76
  d.action = :show
62
77
  d.ident = ident
@@ -747,6 +747,10 @@ module Hoodoo
747
747
  # Hoodoo::Presenters::Text
748
748
  # [:uuid]
749
749
  # Hoodoo::Presenters::UUID
750
+ # [:hash]
751
+ # Hoodoo::Presenters::Hash
752
+ # [:object]
753
+ # Hoodoo::Presenters::Object
750
754
  #
751
755
  def type_option_to_class( type )
752
756
  case type
@@ -776,6 +780,10 @@ module Hoodoo
776
780
  Hoodoo::Presenters::Text
777
781
  when :uuid
778
782
  Hoodoo::Presenters::UUID
783
+ when :object
784
+ Hoodoo::Presenters::Object
785
+ when :hash
786
+ Hoodoo::Presenters::Hash
779
787
  else
780
788
  raise "Unsupported 'type' option value of '#{ type }' in Hoodoo::Presenters::BaseDSL"
781
789
  end
@@ -58,9 +58,12 @@ module Hoodoo
58
58
  end
59
59
 
60
60
  @specific = true
61
- value_klass = block_given? ?
62
- Hoodoo::Presenters::Object :
63
- type_option_to_class( options.delete( :type ) )
61
+
62
+ # If an explicit type is given, use that. Otherwise, default to Field
63
+ # if no block is given, or Object is a block is given.
64
+ #
65
+ value_klass = !options[:type].blank? ? type_option_to_class( options.delete( :type ) ) :
66
+ (block_given? ? Hoodoo::Presenters::Object : Hoodoo::Presenters::Field)
64
67
 
65
68
  # If we're defining specific keys and some of those keys have fields
66
69
  # with defaults, we need to merge those up to provide a whole-Hash
@@ -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.12.0'
15
+ VERSION = '2.12.2'
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-12-17'
20
+ DATE = '2019-07-11'
21
21
 
22
22
  end
@@ -388,6 +388,14 @@ describe Hoodoo::Client do
388
388
  expect( result.platform_errors.has_errors? ).to eq( false )
389
389
  expect( result[ 'kind' ] ).to eq( 'Errors' )
390
390
  end
391
+
392
+ it 'returns a 404 for show(nil)', :wont_create_net_http do
393
+ result = @endpoint.show( nil )
394
+
395
+ expect( result.platform_errors.has_errors? ).to eq( true )
396
+ expect( result.platform_errors.errors[ 0 ][ 'code' ] ).to eq( 'platform.not_found' )
397
+ expect( result.platform_errors.errors[ 0 ][ 'reference' ] ).to eq( 'nil identifier given on :show action' )
398
+ end
391
399
  end
392
400
 
393
401
  before :each do
@@ -451,6 +459,11 @@ describe Hoodoo::Client do
451
459
  end
452
460
 
453
461
  context 'and with an HTTP proxy via custom discoverer' do
462
+ around :each do | example |
463
+ @example_wont_create_net_http = example.metadata[ :wont_create_net_http ]
464
+ example.run
465
+ end
466
+
454
467
  before :each do
455
468
  base_uri = "http://localhost:#{ @port }"
456
469
  proxy_uri = 'http://foo:bar@proxyhost:1234'
@@ -459,17 +472,19 @@ describe Hoodoo::Client do
459
472
  proxy_uri: proxy_uri
460
473
  )
461
474
 
462
- original_new = Net::HTTP.method( :new )
463
-
464
- expect( Net::HTTP ).to receive( :new ).at_least( :once ) do | host, port, proxy_host, proxy_port, proxy_user, proxy_pass |
465
- expect( host ).to eq( 'localhost' )
466
- expect( port ).to eq( @port )
467
- expect( proxy_host ).to eq( 'proxyhost' )
468
- expect( proxy_port ).to eq( 1234 )
469
- expect( proxy_user ).to eq( 'foo' )
470
- expect( proxy_pass ).to eq( 'bar' )
471
-
472
- original_new.call( host, port )
475
+ if @example_wont_create_net_http
476
+ expect( Net::HTTP ).not_to receive( :new )
477
+ else
478
+ expect( Net::HTTP ).to receive( :new ).at_least( :once ).and_wrap_original do | original_new, host, port, proxy_host, proxy_port, proxy_user, proxy_pass |
479
+ expect( host ).to eq( 'localhost' )
480
+ expect( port ).to eq( @port )
481
+ expect( proxy_host ).to eq( 'proxyhost' )
482
+ expect( proxy_port ).to eq( 1234 )
483
+ expect( proxy_user ).to eq( 'foo' )
484
+ expect( proxy_pass ).to eq( 'bar' )
485
+
486
+ original_new.call( host, port )
487
+ end
473
488
  end
474
489
 
475
490
  set_vars_for(
@@ -663,6 +663,94 @@ describe Hoodoo::Presenters::Hash do
663
663
 
664
664
  ############################################################################
665
665
 
666
+ class TestHashKeyWithHashType < Hoodoo::Presenters::Base
667
+ schema do
668
+ hash :key_with_hash_type do
669
+ key :specific_hash, :type => :hash do
670
+ key :optional_field, required: false
671
+ key :required_field, required: true
672
+ end
673
+ key :generic_hash, :type => :hash do
674
+ keys :length => 6
675
+ end
676
+ end
677
+ end
678
+ end
679
+
680
+
681
+ ############################################################################
682
+
683
+ context 'specific key with a hash as the type' do
684
+ context '#render' do
685
+ it 'renders required fields correctly' do
686
+ input_data = { 'key_with_hash_type' => {
687
+ 'specific_hash' => {'required_field' => 'foo'}
688
+ } }
689
+ expected_data = { 'key_with_hash_type' => {
690
+ 'specific_hash' => {'required_field' => 'foo'}
691
+ } }
692
+
693
+ expect( TestHashKeyWithHashType.render( input_data ) ).to eq( expected_data )
694
+ end
695
+
696
+ it 'renders optional fields correctly' do
697
+ input_data = { 'key_with_hash_type' => {
698
+ 'specific_hash' => {'required_field' => 'foo', 'optional_field' => 'bar'},
699
+ 'generic_hash' => {'foo' => 'bar', 'somekey' => 'somevalue'}
700
+ } }
701
+ expected_data = { 'key_with_hash_type' => {
702
+ 'specific_hash' => {'required_field' => 'foo', 'optional_field' => 'bar'},
703
+ 'generic_hash' => {'foo' => 'bar', 'somekey' => 'somevalue'}
704
+ } }
705
+
706
+ expect( TestHashKeyWithHashType.render( input_data ) ).to eq( expected_data )
707
+ end
708
+ end
709
+
710
+ context '#validate' do
711
+ it 'succeeds if the key is optional and absent' do
712
+ expect( TestHashKeyWithHashType.validate( {} ).errors.size ).to( eql( 0 ) )
713
+ end
714
+
715
+ it 'succeeds if the key is present and its specific required keys are present' do
716
+ input_data = { 'key_with_hash_type' => {
717
+ 'specific_hash' => {'required_field' => 'foo'}
718
+ } }
719
+ expect( TestHashKeyWithHashType.validate( input_data ).errors.size ).to( eql( 0 ) )
720
+ end
721
+
722
+ it 'succeeds if the key is present and its specific required and optional keys are present' do
723
+ input_data = { 'key_with_hash_type' => {
724
+ 'specific_hash' => {'required_field' => 'foo', 'optional_field' => 'bar'}
725
+ } }
726
+ expect( TestHashKeyWithHashType.validate( input_data ).errors.size ).to( eql( 0 ) )
727
+ end
728
+
729
+ it 'fails if the key is present and its specific required keys are missing' do
730
+ input_data = { 'key_with_hash_type' => {
731
+ 'specific_hash' => {'optional_field' => 'bar'}
732
+ } }
733
+ expect( TestHashKeyWithHashType.validate( input_data ).errors.size ).to( eql( 1 ) )
734
+ end
735
+
736
+ it 'succeeds if the key is present and its generic keys are valid' do
737
+ input_data = { 'key_with_hash_type' => {
738
+ 'generic_hash' => {'foo' => 'bar'}
739
+ } }
740
+ expect( TestHashKeyWithHashType.validate( input_data ).errors.size ).to( eql( 0 ) )
741
+ end
742
+
743
+ it 'fails if the key is present and its generic keys are invalid' do
744
+ input_data = { 'key_with_hash_type' => {
745
+ 'generic_hash' => {'keynametoolong' => 'bar'}
746
+ } }
747
+ expect( TestHashKeyWithHashType.validate( input_data ).errors.size ).to( eql( 1 ) )
748
+ end
749
+ end
750
+ end
751
+
752
+ ############################################################################
753
+
666
754
  class TestHashGenericKeyPresenterNoValues < Hoodoo::Presenters::Base
667
755
  schema do
668
756
  hash :generic do
@@ -678,11 +678,11 @@ describe Hoodoo::Utilities do
678
678
  it 'rejects invalid input with an exception' do
679
679
  expect {
680
680
  Hoodoo::Utilities.rationalise_datetime( "hello" )
681
- }.to raise_exception
681
+ }.to raise_exception( /Invalid parameter 'hello'/ )
682
682
 
683
683
  expect {
684
684
  Hoodoo::Utilities.rationalise_datetime( Array.new )
685
- }.to raise_exception
685
+ }.to raise_exception( /Invalid parameter '\[\]'/ )
686
686
  end
687
687
  end
688
688
  end
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.12.0
4
+ version: 2.12.2
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-12-17 00:00:00.000000000 Z
11
+ date: 2019-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack