diff --git a/lib/parliament/grom/decorator/business_item.rb b/lib/parliament/grom/decorator/business_item.rb index 231fe47..a0e71cf 100644 --- a/lib/parliament/grom/decorator/business_item.rb +++ b/lib/parliament/grom/decorator/business_item.rb @@ -21,6 +21,17 @@ def procedure_step def date respond_to?(:businessItemDate) ? DateTime.parse(businessItemDate) : nil end + + # Alias businessItemHasWorkPackage with fallback. + # + # @return [Grom::Node, nil] the WorkPackage of the Grom::Node or nil. + def work_package + return @work_package if @work_package + + return nil unless respond_to?(:businessItemHasWorkPackage) + + @work_package = Helpers::Utils.type_safe_first(businessItemHasWorkPackage, Parliament::Grom::Decorator::WorkPackage) + end end end end diff --git a/lib/parliament/grom/decorator/version.rb b/lib/parliament/grom/decorator/version.rb index ac4fadf..3ae0e5f 100644 --- a/lib/parliament/grom/decorator/version.rb +++ b/lib/parliament/grom/decorator/version.rb @@ -1,7 +1,7 @@ module Parliament module Grom module Decorator - VERSION = '1.0.2'.freeze + VERSION = '1.0.3'.freeze end end end diff --git a/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_does_not_have_businessItemHasWorkPackage/returns_nil.yml b/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_does_not_have_businessItemHasWorkPackage/returns_nil.yml new file mode 100644 index 0000000..789033e --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_does_not_have_businessItemHasWorkPackage/returns_nil.yml @@ -0,0 +1,54 @@ +--- +http_interactions: +- request: + method: get + uri: http://localhost:3030/api/v1/statutory_instrument_by_id + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + - application/n-triples + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/n-triples + Content-Disposition: + - inline; filename="index" + Last-Modified: + - Fri, 19 Oct 2018 08:46:40 GMT + X-Content-Type-Options: + - nosniff + Content-Length: + - '622483' + body: + encoding: UTF-8 + string: | + . + . + "2018"^^ . + "SI" . + "509"^^ . + "First-tier Tribunal and Upper Tribunal (Chambers) (Amendment) Order 2018" . + . + . + "2018-04-23+01:00"^^ . + . + . + . + "Ministry of Justice" . + . + . + . + "Made negative" . + http_version: + recorded_at: Fri, 19 Oct 2018 09:00:09 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_has_businessItemHasWorkPackage/where_it_is_an_enumerable/where_the_first_item_is_a_Parliament_Grom_Decorator_WorkPackage_object/returns_the_Parliament_Grom_Decorator_WorkPackage_object.yml b/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_has_businessItemHasWorkPackage/where_it_is_an_enumerable/where_the_first_item_is_a_Parliament_Grom_Decorator_WorkPackage_object/returns_the_Parliament_Grom_Decorator_WorkPackage_object.yml new file mode 100644 index 0000000..a742004 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_has_businessItemHasWorkPackage/where_it_is_an_enumerable/where_the_first_item_is_a_Parliament_Grom_Decorator_WorkPackage_object/returns_the_Parliament_Grom_Decorator_WorkPackage_object.yml @@ -0,0 +1,55 @@ +--- +http_interactions: +- request: + method: get + uri: http://localhost:3030/api/v1/statutory_instrument_by_id + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + - application/n-triples + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/n-triples + Content-Disposition: + - inline; filename="index" + Last-Modified: + - Fri, 19 Oct 2018 08:46:40 GMT + X-Content-Type-Options: + - nosniff + Content-Length: + - '622483' + body: + encoding: UTF-8 + string: | + . + . + "2018"^^ . + "SI" . + "509"^^ . + "First-tier Tribunal and Upper Tribunal (Chambers) (Amendment) Order 2018" . + . + . + "2018-04-23+01:00"^^ . + . + . + . + . + "Ministry of Justice" . + . + . + . + "Made negative" . + http_version: + recorded_at: Fri, 19 Oct 2018 09:00:09 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_has_businessItemHasWorkPackage/where_it_is_an_enumerable/where_the_first_item_is_not_a_Parliament_Grom_Decorator_WorkPackage_object/returns_nil.yml b/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_has_businessItemHasWorkPackage/where_it_is_an_enumerable/where_the_first_item_is_not_a_Parliament_Grom_Decorator_WorkPackage_object/returns_nil.yml new file mode 100644 index 0000000..744fd9b --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_has_businessItemHasWorkPackage/where_it_is_an_enumerable/where_the_first_item_is_not_a_Parliament_Grom_Decorator_WorkPackage_object/returns_nil.yml @@ -0,0 +1,55 @@ +--- +http_interactions: +- request: + method: get + uri: http://localhost:3030/api/v1/statutory_instrument_by_id + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + - application/n-triples + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/n-triples + Content-Disposition: + - inline; filename="index" + Last-Modified: + - Fri, 19 Oct 2018 08:46:40 GMT + X-Content-Type-Options: + - nosniff + Content-Length: + - '622483' + body: + encoding: UTF-8 + string: | + . + . + "2018"^^ . + "SI" . + "509"^^ . + "First-tier Tribunal and Upper Tribunal (Chambers) (Amendment) Order 2018" . + . + . + "2018-04-23+01:00"^^ . + . + . + . + . + "Ministry of Justice" . + . + . + . + "Made negative" . + http_version: + recorded_at: Fri, 19 Oct 2018 09:00:09 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_has_businessItemHasWorkPackage/where_it_is_not_an_enumerable/returns_nil.yml b/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_has_businessItemHasWorkPackage/where_it_is_not_an_enumerable/returns_nil.yml new file mode 100644 index 0000000..40fbfbb --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/node_has_businessItemHasWorkPackage/where_it_is_not_an_enumerable/returns_nil.yml @@ -0,0 +1,53 @@ +--- +http_interactions: +- request: + method: get + uri: http://localhost:3030/api/v1/statutory_instrument_by_id + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + - application/n-triples + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/n-triples + Content-Disposition: + - inline; filename="index" + Last-Modified: + - Fri, 19 Oct 2018 08:46:40 GMT + X-Content-Type-Options: + - nosniff + Content-Length: + - '622483' + body: + encoding: UTF-8 + string: | + . + . + "2018"^^ . + "SI" . + "509"^^ . + "First-tier Tribunal and Upper Tribunal (Chambers) (Amendment) Order 2018" . + . + . + "2018-04-23+01:00"^^ . + . + . + . + . + "Ministry of Justice" . + . + "Made negative" . + http_version: + recorded_at: Fri, 19 Oct 2018 09:00:09 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/when_calling_work_package_twice/the_logic_is_only_called_once.yml b/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/when_calling_work_package_twice/the_logic_is_only_called_once.yml new file mode 100644 index 0000000..a742004 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Parliament_Grom_Decorator_BusinessItem/_work_package/when_calling_work_package_twice/the_logic_is_only_called_once.yml @@ -0,0 +1,55 @@ +--- +http_interactions: +- request: + method: get + uri: http://localhost:3030/api/v1/statutory_instrument_by_id + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + - application/n-triples + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/n-triples + Content-Disposition: + - inline; filename="index" + Last-Modified: + - Fri, 19 Oct 2018 08:46:40 GMT + X-Content-Type-Options: + - nosniff + Content-Length: + - '622483' + body: + encoding: UTF-8 + string: | + . + . + "2018"^^ . + "SI" . + "509"^^ . + "First-tier Tribunal and Upper Tribunal (Chambers) (Amendment) Order 2018" . + . + . + "2018-04-23+01:00"^^ . + . + . + . + . + "Ministry of Justice" . + . + . + . + "Made negative" . + http_version: + recorded_at: Fri, 19 Oct 2018 09:00:09 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/parliament/grom/decorator/business_item_spec.rb b/spec/parliament/grom/decorator/business_item_spec.rb index b484c8a..91b17bf 100644 --- a/spec/parliament/grom/decorator/business_item_spec.rb +++ b/spec/parliament/grom/decorator/business_item_spec.rb @@ -15,8 +15,8 @@ # Test #procedure_step include_examples( - 'type_safe_first', - { + 'type_safe_first', + { request: request_object, filter_type: 'https://id.parliament.uk/schema/BusinessItem', predicate: :businessItemHasProcedureStep, @@ -24,6 +24,17 @@ type_klass: Parliament::Grom::Decorator::ProcedureStep } ) + # Test #work_package + include_examples( + 'type_safe_first', + { + request: request_object, + filter_type: 'https://id.parliament.uk/schema/BusinessItem', + predicate: :businessItemHasWorkPackage, + decorator_method: :work_package, + type_klass: Parliament::Grom::Decorator::WorkPackage + } + ) describe '#date' do context 'Grom::Node has a date' do diff --git a/spec/parliament/grom/decorator/laid_thing_spec.rb b/spec/parliament/grom/decorator/laid_thing_spec.rb index b2d0899..51e0067 100644 --- a/spec/parliament/grom/decorator/laid_thing_spec.rb +++ b/spec/parliament/grom/decorator/laid_thing_spec.rb @@ -7,7 +7,7 @@ decorators: Parliament::Grom::Decorator ).statutory_instrument_by_id - # Test #body + # Test #laying include_examples( 'type_safe_first', {