diff --git a/CHANGELOG.md b/CHANGELOG.md index 049f4dd..08e7250 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Turn `Delivery#address` into a separate `Zaikio::Procurement::Address` object. This + change is breaking if you previously depended on this property being a Hash. + ## [0.3.1] - 2021-10-28 -- **Breaking change for Supplier API**: When operating on `Article` or `Variant` one must provide scope - of `substrate` or `plate`. Calling `all` or `find` without scope will raise an `ArgumentError` +- **Breaking change for Supplier API**: When operating on `Article` or `Variant` one must provide scope + of `substrate` or `plate`. Calling `all` or `find` without scope will raise an `ArgumentError` ## [0.2.2] - 2021-10-25 diff --git a/lib/zaikio/procurement.rb b/lib/zaikio/procurement.rb index 0ab83fa..0bd5c7f 100644 --- a/lib/zaikio/procurement.rb +++ b/lib/zaikio/procurement.rb @@ -6,6 +6,7 @@ # Models require "zaikio/procurement/base" +require "zaikio/procurement/address" require "zaikio/procurement/article" require "zaikio/procurement/variant" require "zaikio/procurement/substrate_search" diff --git a/lib/zaikio/procurement/address.rb b/lib/zaikio/procurement/address.rb new file mode 100644 index 0000000..d93d6d4 --- /dev/null +++ b/lib/zaikio/procurement/address.rb @@ -0,0 +1,22 @@ +module Zaikio + module Procurement + class Address < Base + attributes :addition, + :addressable, + :addressee, + :country_code, + :county, + :kind, + :location, + :number, + :state, + :street, + :text, + :town, + :types, + :zip_code, + :created_at, + :updated_at + end + end +end diff --git a/lib/zaikio/procurement/delivery.rb b/lib/zaikio/procurement/delivery.rb index 87cb6ce..ec00ba8 100644 --- a/lib/zaikio/procurement/delivery.rb +++ b/lib/zaikio/procurement/delivery.rb @@ -6,11 +6,12 @@ class Delivery < Base # Attributes attributes :confirmed_delivery_date, :desired_delivery_date, :references, - :address, :order_id, :created_at, :updated_at + :order_id, :created_at, :updated_at # Associations - belongs_to :order, class_name: "Zaikio::Procurement::Order", - uri: nil + belongs_to :address, class_name: "Zaikio::Procurement::Address", uri: nil + belongs_to :order, class_name: "Zaikio::Procurement::Order", uri: nil + has_many :delivery_line_items, class_name: "Zaikio::Procurement::DeliveryLineItem", uri: "deliveries/:delivery_id/delivery_line_items(/:id)" end diff --git a/test/zaikio/procurement_consumer_test.rb b/test/zaikio/procurement_consumer_test.rb index 81002cc..61090c5 100644 --- a/test/zaikio/procurement_consumer_test.rb +++ b/test/zaikio/procurement_consumer_test.rb @@ -376,11 +376,12 @@ def token end end - test "fetching a specific delivery" do + test "fetching a specific delivery and address" do VCR.use_cassette("delivery") do Zaikio::Procurement.with_token(token) do delivery = Zaikio::Procurement::Delivery.find("46a67d80-ff21-403a-9cb3-5b3a9464ae0f") assert_equal "46a67d80-ff21-403a-9cb3-5b3a9464ae0f", delivery.id + assert_equal "John Doe", delivery.address.addressee end end end