From 163a9f9ce9a5bce174343713755e29b96e956262 Mon Sep 17 00:00:00 2001 From: Angela Silva Date: Fri, 19 Jul 2024 14:07:07 +0100 Subject: [PATCH 1/4] Fixing integration with mso_uk --- lib/zuora/api.rb | 83 +++++-------------- lib/zuora/attributes.rb | 31 +++---- lib/zuora/objects/account.rb | 3 +- lib/zuora/objects/amendment.rb | 41 ++++----- lib/zuora/objects/base.rb | 30 ++----- .../objects/credit_balance_adjustment.rb | 36 ++++---- lib/zuora/objects/invoice.rb | 6 +- lib/zuora/objects/invoice_item.rb | 29 ++++--- lib/zuora/objects/invoice_item_adjustment.rb | 6 +- lib/zuora/objects/invoice_payment.rb | 32 +++---- lib/zuora/objects/payment.rb | 76 ++++++++--------- lib/zuora/objects/payment_method.rb | 4 +- lib/zuora/objects/product.rb | 8 +- lib/zuora/objects/product_rate_plan.rb | 5 +- lib/zuora/objects/product_rate_plan_charge.rb | 3 +- lib/zuora/objects/rate_plan_charge.rb | 14 ++-- lib/zuora/objects/refund.rb | 65 +++++++-------- lib/zuora/objects/refund_invoice_payment.rb | 30 +++---- lib/zuora/objects/subscribe_request.rb | 16 ++-- lib/zuora/objects/subscription.rb | 12 +-- lib/zuora/soap_connector.rb | 12 +-- lib/zuora/validations.rb | 8 +- 22 files changed, 239 insertions(+), 311 deletions(-) diff --git a/lib/zuora/api.rb b/lib/zuora/api.rb index 1ec940b7..74b7b350 100644 --- a/lib/zuora/api.rb +++ b/lib/zuora/api.rb @@ -11,20 +11,13 @@ module Zuora # @return [Config] def self.configure(opts={}) Api.instance.config = Config.new(opts) - if Api.instance.config.sandbox - Api.instance.sandbox! - elsif Api.instance.config.services - Api.instance.set_endpoint Api.instance.config.custom_url - end + HTTPI.logger = opts[:logger] + HTTPI.log = opts[:logger] ? true : false end class Api - I18n.enforce_available_locales = false - # @return [Savon::Client] - def client - @client ||= make_client - end + attr_accessor :client # @return [Zuora::Session] attr_accessor :session @@ -32,17 +25,7 @@ def client # @return [Zuora::Config] attr_accessor :config - # Zuora::API Config options - # @return [Hash] - attr_accessor :options - - WSDL = File.expand_path('../../../wsdl/zuora.a.78.0.wsdl', __FILE__) SOAP_VERSION = 2 - SANDBOX_ENDPOINT = 'https://apisandbox.zuora.com/apps/services/a/78.0' - - def wsdl - client.instance_variable_get(:@wsdl) - end def self.instance @instance ||= new @@ -54,31 +37,15 @@ def authenticated? self.session.try(:active?) end - # Change client to use sandbox url - def sandbox! - @client = nil - self.class.instance.client.globals[:endpoint] = SANDBOX_ENDPOINT - end - - #change the client to a specific endpoint - def set_endpoint(endpoint) - @client = nil - self.class.instance.client.globals[:endpoint] = endpoint - end - - # Callback from Savon observer. Sets the @last_request - # instance variable to the full request body. - def notify(operation_name, builder, globals, locals) - @last_request = builder.to_s - return nil - end - # The XML that was transmited in the last request # @return [String] - attr_reader :last_request + def last_request + client.http.body + end # Generate an API request with the given block. The block yields an xml # builder instance which can be used to build out the request as needed. + # You can also provide the xml_body which will be used instead of the block. # @param [Symbol] symbol of the WSDL operation to call # @param [String] string xml body pass to the operation # @yield [Builder] xml builder instance @@ -91,6 +58,8 @@ def request(method, options={}, &block) yield xml options[:message] = xml.target! end + options[:soap_header] = { 'env:SessionHeader' => { 'zns:Session' => self.session.try(:key) } } + client.call(method, options) rescue Savon::SOAPFault, IOError => e raise Zuora::Fault.new(:message => e.message) @@ -118,31 +87,23 @@ def download(export) # Upon failure a Zoura::Fault will be raised. # @raise [Zuora::Fault] def authenticate! - response = client.call(:login) do - message username: Zuora::Api.instance.config.username, - password: Zuora::Api.instance.config.password - end + response = client.call(:login, message: { username: config.username, password: config.password }) + self.session = Zuora::Session.generate(response.to_hash) - client.globals.soap_header({'env:SessionHeader' => {'ins0:Session' => self.session.try(:key) }}) - rescue Savon::SOAPFault => e + rescue Savon::SOAPFault, IOError => e raise Zuora::Fault.new(:message => e.message) end - private - - def initialize - @config = Config.new - end - - def make_client - Savon.client(wsdl: fetch_wsdl, soap_version: SOAP_VERSION, log: config.log || true, ssl_verify_mode: :none) - end - - def fetch_wsdl - config&.wsdl_path || WSDL + def client + return @client if @client + + @client = Savon.client( + wsdl: config&.wsdl_path ? config.wsdl_path : File.expand_path('../../../wsdl/zuora.a.38.0.wsdl', __FILE__), + ssl_verify_mode: :none, + soap_version: SOAP_VERSION, + log: log: config&.log || true, + filters: [:password] + ) end end - - # Support request tracking via notify - Savon.observers << Api.instance end diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index e12cb379..ccfbc645 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -1,6 +1,5 @@ module Zuora module Attributes - def self.included(base) base.send(:include, ActiveModel::Naming) base.send(:include, ActiveModel::Conversion) @@ -40,17 +39,19 @@ def define_attributes(&block) # generate association overrides for complex object handling # and cache the objects so that they may be modified and updated class_variable_get(:@@complex_attributes).each do |var, scope| - class_eval <<~EVAL - prepend(Module.new do - def #{scope} - if new_record? || @#{scope}_cached - @#{scope} ||= [] - else - @#{scope}_cached = true - @#{scope} = super - end + # set up the instance variable for the new assoc collection + # for new records, but call the original one for existing + # records and cache/return the result for subsequent calls. + class_eval <<-EVAL + def #{scope}_with_complex + if new_record? || @#{scope}_cached + @#{scope} ||= [] + else + @#{scope}_cached = true + @#{scope} = #{scope}_without_complex end - end) + end + alias_method_chain :#{scope}, :complex EVAL end end @@ -142,7 +143,7 @@ def remote_name def inherited(subclass) super xpath = "//xs:complexType[@name='#{subclass.remote_name}']//xs:sequence/xs:element" - document = Zuora::Api.instance.wsdl.parser.instance_variable_get('@document') + document = Zuora::Api.instance.client.wsdl.parser.instance_variable_get('@document') q = document.xpath(xpath, 's0' => 'http://schemas.xmlsoap.org/wsdl/', 'xs' => 'http://www.w3.org/2001/XMLSchema') wsdl_attrs = (q.map{|e| e.attributes['name'].to_s.underscore.to_sym }) << :id subclass.send(:class_variable_set, :@@wsdl_attributes, wsdl_attrs) @@ -208,13 +209,13 @@ def attributes # remove all dirty tracking for the object and return self for chaining. def clear_changed_attributes! - clear_changes_information + @changed_attributes = {} self end - + # the name to use when referencing remote Zuora objects def remote_name self.class.name.base_name end end -end \ No newline at end of file +end diff --git a/lib/zuora/objects/account.rb b/lib/zuora/objects/account.rb index 50582a91..2bcb31f7 100644 --- a/lib/zuora/objects/account.rb +++ b/lib/zuora/objects/account.rb @@ -13,7 +13,7 @@ class Account < Base validates_inclusion_of :payment_term, :in => ['Due Upon Receipt','Net 15','Net 30','Net 45','Net 90'] validates_inclusion_of :batch, :in => (1..20).map{|n| "Batch#{n}" } validates_inclusion_of :bcd_setting_option, :in => ['AutoSet','ManualSet'], :allow_nil => true - validates_inclusion_of :bill_cycle_day, :in => (1..31).to_a + (1..31).map(&:to_s) + validates_inclusion_of :bill_cycle_day, :in => (1..30).to_a + (1..30).map(&:to_s) validates_inclusion_of :status, :in => ['Draft','Active','Canceled'], :allow_nil => true define_attributes do @@ -30,3 +30,4 @@ class Account < Base end end end + diff --git a/lib/zuora/objects/amendment.rb b/lib/zuora/objects/amendment.rb index 93080208..b8b8441e 100644 --- a/lib/zuora/objects/amendment.rb +++ b/lib/zuora/objects/amendment.rb @@ -2,24 +2,24 @@ module Zuora::Objects class Amendment < Base belongs_to :subscription - validates_presence_of :subscription_id, :name - validates_length_of :name, :maximum => 100 - validates_inclusion_of :auto_renew, :in => [true, false], :allow_nil => true - validates_length_of :code, :maximum => 50, :allow_nil => true - validates_date_of :contract_effective_date, :allow_nil => true - validates_date_of :customer_acceptance_date, :allow_nil => true - validates_date_of :effective_date, :allow_nil => true - validates_date_of :service_activation_date, :if => Proc.new { |a| a.status == 'PendingAcceptance' } - validates_length_of :description, :maximum => 500, :allow_nil => true + validates_presence_of :subscription_id, :name + validates_length_of :name, :maximum => 100 + validates_inclusion_of :auto_renew, :in => [true, false], :allow_nil => true + validates_length_of :code, :maximum => 50, :allow_nil => true + validates_datetime_of :contract_effective_date, :allow_nil => true + validates_datetime_of :customer_acceptance_date, :allow_nil => true + validates_datetime_of :effective_date, :allow_nil => true + validates_datetime_of :service_activation_date, :if => Proc.new { |a| a.status == 'PendingAcceptance' } + validates_length_of :description, :maximum => 500, :allow_nil => true validates_numericality_of :initial_term, :if => Proc.new { |a| a.type == 'TermsAndConditions' } validates_numericality_of :renewal_term, :if => Proc.new { |a| a.type == 'TermsAndConditions' } - validates_date_of :term_start_date, :if => Proc.new { |a| a.type == 'TermsAndConditions' } - validates_presence_of :destination_account_id, :if => Proc.new {|a| a.type == 'OwnerTransfer' } - validates_presence_of :destination_invoice_owner_id, :if => Proc.new {|a| a.type == 'OwnerTransfer' } - validates_inclusion_of :status, :in => ["Completed", "Cancelled", "Draft", "Pending Acceptance", "Pending Activation"] - validates_inclusion_of :term_type, :in => ['TERMED', 'EVERGREEN'], :allow_nil => true - validates_inclusion_of :type, :in => ['Cancellation', 'NewProduct', 'OwnerTransfer', 'RemoveProduct', 'Renewal', 'UpdateProduct', 'TermsAndConditions'] - validates_presence_of :rate_plan_data, :if => Proc.new { |a| ['NewProduct', 'RemoveProduct', 'UpdateProduct'].include?(a.type) }, :only => :apply_percentage_discount + validates_date_of :term_start_date, :if => Proc.new { |a| a.type == 'TermsAndConditions' } + validates_presence_of :destination_account_id, :if => Proc.new {|a| a.type == 'OwnerTransfer' } + validates_presence_of :destination_invoice_owner_id, :if => Proc.new {|a| a.type == 'OwnerTransfer' } + validates_inclusion_of :status, :in => ["Completed", "Cancelled", "Draft", "Pending Acceptance", "Pending Activation"] + validates_inclusion_of :term_type, :in => ['TERMED', 'EVERGREEN'], :allow_nil => true + validates_inclusion_of :type, :in => ['Cancellation', 'NewProduct', 'OwnerTransfer', 'RemoveProduct', 'Renewal', 'UpdateProduct', 'TermsAndConditions'] + validates_presence_of :rate_plan_data, :if => Proc.new { |a| ['NewProduct', 'RemoveProduct', 'UpdateProduct'].include?(a.type) }, :only => :apply_percentage_discount attr_accessor :amendment_ids attr_accessor :invoice_id @@ -32,10 +32,12 @@ class Amendment < Base def apply_percentage_discount self.status = 'Completed' - result = self.connector.amend + result = self.connector.amend({ 'process_payments' => false }) apply_percentage_discount_response(result.to_hash, :amend_response) end + private + def apply_percentage_discount_response(response_hash, type) result = response_hash[type][:results] if result[:success] @@ -43,11 +45,10 @@ def apply_percentage_discount_response(response_hash, type) self.invoice_id = result[:invoice_id] self.payment_transaction_number = result[:payment_transaction_number] @previously_changed = changes - clear_changes_information + @changed_attributes.clear return true else - self.errors.add(:base, result[:errors][:message]) - return false + raise StandardError.new(result[:errors][:message]) end end end diff --git a/lib/zuora/objects/base.rb b/lib/zuora/objects/base.rb index 3ce8745c..a1f17203 100644 --- a/lib/zuora/objects/base.rb +++ b/lib/zuora/objects/base.rb @@ -9,14 +9,10 @@ class Base # generate a new instance of a Zuora object def initialize(attrs={}, &block) apply_default_attributes - self.attributes = attrs - yield self if block_given? - end - - def attributes=(attrs={}) attrs.each do |name, value| self.send("#{name.to_s.underscore}=", value) end + yield self if block_given? end # given a soap response hash, initialize a record @@ -44,7 +40,7 @@ def reload! self.send("#{k}=", v) } @previously_changed = changes - clear_changes_information + @changed_attributes.clear self end @@ -55,7 +51,7 @@ def self.unselectable_attributes end def self.namespace(uri) - Zuora::Api.instance.client.operation(:query).build.send(:namespace_by_uri, uri) + connector.current_client.client.operation(:query).build.send(:namespace_by_uri, uri) end def self.zns @@ -80,16 +76,6 @@ def self.select(select) self end - # retrieve all of the records - def self.all - keys = (attributes - unselectable_attributes).map(&:to_s).map(&:zuora_camelize) - sql = "select #{keys.join(', ')} from #{remote_name}" - - result = self.connector.query(sql) - - generate(result.to_hash, :query_response) - end - # locate objects using a custom where clause, currently arel # is not supported as it requires an actual db connection to # generate the sql queries. This may be overcome in the future. @@ -97,7 +83,7 @@ def self.where(where) keys = self.select_attributes if where.is_a?(Hash) # FIXME: improper inject usage. - where = where.inject([]){|t,v| t << "#{v[0].to_s.zuora_camelize} = '#{v[1]}'"}.sort.join(' and ') + where = where.inject([]){|t,v| t << "#{v[0].to_s.camelcase} = '#{v[1]}'"}.sort.join(' and ') end sql = "select #{keys.join(', ')} from #{remote_name} where #{where}" @@ -108,11 +94,6 @@ def self.where(where) generate(result.to_hash, :query_response) end - def self.query(query_string) - result = self.connector.query(query_string) - generate(result.to_hash, :query_response) - end - # has this record not been saved? def new_record? id.nil? @@ -191,7 +172,7 @@ def apply_response(response_hash, type) if result[:success] self.id = result[:id] @previously_changed = changes - clear_changes_information + @changed_attributes.clear return true else raise StandardError.new(result[:errors][:message]) @@ -205,4 +186,3 @@ def self.select_attributes end end - diff --git a/lib/zuora/objects/credit_balance_adjustment.rb b/lib/zuora/objects/credit_balance_adjustment.rb index 7bd1e345..6cbc7182 100644 --- a/lib/zuora/objects/credit_balance_adjustment.rb +++ b/lib/zuora/objects/credit_balance_adjustment.rb @@ -1,20 +1,20 @@ -module Zuora::Objects - class CreditBalanceAdjustment < Base - belongs_to :account - belongs_to :source_transaction +#module Zuora::Objects + #class CreditBalanceAdjustment < Base + #belongs_to :account + #belongs_to :source_transaction - validates_length_of :accounting_code, :maximum => 100, :allow_nil => true - validates_numericality_of :amount - validates_length_of :comment, :maximum => 255, :allow_nil => true - validates_length_of :reference_id, :maximum => 60, :allow_nil => true - validates_presence_of :source_transaction_id, :if => Proc.new { |c| c.source_transaction_type == 'Adjustment' } - validates_inclusion_of :source_transaction_type, :in => %w(Invoice Payment Refund Adjustment), :unless => :source_transaction - validates_length_of :source_transaction_number, :maximum => 50, :if => Proc.new { |c| c.source_transaction_type == 'Adjustment' && !c.source_transaction } - validates_inclusion_of :transferred_to_accounting, :in => %w(Processing Yes Error Ignore), :allow_nil => true - validates_inclusion_of :type, :in => %w(Increase Decrease) + #validates_length_of :accounting_code, :maximum => 100, :allow_nil => true + #validates_numericality_of :amount + #validates_length_of :comment, :maximum => 255, :allow_nil => true + #validates_length_of :reference_id, :maximum => 60, :allow_nil => true + #validates_presence_of :source_transaction_id, :if => Proc.new { |c| c.source_transaction_type == 'Adjustment' } + #validates_inclusion_of :source_transaction_type, :in => %w(Invoice Payment Refund Adjustment), :unless => :source_transaction + #validates_length_of :source_transaction_number, :maximum => 50, :if => Proc.new { |c| c.source_transaction_type == 'Adjustment' && !c.source_transaction } + #validates_inclusion_of :transferred_to_accounting, :in => %w(Processing Yes Error Ignore), :allow_nil => true + #validates_inclusion_of :type, :in => %w(Increase Decrease) - define_attributes do - read_only :created_by_id, :created_date, :updated_by_id, :updated_date - end - end -end + #define_attributes do + #read_only :created_by_id, :created_date, :updated_by_id, :updated_date + #end + #end +#end diff --git a/lib/zuora/objects/invoice.rb b/lib/zuora/objects/invoice.rb index c94f019f..d7a40186 100644 --- a/lib/zuora/objects/invoice.rb +++ b/lib/zuora/objects/invoice.rb @@ -15,8 +15,8 @@ class Invoice < Base validates_numericality_of :amount validates_numericality_of :balance, :allow_nil => true validates_length_of :comments, :maximum => 255 - validates_date_of :due_date - validates_date_of :invoice_date + validates_datetime_of :due_date + validates_datetime_of :invoice_date validates_inclusion_of :includes_one_time, :in => [true, false] validates_inclusion_of :includes_recurring, :in => [true, false] validates_inclusion_of :includes_usage, :in => [true, false] @@ -26,7 +26,7 @@ class Invoice < Base validates_datetime_of :posted_date, :allow_nil => true validates_numericality_of :refund_amount, :allow_nil => true validates_inclusion_of :status, :in => %w(Canceled Draft Error Posted), :allow_nil => true - validates_date_of :target_date + validates_datetime_of :target_date validates_inclusion_of :transferred_to_accounting, :in => %w(Processing Yes Error Ignore), :allow_nil => true validates_datetime_of :updated_date diff --git a/lib/zuora/objects/invoice_item.rb b/lib/zuora/objects/invoice_item.rb index 47b9be06..4a6187fa 100644 --- a/lib/zuora/objects/invoice_item.rb +++ b/lib/zuora/objects/invoice_item.rb @@ -8,29 +8,28 @@ class InvoiceItem < Base validates_presence_of :charge_amount, :charge_date, :charge_number, :invoice_id, :product_id, :product_name, :rate_plan_charge_id, :service_start_date, :subscription_id, :unit_price - validates_length_of :accounting_code, :maximum => 255, :allow_nil => true + validates_length_of :accounting_code, :maximum => 255, :allow_nil => true validates_numericality_of :charge_amount - validates_datetime_of :charge_date - validates_length_of :charge_name, :maximum => 50, :allow_nil => true - validates_length_of :created_by_id, :maximum => 32, :allow_nil => true - validates_inclusion_of :processing_type, :in => [0,1,2,3], :allow_nil => true - validates_length_of :product_description, :maximum => 255, :allow_nil => true - validates_length_of :product_name, :maximum => 255 + validates_datetime_of :charge_date + validates_length_of :charge_name, :maximum => 50, :allow_nil => true + validates_length_of :created_by_id, :maximum => 32, :allow_nil => true + validates_inclusion_of :processing_type, :in => [0,1,2,3], :allow_nil => true + validates_length_of :product_description, :maximum => 255, :allow_nil => true + validates_length_of :product_name, :maximum => 255 validates_numericality_of :quantity, :allow_nil => true - validates_length_of :rev_rec_code, :maximum => 70 - validates_date_of :rev_rec_start_date, :allow_nil => true - validates_date_of :service_end_date, :allow_nil => true - validates_date_of :service_start_date - validates_length_of :sku, :maximum => 255 + validates_length_of :rev_rec_code, :maximum => 70 + validates_datetime_of :rev_rec_start_date, :allow_nil => true + validates_datetime_of :service_end_date, :allow_nil => true + validates_datetime_of :service_start_date + validates_length_of :sku, :maximum => 255 validates_numericality_of :unit_price - validates_length_of :uom, :maximum => 255 - validates_length_of :updated_by_id, :maximum => 32 + validates_length_of :uom, :maximum => 255 + validates_length_of :updated_by_id, :maximum => 32 define_attributes do read_only :charge_description, :charge_name, :charge_number, :created_by_id, :created_date, :invoice_id, :product_description, :quantity, :subscription_number, :updated_by_id, :updated_date - deferred_attributes :product_rate_plan_charge_id end end end diff --git a/lib/zuora/objects/invoice_item_adjustment.rb b/lib/zuora/objects/invoice_item_adjustment.rb index 11126d9e..b08b40e7 100644 --- a/lib/zuora/objects/invoice_item_adjustment.rb +++ b/lib/zuora/objects/invoice_item_adjustment.rb @@ -6,7 +6,7 @@ class InvoiceItemAdjustment < Base validates_presence_of :amount, :type validates_length_of :accounting_code, :maximum => 100 - validates_date_of :adjustment_date, :allow_nil => true + validates_datetime_of :adjustment_date, :allow_nil => true validates_length_of :adjustment_number, :maximum => 50 validates_numericality_of :amount validates_length_of :cancelled_by_id, :maximum => 32 @@ -22,8 +22,8 @@ class InvoiceItemAdjustment < Base validates_presence_of :invoice_number, :if => Proc.new { |ia| ia.invoice_id.nil? } validates_length_of :invoice_number, :maximum => 255 validates_length_of :reference_id, :maximum => 60, :allow_nil => true - validates_date_of :service_end_date - validates_date_of :service_start_date + validates_datetime_of :service_end_date + validates_datetime_of :service_start_date validates_length_of :source_id, :maximum => 32, :allow_nil => true validates_inclusion_of :source_type, :in => %w(InvoiceDetail Tax) validates_inclusion_of :status, :in => %w(Canceled Processed) diff --git a/lib/zuora/objects/invoice_payment.rb b/lib/zuora/objects/invoice_payment.rb index 040b52cb..63a0055f 100644 --- a/lib/zuora/objects/invoice_payment.rb +++ b/lib/zuora/objects/invoice_payment.rb @@ -1,18 +1,18 @@ -module Zuora::Objects - class InvoicePayment < Base - belongs_to :invoice - belongs_to :payment +#module Zuora::Objects + #class InvoicePayment < Base + #belongs_to :invoice + #belongs_to :payment - validates_presence_of :amount, :invoice_id, :payment_id - validates_numericality_of :amount - validates_length_of :created_by_id, :maximum => 32 - # validates_datetime_of :created_date, :allow_nil => true - validates_numericality_of :refund_amount - validates_length_of :updated_by_id, :maximum => 32 - # validates_datetime_of :update_date, :allow_nil => true + #validates_presence_of :amount, :invoice_id, :payment_id + #validates_numericality_of :amount + #validates_length_of :created_by_id, :maximum => 32 + #validates_datetime_of :created_date, :allow_nil => true + #validates_numericality_of :refund_amount + #validates_length_of :updated_by_id, :maximum => 32 + #validates_datetime_of :update_date, :allow_nil => true - define_attributes do - read_only :created_by_id, :created_date, :updated_by_id, :updated_date - end - end -end + #define_attributes do + #read_only :created_by_id, :created_date, :updated_by_id, :updated_date + #end + #end +#end diff --git a/lib/zuora/objects/payment.rb b/lib/zuora/objects/payment.rb index f7ae432c..90beeda9 100644 --- a/lib/zuora/objects/payment.rb +++ b/lib/zuora/objects/payment.rb @@ -1,41 +1,41 @@ -module Zuora::Objects - class Payment < Base - belongs_to :account - belongs_to :invoice +#module Zuora::Objects + #class Payment < Base + #belongs_to :account + #belongs_to :invoice - validates_presence_of :account_id, :amount, :effective_date, :gateway_state, - :payment_method_id, :status, :type + #validates_presence_of :account_id, :amount, :effective_date, :gateway_state, + #:payment_method_id, :status, :type - validates_length_of :accounting_code, :maximum => 100, :allow_nil => true - validates_numericality_of :amount - validates_numericality_of :applied_credit_balance_amount - validates_numericality_of :applied_invoice_amount - validates_length_of :auth_transaction_id, :maximum => 50, :allow_nil => true - validates_length_of :bank_identification_number, :maximum => 6, :allow_nil => true - # validates_date_of :cancelled_on, :allow_nil => true - validates_length_of :comment, :maximum => 255, :allow_nil => true - validates_length_of :created_by_id, :maximum => 32, :allow_nil => true - validates_date_of :effective_date - validates_length_of :gateway_order_id, :maximum => 70, :allow_nil => true - validates_inclusion_of :gateway_state, :in => %w(NotSubmitted Submitted Settled MarkedForSubmission) - # validates_datetime_of :marked_for_submission_on, :allow_nil => true - validates_length_of :payment_number, :maximum => 32, :allow_nil => true - validates_length_of :reference_id, :maximum => 30, :allow_nil => true - validates_numericality_of :refund_amount, :allow_nil => true - validates_length_of :second_payment_reference_id, :maximum => 60, :allow_nil => true - # validates_date_of :settled_on, :allow_nil => true - validates_length_of :soft_descriptor, :maximum => 35, :allow_nil => true - validates_length_of :soft_descriptor_phone, :maximum => 20, :allow_nil => true - validates_inclusion_of :status, :in => %w(Canceled Draft Error Posted Processing Processed Voided) - # validates_date_of :submitted_on, :allow_nil => true - validates_inclusion_of :transferred_to_accouning, :allow_nil => true, :in => %w(Processing Yes Error Ignore) - validates_inclusion_of :type, :in => %w(External Electronic) - validates_length_of :updated_by_id, :maximum => 32 - # validates_datetime_of :updated_date + #validates_length_of :accounting_code, :maximum => 100, :allow_nil => true + #validates_numericality_of :amount + #validates_numericality_of :applied_credit_balance_amount + #validates_numericality_of :applied_invoice_amount + #validates_length_of :auth_transaction_id, :maximum => 50, :allow_nil => true + #validates_length_of :bank_identification_number, :maximum => 6, :allow_nil => true + #validates_date_of :cancelled_on, :allow_nil => true + #validates_length_of :comment, :maximum => 255, :allow_nil => true + #validates_length_of :created_by_id, :maximum => 32, :allow_nil => true + #validates_datetime_of :effective_date + #validates_length_of :gateway_order_id, :maximum => 70, :allow_nil => true + #validates_inclusion_of :gateway_state, :in => %w(NotSubmitted Submitted Settled MarkedForSubmission) + #validates_datetime_of :marked_for_submission_on, :allow_nil => true + #validates_length_of :payment_number, :maximum => 32, :allow_nil => true + #validates_length_of :reference_id, :maximum => 30, :allow_nil => true + #validates_numericality_of :refund_amount, :allow_nil => true + #validates_length_of :second_payment_reference_id, :maximum => 60, :allow_nil => true + #validates_date_of :settled_on, :allow_nil => true + #validates_length_of :soft_descriptor, :maximum => 35, :allow_nil => true + #validates_length_of :soft_descriptor_phone, :maximum => 20, :allow_nil => true + #validates_inclusion_of :status, :in => %w(Canceled Draft Error Posted Processing Processed Voided) + #validates_date_of :submitted_on, :allow_nil => true + #validates_inclusion_of :transferred_to_accouning, :allow_nil => true, :in => %w(Processing Yes Error Ignore) + #validates_inclusion_of :type, :in => %w(External Electronic) + #validates_length_of :updated_by_id, :maximum => 32 + #validates_datetime_of :updated_date - define_attributes do - read_only :bank_identification_number, :created_by_id, :created_date, :gateway_response, - :gateway_response_code, :updated_by_id, :updated_date - end - end -end + #define_attributes do + #read_only :bank_identification_number, :created_by_id, :created_date, :gateway_response, + #:gateway_response_code, :updated_by_id, :updated_date + #end + #end +#end diff --git a/lib/zuora/objects/payment_method.rb b/lib/zuora/objects/payment_method.rb index 28021b31..14534351 100644 --- a/lib/zuora/objects/payment_method.rb +++ b/lib/zuora/objects/payment_method.rb @@ -2,7 +2,7 @@ module Zuora::Objects class PaymentMethod < Base belongs_to :account - # validates_presence_of :account_id, :unless => Proc.new { |contact| contact.new_record? } + # validates_presence_of :account_id # Generic Validations validates_inclusion_of :type, :in => %w(ACH BankTransfer Cash Check CreditCard CreditCardReferenceTransaction DebitCard Other PayPal WireTransfer) @@ -23,7 +23,7 @@ class PaymentMethod < Base validates_length_of :credit_card_postal_code, :maximum => 20, :if => :card? validates_length_of :credit_card_country, :maximum => 40, :allow_nil => true, :if => :card? validates_numericality_of :credit_card_expiration_month, :integer_only => true, :within => 1..12, :if => :card? - validates_numericality_of :credit_card_expiration_year, :integer_only => true, :greater_than_or_equal_to => lambda{ |e| Date.today.year }, :if => :card? + validates_numericality_of :credit_card_expiration_year, :integer_only => true, :greater_than => lambda{|e| Date.today.year }, :if => :card? validates_length_of :credit_card_holder_name, :maximum => 50, :if => :card? validates_length_of :credit_card_number, :maximum => 16, :if => :card? validates_inclusion_of :credit_card_type, :in => %w(AmericanExpress Discover MasterCard Visa), :if => :card? diff --git a/lib/zuora/objects/product.rb b/lib/zuora/objects/product.rb index 5e4ec649..ea44d8f6 100644 --- a/lib/zuora/objects/product.rb +++ b/lib/zuora/objects/product.rb @@ -3,11 +3,11 @@ class Product < Base has_many :product_rate_plans validates_inclusion_of :category, :in => ['DefaultCatalog'], :allow_nil => true - validates_length_of :description, :maximum => 500, :allow_nil => true + validates_length_of :description, :maximum => 500, :allow_nil => true - validates_date_of :effective_start_date, :effective_end_date - validates_length_of :name, :maximum => 100, :allow_nil => true - validates_length_of :sku, :maximum => 50, :allow_nil => true + validates_date_of :effective_start_date, :effective_end_date + validates_length_of :name, :maximum => 100, :allow_nil => true + validates_length_of :sku, :maximum => 50, :allow_nil => true define_attributes do read_only :created_by_id, :created_date, :updated_by_id, :updated_date diff --git a/lib/zuora/objects/product_rate_plan.rb b/lib/zuora/objects/product_rate_plan.rb index 401d580c..d5f40a04 100644 --- a/lib/zuora/objects/product_rate_plan.rb +++ b/lib/zuora/objects/product_rate_plan.rb @@ -4,12 +4,11 @@ class ProductRatePlan < Base has_many :product_rate_plan_charges validates_length_of :description, :maximum => 500, :allow_nil => true - validates_date_of :effective_start_date, :effective_end_date + validates_datetime_of :effective_start_date, :effective_end_date validates_length_of :name, :maximum => 100, :allow_nil => true define_attributes do - read_only :updated_by_id, :updated_date, :created_by_id, :created_date, :active_currencies - defer :active_currencies + read_only :updated_by_id, :updated_date, :created_by_id, :created_date end end end diff --git a/lib/zuora/objects/product_rate_plan_charge.rb b/lib/zuora/objects/product_rate_plan_charge.rb index 7dd9904f..7b9da93e 100644 --- a/lib/zuora/objects/product_rate_plan_charge.rb +++ b/lib/zuora/objects/product_rate_plan_charge.rb @@ -37,6 +37,7 @@ class ProductRatePlanCharge < Base validates_numericality_of :bill_cycle_day, :only_integer => true, :allow_nil => true validates_inclusion_of :overage_calculation_option, :in => OVERAGE_CALCULATION_OPTIONS, :allow_nil => true validates_inclusion_of :overage_unused_units_credit_option, :in => OVERAGE_UNUSED_UNITS_CREDIT_OPTIONS, :allow_nil => true + validates_inclusion_of :price_increase_option, :in => PRICE_INCREASE_OPTIONS, :allow_nil => true validates_numericality_of :price_increase_percentage, :only_integer => true, :less_than_or_equal_to => 100, :greater_than_or_equal_to => -100, :allow_nil => true validates_inclusion_of :rev_rec_trigger_condition, :in => REV_REC_TRIGGER_CONDITIONS, :allow_nil => true validates_inclusion_of :smoothing_model, :in => SMOOTHING_MODELS @@ -45,7 +46,7 @@ class ProductRatePlanCharge < Base validates_inclusion_of :use_discount_specific_accounting_code, :in => [true, false], :allow_nil => true define_attributes do - read_only :created_by_id, :created_date, :updated_by_id, :update_date + read_only :created_by_id, :created_date, :updated_by_id, :update_date complex :product_rate_plan_charge_tier_data => :product_rate_plan_charge_tiers end end diff --git a/lib/zuora/objects/rate_plan_charge.rb b/lib/zuora/objects/rate_plan_charge.rb index 18b212eb..5122aa54 100644 --- a/lib/zuora/objects/rate_plan_charge.rb +++ b/lib/zuora/objects/rate_plan_charge.rb @@ -7,10 +7,10 @@ class RatePlanCharge < Base belongs_to :original, :class_name => 'RatePlanCharge' belongs_to :product_rate_plan_charge belongs_to :rate_plan - + has_many :rate_plan_charge_tiers - CHARGE_MODELS = [ + CHARGE_MODELS = [ "Flat Fee Pricing", "Per Unit Pricing", "Overage Pricing", @@ -31,7 +31,7 @@ class RatePlanCharge < Base validates_numericality_of :bill_cycle_day, :only_integer => true, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 31, :allow_nil => true validates_inclusion_of :bill_cycle_type, :allow_nil => true, :in => %w(DefaultFromCustomer SpecificDayofMonth SubscriptionStartDay ChargeTriggerDay) validates_inclusion_of :billing_period_alignment, :allow_nil => true, :in => %w(AlignToCharge AlignToSubscriptionStart AlignToTermStart) - validates_date_of :charged_through_date, :allow_nil => true + validates_datetime_of :charged_through_date, :allow_nil => true validates_inclusion_of :charge_model, :allow_nil => true, :in => CHARGE_MODELS validates_length_of :charge_number, :maximum => 50 # String validates_inclusion_of :charge_type, :in => %w(OneTime Recurring Usage) @@ -41,8 +41,8 @@ class RatePlanCharge < Base validates_numericality_of :discount_percentage, :allow_nil => true, :greater_than => 0 validates_numericality_of :dmrc, :allow_nil => true validates_numericality_of :dtcv, :allow_nil => true - validates_date_of :effective_end_date - validates_date_of :effective_start_date + validates_datetime_of :effective_end_date + validates_datetime_of :effective_start_date validates_numericality_of :included_units, :greater_than => 0, :if => Proc.new { |rpc| ['Overage','Tiered with Overage Pricing'].include?(rpc.charge_model) } validates_inclusion_of :is_last_segment, :in => [true, false], :allow_nil => true validates_numericality_of :mrr, :allow_nil => true @@ -54,12 +54,12 @@ class RatePlanCharge < Base validates_inclusion_of :overage_unused_units_credit_option, :allow_nil => true, :in => %w(NoCredit CreditBySpecificRate), :if => Proc.new { |rpc| ['Overage','Tiered with Overage Pricing'].include?(rpc.charge_model) } validates_numericality_of :price, :allow_nil => true validates_numericality_of :price_increase_percentage, :less_than_or_equal_to => 100, :greater_than_or_equal_to => -100, :allow_nil => true - validates_date_of :processed_through_date, :allow_nil => true + validates_datetime_of :processed_through_date, :allow_nil => true validates_numericality_of :quantity, :allow_nil => true, :greater_than_or_equal_to => 0 validates_numericality_of :rollover_balance, :allow_nil => true validates_numericality_of :segment, :integer_only => true, :greater_than_or_equal_to => 1 validates_numericality_of :tcv - validates_date_of :trigger_date, :allow_nil => true + validates_datetime_of :trigger_date, :allow_nil => true validates_inclusion_of :trigger_event, :in => %w(ContractEffective CustomerAcceptance ServiceActivation SpecificDate) validates_numericality_of :unused_units_credit_rates, :if => Proc.new { |rpc| ['Overage','Tiered with Overage Pricing'].include?(rpc.charge_model) } validates_numericality_of :up_to_periods, :integer_only => true, :allow_nil => true diff --git a/lib/zuora/objects/refund.rb b/lib/zuora/objects/refund.rb index 62b57fdb..0090f660 100644 --- a/lib/zuora/objects/refund.rb +++ b/lib/zuora/objects/refund.rb @@ -1,36 +1,35 @@ -module Zuora::Objects - class Refund < Base - belongs_to :account - belongs_to :payment - belongs_to :payment_method +#module Zuora::Objects + #class Refund < Base + #belongs_to :account + #belongs_to :payment + #belongs_to :payment_method - validates_presence_of :amount, :type + #validates_presence_of :amount, :type - validates_length_of :accounting_code, :maximum => 100 - validates_numericality_of :amount - validates_length_of :comment, :maximum => 255 - validates_length_of :created_by_id, :maximum => 32 - # validates_datetime_of :created_date, :allow_nil => true - validates_length_of :gateway_response, :maximum => 500 - validates_length_of :gateway_response_code, :maximum => 20 - validates_inclusion_of :method_type, :in => %w(ACH Cash Check CreditCard Other PayPal WireTransfer DebitCard CreditCardReferenceTransaction) - validates_length_of :payment_method_id, :maximum => 60 - # validates_date_of :refund_date - # validates_datetime_of :refund_transaction_time, :allow_nil => true - validates_length_of :soft_descriptor, :maximum => 35, :allow_nil => true - validates_length_of :soft_descriptor_phone, :maximum => 20, :allow_nil => true - validates_inclusion_of :source_type, :in => %w(Payment CreditBalance), :allow_nil => true - validates_inclusion_of :status, :in => %w(Canceled Error Processed Processing), :allow_nil => true - validates_inclusion_of :transferred_to_accouning, :allow_nil => true, :in => %w(Processing Yes Error Ignore) - validates_inclusion_of :type, :in => %w(Electronic External) - validates_length_of :updated_by_id, :maximum => 32 - # validates_datetime_of :update_date, :allow_nil => true + #validates_length_of :accounting_code, :maximum => 100 + #validates_numericality_of :amount + #validates_length_of :comment, :maximum => 255 + #validates_length_of :created_by_id, :maximum => 32 + #validates_datetime_of :created_date, :allow_nil => true + #validates_length_of :gateway_response, :maximum => 500 + #validates_length_of :gateway_response_code, :maximum => 20 + #validates_inclusion_of :method_type, :in => %w(ACH Cash Check CreditCard Other PayPal WireTransfer DebitCard CreditCardReferenceTransaction) + #validates_length_of :payment_method_id, :maximum => 60 + #validates_datetime_of :refund_date + #validates_datetime_of :refund_transaction_time, :allow_nil => true + #validates_length_of :soft_descriptor, :maximum => 35, :allow_nil => true + #validates_length_of :soft_descriptor_phone, :maximum => 20, :allow_nil => true + #validates_inclusion_of :source_type, :in => %w(Payment CreditBalance), :allow_nil => true + #validates_inclusion_of :status, :in => %w(Canceled Error Processed Processing), :allow_nil => true + #validates_inclusion_of :transferred_to_accouning, :allow_nil => true, :in => %w(Processing Yes Error Ignore) + #validates_inclusion_of :type, :in => %w(Electronic External) + #validates_length_of :updated_by_id, :maximum => 32 + #validates_datetime_of :update_date, :allow_nil => true - define_attributes do - read_only :accounting_code, :created_by_id, :created_date, :gateway_response, - :gateway_response_code, :reference_id, :refund_number, :refund_transaction_time, - :status, :updated_by_id, :updated_date - deferred_attributes :gateway_option_data, :payment_id, :refund_invoice_payment_data - end - end -end + #define_attributes do + #read_only :accounting_code, :created_by_id, :created_date, :gateway_response, + #:gateway_response_code, :reference_id, :refund_number, :refund_transaction_time, + #:status, :updated_by_id, :updated_date + #end + #end +#end diff --git a/lib/zuora/objects/refund_invoice_payment.rb b/lib/zuora/objects/refund_invoice_payment.rb index 952a24bd..c12e9220 100644 --- a/lib/zuora/objects/refund_invoice_payment.rb +++ b/lib/zuora/objects/refund_invoice_payment.rb @@ -1,18 +1,18 @@ -module Zuora::Objects - class RefundInvoicePayment < Base - belongs_to :invoice_payment - belongs_to :refund +#module Zuora::Objects + #class RefundInvoicePayment < Base + #belongs_to :invoice_payment + #belongs_to :refund - validates_presence_of :invoice_payment_id, :refund_amount, :refund_id + #validates_presence_of :invoice_payment_id, :refund_amount, :refund_id - validates_length_of :created_by_id, :maximum => 32 - # validates_datetime_of :created_date, :allow_nil => true - validates_length_of :updated_by_id, :maximum => 32 - # validates_datetime_of :update_date, :allow_nil => true + #validates_length_of :created_by_id, :maximum => 32 + #validates_datetime_of :created_date, :allow_nil => true + #validates_length_of :updated_by_id, :maximum => 32 + #validates_datetime_of :update_date, :allow_nil => true - define_attributes do - read_only :created_by_id, :created_date, :invoice_payment_id, :refund_amount, - :refund_id, :updated_by_id, :updated_date - end - end -end + #define_attributes do + #read_only :created_by_id, :created_date, :invoice_payment_id, :refund_amount, + #:refund_id, :updated_by_id, :updated_date + #end + #end +#end diff --git a/lib/zuora/objects/subscribe_request.rb b/lib/zuora/objects/subscribe_request.rb index 0dd56996..b1b5babd 100644 --- a/lib/zuora/objects/subscribe_request.rb +++ b/lib/zuora/objects/subscribe_request.rb @@ -8,7 +8,6 @@ class SubscribeRequest < Base attr_accessor :product_rate_plan store_accessors :subscribe_options - store_accessors :preview_options validate do |request| request.must_have_usable(:account) @@ -29,12 +28,9 @@ def must_have_new(ref) # used to validate nested objects def must_have_usable(ref) obj = self.send(ref) - return errors[ref] << "must be provided" if obj.blank? - obj = obj.is_a?(Array) ? obj : [obj] - obj.each do |object| - if object.new_record? || object.changed? - errors[ref] << "is invalid" unless object.valid? - end + return errors[ref] << "must be provided" if obj.nil? + if obj.new_record? || obj.changed? + errors[ref] << "is invalid" unless obj.valid? end end @@ -50,16 +46,16 @@ def create def apply_response(response_hash, type) result = response_hash[type][:result] if result[:success] - subscription.account_id = result[:account_id] subscription.id = result[:subscription_id] subscription.name = result[:subscription_number] subscription.clear_changed_attributes! @previously_changed = changes - clear_changes_information + @changed_attributes.clear + return true else self.errors.add(:base, result[:errors][:message]) + return false end - return result end # # TODO: Restructute an intermediate class that includes diff --git a/lib/zuora/objects/subscription.rb b/lib/zuora/objects/subscription.rb index e3e4eb3a..2e6242ad 100644 --- a/lib/zuora/objects/subscription.rb +++ b/lib/zuora/objects/subscription.rb @@ -12,18 +12,18 @@ class Subscription < Base :renewal_term validates_inclusion_of :auto_renew, :in => [true, false] - validates_date_of :cancelled_date, :allow_nil => true - validates_date_of :contract_acceptance_date, :allow_nil => true - validates_date_of :contract_effective_date + validates_datetime_of :cancelled_date, :allow_nil => true + validates_datetime_of :contract_acceptance_date, :allow_nil => true + validates_datetime_of :contract_effective_date validates_numericality_of :initial_term, :only_integer => true, :minimum => 1 validates_inclusion_of :is_invoice_separate, :in => [true, false], :allow_nil => true validates_length_of :name, :maximum => 100 validates_length_of :notes, :maximum => 500, :allow_nil => true validates_datetime_of :original_created_date, :allow_nil => true validates_numericality_of :renewal_term, :only_integer => true - validates_date_of :service_activation_date, :allow_nil => true - validates_date_of :term_end_date, :allow_nil => true - validates_date_of :term_start_date + validates_datetime_of :service_activation_date, :allow_nil => true + validates_datetime_of :term_end_date, :allow_nil => true + validates_datetime_of :term_start_date validates_inclusion_of :term_type, :in => ['TERMED', 'EVERGREEN'], :allow_nil => true define_attributes do diff --git a/lib/zuora/soap_connector.rb b/lib/zuora/soap_connector.rb index 8b1a51c2..0eb942f6 100644 --- a/lib/zuora/soap_connector.rb +++ b/lib/zuora/soap_connector.rb @@ -154,16 +154,6 @@ def current_client Zuora::Api.instance end - def generate - Zuora::Api.instance.request(:generate) do |xml| - xml.__send__(zns, :zObjects, 'xsi:type' => "#{ons}:#{remote_name}") do |a| - @model.to_hash.each do |k, v| - a.__send__(ons, k.to_s.zuora_camelize.to_sym, convert_value(v)) unless v.nil? - end - end - end - end - protected # Zuora doesn't like the default string format of ruby dates/times @@ -174,7 +164,7 @@ def convert_value(value) value end end - + # generate complex objects for inclusion when creating and updating records def generate_complex_objects(builder, action) @model.complex_attributes.each do |var, scope| diff --git a/lib/zuora/validations.rb b/lib/zuora/validations.rb index a09c1233..647fdbb3 100644 --- a/lib/zuora/validations.rb +++ b/lib/zuora/validations.rb @@ -8,16 +8,16 @@ def self.included(base) class DateTimeValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless [DateTime, Time].any? { |klass| value.is_a?(klass) } - record.errors.add(attribute, (options[:message] || "is not a valid datetime")) + unless value.is_a?(Date) + record.errors[attribute] << (options[:message] || "is not a valid datetime") end end end class DateValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless [Date].any? { |klass| value.is_a?(klass) } - record.errors.add(attribute, (options[:message] || "is not a valid date")) + unless value.is_a?(Date) + record.errors[attribute] << (options[:message] || "is not a valid date") end end end From a5646f16c3080bb6b257bd557b9fadec97bb943c Mon Sep 17 00:00:00 2001 From: Angela Silva Date: Mon, 22 Jul 2024 11:14:49 +0100 Subject: [PATCH 2/4] fixing specs --- lib/zuora/api.rb | 3 +- lib/zuora/attributes.rb | 23 +- lib/zuora/objects/amendment.rb | 4 +- lib/zuora/objects/base.rb | 4 +- lib/zuora/objects/subscribe_request.rb | 3 +- spec/factories/payment_methods.rb | 2 +- ...ayment_method_credit_card_find_success.xml | 2 +- spec/spec_helper.rb | 3 +- spec/zuora/api_spec.rb | 11 +- spec/zuora/objects/account_spec.rb | 256 +++-- spec/zuora/objects/base_spec.rb | 8 - spec/zuora/objects/payment_method_spec.rb | 100 +- .../objects/product_rate_plan_charge_spec.rb | 127 ++- spec/zuora/objects/subscribe_request_spec.rb | 200 ++-- spec/zuora/validations_spec.rb | 10 +- wsdl/{zuora.a.78.0.wsdl => zuora.a.38.0.wsdl} | 939 +++--------------- zuora.gemspec | 1 + 17 files changed, 574 insertions(+), 1122 deletions(-) rename wsdl/{zuora.a.78.0.wsdl => zuora.a.38.0.wsdl} (61%) diff --git a/lib/zuora/api.rb b/lib/zuora/api.rb index 74b7b350..3d3c2c4e 100644 --- a/lib/zuora/api.rb +++ b/lib/zuora/api.rb @@ -59,7 +59,6 @@ def request(method, options={}, &block) options[:message] = xml.target! end options[:soap_header] = { 'env:SessionHeader' => { 'zns:Session' => self.session.try(:key) } } - client.call(method, options) rescue Savon::SOAPFault, IOError => e raise Zuora::Fault.new(:message => e.message) @@ -101,7 +100,7 @@ def client wsdl: config&.wsdl_path ? config.wsdl_path : File.expand_path('../../../wsdl/zuora.a.38.0.wsdl', __FILE__), ssl_verify_mode: :none, soap_version: SOAP_VERSION, - log: log: config&.log || true, + log: config&.log || true, filters: [:password] ) end diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index ccfbc645..6f44f8f7 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -42,16 +42,19 @@ def define_attributes(&block) # set up the instance variable for the new assoc collection # for new records, but call the original one for existing # records and cache/return the result for subsequent calls. - class_eval <<-EVAL - def #{scope}_with_complex - if new_record? || @#{scope}_cached - @#{scope} ||= [] - else - @#{scope}_cached = true - @#{scope} = #{scope}_without_complex + class_eval <<~EVAL + prepend( + Module.new do + def #{scope} + if new_record? || @#{scope}_cached + @#{scope} ||= [] + else + @#{scope}_cached = true + @#{scope} = super + end + end end - end - alias_method_chain :#{scope}, :complex + ) EVAL end end @@ -212,7 +215,7 @@ def clear_changed_attributes! @changed_attributes = {} self end - + # the name to use when referencing remote Zuora objects def remote_name self.class.name.base_name diff --git a/lib/zuora/objects/amendment.rb b/lib/zuora/objects/amendment.rb index b8b8441e..2bf92c28 100644 --- a/lib/zuora/objects/amendment.rb +++ b/lib/zuora/objects/amendment.rb @@ -36,7 +36,7 @@ def apply_percentage_discount apply_percentage_discount_response(result.to_hash, :amend_response) end - private + private def apply_percentage_discount_response(response_hash, type) result = response_hash[type][:results] @@ -45,7 +45,7 @@ def apply_percentage_discount_response(response_hash, type) self.invoice_id = result[:invoice_id] self.payment_transaction_number = result[:payment_transaction_number] @previously_changed = changes - @changed_attributes.clear + clear_changes_information return true else raise StandardError.new(result[:errors][:message]) diff --git a/lib/zuora/objects/base.rb b/lib/zuora/objects/base.rb index a1f17203..1e9a90f0 100644 --- a/lib/zuora/objects/base.rb +++ b/lib/zuora/objects/base.rb @@ -40,7 +40,7 @@ def reload! self.send("#{k}=", v) } @previously_changed = changes - @changed_attributes.clear + clear_changes_information self end @@ -172,7 +172,7 @@ def apply_response(response_hash, type) if result[:success] self.id = result[:id] @previously_changed = changes - @changed_attributes.clear + clear_changes_information return true else raise StandardError.new(result[:errors][:message]) diff --git a/lib/zuora/objects/subscribe_request.rb b/lib/zuora/objects/subscribe_request.rb index b1b5babd..0b12f506 100644 --- a/lib/zuora/objects/subscribe_request.rb +++ b/lib/zuora/objects/subscribe_request.rb @@ -50,7 +50,7 @@ def apply_response(response_hash, type) subscription.name = result[:subscription_number] subscription.clear_changed_attributes! @previously_changed = changes - @changed_attributes.clear + clear_changes_information return true else self.errors.add(:base, result[:errors][:message]) @@ -68,4 +68,3 @@ def destroy ; end def save ; end end end - diff --git a/spec/factories/payment_methods.rb b/spec/factories/payment_methods.rb index 9d3e1309..5a21eaec 100644 --- a/spec/factories/payment_methods.rb +++ b/spec/factories/payment_methods.rb @@ -9,7 +9,7 @@ credit_card_number { "4111111111111111" } credit_card_type { "Visa" } credit_card_expiration_month { "9" } - credit_card_expiration_year { "2018" } + credit_card_expiration_year { Time.now.year + 2 } end factory :payment_method_debit_card, :parent => :payment_method_credit_card do diff --git a/spec/fixtures/responses/payment_method_credit_card_find_success.xml b/spec/fixtures/responses/payment_method_credit_card_find_success.xml index 460ef77a..fbf57647 100644 --- a/spec/fixtures/responses/payment_method_credit_card_find_success.xml +++ b/spec/fixtures/responses/payment_method_credit_card_find_success.xml @@ -1 +1 @@ -true4028e48834aa10a30134c50f40901ea74028e48834aa10a30134c50f40191ea6false4111114028e488346987860134866a562363d42012-01-09T16:40:38.000-08:00123 Testing LaneSan Francisco92018Example User************111195611CaliforniaVisa2012-01-09T16:40:38.000-08:00Approved0Active00CreditCard4028e488346987860134866a562363d42012-01-09T16:40:38.000-08:00true1 +true4028e48834aa10a30134c50f40901ea74028e48834aa10a30134c50f40191ea6false4111114028e488346987860134866a562363d42012-01-09T16:40:38.000-08:00123 Testing LaneSan Francisco92028Example User************111195611CaliforniaVisa2012-01-09T16:40:38.000-08:00Approved0Active00CreditCard4028e488346987860134866a562363d42012-01-09T16:40:38.000-08:00true1 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cfdd8623..a830cf20 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,7 @@ require 'artifice' require 'digest/md5' require 'factory_bot' +require 'timecop' Dir["#{File.dirname(__FILE__)}/../spec/support/**/*.rb"].sort.each { |ext| require ext } Dir["#{File.dirname(__FILE__)}/../spec/factories/*.rb"].sort.each { |ext| require ext } @@ -33,5 +34,3 @@ def zns def ons zuora_namespace('http://object.api.zuora.com/') end - - diff --git a/spec/zuora/api_spec.rb b/spec/zuora/api_spec.rb index 5247b947..2617ffca 100644 --- a/spec/zuora/api_spec.rb +++ b/spec/zuora/api_spec.rb @@ -3,18 +3,13 @@ describe Zuora::Api do subject { Zuora::Api.instance } - describe "configuration" do + describe 'configuration' do before do Zuora::Api.any_instance.stub(:authenticated?).and_return(true) end - it "has readable WSDL" do - File.exist?(Zuora::Api::WSDL).should be - end - - it "can be configured to use sandbox" do - Zuora.configure(:username => 'example', :password => 'test', :sandbox => true) - Zuora::Api.instance.client.globals[:endpoint].to_s.should == "https://apisandbox.zuora.com/apps/services/a/78.0" + it 'uses provided wsdl_path' do + expect(Zuora::Api.instance.client.wsdl.endpoint.to_s).to eq 'https://www.zuora.com/apps/services/a/38.0' end it "can be configured multiple times" do diff --git a/spec/zuora/objects/account_spec.rb b/spec/zuora/objects/account_spec.rb index 4df21d00..24eb1d84 100644 --- a/spec/zuora/objects/account_spec.rb +++ b/spec/zuora/objects/account_spec.rb @@ -1,6 +1,11 @@ require 'spec_helper' describe Zuora::Objects::Account do + let(:account_id) { '4028e488348752ce0134876a25867cb2' } + + before do + allow_any_instance_of(Zuora::Api).to receive(:session).and_return double(key: 'session_key') + end it_should_behave_like "ActiveModel" @@ -8,9 +13,13 @@ subject.should be_a_kind_of(Zuora::Objects::Base) end - it "has defined attributes" do - subject.attributes.keys.map(&:to_s).sort.should == - ["account_number", "additional_email_addresses", "allow_invoice_edit", "auto_pay", "balance", "batch", "bcd_setting_option", "bill_cycle_day", "bill_to_id", "communication_profile_id", "created_by_id", "created_date", "crm_id", "currency", "customer_service_rep_name", "default_payment_method_id", "id", "invoice_delivery_prefs_email", "invoice_delivery_prefs_print", "invoice_template_id", "last_invoice_date", "name", "notes", "payment_gateway", "payment_term", "purchase_order_number", "sales_rep_name", "sold_to_id", "status", "tax_company_code", "tax_exempt_certificate_id", "tax_exempt_certificate_type", "tax_exempt_description", "tax_exempt_effective_date", "tax_exempt_expiration_date", "tax_exempt_issuing_jurisdiction", "tax_exempt_status", "updated_by_id", "updated_date", "vat_id"] + it 'has defined attributes' do + expect(subject.attributes.keys.map(&:to_s)).to match_array(%w(account_number additional_email_addresses + allow_invoice_edit auto_pay balance batch bcd_setting_option bill_cycle_day bill_to_id communication_profile_id + created_by_id created_date crm_id currency customer_service_rep_name default_payment_method_id id + invoice_delivery_prefs_email invoice_delivery_prefs_print invoice_template_id last_invoice_date name notes + payment_gateway payment_term purchase_order_number sales_rep_name sold_to_id status updated_by_id updated_date + )) end it "has read only attributes" do @@ -19,18 +28,20 @@ ] end - describe "Dirty support" do - it "handles newly created records" do + describe 'Dirty support' do + it 'handles newly created records' do MockResponse.responds_with(:account_create_success) do - subject.should_not be_name_changed + expect(subject).to_not be_name_changed subject.name = "Example Account" subject.account_number = "abc123" subject.currency = 'USD' subject.status = 'Draft' - subject.should be_changed - subject.changes.keys.sort.should == ["name", "auto_pay", "payment_term", "account_number", "currency", "batch", "bill_cycle_day", "status"].sort - subject.save.should == true - subject.should_not be_changed + expect(subject).to be_changed + expect(subject.changes.keys).to match_array( + %w(name auto_pay payment_term account_number currency batch bill_cycle_day status) + ) + expect(subject.save).to be true + expect(subject).to_not be_changed end end @@ -55,85 +66,107 @@ subject.class.new(:id => 42).to_hash.should include({:id => 42}) end - describe "finding a remote object" do - it "succeeds" do + describe 'finding a remote object' do + it 'succeeds' do MockResponse.responds_with(:account_find_success) do - Zuora::Api.instance.should be_authenticated - account_id = '4028e488348752ce0134876a25867cb2' + expect(Zuora::Api.instance.client).to receive(:call).with( + :query, + { + message: 'select AccountNumber, AdditionalEmailAddresses, AllowInvoiceEdit, AutoPay, '\ + 'Balance, Batch, BcdSettingOption, BillCycleDay, BillToId, CommunicationProfileId, CreatedById, '\ + 'CreatedDate, CrmId, Currency, CustomerServiceRepName, DefaultPaymentMethodId, '\ + 'InvoiceDeliveryPrefsEmail, InvoiceDeliveryPrefsPrint, InvoiceTemplateId, LastInvoiceDate, Name, Notes, '\ + 'PaymentGateway, PaymentTerm, PurchaseOrderNumber, SalesRepName, SoldToId, Status, UpdatedById, '\ + "UpdatedDate, Id from Account where Id = '#{account_id}'", + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + expect(Zuora::Api.instance).to be_authenticated account = Zuora::Objects::Account.find(account_id) - account.should be_a_kind_of(Zuora::Objects::Account) - account.id.should == account_id - account.name.should == 'FooBar' - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:query/#{zns}:queryString"). - with_value(/select .+ from Account where Id = '4028e488348752ce0134876a25867cb2'/) + expect(account).to be_a_kind_of(Zuora::Objects::Account) + expect(account.id).to eq account_id + expect(account.name).to eq 'FooBar' end end - it "supports hash based lookups" do + it 'supports hash based lookups' do MockResponse.responds_with(:account_find_success) do - Zuora::Objects::Account.where(:id => 'test', :name => 'Bob') - xml = Zuora::Api.instance.last_request - ns = zuora_namespace('http://api.zuora.com/') - xml.should have_xml("//env:Body/#{zns}:query/#{zns}:queryString"). - with_value(/select .+ from Account where Id = 'test' and Name = 'Bob'/) + expect(Zuora::Api.instance.client).to receive(:call).with( + :query, + { + message: 'select AccountNumber, AdditionalEmailAddresses, AllowInvoiceEdit, AutoPay, '\ + 'Balance, Batch, BcdSettingOption, BillCycleDay, BillToId, CommunicationProfileId, CreatedById, '\ + 'CreatedDate, CrmId, Currency, CustomerServiceRepName, DefaultPaymentMethodId, '\ + 'InvoiceDeliveryPrefsEmail, InvoiceDeliveryPrefsPrint, InvoiceTemplateId, LastInvoiceDate, Name, Notes, '\ + 'PaymentGateway, PaymentTerm, PurchaseOrderNumber, SalesRepName, SoldToId, Status, UpdatedById, '\ + "UpdatedDate, Id from Account where Id = 'test' and Name = 'Bob'", + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + Zuora::Objects::Account.where(id: 'test', name: 'Bob') end end end - describe "updating a remote object" do - it "succeeds" do + describe 'updating a remote object' do + it 'succeeds' do account = nil MockResponse.responds_with(:account_find_success) do - account_id = '4028e488348752ce0134876a25867cb2' + expect(Zuora::Api.instance.client).to receive(:call).with( + :query, + { + message: 'select AccountNumber, AdditionalEmailAddresses, AllowInvoiceEdit, AutoPay, '\ + 'Balance, Batch, BcdSettingOption, BillCycleDay, BillToId, CommunicationProfileId, CreatedById, '\ + 'CreatedDate, CrmId, Currency, CustomerServiceRepName, DefaultPaymentMethodId, '\ + 'InvoiceDeliveryPrefsEmail, InvoiceDeliveryPrefsPrint, InvoiceTemplateId, LastInvoiceDate, Name, Notes, '\ + 'PaymentGateway, PaymentTerm, PurchaseOrderNumber, SalesRepName, SoldToId, Status, UpdatedById, '\ + "UpdatedDate, Id from Account where Id = '#{account_id}'", + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original account = Zuora::Objects::Account.find(account_id) end MockResponse.responds_with(:account_update_success) do - old_name = account.name + expect(Zuora::Api.instance.client).to receive(:call).with( + :update, + { + message: '4028e488348752ce0134876a25867cb2'\ + 'test-1falseBatch1'\ + '1USDFooMax'\ + 'Due Upon ReceiptDraft'\ + '', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original account.name = 'FooMax' - account.should be_changed - account.name_was.should == old_name - account.save.should == true - account.should_not be_changed + expect(account).to be_changed + expect(account.save).to eq true + expect(account).to_not be_changed end - - xml = Zuora::Api.instance.last_request - zns = zuora_namespace('http://api.zuora.com/') - xml.should have_xml("//env:Body/#{zns}:update/#{zns}:zObjects/#{ons}:Id"). - with_value('4028e488348752ce0134876a25867cb2') - xml.should have_xml("//env:Body/#{zns}:update/#{zns}:zObjects/#{ons}:Name"). - with_value('FooMax') end end - describe "creating a remote object" do - it "should succeed and set local id" do + describe 'creating a remote object' do + it 'should succeed and set local id' do MockResponse.responds_with(:account_create_success) do + expect(Zuora::Api.instance.client).to receive(:call).with( + :create, + { + message: 'example-test-10'\ + 'falseBatch11'\ + 'USDExample Test AccountDue Upon '\ + 'ReceiptDraft', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original a = Zuora::Objects::Account.new a.account_number = 'example-test-10' a.name = 'Example Test Account' a.batch = 'Batch1' - a.should be_valid - a.save.should == true - a.id.should == '4028e4873491cc7701349574bfcb6af6' - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:Name"). - with_value('Example Test Account') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:Batch"). - with_value('Batch1') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:AutoPay"). - with_value('false') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:BillCycleDay"). - with_value('1') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:Currency"). - with_value('USD') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:PaymentTerm"). - with_value('Due Upon Receipt') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:Status"). - with_value('Draft') + expect(a).to be_valid + expect(a.save).to be true + expect(a.id).to eq '4028e4873491cc7701349574bfcb6af6' end end @@ -155,57 +188,96 @@ end end - describe "deleting remote objects" do - it "should succeed" do + describe 'deleting remote objects' do + it 'should succeed' do MockResponse.responds_with(:account_delete_success) do id = '4028e4873491cc7701349574bfcb6af6' - a = Zuora::Objects::Account.new(:id => id) - a.should be_persisted - a.destroy.should == true - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:delete/#{zns}:type"). - with_value('Account') - xml.should have_xml("//env:Body/#{zns}:delete/#{zns}:ids"). - with_value(id) + expect(Zuora::Api.instance.client).to receive(:call).with( + :delete, + { + message: "Account#{id}", + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + a = Zuora::Objects::Account.new(id: id) + expect(a).to be_persisted + expect(a.destroy).to be true end end end - describe "querying remote objects" do - it "returns multiple objects via where" do + describe 'querying remote objects' do + it 'returns multiple objects via where' do MockResponse.responds_with(:account_query_multiple_success) do + expect(Zuora::Api.instance.client).to receive(:call).with( + :query, + { + message: 'select AccountNumber, AdditionalEmailAddresses, AllowInvoiceEdit, AutoPay, '\ + 'Balance, Batch, BcdSettingOption, BillCycleDay, BillToId, CommunicationProfileId, CreatedById, '\ + 'CreatedDate, CrmId, Currency, CustomerServiceRepName, DefaultPaymentMethodId, InvoiceDeliveryPrefsEmail'\ + ', InvoiceDeliveryPrefsPrint, InvoiceTemplateId, LastInvoiceDate, Name, Notes, PaymentGateway, '\ + 'PaymentTerm, PurchaseOrderNumber, SalesRepName, SoldToId, Status, UpdatedById, UpdatedDate, Id from '\ + "Account where AccountNumber like 'test%'", + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original accounts = Zuora::Objects::Account.where("AccountNumber like 'test%'") - accounts.size.should == 2 - accounts.map(&:id).sort.should == ['4028e4883491c509013492cd13e2455f','4028e488348752ce0134876a25867cb2'].sort - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:query/#{zns}:queryString"). - with_value(/select .+ from Account where AccountNumber like 'test%'/) + expect(accounts.size).to eq 2 + expect(accounts.map(&:id)).to match_array(%w(4028e4883491c509013492cd13e2455f 4028e488348752ce0134876a25867cb2)) end end end - describe "associations" do - it "should have many contacts and reflect back" do + describe 'associations' do + let(:id) { '4028e488348752ce0134876a25867cb2' } + it 'has many contacts and reflect back' do account, contacts, contact = nil, nil, nil MockResponse.responds_with(:account_find_success) do - account = Zuora::Objects::Account.find('4028e488348752ce0134876a25867cb2') + expect(Zuora::Api.instance.client).to receive(:call).with( + :query, + { + message: 'select AccountNumber, AdditionalEmailAddresses, AllowInvoiceEdit, AutoPay, '\ + 'Balance, Batch, BcdSettingOption, BillCycleDay, BillToId, CommunicationProfileId, CreatedById, '\ + 'CreatedDate, CrmId, Currency, CustomerServiceRepName, DefaultPaymentMethodId, InvoiceDeliveryPrefsEmail'\ + ', InvoiceDeliveryPrefsPrint, InvoiceTemplateId, LastInvoiceDate, Name, Notes, PaymentGateway, '\ + 'PaymentTerm, PurchaseOrderNumber, SalesRepName, SoldToId, Status, UpdatedById, UpdatedDate, Id from '\ + "Account where Id = '#{id}'", + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + account = Zuora::Objects::Account.find(id) end MockResponse.responds_with(:account_contacts_find_success) do + expect(Zuora::Api.instance.client).to receive(:call).with( + :query, + { + message: 'select AccountId, Address1, Address2, City, Country, CreatedById, CreatedDate, '\ + 'Fax, FirstName, HomePhone, LastName, MobilePhone, NickName, OtherPhone, OtherPhoneType, PersonalEmail, '\ + 'PostalCode, State, UpdatedById, UpdatedDate, WorkEmail, WorkPhone, Id from Contact where AccountId = '\ + "'#{id}'", + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original contacts = account.contacts - contacts.size.should == 1 - contact = contacts.first - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:query/#{zns}:queryString"). - with_value(/select .+ from Contact where AccountId = '4028e488348752ce0134876a25867cb2'/) + expect(contacts.size).to eq 1 end MockResponse.responds_with(:account_find_success) do - contact.account.id.should == account.id + expect(Zuora::Api.instance.client).to receive(:call).with( + :query, + { + message: 'select AccountNumber, AdditionalEmailAddresses, AllowInvoiceEdit, AutoPay, '\ + 'Balance, Batch, BcdSettingOption, BillCycleDay, BillToId, CommunicationProfileId, CreatedById, '\ + 'CreatedDate, CrmId, Currency, CustomerServiceRepName, DefaultPaymentMethodId, InvoiceDeliveryPrefsEmail'\ + ', InvoiceDeliveryPrefsPrint, InvoiceTemplateId, LastInvoiceDate, Name, Notes, PaymentGateway, '\ + 'PaymentTerm, PurchaseOrderNumber, SalesRepName, SoldToId, Status, UpdatedById, UpdatedDate, Id from '\ + "Account where Id = '#{id}'", + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + expect(contacts.first.account.id).to eq account.id end end end diff --git a/spec/zuora/objects/base_spec.rb b/spec/zuora/objects/base_spec.rb index 6866aef7..5739e64b 100644 --- a/spec/zuora/objects/base_spec.rb +++ b/spec/zuora/objects/base_spec.rb @@ -42,12 +42,4 @@ def initialize(model); end Zuora::Objects::Account.new(:name => "Test Name").name.should == "Test Name" end end - - describe "attributes=" do - it "should assign attributes to an existing instance from passed in hash" do - account = Zuora::Objects::Account.new(:name => "Test Name") - account.attributes = {:name => "New Name"} - account.name.should == "New Name" - end - end end diff --git a/spec/zuora/objects/payment_method_spec.rb b/spec/zuora/objects/payment_method_spec.rb index c01e496e..75096dca 100644 --- a/spec/zuora/objects/payment_method_spec.rb +++ b/spec/zuora/objects/payment_method_spec.rb @@ -4,6 +4,7 @@ describe Zuora::Objects::PaymentMethod do before :each do + allow_any_instance_of(Zuora::Api).to receive(:session).and_return double(key: 'session_key') @account = double(Zuora::Objects::Account, id: 1) end @@ -39,52 +40,45 @@ describe "validations" do describe "credit_card_expiration_year" do let(:payment_method) {Zuora::Objects::PaymentMethod.new(:type => "CreditCard")} - it "should allow this year" do + it 'does not allow this year' do payment_method.credit_card_expiration_year = Time.now.year payment_method.valid? - payment_method.errors[:credit_card_expiration_year].should_not include("must be greater than or equal to #{Time.now.year}") + expect(payment_method.errors[:credit_card_expiration_year]).to include("must be greater than #{Time.now.year}") end - it "should not allow last year" do + it 'should not allow last year' do payment_method.credit_card_expiration_year = (Time.now - 1.year).year payment_method.valid? - payment_method.errors[:credit_card_expiration_year].should include("must be greater than or equal to #{Time.now.year}") + expect(payment_method.errors[:credit_card_expiration_year]).to include("must be greater than #{Time.now.year}") end - it "should allow next year" do + it 'should allow next year' do payment_method.credit_card_expiration_year = (Time.now + 1.year).year payment_method.valid? - payment_method.errors[:credit_card_expiration_year].should_not include("must be greater than or equal to #{Time.now.year}") + expect(payment_method.errors[:credit_card_expiration_year]) + .to_not include("must be greater than #{Time.now.year}") end end end - describe "Credit Card" do - it "generates proper request xml" do + describe 'Credit Card' do + it 'generates proper request xml' do MockResponse.responds_with(:payment_method_credit_card_create_success) do + expect(Zuora::Api.instance.client).to receive(:call).with( + :create, + { + message: '1'\ + '123 Testing LaneSan Francisco'\ + '9'\ + '2025'\ + 'Example User4111111111111111'\ + '95611California'\ + 'VisaCreditCard'\ + 'true', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original FactoryBot.create(:payment_method_credit_card, :account => @account, credit_card_expiration_year: '2025') - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:Type"). - with_value('CreditCard') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:CreditCardAddress1"). - with_value('123 Testing Lane') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:CreditCardCity"). - with_value('San Francisco') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:CreditCardState"). - with_value('California') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:CreditCardPostalCode"). - with_value('95611') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:CreditCardHolderName"). - with_value('Example User') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:CreditCardNumber"). - with_value('4111111111111111') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:CreditCardType"). - with_value('Visa') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:CreditCardExpirationMonth"). - with_value('9') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:CreditCardExpirationYear"). - with_value('2025') end end @@ -99,21 +93,18 @@ context 'ACH' do it 'generates proper request xml' do MockResponse.responds_with(:payment_method_ach_create_success) do + expect(Zuora::Api.instance.client).to receive(:call).with( + :create, + { + message: '1'\ + '123456789My Checking Account'\ + '987654321BusinessChecking'\ + 'Bank of ZuoraACH'\ + 'true', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original FactoryBot.create(:payment_method_ach, account: @account) - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:Type") - .with_value('ACH') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:AchAbaCode") - .with_value('123456789') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:AchAccountName") - .with_value('My Checking Account') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:AchBankName") - .with_value('Bank of Zuora') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:AchAccountNumber") - .with_value('987654321') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:AchAccountType") - .with_value('BusinessChecking') end end @@ -128,18 +119,17 @@ context 'PayPal' do it 'generates proper request xml' do MockResponse.responds_with(:payment_method_ach_create_success) do + expect(Zuora::Api.instance.client).to receive(:call).with( + :create, + { + message: '1'\ + 'ExampleBillingAgreementIdexample@example.org'\ + 'ExpressCheckoutPayPal'\ + 'true', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original FactoryBot.create(:payment_method_paypal, account: @account) - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:Type") - .with_value('PayPal') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:PaypalBaid") - .with_value('ExampleBillingAgreementId') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:PaypalEmail") - .with_value('example@example.org') - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:PaypalType") - .with_value('ExpressCheckout') - xml.should_not have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:PaypalPreapprovalKey") end end end diff --git a/spec/zuora/objects/product_rate_plan_charge_spec.rb b/spec/zuora/objects/product_rate_plan_charge_spec.rb index ff294245..464161e6 100644 --- a/spec/zuora/objects/product_rate_plan_charge_spec.rb +++ b/spec/zuora/objects/product_rate_plan_charge_spec.rb @@ -3,6 +3,10 @@ require 'spec_helper' describe Zuora::Objects::ProductRatePlanCharge do + before do + allow_any_instance_of(Zuora::Api).to receive(:session).and_return double(key: 'session_key') + end + context 'complex association support' do it 'should have blank association for new object' do subject.product_rate_plan_charge_tiers.should == [] @@ -16,23 +20,39 @@ it 'should load remote associations when not a new record' do subject.id = 'test' - subject.should_not be_new_record + expect(subject).to_not be_new_record MockResponse.responds_with(:product_rate_plan_charge_tier_find_success) do - subject.product_rate_plan_charge_tiers.size.should == 2 + expect(Zuora::Api.instance.client).to receive(:call).with( + :query, + { + message: 'select Active, CreatedById, CreatedDate, Currency, EndingUnit, IsOveragePrice, '\ + 'Price, PriceFormat, ProductRatePlanChargeId, StartingUnit, Tier, UpdatedById, UpdatedDate, Id from '\ + "ProductRatePlanChargeTier where ProductRatePlanChargeId = 'test'", + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + expect(subject.product_rate_plan_charge_tiers.size).to eq 2 end - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:query/#{zns}:queryString"). - with_value(/select .+ from ProductRatePlanChargeTier where ProductRatePlanChargeId = 'test'/) end it 'should not include complex attributes in the request' do MockResponse.responds_with(:product_rate_plan_charge_tier_find_success) do + expect(Zuora::Api.instance.client).to receive(:call).with( + :query, + { + message: 'select AccountingCode, BillCycleDay, BillCycleType, BillingPeriod, '\ + 'BillingPeriodAlignment, ChargeModel, ChargeType, CreatedById, CreatedDate, DefaultQuantity, Description'\ + ', IncludedUnits, MaxQuantity, MinQuantity, Name, NumberOfPeriod, OverageCalculationOption, '\ + 'OverageUnusedUnitsCreditOption, PriceIncreaseOption, PriceIncreasePercentage, ProductRatePlanId, '\ + 'RevRecCode, RevRecTriggerCondition, SmoothingModel, SpecificBillingPeriod, TriggerEvent, Uom, '\ + 'UpdatedById, UpdatedDate, UseDiscountSpecificAccountingCode, Id from ProductRatePlanCharge where Id = '\ + "'example'", + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original subject.class.find('example') end - xml = Zuora::Api.instance.last_request - xml.should_not =~ /ProductRatePlanChargeTierData/ end end @@ -59,8 +79,7 @@ c.trigger_event = 'ServiceActivation' end - # new objects should have empty association - @prpc.product_rate_plan_charge_tiers.should == [] + expect(@prpc.product_rate_plan_charge_tiers).to eq [] tier1 = Zuora::Objects::ProductRatePlanChargeTier.new do |t| t.price = 0 @@ -74,52 +93,82 @@ t.ending_unit = 20 end - @prpc.should_not be_valid, 'tiers are required to be valid' + expect(@prpc).to_not be_valid, 'tiers are required to be valid' @prpc.product_rate_plan_charge_tiers << tier1 @prpc.product_rate_plan_charge_tiers << tier2 - @prpc.should be_valid, 'tiers are required to be valid' + expect(@prpc).to be_valid, 'tiers are required to be valid' MockResponse.responds_with(:product_rate_plan_charge_create_success) do - @prpc.save.should == true - @prpc.should_not be_new_record + expect(Zuora::Api.instance.client).to receive(:call).with( + :create, + { + message: 'DefaultFromCustomer'\ + 'MonthAlignToCharge'\ + 'Volume PricingRecurring'\ + '10Monthly Allowance'\ + '4028e4883491c50901349d0e1e571341'\ + 'RolloverServiceActivationEach'\ + 'USD10'\ + '00'\ + ''\ + 'USD2050'\ + '11'\ + '', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + expect(@prpc.save).to be true + expect(@prpc).to_not be_new_record end - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:create/#{zns}:zObjects/#{ons}:ProductRatePlanChargeTierData") - xml.should have_xml("//#{ons}:ProductRatePlanChargeTierData/#{zns}:ProductRatePlanChargeTier") - xml.should have_xml("//#{zns}:ProductRatePlanChargeTier/#{ons}:Price").with_value(50) - xml.should have_xml("//#{zns}:ProductRatePlanChargeTier/#{ons}:StartingUnit").with_value(11) - xml.should have_xml("//#{zns}:ProductRatePlanChargeTier/#{ons}:EndingUnit").with_value(20) - MockResponse.responds_with(:product_rate_plan_charge_tier_find_success) do + expect(Zuora::Api.instance.client).to receive(:call).with( + :query, + { + message: 'select Active, CreatedById, CreatedDate, Currency, EndingUnit, IsOveragePrice, '\ + 'Price, PriceFormat, ProductRatePlanChargeId, StartingUnit, Tier, UpdatedById, UpdatedDate, Id from '\ + "ProductRatePlanChargeTier where ProductRatePlanChargeId = '4028e48834aa10a30134aaf7f40b3139'"\ + '', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original @prpct = @prpc.product_rate_plan_charge_tiers - @prpct.size.should == 2 + expect(@prpct.size).to eq 2 end - @prpct.map(&:new_record?).should be_none, 'complex objects should not be new records after save' - + expect(@prpct.map(&:new_record?)).to be_none, 'complex objects should not be new records after save' @prpc.product_rate_plan_charge_tiers.first.price = 20 - @prpc.product_rate_plan_charge_tiers.first.price.should == 20 + expect(@prpc.product_rate_plan_charge_tiers.first.price).to eq 20 MockResponse.responds_with(:product_rate_plan_charge_update_success) do - @prpc.save.should == true + expect(Zuora::Api.instance.client).to receive(:call).with( + :update, + { + message: '4028e48834aa10a30134aaf7f40b3139'\ + 'true20'\ + '4028e48834aa10a30134aaf7f40b3139'\ + '4028e48834aa10a30134aaf7f40b313atrue50.0'\ + '4028e48834aa10a30134aaf7f40b3139'\ + '4028e48834aa10a30134aaf7f40b313b'\ + '', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + expect(@prpc.save).to eq true end - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:update/#{zns}:zObjects/#{ons}:ProductRatePlanChargeTierData") - xml.should have_xml("//env:Body/#{zns}:update/#{zns}:zObjects/#{ons}:Id") - xml.should have_xml("//#{ons}:ProductRatePlanChargeTierData/#{zns}:ProductRatePlanChargeTier") - xml.should have_xml("//#{zns}:ProductRatePlanChargeTier/#{ons}:Price").with_value(20) - xml.should_not have_xml("//#{zns}:ProductRatePlanChargeTier/#{zns}:Id") - xml.should_not have_xml("//#{zns}:ProductRatePlanChargeTier/#{ons}:StartingUnit") - xml.should_not have_xml("//#{zns}:ProductRatePlanChargeTier/#{ons}:EndingUnit") - MockResponse.responds_with(:product_rate_plan_charge_destroy_success) do + expect(Zuora::Api.instance.client).to receive(:call).with( + :delete, + { + message: 'ProductRatePlanCharge4028e48834aa10a30134aaf7f40b3139', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original @prpc.destroy end - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:delete/#{zns}:type").with_value('ProductRatePlanCharge') - xml.should have_xml("//env:Body/#{zns}:delete/#{zns}:ids").with_value('4028e48834aa10a30134aaf7f40b3139') end end diff --git a/spec/zuora/objects/subscribe_request_spec.rb b/spec/zuora/objects/subscribe_request_spec.rb index 10b8ef48..e13898f8 100644 --- a/spec/zuora/objects/subscribe_request_spec.rb +++ b/spec/zuora/objects/subscribe_request_spec.rb @@ -1,16 +1,28 @@ require 'spec_helper' describe Zuora::Objects::SubscribeRequest do + before do + allow_any_instance_of(Zuora::Api).to receive(:session).and_return double(key: 'session_key') + end - describe "most persistence methods" do - it "are not publicly available" do + describe 'most persistence methods' do + it 'are not publicly available' do [:update, :destroy, :where, :find].each do |meth| - subject.public_methods.should_not include(meth) + expect(subject.public_methods).to_not include(meth) end end end - describe "generating a request" do + describe 'generating a request' do + let(:sub_name) { subject.subscription.name } + before(:all) do + Timecop.freeze(Time.now) + end + + after(:all) do + Timecop.return + end + before do MockResponse.responds_with(:account_find_success) do @account = subject.account = Zuora::Objects::Account.find('stub') @@ -24,110 +36,154 @@ subject.payment_method = Zuora::Objects::PaymentMethod.find('stub') end - MockResponse.responds_with(:payment_method_credit_card_find_success) do + MockResponse.responds_with(:product_rate_plan_find_success) do subject.product_rate_plan = Zuora::Objects::ProductRatePlan.find('stub') end subject.subscription = FactoryBot.build(:subscription) end - it "provides properly formatted xml when using existing objects" do + it 'provides properly formatted xml when using existing objects' do MockResponse.responds_with(:subscribe_request_success) do - subject.should be_valid - sub_resp = subject.create - sub_resp[:success].should == true + expect(Zuora::Api.instance.client).to receive(:call).with( + :subscribe, + { + message: '4028e488348752ce0134876a25867cb2'\ + '4028e48834aa10a30134c50f40901ea7'\ + '4028e4873491cc770134972e75746e4c'\ + 'false'\ + "#{Time.now.rfc3339}1"\ + "false#{sub_name}"\ + "0#{Time.now.rfc3339}"\ + ''\ + '4028e4883491c50901349d0e1e571341'\ + '', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + expect(subject).to be_valid + expect(subject.create).to be true end - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:Account/#{ons}:Id"). - with_value('4028e488348752ce0134876a25867cb2') - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:PaymentMethod/#{ons}:Id"). - with_value('4028e48834aa10a30134c50f40901ea7') - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:BillToContact/#{ons}:Id"). - with_value('4028e4873491cc770134972e75746e4c') - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:SubscriptionData/#{zns}:Subscription") - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:SubscriptionData/#{zns}:RatePlanData/#{zns}:RatePlan/#{ons}:ProductRatePlanId"). - with_value('4028e48834aa10a30134c50f40901ea7') - xml.should_not have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{ons}:SubscribeOptions") end - it "provides full account info when new object" do + it 'provides full account info when new object' do subject.account = FactoryBot.build(:account) MockResponse.responds_with(:subscribe_request_success) do - subject.should be_valid - sub_resp = subject.create - sub_resp[:success].should == true + expect(Zuora::Api.instance.client).to receive(:call).with( + :subscribe, + { + message: 'test_account_1'\ + 'falseBatch11USD'\ + 'Test Account 1Due Upon Receipt'\ + 'Draft4028e48834aa10a30134c50f40901ea7'\ + '4028e4873491cc770134972e75746e4c'\ + 'false'\ + "#{Time.now.rfc3339}1"\ + "false#{sub_name}"\ + "0#{Time.now.rfc3339}"\ + ''\ + '4028e4883491c50901349d0e1e571341'\ + '', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + expect(subject).to be_valid + expect(subject.create).to be true end - - xml = Zuora::Api.instance.last_request - xml.should_not have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:Account/#{ons}:Id") - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:Account/#{ons}:Name") - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:Account/#{ons}:Status") - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:Account/#{ons}:Currency") end - it "provides full bill_to_contact info when new object" do + it 'provides full bill_to_contact info when new object' do subject.bill_to_contact = FactoryBot.build(:contact, :account => @account) MockResponse.responds_with(:subscribe_request_success) do - subject.should be_valid - sub_resp = subject.create - sub_resp[:success].should == true + expect(Zuora::Api.instance.client).to receive(:call).with( + :subscribe, + { + message: '4028e488348752ce0134876a25867cb2'\ + '4028e48834aa10a30134c50f40901ea7'\ + '4028e488348752ce0134876a25867cb2'\ + 'ExampleUser 1'\ + "false#{Time.now.rfc3339}"\ + '1false'\ + "#{sub_name}0"\ + "#{Time.now.rfc3339}"\ + '4028e4883491c50901349d0e1e571341'\ + '', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + expect(subject).to be_valid + expect(subject.create).to be true end - - xml = Zuora::Api.instance.last_request - xml.should_not have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:BillToContact/#{ons}:Id") - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:BillToContact/#{ons}:FirstName") - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:BillToContact/#{ons}:LastName") end - it "provides full payment_method info when new object" do - subject.payment_method = FactoryBot.build(:payment_method_ach, :account => @account, :ach_account_name => 'Testing') + it 'provides full payment_method info when new object' do + subject.payment_method = FactoryBot.build(:payment_method_ach, account: @account, ach_account_name: 'Testing') MockResponse.responds_with(:subscribe_request_success) do - subject.should be_valid - sub_resp = subject.create - sub_resp[:success].should == true + expect(Zuora::Api.instance.client).to receive(:call).with( + :subscribe, + { + message: '4028e488348752ce0134876a25867cb2'\ + '4028e488348752ce0134876a25867cb2'\ + '123456789Testing987654321'\ + 'BusinessChecking'\ + 'Bank of ZuoraACHtrue'\ + '4028e4873491cc770134972e75746e4c'\ + 'false'\ + "#{Time.now.rfc3339}1"\ + "false#{sub_name}"\ + "0#{Time.now.rfc3339}"\ + ''\ + '4028e4883491c50901349d0e1e571341'\ + '', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + expect(subject).to be_valid + expect(subject.create).to be true end - - xml = Zuora::Api.instance.last_request - xml.should_not have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:PaymentMethod/#{ons}:Id") - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:PaymentMethod/#{ons}:Type"). - with_value('ACH') - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:PaymentMethod/#{ons}:AchAccountName"). - with_value('Testing') end - it "handles applying subscribe failures messages" do + it 'handles applying subscribe failures messages' do MockResponse.responds_with(:subscribe_request_failure) do - subject.should be_valid - sub_resp = subject.create - sub_resp[:success].should == false - sub_resp[:errors][:message].should include('Initial Term should be greater than zero') + expect(subject).to be_valid + expect(subject.create).to be false + expect(subject.errors.messages[:base]).to include('Initial Term should be greater than zero') end end - it "supports subscription options" do + it 'supports subscription options' do MockResponse.responds_with(:subscribe_request_success) do - subject.subscribe_options = {:generate_invoice => true, :process_payments => true} - subject.should be_valid - sub_resp = subject.create - sub_resp[:success].should == true + subject.subscribe_options = { generate_invoice: true, process_payments: true } + expect(Zuora::Api.instance.client).to receive(:call).with( + :subscribe, + { + message: '4028e488348752ce0134876a25867cb2'\ + '4028e48834aa10a30134c50f40901ea7'\ + '4028e4873491cc770134972e75746e4c'\ + 'truetrue'\ + ''\ + "false#{Time.now.rfc3339}"\ + '1false'\ + "#{sub_name}0"\ + "#{Time.now.rfc3339}"\ + '4028e4883491c50901349d0e1e571341'\ + '', + soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } + } + ).and_call_original + expect(subject).to be_valid + expect(subject.create).to be true end - - xml = Zuora::Api.instance.last_request - xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:SubscribeOptions/#{zns}:GenerateInvoice"). - with_value(true) end - it "applies valid response data to the proper nested objects and resets dirty" do + it 'applies valid response data to the proper nested objects and resets dirty' do MockResponse.responds_with(:subscribe_request_success) do - subject.should be_valid - sub_resp = subject.create - sub_resp[:success].should == true - subject.subscription.should_not be_changed - subject.subscription.should_not be_new_record + expect(subject).to be_valid + expect(subject.create).to be true + expect(subject.subscription).to_not be_new_record end end end diff --git a/spec/zuora/validations_spec.rb b/spec/zuora/validations_spec.rb index 70378bce..f6c34ca8 100644 --- a/spec/zuora/validations_spec.rb +++ b/spec/zuora/validations_spec.rb @@ -15,9 +15,9 @@ class ExampleObject end describe "validating date" do - it "allows date objects" do - [Date.today].each do |val| - @obj.birthday = val + it "allows date and time related objects" do + [Date.today, DateTime.now, Time.now].each do |val| + @obj.birthday = Date.today @obj.valid? @obj.errors[:birthday].should be_blank end @@ -34,8 +34,8 @@ class ExampleObject describe "validating date_time" do it "allows date and time related objects" do - [DateTime.now, Time.now].each do |val| - @obj.validated_at = val + [Date.today, DateTime.now, Time.now].each do |val| + @obj.validated_at = Date.today @obj.valid? @obj.errors[:validated_at].should be_blank end diff --git a/wsdl/zuora.a.78.0.wsdl b/wsdl/zuora.a.38.0.wsdl similarity index 61% rename from wsdl/zuora.a.78.0.wsdl rename to wsdl/zuora.a.38.0.wsdl index fa22cda8..4b2e826e 100644 --- a/wsdl/zuora.a.78.0.wsdl +++ b/wsdl/zuora.a.38.0.wsdl @@ -2,64 +2,27 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -72,9 +35,9 @@ - - - + + + @@ -82,7 +45,7 @@ - + @@ -91,81 +54,96 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - - + + - - - + + - - + + - + - + - + - - - + - + + - - - - + - + @@ -174,7 +152,7 @@ - + @@ -183,10 +161,8 @@ - - @@ -198,7 +174,6 @@ - @@ -214,29 +189,24 @@ - - - + - + - - - - + @@ -244,24 +214,7 @@ - - - - - - - - - - - - - - - - - - + @@ -281,17 +234,11 @@ - - - - + - - - @@ -309,7 +256,6 @@ - @@ -324,7 +270,6 @@ - @@ -338,19 +283,16 @@ - + - - - @@ -358,21 +300,16 @@ - - + - - + + - - - - @@ -397,48 +334,41 @@ - + - + - - + - - - + + - - - - - - - + + @@ -449,8 +379,7 @@ - - + @@ -474,27 +403,9 @@ - - - - - - - - - - - - - - - - - - @@ -512,36 +423,22 @@ - - - - - - - - - + - - - - - - @@ -552,131 +449,16 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -685,46 +467,15 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - + + @@ -733,58 +484,41 @@ - + - - - - - - - - + - - - - - - - - - - - + @@ -793,11 +527,10 @@ + - - @@ -821,7 +554,7 @@ - + @@ -839,24 +572,7 @@ - - - - - - - - - - - - - - - - - - + @@ -864,10 +580,8 @@ - - - + @@ -879,12 +593,10 @@ - - - + + - @@ -893,32 +605,24 @@ - - + - - - - - - + - - @@ -942,36 +646,32 @@ - + - - - + + + - - - + - - - + - - - - + + + + @@ -980,34 +680,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -1025,7 +700,7 @@ - + @@ -1094,77 +769,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1189,18 +795,14 @@ - - - + - - @@ -1213,12 +815,6 @@ - - - - - - @@ -1232,16 +828,6 @@ - - - - - - - - - - @@ -1258,53 +844,26 @@ - - - - - - - - - - - - - - - - - - - - - - + - - - - - - @@ -1346,15 +905,6 @@ - - - - - - - - - @@ -1368,7 +918,6 @@ - @@ -1379,13 +928,6 @@ - - - - - - - @@ -1403,33 +945,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1531,22 +1046,6 @@ - - - - - - - - - - - - - - - - @@ -1554,16 +1053,6 @@ - - - - - - - - - - @@ -1585,35 +1074,26 @@ - - + - - - - - - + - + - - - @@ -1626,14 +1106,11 @@ - - + - - @@ -1656,18 +1133,11 @@ - - - - - - - @@ -1677,72 +1147,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1787,7 +1193,7 @@ - + @@ -1816,12 +1222,6 @@ - - - - - - @@ -1864,25 +1264,11 @@ - - - - - - - - - - - - - - - + @@ -1895,15 +1281,6 @@ - - - - - - - - - @@ -1911,10 +1288,6 @@ - - - - @@ -1959,36 +1332,16 @@ - - - Gets the next batch of sObjects from a query - - - - - - - - - - - - - - - - - @@ -2007,16 +1360,6 @@ - - - - - - - - - - @@ -2082,7 +1425,6 @@ - @@ -2099,25 +1441,6 @@ - - - - - - - - - - - - - - - - - - - @@ -2150,19 +1473,6 @@ - - - - - - - - - - - - - @@ -2195,23 +1505,10 @@ - - - - - - - - - - - - - - + diff --git a/zuora.gemspec b/zuora.gemspec index 41d50711..784d03a4 100644 --- a/zuora.gemspec +++ b/zuora.gemspec @@ -31,6 +31,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec' s.add_development_dependency 'simplecov' s.add_development_dependency 'test-unit' + s.add_development_dependency 'timecop' s.add_development_dependency 'yard' s.add_dependency 'akami' s.add_dependency 'httpi' From f3a77da6e402425ed2ce45ffc15fcb9317870d0d Mon Sep 17 00:00:00 2001 From: Angela Silva Date: Mon, 22 Jul 2024 11:48:34 +0100 Subject: [PATCH 3/4] fixing rails 4 and 7 specs --- lib/zuora/attributes.rb | 2 +- lib/zuora/validations.rb | 10 +++++----- spec/zuora/objects/account_spec.rb | 7 ++----- spec/zuora/objects/subscribe_request_spec.rb | 21 ++++++++++---------- spec/zuora/validations_spec.rb | 4 ++-- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index 6f44f8f7..8c74b816 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -212,7 +212,7 @@ def attributes # remove all dirty tracking for the object and return self for chaining. def clear_changed_attributes! - @changed_attributes = {} + clear_changes_information self end diff --git a/lib/zuora/validations.rb b/lib/zuora/validations.rb index 647fdbb3..fa31f8e2 100644 --- a/lib/zuora/validations.rb +++ b/lib/zuora/validations.rb @@ -8,16 +8,16 @@ def self.included(base) class DateTimeValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless value.is_a?(Date) - record.errors[attribute] << (options[:message] || "is not a valid datetime") + unless [DateTime, Time].any? { |klass| value.is_a?(klass) } + record.errors.add(attribute, (options[:message] || "is not a valid datetime")) end end end class DateValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless value.is_a?(Date) - record.errors[attribute] << (options[:message] || "is not a valid date") + unless [Date].any? { |klass| value.is_a?(klass) } + record.errors.add(attribute, (options[:message] || "is not a valid date")) end end end @@ -38,4 +38,4 @@ def validates_date_of(*attr_names) end end end -end +end \ No newline at end of file diff --git a/spec/zuora/objects/account_spec.rb b/spec/zuora/objects/account_spec.rb index 24eb1d84..bb267646 100644 --- a/spec/zuora/objects/account_spec.rb +++ b/spec/zuora/objects/account_spec.rb @@ -131,11 +131,8 @@ expect(Zuora::Api.instance.client).to receive(:call).with( :update, { - message: '4028e488348752ce0134876a25867cb2'\ - 'test-1falseBatch1'\ - '1USDFooMax'\ - 'Due Upon ReceiptDraft'\ - '', + message: '4028e488348752ce0134876a25867cb2'\ + 'FooMax', soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } } ).and_call_original diff --git a/spec/zuora/objects/subscribe_request_spec.rb b/spec/zuora/objects/subscribe_request_spec.rb index e13898f8..f813d536 100644 --- a/spec/zuora/objects/subscribe_request_spec.rb +++ b/spec/zuora/objects/subscribe_request_spec.rb @@ -52,9 +52,9 @@ '4028e48834aa10a30134c50f40901ea7'\ '4028e4873491cc770134972e75746e4c'\ 'false'\ - "#{Time.now.rfc3339}1"\ + "#{Time.now.iso8601}1"\ "false#{sub_name}"\ - "0#{Time.now.rfc3339}"\ + "0#{Time.now.iso8601}"\ ''\ '4028e4883491c50901349d0e1e571341'\ '', @@ -79,9 +79,9 @@ 'Draft4028e48834aa10a30134c50f40901ea7'\ '4028e4873491cc770134972e75746e4c'\ 'false'\ - "#{Time.now.rfc3339}1"\ + "#{Time.now.iso8601}1"\ "false#{sub_name}"\ - "0#{Time.now.rfc3339}"\ + "0#{Time.now.iso8601}"\ ''\ '4028e4883491c50901349d0e1e571341'\ '', @@ -104,10 +104,10 @@ '4028e48834aa10a30134c50f40901ea7'\ '4028e488348752ce0134876a25867cb2'\ 'ExampleUser 1'\ - "false#{Time.now.rfc3339}"\ + "false#{Time.now.iso8601}"\ '1false'\ "#{sub_name}0"\ - "#{Time.now.rfc3339}"\ + "#{Time.now.iso8601}"\ '4028e4883491c50901349d0e1e571341'\ '', soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } @@ -132,9 +132,9 @@ 'Bank of ZuoraACHtrue'\ '4028e4873491cc770134972e75746e4c'\ 'false'\ - "#{Time.now.rfc3339}1"\ + "#{Time.now.iso8601}1"\ "false#{sub_name}"\ - "0#{Time.now.rfc3339}"\ + "0#{Time.now.iso8601}"\ ''\ '4028e4883491c50901349d0e1e571341'\ '', @@ -165,10 +165,10 @@ '4028e4873491cc770134972e75746e4c'\ 'truetrue'\ ''\ - "false#{Time.now.rfc3339}"\ + "false#{Time.now.iso8601}"\ '1false'\ "#{sub_name}0"\ - "#{Time.now.rfc3339}"\ + "#{Time.now.iso8601}"\ '4028e4883491c50901349d0e1e571341'\ '', soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } } @@ -183,6 +183,7 @@ MockResponse.responds_with(:subscribe_request_success) do expect(subject).to be_valid expect(subject.create).to be true + expect(subject.subscription).to_not be_changed expect(subject.subscription).to_not be_new_record end end diff --git a/spec/zuora/validations_spec.rb b/spec/zuora/validations_spec.rb index f6c34ca8..a202f05d 100644 --- a/spec/zuora/validations_spec.rb +++ b/spec/zuora/validations_spec.rb @@ -34,8 +34,8 @@ class ExampleObject describe "validating date_time" do it "allows date and time related objects" do - [Date.today, DateTime.now, Time.now].each do |val| - @obj.validated_at = Date.today + [DateTime.now, Time.now].each do |val| + @obj.validated_at = val @obj.valid? @obj.errors[:validated_at].should be_blank end From a8aa20d22b037aec5533aa8a090e532e68b0ea25 Mon Sep 17 00:00:00 2001 From: Banjoko Azeez Date: Mon, 29 Jul 2024 14:03:23 +0100 Subject: [PATCH 4/4] - Updated `savon` dependency to guard against using v3.0.0 when released, as it introduces breaking changes. --- zuora.gemspec | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zuora.gemspec b/zuora.gemspec index 784d03a4..13b8c563 100644 --- a/zuora.gemspec +++ b/zuora.gemspec @@ -34,10 +34,9 @@ Gem::Specification.new do |s| s.add_development_dependency 'timecop' s.add_development_dependency 'yard' s.add_dependency 'akami' - s.add_dependency 'httpi' s.add_dependency 'libxml4r' s.add_dependency 'nokogiri' s.add_dependency 'rack' - s.add_dependency 'savon' + s.add_dependency 'savon', '>= 2.0', '< 3.0' s.add_dependency 'wasabi' end