diff --git a/CHANGELOG.md b/CHANGELOG.md index 363cca8..bef2943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.2.5] - 2020-01-08 + +### Fixed + +- Fixes [issues/5](https://github.com/patch-technology/patch-ruby/issues/5). Adds method `.openapi_nullable` which returns a set with all nullable properties. This method is referenced in `#to_hash` which returns a hash representation of the resource. +- Removes non-deterministic integration spec that is creating an Estimate with a specific project-id. Since we do not control the test data (yet) and make queries against our Test projects, we cannot be sure that we will have offsets available for a project ID. Instead we can rely on Patch core specs to cover this. +- Fixes a spec that was failing due to a Patch core change. +- Add spec factories and refactor generated method specs to shared examples. + ## [1.2.4] - 2020-10-14 ### Added diff --git a/Gemfile b/Gemfile index b572ad0..76018c7 100644 --- a/Gemfile +++ b/Gemfile @@ -6,4 +6,5 @@ group :development, :test do gem 'rake', '~> 13.0.1' gem 'pry-byebug' gem 'rubocop' + gem 'factory_bot' end diff --git a/Gemfile.lock b/Gemfile.lock index 725b6e9..60f45a5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,22 +1,34 @@ PATH remote: . specs: - patch_ruby (1.2.4) + patch_ruby (1.2.5) json (~> 2.1, >= 2.1.0) typhoeus (~> 1.0, >= 1.0.1) GEM remote: https://rubygems.org/ specs: + activesupport (6.1.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) ast (2.4.1) byebug (11.1.3) coderay (1.1.3) + concurrent-ruby (1.1.7) diff-lcs (1.4.3) ethon (0.12.0) ffi (>= 1.3.0) + factory_bot (6.1.0) + activesupport (>= 5.0.0) ffi (1.13.1) - json (2.3.1) + i18n (1.8.7) + concurrent-ruby (~> 1.0) + json (2.4.1) method_source (1.0.0) + minitest (5.14.3) parallel (1.19.2) parser (2.7.1.4) ast (~> 2.4.1) @@ -57,12 +69,16 @@ GEM ruby-progressbar (1.10.1) typhoeus (1.4.0) ethon (>= 0.9.0) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) unicode-display_width (1.7.0) + zeitwerk (2.4.2) PLATFORMS ruby DEPENDENCIES + factory_bot patch_ruby! pry-byebug rake (~> 13.0.1) diff --git a/lib/patch_ruby/models/allocation.rb b/lib/patch_ruby/models/allocation.rb index 78da294..47d40b8 100644 --- a/lib/patch_ruby/models/allocation.rb +++ b/lib/patch_ruby/models/allocation.rb @@ -14,10 +14,13 @@ module Patch class Allocation + # A unique uid for the record. UIDs will be prepended by all_prod or all_test depending on the mode it was created in. attr_accessor :id + # A boolean indicating if this project is a production or test mode project. attr_accessor :production + # The amount (in grams) of allocated carbon offsets. attr_accessor :mass_g # Attribute mapping from ruby-style variable name to JSON key. @@ -38,6 +41,13 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/create_mass_estimate_request.rb b/lib/patch_ruby/models/create_mass_estimate_request.rb index 7c831aa..b101134 100644 --- a/lib/patch_ruby/models/create_mass_estimate_request.rb +++ b/lib/patch_ruby/models/create_mass_estimate_request.rb @@ -34,6 +34,13 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/create_order_request.rb b/lib/patch_ruby/models/create_order_request.rb index 45a1c79..ed3eff5 100644 --- a/lib/patch_ruby/models/create_order_request.rb +++ b/lib/patch_ruby/models/create_order_request.rb @@ -42,6 +42,13 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/create_preference_request.rb b/lib/patch_ruby/models/create_preference_request.rb index 01c6920..d069ac7 100644 --- a/lib/patch_ruby/models/create_preference_request.rb +++ b/lib/patch_ruby/models/create_preference_request.rb @@ -30,6 +30,13 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/error_response.rb b/lib/patch_ruby/models/error_response.rb index e9f70c8..dd0ff95 100644 --- a/lib/patch_ruby/models/error_response.rb +++ b/lib/patch_ruby/models/error_response.rb @@ -38,6 +38,15 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("data") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/estimate.rb b/lib/patch_ruby/models/estimate.rb index eaf55bc..aebe3fa 100644 --- a/lib/patch_ruby/models/estimate.rb +++ b/lib/patch_ruby/models/estimate.rb @@ -14,12 +14,16 @@ module Patch class Estimate + # A unique uid for the record. UIDs will be prepended by est_prod or est_test depending on the mode it was created in. attr_accessor :id + # A boolean indicating if this estimate is a production or test mode estimate. attr_accessor :production + # The type of estimate. Currently mass is the only supported value. attr_accessor :type + # An object returning the order associated with this estimate. See the [Order section](/?id=orders) for the full schema. attr_accessor :order # Attribute mapping from ruby-style variable name to JSON key. @@ -42,6 +46,15 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("order") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order @@ -226,7 +239,7 @@ def to_hash is_nullable = self.class.openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end - + hash[param] = _to_hash(value) end hash diff --git a/lib/patch_ruby/models/estimate_list_response.rb b/lib/patch_ruby/models/estimate_list_response.rb index 6866d42..8762d98 100644 --- a/lib/patch_ruby/models/estimate_list_response.rb +++ b/lib/patch_ruby/models/estimate_list_response.rb @@ -42,6 +42,15 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("error") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/estimate_response.rb b/lib/patch_ruby/models/estimate_response.rb index aaed5d1..bc36f5f 100644 --- a/lib/patch_ruby/models/estimate_response.rb +++ b/lib/patch_ruby/models/estimate_response.rb @@ -38,6 +38,15 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("error") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/meta_index_object.rb b/lib/patch_ruby/models/meta_index_object.rb index fe2cc06..5eac744 100644 --- a/lib/patch_ruby/models/meta_index_object.rb +++ b/lib/patch_ruby/models/meta_index_object.rb @@ -34,6 +34,17 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("prev_page") + + nullable_properties.add("next_page") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/order.rb b/lib/patch_ruby/models/order.rb index 55b5bb1..5418e41 100644 --- a/lib/patch_ruby/models/order.rb +++ b/lib/patch_ruby/models/order.rb @@ -14,22 +14,31 @@ module Patch class Order + # A unique uid for the record. UIDs will be prepended by ord_prod or ord_test depending on the mode it was created in. attr_accessor :id + # The amount of carbon offsets in grams purchased through this order. attr_accessor :mass_g + # A boolean indicating if this order is a production or test mode order. attr_accessor :production + # The current state of the order. attr_accessor :state + # The current state of the allocated carbon offsets of the order. attr_accessor :allocation_state + # The total price in cents USD of the carbon offsets purchased through this order. attr_accessor :price_cents_usd + # The Patch Fee in cents USD for this order. attr_accessor :patch_fee_cents_usd + # An array containing the inventory allocations for this order. attr_accessor :allocations + # An optional JSON object containing metadata for this order. attr_accessor :metadata class EnumAttributeValidator @@ -84,6 +93,17 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("price_cents_usd") + + nullable_properties.add("patch_fee_cents_usd") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/order_list_response.rb b/lib/patch_ruby/models/order_list_response.rb index 9d889b0..5786b7c 100644 --- a/lib/patch_ruby/models/order_list_response.rb +++ b/lib/patch_ruby/models/order_list_response.rb @@ -42,6 +42,15 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("error") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/order_response.rb b/lib/patch_ruby/models/order_response.rb index 4af787c..f42405a 100644 --- a/lib/patch_ruby/models/order_response.rb +++ b/lib/patch_ruby/models/order_response.rb @@ -38,6 +38,15 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("error") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/photo.rb b/lib/patch_ruby/models/photo.rb index fb9671b..35c7bf2 100644 --- a/lib/patch_ruby/models/photo.rb +++ b/lib/patch_ruby/models/photo.rb @@ -16,20 +16,31 @@ module Patch class Photo attr_accessor :url + attr_accessor :id + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { - :'url' => :'url' + :'url' => :'url', + :'id' => :'id' } end # Attribute type mapping. def self.openapi_types { - :'url' => :'String' + :'url' => :'String', + :'id' => :'String' } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order @@ -69,6 +80,10 @@ def list_invalid_properties invalid_properties.push('invalid value for "url", url cannot be nil.') end + if @id.nil? + invalid_properties.push('invalid value for "id", id cannot be nil.') + end + invalid_properties end @@ -76,6 +91,7 @@ def list_invalid_properties # @return true if the model is valid def valid? return false if @url.nil? + return false if @id.nil? true end @@ -84,7 +100,8 @@ def valid? def ==(o) return true if self.equal?(o) self.class == o.class && - url == o.url + url == o.url && + id == o.id end # @see the `==` method @@ -96,7 +113,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [url].hash + [url, id].hash end # Builds the object from hash diff --git a/lib/patch_ruby/models/preference.rb b/lib/patch_ruby/models/preference.rb index 10bea26..48678c6 100644 --- a/lib/patch_ruby/models/preference.rb +++ b/lib/patch_ruby/models/preference.rb @@ -14,10 +14,13 @@ module Patch class Preference + # A unique uid for the record. UIDs will be prepended by pre_prod or pre_test depending on the mode it was created in. attr_accessor :id + # Percentage of total purchased offsets that should go to a project. Default is 100%. attr_accessor :allocation_percentage + # An object returning the Project record this Preference is associated with. See the [Project section](/?id=projects) for the full schema. attr_accessor :project # Attribute mapping from ruby-style variable name to JSON key. @@ -38,6 +41,13 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/preference_list_response.rb b/lib/patch_ruby/models/preference_list_response.rb index fc8c29a..94ff4fc 100644 --- a/lib/patch_ruby/models/preference_list_response.rb +++ b/lib/patch_ruby/models/preference_list_response.rb @@ -42,6 +42,15 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("error") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/preference_response.rb b/lib/patch_ruby/models/preference_response.rb index eb9c7ff..b3af523 100644 --- a/lib/patch_ruby/models/preference_response.rb +++ b/lib/patch_ruby/models/preference_response.rb @@ -38,6 +38,15 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("error") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/project.rb b/lib/patch_ruby/models/project.rb index 0ce275b..c39529e 100644 --- a/lib/patch_ruby/models/project.rb +++ b/lib/patch_ruby/models/project.rb @@ -14,26 +14,37 @@ module Patch class Project + # A unique uid for the record. UIDs will be prepended by pro_prod or pro_test depending on the mode it was created in. attr_accessor :id + # A boolean indicating if this project is a production or test mode project. attr_accessor :production + # The name of the project. attr_accessor :name + # The description of the project. attr_accessor :description + # The type of carbon removal project, currently available project types are Biomass, Dac, Forestry, Mineralization, Ocean, Soil. attr_accessor :type + # The country of origin of the project. attr_accessor :country + # The name of the project developer. attr_accessor :developer + # An array of URLs for photos of the project. attr_accessor :photos + # The average price per tonne in USD cents for carbon offsets supplied by this project. attr_accessor :average_price_per_tonne_cents_usd + # The remaining mass in grams available for purchase for this project. attr_accessor :remaining_mass_g + # An object returning the Standard associated with this project. attr_accessor :standard class EnumAttributeValidator @@ -92,6 +103,17 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("photos") + + nullable_properties.add("standard") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/project_list_response.rb b/lib/patch_ruby/models/project_list_response.rb index ca207a8..c3ccb92 100644 --- a/lib/patch_ruby/models/project_list_response.rb +++ b/lib/patch_ruby/models/project_list_response.rb @@ -42,6 +42,15 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("error") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/project_response.rb b/lib/patch_ruby/models/project_response.rb index 3dfa634..96cb48b 100644 --- a/lib/patch_ruby/models/project_response.rb +++ b/lib/patch_ruby/models/project_response.rb @@ -38,6 +38,15 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties.add("error") + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/models/standard.rb b/lib/patch_ruby/models/standard.rb index d99883e..04a9cf1 100644 --- a/lib/patch_ruby/models/standard.rb +++ b/lib/patch_ruby/models/standard.rb @@ -14,10 +14,13 @@ module Patch class Standard + # The standard type. attr_accessor :type + # The acronym for the standard. attr_accessor :acronym + # The description of the standard. attr_accessor :description # Attribute mapping from ruby-style variable name to JSON key. @@ -38,6 +41,13 @@ def self.openapi_types } end + # Set with nullable attributes. + def self.openapi_nullable + nullable_properties = Set.new + + nullable_properties + end + # Allows models with corresponding API classes to delegate API operations to those API classes # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order diff --git a/lib/patch_ruby/version.rb b/lib/patch_ruby/version.rb index 0260ec8..dbdffe7 100644 --- a/lib/patch_ruby/version.rb +++ b/lib/patch_ruby/version.rb @@ -11,5 +11,5 @@ =end module Patch - VERSION = '1.2.4' + VERSION = '1.2.5' end diff --git a/spec/factories/allocations.rb b/spec/factories/allocations.rb new file mode 100644 index 0000000..ac14f80 --- /dev/null +++ b/spec/factories/allocations.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :allocation, class: Patch::Allocation do + sequence(:id) { |n| n } + production { false } + mass_g { 100 } + end +end diff --git a/spec/factories/create_mass_estimate_requests.rb b/spec/factories/create_mass_estimate_requests.rb new file mode 100644 index 0000000..c86faa7 --- /dev/null +++ b/spec/factories/create_mass_estimate_requests.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :create_mass_estimate_request, class: Patch::CreateMassEstimateRequest do + sequence(:project_id) { |n| n } + mass_g { 100 } + end +end diff --git a/spec/factories/create_order_requests.rb b/spec/factories/create_order_requests.rb new file mode 100644 index 0000000..eae587e --- /dev/null +++ b/spec/factories/create_order_requests.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :create_order_request, class: Patch::CreateOrderRequest do + sequence(:project_id) { |n| n } + mass_g { 100 } + total_price_cents_usd { 100 } + metadata { {} } + end +end diff --git a/spec/factories/create_preference_requests.rb b/spec/factories/create_preference_requests.rb new file mode 100644 index 0000000..7dbce3f --- /dev/null +++ b/spec/factories/create_preference_requests.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :create_preference_request, class: Patch::CreatePreferenceRequest do + sequence(:project_id) { |n| n } + end +end diff --git a/spec/factories/error_responses.rb b/spec/factories/error_responses.rb new file mode 100644 index 0000000..0ff64f5 --- /dev/null +++ b/spec/factories/error_responses.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :error_response, class: Patch::ErrorResponse do + success { true } + error { {} } + data { {} } + end +end diff --git a/spec/factories/estimate_list_responses.rb b/spec/factories/estimate_list_responses.rb new file mode 100644 index 0000000..9aa3af6 --- /dev/null +++ b/spec/factories/estimate_list_responses.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :estimate_list_response, class: Patch::EstimateListResponse do + success { true } + error { {} } + data { {} } + meta { {} } + end +end diff --git a/spec/factories/estimate_responses.rb b/spec/factories/estimate_responses.rb new file mode 100644 index 0000000..ff27c80 --- /dev/null +++ b/spec/factories/estimate_responses.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :estimate_response, class: Patch::EstimateResponse do + success { true } + error { {} } + data { {} } + end +end diff --git a/spec/factories/estimates.rb b/spec/factories/estimates.rb new file mode 100644 index 0000000..afc8033 --- /dev/null +++ b/spec/factories/estimates.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :estimate, class: Patch::Estimate do + sequence(:id) { |n| n } + association :order + production { false } + type { "mass" } + end +end diff --git a/spec/factories/meta_index_objects.rb b/spec/factories/meta_index_objects.rb new file mode 100644 index 0000000..a504cf0 --- /dev/null +++ b/spec/factories/meta_index_objects.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :meta_index_object, class: Patch::MetaIndexObject do + sequence(:next_page) { |n| n + 1 } + sequence(:prev_page) { |n| n - 1 } + end +end diff --git a/spec/factories/order_list_responses.rb b/spec/factories/order_list_responses.rb new file mode 100644 index 0000000..b1f6b46 --- /dev/null +++ b/spec/factories/order_list_responses.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :order_list_response, class: Patch::OrderListResponse do + success { true } + error { {} } + data { {} } + meta { {} } + end +end diff --git a/spec/factories/order_responses.rb b/spec/factories/order_responses.rb new file mode 100644 index 0000000..3bde446 --- /dev/null +++ b/spec/factories/order_responses.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :order_response, class: Patch::OrderResponse do + success { true } + error { {} } + data { {} } + end +end diff --git a/spec/factories/orders.rb b/spec/factories/orders.rb new file mode 100644 index 0000000..1b4457f --- /dev/null +++ b/spec/factories/orders.rb @@ -0,0 +1,12 @@ +FactoryBot.define do + factory :order, class: Patch::Order do + sequence(:id) { |n| n } + mass_g { 1_000 } + production { false } + state { "draft" } + allocation_state { "pending" } + price_cents_usd { 500 } + patch_fee_cents_usd { 5 } + metadata { {} } + end +end diff --git a/spec/factories/preference_list_responses.rb b/spec/factories/preference_list_responses.rb new file mode 100644 index 0000000..f163ade --- /dev/null +++ b/spec/factories/preference_list_responses.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :preference_list_response, class: Patch::PreferenceListResponse do + success { true } + error { {} } + data { {} } + meta { {} } + end +end diff --git a/spec/factories/preference_responses.rb b/spec/factories/preference_responses.rb new file mode 100644 index 0000000..1fcb2a3 --- /dev/null +++ b/spec/factories/preference_responses.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :preference_response, class: Patch::PreferenceResponse do + success { true } + error { {} } + data { {} } + end +end diff --git a/spec/factories/preferences.rb b/spec/factories/preferences.rb new file mode 100644 index 0000000..7489ade --- /dev/null +++ b/spec/factories/preferences.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :preference, class: Patch::Preference do + sequence(:id) { |n| n } + association :project + allocation_percentage { 1 } + end +end diff --git a/spec/factories/project_list_responses.rb b/spec/factories/project_list_responses.rb new file mode 100644 index 0000000..4d06f06 --- /dev/null +++ b/spec/factories/project_list_responses.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :project_list_response, class: Patch::ProjectListResponse do + success { true } + error { {} } + data { {} } + meta { {} } + end +end diff --git a/spec/factories/project_responses.rb b/spec/factories/project_responses.rb new file mode 100644 index 0000000..331be37 --- /dev/null +++ b/spec/factories/project_responses.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :project_response, class: Patch::ProjectResponse do + success { true } + error { {} } + data { {} } + end +end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb new file mode 100644 index 0000000..dea7ab7 --- /dev/null +++ b/spec/factories/projects.rb @@ -0,0 +1,15 @@ +FactoryBot.define do + factory :project, class: Patch::Project do + sequence(:id) { |n| n } + production { false } + name { "New Project" } + description { "New Descirption" } + type { "biomass" } + country { "DK" } + developer { "Danish Developer" } + photos { [] } + average_price_per_tonne_cents_usd { 120 } + remaining_mass_g { 1_000 } + standard { 'european_biochar_certificate' } + end +end diff --git a/spec/integration/estimates_spec.rb b/spec/integration/estimates_spec.rb index caf2b9c..3e1e2e7 100644 --- a/spec/integration/estimates_spec.rb +++ b/spec/integration/estimates_spec.rb @@ -24,15 +24,4 @@ expect(estimates.length).not_to be_zero end - - it 'supports create with a project-id' do - retrieve_projects_response = Patch::Project.retrieve_projects(page: 1) - project_id = retrieve_projects_response.data.first.id - create_estimate_response = Patch::Estimate.create_mass_estimate(mass_g: 100, project_id: project_id) - estimate_id = create_estimate_response.data.id - - expect(create_estimate_response.success).to eq true - expect(create_estimate_response.data.order.id).not_to be_nil - expect(create_estimate_response.data.order.mass_g).to eq(100) - end end diff --git a/spec/integration/orders_spec.rb b/spec/integration/orders_spec.rb index 8ea70af..e9bf2d2 100644 --- a/spec/integration/orders_spec.rb +++ b/spec/integration/orders_spec.rb @@ -65,7 +65,7 @@ order = create_order_response.data expect(order.id).not_to be_nil - expect(order.mass_g).to eq(5_000_000) + expect(order.mass_g).to eq(5_00_000) expect(order.price_cents_usd.to_i).to eq(500) expect(order.patch_fee_cents_usd).not_to be_empty expect( diff --git a/spec/models/allocation_spec.rb b/spec/models/allocation_spec.rb index 52b6467..80cc959 100644 --- a/spec/models/allocation_spec.rb +++ b/spec/models/allocation_spec.rb @@ -20,18 +20,25 @@ describe 'Allocation' do before do # run before each test - @instance = Patch::Allocation.new + @instance = build(:allocation) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { id: @instance.id, mass_g: @instance.mass_g, production: @instance.production } } + let(:nullable_properties) { Set.new } + end + describe 'test an instance of Allocation' do it 'should create an instance of Allocation' do expect(@instance).to be_instance_of(Patch::Allocation) end end + describe 'test attribute "id"' do it 'should work' do # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers diff --git a/spec/models/create_mass_estimate_request_spec.rb b/spec/models/create_mass_estimate_request_spec.rb index d1d6c3a..a001df1 100644 --- a/spec/models/create_mass_estimate_request_spec.rb +++ b/spec/models/create_mass_estimate_request_spec.rb @@ -20,13 +20,19 @@ describe 'CreateMassEstimateRequest' do before do # run before each test - @instance = Patch::CreateMassEstimateRequest.new + @instance = build(:create_mass_estimate_request) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g } } + let(:nullable_properties) { Set.new } + end + describe 'test an instance of CreateMassEstimateRequest' do it 'should create an instance of CreateMassEstimateRequest' do expect(@instance).to be_instance_of(Patch::CreateMassEstimateRequest) diff --git a/spec/models/create_order_request_spec.rb b/spec/models/create_order_request_spec.rb index 702f2ac..dd4ed72 100644 --- a/spec/models/create_order_request_spec.rb +++ b/spec/models/create_order_request_spec.rb @@ -20,13 +20,19 @@ describe 'CreateOrderRequest' do before do # run before each test - @instance = Patch::CreateOrderRequest.new + @instance = build(:create_order_request) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g, total_price_cents_usd: @instance.total_price_cents_usd, metadata: @instance.metadata } } + let(:nullable_properties) { Set.new } + end + describe 'test an instance of CreateOrderRequest' do it 'should create an instance of CreateOrderRequest' do expect(@instance).to be_instance_of(Patch::CreateOrderRequest) diff --git a/spec/models/create_preference_request_spec.rb b/spec/models/create_preference_request_spec.rb index 4fb6008..619d7b6 100644 --- a/spec/models/create_preference_request_spec.rb +++ b/spec/models/create_preference_request_spec.rb @@ -20,18 +20,25 @@ describe 'CreatePreferenceRequest' do before do # run before each test - @instance = Patch::CreatePreferenceRequest.new + @instance = build(:create_preference_request) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { project_id: @instance.project_id } } + let(:nullable_properties) { Set.new } + end + describe 'test an instance of CreatePreferenceRequest' do it 'should create an instance of CreatePreferenceRequest' do expect(@instance).to be_instance_of(Patch::CreatePreferenceRequest) end end + describe 'test attribute "project_id"' do it 'should work' do # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers diff --git a/spec/models/error_response_spec.rb b/spec/models/error_response_spec.rb index ef7fcf8..ca04fbc 100644 --- a/spec/models/error_response_spec.rb +++ b/spec/models/error_response_spec.rb @@ -20,13 +20,19 @@ describe 'ErrorResponse' do before do # run before each test - @instance = Patch::ErrorResponse.new + @instance = build(:error_response) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data } } + let(:nullable_properties) { Set.new(["data"]) } + end + describe 'test an instance of ErrorResponse' do it 'should create an instance of ErrorResponse' do expect(@instance).to be_instance_of(Patch::ErrorResponse) diff --git a/spec/models/estimate_list_response_spec.rb b/spec/models/estimate_list_response_spec.rb index 35b3220..68c2af6 100644 --- a/spec/models/estimate_list_response_spec.rb +++ b/spec/models/estimate_list_response_spec.rb @@ -20,13 +20,19 @@ describe 'EstimateListResponse' do before do # run before each test - @instance = Patch::EstimateListResponse.new + @instance = build(:estimate_list_response) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data, meta: @instance.meta } } + let(:nullable_properties) { Set.new(["error"]) } + end + describe 'test an instance of EstimateListResponse' do it 'should create an instance of EstimateListResponse' do expect(@instance).to be_instance_of(Patch::EstimateListResponse) diff --git a/spec/models/estimate_response_spec.rb b/spec/models/estimate_response_spec.rb index c206824..1d41216 100644 --- a/spec/models/estimate_response_spec.rb +++ b/spec/models/estimate_response_spec.rb @@ -20,13 +20,19 @@ describe 'EstimateResponse' do before do # run before each test - @instance = Patch::EstimateResponse.new + @instance = build(:estimate_response) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data } } + let(:nullable_properties) { Set.new(["error"]) } + end + describe 'test an instance of EstimateResponse' do it 'should create an instance of EstimateResponse' do expect(@instance).to be_instance_of(Patch::EstimateResponse) diff --git a/spec/models/estimate_spec.rb b/spec/models/estimate_spec.rb index e0dc324..34ddae7 100644 --- a/spec/models/estimate_spec.rb +++ b/spec/models/estimate_spec.rb @@ -20,18 +20,25 @@ describe 'Estimate' do before do # run before each test - @instance = Patch::Estimate.new + @instance = build(:estimate) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { id: @instance.id, order: @instance.order.to_hash, production: @instance.production, type: @instance.type } } + let(:nullable_properties) { Set.new(["order"]) } + end + describe 'test an instance of Estimate' do it 'should create an instance of Estimate' do expect(@instance).to be_instance_of(Patch::Estimate) end end + describe 'test attribute "id"' do it 'should work' do # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers diff --git a/spec/models/meta_index_object_spec.rb b/spec/models/meta_index_object_spec.rb index 43b2db1..0ea5c08 100644 --- a/spec/models/meta_index_object_spec.rb +++ b/spec/models/meta_index_object_spec.rb @@ -20,13 +20,19 @@ describe 'MetaIndexObject' do before do # run before each test - @instance = Patch::MetaIndexObject.new + @instance = build(:meta_index_object) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { next_page: @instance.next_page, prev_page: @instance.prev_page } } + let(:nullable_properties) { Set.new(["next_page", "prev_page"]) } + end + describe 'test an instance of MetaIndexObject' do it 'should create an instance of MetaIndexObject' do expect(@instance).to be_instance_of(Patch::MetaIndexObject) diff --git a/spec/models/order_list_response_spec.rb b/spec/models/order_list_response_spec.rb index db4238a..4e85078 100644 --- a/spec/models/order_list_response_spec.rb +++ b/spec/models/order_list_response_spec.rb @@ -20,13 +20,19 @@ describe 'OrderListResponse' do before do # run before each test - @instance = Patch::OrderListResponse.new + @instance = build(:order_list_response) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data, meta: @instance.meta } } + let(:nullable_properties) { Set.new(["error"]) } + end + describe 'test an instance of OrderListResponse' do it 'should create an instance of OrderListResponse' do expect(@instance).to be_instance_of(Patch::OrderListResponse) diff --git a/spec/models/order_response_spec.rb b/spec/models/order_response_spec.rb index dd2758a..9880ff9 100644 --- a/spec/models/order_response_spec.rb +++ b/spec/models/order_response_spec.rb @@ -20,13 +20,19 @@ describe 'OrderResponse' do before do # run before each test - @instance = Patch::OrderResponse.new + @instance = build(:order_response) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data } } + let(:nullable_properties) { Set.new(["error"]) } + end + describe 'test an instance of OrderResponse' do it 'should create an instance of OrderResponse' do expect(@instance).to be_instance_of(Patch::OrderResponse) diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 1a79a7c..a1e49d7 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -20,13 +20,30 @@ describe 'Order' do before do # run before each test - @instance = Patch::Order.new + @instance = build(:order) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { + { + id: @instance.id, + mass_g: @instance.mass_g, + production: @instance.production, + state: @instance.state, + allocation_state: @instance.allocation_state, + price_cents_usd: @instance.price_cents_usd, + patch_fee_cents_usd: @instance.patch_fee_cents_usd, + metadata: @instance.metadata + } + } + let(:nullable_properties) { Set.new(["patch_fee_cents_usd", "price_cents_usd"]) } + end + describe 'test an instance of Order' do it 'should create an instance of Order' do expect(@instance).to be_instance_of(Patch::Order) diff --git a/spec/models/preference_list_response_spec.rb b/spec/models/preference_list_response_spec.rb index d85a79d..7388d7f 100644 --- a/spec/models/preference_list_response_spec.rb +++ b/spec/models/preference_list_response_spec.rb @@ -20,13 +20,19 @@ describe 'PreferenceListResponse' do before do # run before each test - @instance = Patch::PreferenceListResponse.new + @instance = build(:preference_list_response) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data, meta: @instance.meta } } + let(:nullable_properties) { Set.new(["error"]) } + end + describe 'test an instance of PreferenceListResponse' do it 'should create an instance of PreferenceListResponse' do expect(@instance).to be_instance_of(Patch::PreferenceListResponse) diff --git a/spec/models/preference_response_spec.rb b/spec/models/preference_response_spec.rb index a171d1e..e19ad9d 100644 --- a/spec/models/preference_response_spec.rb +++ b/spec/models/preference_response_spec.rb @@ -20,13 +20,19 @@ describe 'PreferenceResponse' do before do # run before each test - @instance = Patch::PreferenceResponse.new + @instance = build(:preference_response) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data } } + let(:nullable_properties) { Set.new(["error"]) } + end + describe 'test an instance of PreferenceResponse' do it 'should create an instance of PreferenceResponse' do expect(@instance).to be_instance_of(Patch::PreferenceResponse) diff --git a/spec/models/preference_spec.rb b/spec/models/preference_spec.rb index 54e21ca..abf0fe9 100644 --- a/spec/models/preference_spec.rb +++ b/spec/models/preference_spec.rb @@ -20,13 +20,19 @@ describe 'Preference' do before do # run before each test - @instance = Patch::Preference.new + @instance = build(:preference) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { id: @instance.id, project: @instance.project.to_hash, allocation_percentage: @instance.allocation_percentage } } + let(:nullable_properties) { Set.new } + end + describe 'test an instance of Preference' do it 'should create an instance of Preference' do expect(@instance).to be_instance_of(Patch::Preference) diff --git a/spec/models/project_list_response_spec.rb b/spec/models/project_list_response_spec.rb index a2897f3..c83f631 100644 --- a/spec/models/project_list_response_spec.rb +++ b/spec/models/project_list_response_spec.rb @@ -20,13 +20,19 @@ describe 'ProjectListResponse' do before do # run before each test - @instance = Patch::ProjectListResponse.new + @instance = build(:project_list_response) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data, meta: @instance.meta } } + let(:nullable_properties) { Set.new(["error"]) } + end + describe 'test an instance of ProjectListResponse' do it 'should create an instance of ProjectListResponse' do expect(@instance).to be_instance_of(Patch::ProjectListResponse) diff --git a/spec/models/project_response_spec.rb b/spec/models/project_response_spec.rb index 3bfee28..49f0965 100644 --- a/spec/models/project_response_spec.rb +++ b/spec/models/project_response_spec.rb @@ -20,13 +20,19 @@ describe 'ProjectResponse' do before do # run before each test - @instance = Patch::ProjectResponse.new + @instance = build(:project_response) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data } } + let(:nullable_properties) { Set.new(["error"]) } + end + describe 'test an instance of ProjectResponse' do it 'should create an instance of ProjectResponse' do expect(@instance).to be_instance_of(Patch::ProjectResponse) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 42e509f..bc13bfa 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -20,13 +20,33 @@ describe 'Project' do before do # run before each test - @instance = Patch::Project.new + @instance = build(:project) end after do # run after each test end + it_behaves_like "a generated class" do + let(:instance) { @instance } + let(:instance_hash) { + { + id: @instance.id, + name: @instance.name, + description: @instance.description, + production: @instance.production, + type: @instance.type, + country: @instance.country, + developer: @instance.developer, + photos: @instance.photos, + average_price_per_tonne_cents_usd: @instance.average_price_per_tonne_cents_usd, + remaining_mass_g: @instance.remaining_mass_g, + standard: @instance.standard + } + } + let(:nullable_properties) { Set.new(["photos", "standard"]) } + end + describe 'test an instance of Project' do it 'should create an instance of Project' do expect(@instance).to be_instance_of(Patch::Project) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2ed41b9..f9bc511 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,10 @@ # load the gem require 'patch_ruby' require 'constants' +require 'factory_bot' + +# Require shared spec examples +Dir["./spec/support/**/*.rb"].sort.each { |f| require f } # The following was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. @@ -33,6 +37,12 @@ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| + # Use FactoryBot for test factories + config.include FactoryBot::Syntax::Methods + config.before(:suite) do + FactoryBot.find_definitions + end + # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. diff --git a/spec/support/shared/generated_classes.rb b/spec/support/shared/generated_classes.rb new file mode 100644 index 0000000..b9cf3d5 --- /dev/null +++ b/spec/support/shared/generated_classes.rb @@ -0,0 +1,13 @@ +RSpec.shared_examples "a generated class" do + describe '.openapi_nullable' do + it 'returns a set with nullable properties' do + expect(instance.class.openapi_nullable).to eq nullable_properties + end + end + + describe '#to_hash' do + it 'returns a set with nullable properties' do + expect(@instance.to_hash).to eq(instance_hash) + end + end +end