From bddeb2ae2e49752670a3511f2fb269a300fe5343 Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Mon, 21 May 2012 14:17:15 +0100 Subject: [PATCH 01/36] Modifications for sageone integration --- lib/zuora/attributes.rb | 2 +- lib/zuora/objects/payment_method.rb | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index 3bfaac23..a00d22db 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -137,7 +137,7 @@ def inherited(subclass) xpath = "//xs:complexType[@name='#{subclass.remote_name}']//xs:sequence/xs:element" 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'].value.underscore.to_sym }) << :id + wsdl_attrs = (q.map{|e| e.attributes['name'].underscore.to_sym }) << :id subclass.send(:class_variable_set, :@@wsdl_attributes, wsdl_attrs) subclass.send(:class_variable_set, :@@read_only_attributes, []) subclass.send(:class_variable_set, :@@default_attributes, {}) diff --git a/lib/zuora/objects/payment_method.rb b/lib/zuora/objects/payment_method.rb index dd707a94..14534351 100644 --- a/lib/zuora/objects/payment_method.rb +++ b/lib/zuora/objects/payment_method.rb @@ -48,13 +48,12 @@ class PaymentMethod < Base :created_date, :credit_card_mask_number, :last_failed_sale_transaction_date, :last_transaction_status, :name, :num_consecutive_failures, :updated_date, :total_number_of_error_payments, :total_number_of_processed_payments, :active, - :bank_city, :bank_code, :bank_name, :bank_postal_code, :bank_street_name, - :bank_street_number, :bank_transfer_account_name, :bank_transfer_account_number, - :bank_transfer_account_type, :bank_transfer_account_number, :bank_transfer_account_type, - :bank_transfer_type, :last_transaction_datetime, :payment_method_status + :bank_city, :bank_name, :bank_postal_code, :bank_street_name, + :bank_street_number, :bank_transfer_account_type, :last_transaction_datetime, + :payment_method_status write_only :ach_account_number, :credit_card_number, :credit_card_security_code, - :gateway_option_data, :skip_validation + :gateway_option_data, :skip_validation, :bank_transfer_account_number default_attributes :use_default_retry_rule => true end From 22a9e1c20cb605d4b4a2dbae46558e90aab036a4 Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Mon, 21 May 2012 14:19:20 +0100 Subject: [PATCH 02/36] Fixing tests: --- lib/zuora/attributes.rb | 2 +- spec/zuora/objects/payment_method_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index a00d22db..3bfaac23 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -137,7 +137,7 @@ def inherited(subclass) xpath = "//xs:complexType[@name='#{subclass.remote_name}']//xs:sequence/xs:element" 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'].underscore.to_sym }) << :id + wsdl_attrs = (q.map{|e| e.attributes['name'].value.underscore.to_sym }) << :id subclass.send(:class_variable_set, :@@wsdl_attributes, wsdl_attrs) subclass.send(:class_variable_set, :@@read_only_attributes, []) subclass.send(:class_variable_set, :@@default_attributes, {}) diff --git a/spec/zuora/objects/payment_method_spec.rb b/spec/zuora/objects/payment_method_spec.rb index 2e9e8dde..25e19183 100644 --- a/spec/zuora/objects/payment_method_spec.rb +++ b/spec/zuora/objects/payment_method_spec.rb @@ -31,7 +31,7 @@ describe "write only attributes" do ach = FactoryGirl.build(:payment_method_ach) ach.write_only_attributes.should == [:ach_account_number, :credit_card_number, - :credit_card_security_code, :gateway_option_data, :skip_validation] + :credit_card_security_code, :gateway_option_data, :skip_validation, :bank_transfer_account_number] end describe "Credit Card" do From 308ccdf64c6f62ec70b93764a745bd9058743958 Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Mon, 21 May 2012 14:44:34 +0100 Subject: [PATCH 03/36] Now works with both tests and sageone codebase --- lib/zuora/attributes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index 3bfaac23..1e9f5ff9 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -137,7 +137,7 @@ def inherited(subclass) xpath = "//xs:complexType[@name='#{subclass.remote_name}']//xs:sequence/xs:element" 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'].value.underscore.to_sym }) << :id + wsdl_attrs = (q.map{|e| e.attributes['name'].to_s.underscore.to_sym }) << :id subclass.send(:class_variable_set, :@@wsdl_attributes, wsdl_attrs) subclass.send(:class_variable_set, :@@read_only_attributes, []) subclass.send(:class_variable_set, :@@default_attributes, {}) From 2688e82e44479c9e6590aa30bf8b66c07738dbda Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Tue, 22 May 2012 17:22:39 +0100 Subject: [PATCH 04/36] Readded autoincrmeent in scheme and changed selec to select ALL attributes, even write_only ones for testing --- lib/zuora/sqlite_connector.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/zuora/sqlite_connector.rb b/lib/zuora/sqlite_connector.rb index 9954d352..7bbb4c09 100644 --- a/lib/zuora/sqlite_connector.rb +++ b/lib/zuora/sqlite_connector.rb @@ -10,6 +10,7 @@ def initialize(model) end def query(sql) + sql = sql.gsub /select .* from/, 'select * from' result = db.query sql hashed_result = result.map {|r| hash_result_row(r, result) } { @@ -151,7 +152,7 @@ def self.create_table(model) attributes = attributes.map do |a| "'#{a.to_s.camelize}' text" end - autoid = "'Id' integer primary key" + autoid = "'Id' integer primary key autoincrement" attributes.unshift autoid attributes = attributes.join(", ") schema = "CREATE TABLE 'main'.'#{table_name}' (#{attributes});" From 5ff0995e9b26e910c60543fba665e699ee4b90e0 Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Wed, 23 May 2012 16:27:06 +0100 Subject: [PATCH 05/36] added api failure exception including zuora error message --- lib/zuora.rb | 1 + lib/zuora/api_failure.rb | 4 ++++ lib/zuora/objects/base.rb | 4 +--- spec/zuora/objects/account_spec.rb | 3 +-- spec/zuora/objects/base_spec.rb | 8 ++++++++ spec/zuora/sqlite_connector_spec.rb | 3 ++- 6 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 lib/zuora/api_failure.rb diff --git a/lib/zuora.rb b/lib/zuora.rb index dbfc0fbd..b1df8715 100644 --- a/lib/zuora.rb +++ b/lib/zuora.rb @@ -9,6 +9,7 @@ module Zuora require 'zuora/fault' require 'zuora/session' require 'zuora/api' + require 'zuora/api_failure' require 'zuora/validations' require 'zuora/associations' require 'zuora/attributes' diff --git a/lib/zuora/api_failure.rb b/lib/zuora/api_failure.rb new file mode 100644 index 00000000..406541c7 --- /dev/null +++ b/lib/zuora/api_failure.rb @@ -0,0 +1,4 @@ +module Zuora + class ApiFailure < Exception + end +end diff --git a/lib/zuora/objects/base.rb b/lib/zuora/objects/base.rb index 3706a0dc..9cf5f091 100644 --- a/lib/zuora/objects/base.rb +++ b/lib/zuora/objects/base.rb @@ -167,11 +167,9 @@ def apply_response(response_hash, type) @changed_attributes.clear return true else - self.errors.add(:base, result[:errors][:message]) - return false + raise Zuora::ApiFailure.new result[:errors][:message] end end - end end diff --git a/spec/zuora/objects/account_spec.rb b/spec/zuora/objects/account_spec.rb index d0c8ad02..f823a05c 100644 --- a/spec/zuora/objects/account_spec.rb +++ b/spec/zuora/objects/account_spec.rb @@ -154,8 +154,7 @@ a.payment_term = 'Due Upon Receipt' a.status = 'Draft' a.should be_valid - a.save.should == false - a.errors[:base].should include('The account number example-test-10 is invalid.') + expect { a.save }.to raise_error Zuora::ApiFailure a.id.should be_nil end end diff --git a/spec/zuora/objects/base_spec.rb b/spec/zuora/objects/base_spec.rb index f76134c9..10964830 100644 --- a/spec/zuora/objects/base_spec.rb +++ b/spec/zuora/objects/base_spec.rb @@ -28,4 +28,12 @@ def initialize(model) Zuora::Objects::Invoice.new(:includes_usage => false).includes_usage.should be_false end end + + describe :apply_response do + context "when a failure" do + it "raises an exception" do + expect { subject.send(:apply_response, { :foo => { :result => { :errors => { :message => 'Some error' } } } }, :foo )}.to raise_error Zuora::ApiFailure, 'Some error' + end + end + end end diff --git a/spec/zuora/sqlite_connector_spec.rb b/spec/zuora/sqlite_connector_spec.rb index dc1ac937..571821e3 100644 --- a/spec/zuora/sqlite_connector_spec.rb +++ b/spec/zuora/sqlite_connector_spec.rb @@ -13,7 +13,8 @@ it "builds a table schema for all Zuora::Object::Base classes" do result = @db.execute "SELECT t.sql sql FROM 'main'.sqlite_master t WHERE t.type='table'" - result.length.should == @models.length + sys_tables = 1 + result.length.should == @models.length + sys_tables end it "creates a column for each attribute" do From c544f8b18b0096aaa2c8a3922a3fab932566ef8b Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Thu, 24 May 2012 11:29:49 +0100 Subject: [PATCH 06/36] amended validation as account number is now not passed to zuora --- lib/zuora/objects/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zuora/objects/account.rb b/lib/zuora/objects/account.rb index 55a75654..2bcb31f7 100644 --- a/lib/zuora/objects/account.rb +++ b/lib/zuora/objects/account.rb @@ -7,7 +7,7 @@ class Account < Base belongs_to :bill_to, :class_name => 'Contact' belongs_to :sold_to, :class_name => 'Contact' - validates_presence_of :account_number, :name, :status, :payment_term, :batch, :currency + validates_presence_of :name, :status, :payment_term, :batch, :currency validates_length_of :name, :maximum => 50 validates_length_of :purchase_order_number, :maximum => 100, :allow_nil => true validates_inclusion_of :payment_term, :in => ['Due Upon Receipt','Net 15','Net 30','Net 45','Net 90'] From a681bd06b815b61d930cf9f9f4b3d75869fac6ea Mon Sep 17 00:00:00 2001 From: Jorge Alvarez Date: Fri, 25 May 2012 13:15:03 +0100 Subject: [PATCH 07/36] Added arel like select functionality --- lib/zuora/objects/base.rb | 13 ++++++++++++- spec/zuora/sqlite_connector_spec.rb | 22 +++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/zuora/objects/base.rb b/lib/zuora/objects/base.rb index 6fcefa6f..329ad68d 100644 --- a/lib/zuora/objects/base.rb +++ b/lib/zuora/objects/base.rb @@ -70,11 +70,17 @@ def ons self.class.ons end + # select fields to retreive from query + def self.select(select) + @select = select + self + 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. def self.where(where) - keys = (attributes - unselectable_attributes).map(&:to_s).map(&:camelcase) + keys = self.select_attributes if where.is_a?(Hash) # FIXME: improper inject usage. where = where.inject([]){|t,v| t << "#{v[0].to_s.camelcase} = '#{v[1]}'"}.sort.join(' and ') @@ -172,6 +178,11 @@ def apply_response(response_hash, type) end end + def self.select_attributes + select_attributes = @select.present? ? @select : attributes + (select_attributes - unselectable_attributes).map(&:to_s).map(&:camelcase) + end + end end diff --git a/spec/zuora/sqlite_connector_spec.rb b/spec/zuora/sqlite_connector_spec.rb index 1158f7a2..e269f1b6 100644 --- a/spec/zuora/sqlite_connector_spec.rb +++ b/spec/zuora/sqlite_connector_spec.rb @@ -37,7 +37,7 @@ Zuora::Objects::Base.connector_class = old_class end - describe :where do + describe "Arel like methods" do before :each do @model = Zuora::Objects::Product @db = described_class.db @@ -48,13 +48,25 @@ @product2.create end - it "returns matching records" do - records = @model.where(:name => 'Product One') - records.first.name.should == @product1.name - records.first.id.should == @product1.id + describe :where do + it "returns matching records" do + records = @model.where(:name => 'Product One') + records.first.name.should == @product1.name + records.first.id.should == @product1.id + end + end + + describe :select do + it "returns only selected fields" do + records = @model.select([:id, :name]).where(:name => 'Product One') + records.first.name.should == @product1.name + records.first.id.should == @product1.id + records.first.description.should == nil + end end end + describe :create do before :each do @model = Zuora::Objects::Product.new From 2ff347c0b2b8bb036bda32a75aa212732dcd595e Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Fri, 25 May 2012 17:02:48 +0100 Subject: [PATCH 08/36] Added support for custom fields, the underscores were playing havoc --- lib/zuora/attributes.rb | 6 ++++++ lib/zuora/sqlite_connector.rb | 4 ++-- spec/zuora/sqlite_connector_spec.rb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index 1e9f5ff9..cae59f42 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -125,6 +125,12 @@ def attributes class_variable_get(:@@all_attributes).map(&:to_sym) end + def original_attributes + attributes.map do |attr| + attr.to_s.split('__').map { |a| a.camelize }.join('__') + end + end + # the name to use when referencing remote Zuora objects def remote_name self.name.base_name diff --git a/lib/zuora/sqlite_connector.rb b/lib/zuora/sqlite_connector.rb index 7bbb4c09..d675f9d0 100644 --- a/lib/zuora/sqlite_connector.rb +++ b/lib/zuora/sqlite_connector.rb @@ -148,9 +148,9 @@ def self.generate_tables def self.create_table(model) table_name = self.table_name(model) - attributes = model.attributes - [:id] + attributes = model.original_attributes - ['Id'] attributes = attributes.map do |a| - "'#{a.to_s.camelize}' text" + "'#{a}' text" end autoid = "'Id' integer primary key autoincrement" attributes.unshift autoid diff --git a/spec/zuora/sqlite_connector_spec.rb b/spec/zuora/sqlite_connector_spec.rb index 03bc6277..7e43bcd4 100644 --- a/spec/zuora/sqlite_connector_spec.rb +++ b/spec/zuora/sqlite_connector_spec.rb @@ -22,7 +22,7 @@ table_name = described_class.table_name(m) table = @db.table_info(table_name) columns = table.map {|t| t["name"] } - camel_attrs = m.attributes.map { |a| a.to_s.camelize } + camel_attrs = m.original_attributes (camel_attrs - columns).should == [] end end From 8135d9a146759f658a11056007d920ab0d86f716 Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Fri, 25 May 2012 17:10:36 +0100 Subject: [PATCH 09/36] Fixing original attr stuff to work with API --- lib/zuora/attributes.rb | 6 +++++- lib/zuora/objects/base.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index cae59f42..be08f375 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -125,9 +125,13 @@ def attributes class_variable_get(:@@all_attributes).map(&:to_sym) end + def original_attr(attr) + attr.to_s.split('__').map { |a| a.camelize }.join('__') + end + def original_attributes attributes.map do |attr| - attr.to_s.split('__').map { |a| a.camelize }.join('__') + original_attr(attr) end end diff --git a/lib/zuora/objects/base.rb b/lib/zuora/objects/base.rb index e9c46d3a..4899c9c9 100644 --- a/lib/zuora/objects/base.rb +++ b/lib/zuora/objects/base.rb @@ -83,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.camelcase} = '#{v[1]}'"}.sort.join(' and ') + where = where.inject([]){|t,v| t << "#{original_attr(v[0])} = '#{v[1]}'"}.sort.join(' and ') end sql = "select #{keys.join(', ')} from #{remote_name} where #{where}" From 56681f15d49b0bef16eff585132808258ff3301c Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Mon, 28 May 2012 09:24:53 +0100 Subject: [PATCH 10/36] Revert "Fixing original attr stuff to work with API" This reverts commit 8135d9a146759f658a11056007d920ab0d86f716. --- lib/zuora/attributes.rb | 6 +----- lib/zuora/objects/base.rb | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index be08f375..cae59f42 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -125,13 +125,9 @@ def attributes class_variable_get(:@@all_attributes).map(&:to_sym) end - def original_attr(attr) - attr.to_s.split('__').map { |a| a.camelize }.join('__') - end - def original_attributes attributes.map do |attr| - original_attr(attr) + attr.to_s.split('__').map { |a| a.camelize }.join('__') end end diff --git a/lib/zuora/objects/base.rb b/lib/zuora/objects/base.rb index 4899c9c9..e9c46d3a 100644 --- a/lib/zuora/objects/base.rb +++ b/lib/zuora/objects/base.rb @@ -83,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 << "#{original_attr(v[0])} = '#{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}" From 84bf19a6d80a262be1e9b4bde13769fbbc83d048 Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Mon, 28 May 2012 09:25:08 +0100 Subject: [PATCH 11/36] Revert "Added support for custom fields, the underscores were playing havoc" This reverts commit 2ff347c0b2b8bb036bda32a75aa212732dcd595e. --- lib/zuora/attributes.rb | 6 ------ lib/zuora/sqlite_connector.rb | 4 ++-- spec/zuora/sqlite_connector_spec.rb | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index cae59f42..1e9f5ff9 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -125,12 +125,6 @@ def attributes class_variable_get(:@@all_attributes).map(&:to_sym) end - def original_attributes - attributes.map do |attr| - attr.to_s.split('__').map { |a| a.camelize }.join('__') - end - end - # the name to use when referencing remote Zuora objects def remote_name self.name.base_name diff --git a/lib/zuora/sqlite_connector.rb b/lib/zuora/sqlite_connector.rb index d675f9d0..7bbb4c09 100644 --- a/lib/zuora/sqlite_connector.rb +++ b/lib/zuora/sqlite_connector.rb @@ -148,9 +148,9 @@ def self.generate_tables def self.create_table(model) table_name = self.table_name(model) - attributes = model.original_attributes - ['Id'] + attributes = model.attributes - [:id] attributes = attributes.map do |a| - "'#{a}' text" + "'#{a.to_s.camelize}' text" end autoid = "'Id' integer primary key autoincrement" attributes.unshift autoid diff --git a/spec/zuora/sqlite_connector_spec.rb b/spec/zuora/sqlite_connector_spec.rb index 7e43bcd4..03bc6277 100644 --- a/spec/zuora/sqlite_connector_spec.rb +++ b/spec/zuora/sqlite_connector_spec.rb @@ -22,7 +22,7 @@ table_name = described_class.table_name(m) table = @db.table_info(table_name) columns = table.map {|t| t["name"] } - camel_attrs = m.original_attributes + camel_attrs = m.attributes.map { |a| a.to_s.camelize } (camel_attrs - columns).should == [] end end From f27326b43503dce9338de2942f928a79a2557ddd Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Mon, 28 May 2012 10:21:33 +0100 Subject: [PATCH 12/36] Support for custom attributes with __c on the end --- lib/zuora/attributes.rb | 8 ++++++++ lib/zuora/objects/base.rb | 2 +- lib/zuora/sqlite_connector.rb | 6 +++--- spec/zuora/sqlite_connector_spec.rb | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/zuora/attributes.rb b/lib/zuora/attributes.rb index 1e9f5ff9..ccfbc645 100644 --- a/lib/zuora/attributes.rb +++ b/lib/zuora/attributes.rb @@ -125,6 +125,14 @@ def attributes class_variable_get(:@@all_attributes).map(&:to_sym) end + def api_attr(lower) + if lower =~ /__c$/ + lower.to_s[0..-4].camelize + '__c' + else + lower.to_s.camelize + end + end + # the name to use when referencing remote Zuora objects def remote_name self.name.base_name diff --git a/lib/zuora/objects/base.rb b/lib/zuora/objects/base.rb index e9c46d3a..aa82964e 100644 --- a/lib/zuora/objects/base.rb +++ b/lib/zuora/objects/base.rb @@ -181,7 +181,7 @@ def apply_response(response_hash, type) def self.select_attributes select_attributes = @select.present? ? @select : attributes - (select_attributes - unselectable_attributes).map(&:to_s).map(&:camelcase) + (select_attributes - unselectable_attributes).map(&:to_s).map { |a| api_attr(a) } end end diff --git a/lib/zuora/sqlite_connector.rb b/lib/zuora/sqlite_connector.rb index 7bbb4c09..6dcb2ae1 100644 --- a/lib/zuora/sqlite_connector.rb +++ b/lib/zuora/sqlite_connector.rb @@ -31,7 +31,7 @@ def create keys = [] values = [] hash.each do |key, value| - keys << key.to_s.camelize + keys << @model.class.api_attr(key) values << value.to_s end place_holder = ['?'] * keys.length @@ -57,7 +57,7 @@ def update keys = [] values = [] hash.each do |key, value| - keys << "#{key.to_s.camelize}=?" + keys << "#{@model.class.api_attr(key)}=?" values << value.to_s end keys = keys.join(', ') @@ -150,7 +150,7 @@ def self.create_table(model) table_name = self.table_name(model) attributes = model.attributes - [:id] attributes = attributes.map do |a| - "'#{a.to_s.camelize}' text" + "'#{model.api_attr(a)}' text" end autoid = "'Id' integer primary key autoincrement" attributes.unshift autoid diff --git a/spec/zuora/sqlite_connector_spec.rb b/spec/zuora/sqlite_connector_spec.rb index 03bc6277..e11553f5 100644 --- a/spec/zuora/sqlite_connector_spec.rb +++ b/spec/zuora/sqlite_connector_spec.rb @@ -26,6 +26,20 @@ (camel_attrs - columns).should == [] end end + + it "creates the correct column for custom attributes" do + model = @models.first + model.stub(:attributes).and_return([:api_service_id__c]) + + described_class.build_schema + @db = described_class.db + + table_name = described_class.table_name(model) + table = @db.table_info(table_name) + columns = table.map {|t| t["name"] } + + columns.should include 'ApiServiceId__c' + end end From 857111cfc968d96d16a6b3c6b932a1b17bba041b Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Mon, 28 May 2012 13:36:00 +0100 Subject: [PATCH 13/36] Added some extra functionality to subscribe in test connector, made ancestor_acount_id write only, and made sure subscription_number comes back after a subscribe request --- lib/zuora/objects/subscribe_request.rb | 1 + lib/zuora/objects/subscription.rb | 2 ++ lib/zuora/sqlite_connector.rb | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/zuora/objects/subscribe_request.rb b/lib/zuora/objects/subscribe_request.rb index e86c78e1..b1b5babd 100644 --- a/lib/zuora/objects/subscribe_request.rb +++ b/lib/zuora/objects/subscribe_request.rb @@ -47,6 +47,7 @@ def apply_response(response_hash, type) result = response_hash[type][:result] if result[:success] subscription.id = result[:subscription_id] + subscription.name = result[:subscription_number] subscription.clear_changed_attributes! @previously_changed = changes @changed_attributes.clear diff --git a/lib/zuora/objects/subscription.rb b/lib/zuora/objects/subscription.rb index 42feb413..a024f27b 100644 --- a/lib/zuora/objects/subscription.rb +++ b/lib/zuora/objects/subscription.rb @@ -30,6 +30,8 @@ class Subscription < Base :original_created_date, :original_id, :previous_subscription_id, :status, :subscription_end_date, :term_end_date, :version, :subscription_start_date + write_only :ancestor_account_id + defaults :auto_renew => false, :initial_term => 1, :is_invoice_separate => false, diff --git a/lib/zuora/sqlite_connector.rb b/lib/zuora/sqlite_connector.rb index 6dcb2ae1..445e2850 100644 --- a/lib/zuora/sqlite_connector.rb +++ b/lib/zuora/sqlite_connector.rb @@ -88,6 +88,8 @@ def destroy end def subscribe + @model.subscription.account = @model.account + @model.subscription.name = '12345' [ :account, :subscription, @@ -110,7 +112,8 @@ def subscribe :subscribe_response => { :result => { :success => true, - :id => nil + :id => nil, + :subscription_number => '12345' } } } From 100b8ad8e19477421407211738725d0956badbe1 Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Tue, 29 May 2012 15:01:18 +0100 Subject: [PATCH 14/36] Removed validation for rate plan object which was unneccessary --- lib/zuora/objects/rate_plan.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zuora/objects/rate_plan.rb b/lib/zuora/objects/rate_plan.rb index 6339d938..841b01fd 100644 --- a/lib/zuora/objects/rate_plan.rb +++ b/lib/zuora/objects/rate_plan.rb @@ -5,7 +5,7 @@ class RatePlan < Base has_many :rate_plan_charges belongs_to :subscription - validates_presence_of :name, :product_rate_plan_id, :subscription_id + validates_presence_of :product_rate_plan_id validates_inclusion_of :amendment_type, :in => %w(Cancellation NewProduct OwnerTransfer RemoveProduct Renewal TermsAndConditions UpdateProduct), :allow_nil => true validates_length_of :created_by_id, :maximum => 32, :allow_nil => true From 088001ad24e29572e6c18ea3cc7f1866fc724172 Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Wed, 30 May 2012 10:53:44 +0100 Subject: [PATCH 15/36] Added amendments relationship to subscription --- lib/zuora/objects/subscription.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/zuora/objects/subscription.rb b/lib/zuora/objects/subscription.rb index a024f27b..02d67304 100644 --- a/lib/zuora/objects/subscription.rb +++ b/lib/zuora/objects/subscription.rb @@ -5,6 +5,7 @@ class Subscription < Base belongs_to :creator_account, :class_name => 'Account' belongs_to :creator_invoice_owner, :class_name => 'Account' has_many :rate_plans + has_many :amendments validates_presence_of :contract_effective_date, :initial_term, :renewal_term From 1fcbdd3b2e664bc4fa32ebd6f7511b3e42397c38 Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Wed, 30 May 2012 16:10:03 +0100 Subject: [PATCH 16/36] Changed sql connector to return nil for empty values - this more closely matches the actual zuora implementation --- lib/zuora/sqlite_connector.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zuora/sqlite_connector.rb b/lib/zuora/sqlite_connector.rb index 445e2850..5be63317 100644 --- a/lib/zuora/sqlite_connector.rb +++ b/lib/zuora/sqlite_connector.rb @@ -139,7 +139,7 @@ def self.table_name(model) protected def hash_result_row(row, result) - row = row.map {|r| r.nil? ? "" : r } + row = row.map {|r| r == "" ? nil : r } Hash[result.columns.zip(row.to_a)] end From e6f09036bbcabba7f2bc6df277095cf52fd00b9e Mon Sep 17 00:00:00 2001 From: Dave Elliott Date: Tue, 12 Jun 2012 16:01:53 +0100 Subject: [PATCH 17/36] Added support for creating exports, checking if they are ready and downloading them --- .gitignore | 1 + lib/zuora/api.rb | 15 +++++++++++ lib/zuora/objects.rb | 3 ++- lib/zuora/objects/export.rb | 15 +++++++++++ lib/zuora/soap_connector.rb | 4 +++ lib/zuora/sqlite_connector.rb | 10 ++++++++ spec/spec_helper.rb | 5 ++++ spec/zuora/api_spec.rb | 19 ++++++++++++++ spec/zuora/objects/export_spec.rb | 40 +++++++++++++++++++++++++++++ spec/zuora/sqlite_connector_spec.rb | 32 +++++++++++++++++++++++ zuora.gemspec | 27 +++++++++---------- 11 files changed, 157 insertions(+), 14 deletions(-) create mode 100644 lib/zuora/objects/export.rb create mode 100644 spec/zuora/objects/export_spec.rb diff --git a/.gitignore b/.gitignore index ad7e67b6..7ec46fb4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ doc gemfiles/*.gemfile.lock zuora.log Gemfile.lock +coverage diff --git a/lib/zuora/api.rb b/lib/zuora/api.rb index 91ecaa6b..12f73359 100644 --- a/lib/zuora/api.rb +++ b/lib/zuora/api.rb @@ -1,4 +1,5 @@ require 'savon' +require 'net/http' module Zuora @@ -67,6 +68,20 @@ def request(method, xml_body=nil, &block) raise Zuora::Fault.new(:message => e.message) end + def download(export) + authenticate! unless authenticated? + + uri = URI(URI.join(config.download_url, export.file_id)) + req = Net::HTTP::Get.new(uri.request_uri) + req['Authorization'] = 'ZSession ' + session.try(:key) + + http = Net::HTTP.new(uri.hostname, uri.port) + http.use_ssl = true + + res = http.start { |http| http.request(req) } + res.body + end + # Attempt to authenticate against Zuora and initialize the Zuora::Session object # # @note that the Zuora API requires username to come first in the SOAP request so diff --git a/lib/zuora/objects.rb b/lib/zuora/objects.rb index ea7384cf..2443ba25 100644 --- a/lib/zuora/objects.rb +++ b/lib/zuora/objects.rb @@ -2,9 +2,10 @@ module Zuora module Objects autoload :Base, 'zuora/objects/base' autoload :Account, 'zuora/objects/account' - autoload :Contact, 'zuora/objects/contact' autoload :Amendment, 'zuora/objects/amendment' autoload :CommunicationProfile, 'zuora/objects/communication_profile' + autoload :Contact, 'zuora/objects/contact' + autoload :Export, 'zuora/objects/export' # autoload :CreditBalanceAdjustment, 'zuora/objects/credit_balance_adjustment' autoload :Invoice, 'zuora/objects/invoice' autoload :InvoiceAdjustment, 'zuora/objects/invoice_adjustment' diff --git a/lib/zuora/objects/export.rb b/lib/zuora/objects/export.rb new file mode 100644 index 00000000..ffe37ce2 --- /dev/null +++ b/lib/zuora/objects/export.rb @@ -0,0 +1,15 @@ +module Zuora::Objects + class Export < Base + def download + connector.download(self) + end + + def ready? + self.status == 'Completed' + end + + define_attributes do + defaults :format => 'csv' + end + end +end diff --git a/lib/zuora/soap_connector.rb b/lib/zuora/soap_connector.rb index 2c416dec..6aa46bfe 100644 --- a/lib/zuora/soap_connector.rb +++ b/lib/zuora/soap_connector.rb @@ -84,6 +84,10 @@ def subscribe end end + def download(export) + current_client.download(export) + end + # Remove empty attributes from response hash # and typecast any known types from the wsdl def parse_attributes(type, attrs={}) diff --git a/lib/zuora/sqlite_connector.rb b/lib/zuora/sqlite_connector.rb index 5be63317..2700759d 100644 --- a/lib/zuora/sqlite_connector.rb +++ b/lib/zuora/sqlite_connector.rb @@ -1,4 +1,5 @@ require 'sqlite3' +require 'csv' module Zuora #Sqlite3 in memoroy connector to simulate Zuora in test environments @@ -9,6 +10,15 @@ def initialize(model) @model = model end + def download(export) + records = query(export.query)[:query_response][:result][:records] + CSV.generate do |csv| + records.each do |record| + csv << record.values + end + end + end + def query(sql) sql = sql.gsub /select .* from/, 'select * from' result = db.query sql diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d2cca98..2c2a9974 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,8 @@ +require 'simplecov' +SimpleCov.start do + add_filter 'spec/' +end + require 'zuora' require 'artifice' require 'digest/md5' diff --git a/spec/zuora/api_spec.rb b/spec/zuora/api_spec.rb index 08625d2a..71e747ca 100644 --- a/spec/zuora/api_spec.rb +++ b/spec/zuora/api_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Zuora::Api do + subject { Zuora::Api.instance } + describe "configuration" do before do Zuora::Api.any_instance.stub(:authenticated?).and_return(true) @@ -56,5 +58,22 @@ end.should raise_error(Zuora::Fault) end end + + describe :download do + it "uses NET::HTTP to download the csv" do + Zuora.configure( + :username => 'example', + :password => 'test', + :download_url => 'http://example.com/foo/bar' + ) + + export = ::Zuora::Objects::Export.new + export.file_id = 'FOOBAR_FILE' + + Net::HTTP.any_instance.should_receive(:start).and_return(mock(Object, :body => '')) + + subject.download(export) + end + end end diff --git a/spec/zuora/objects/export_spec.rb b/spec/zuora/objects/export_spec.rb new file mode 100644 index 00000000..5a48acd0 --- /dev/null +++ b/spec/zuora/objects/export_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Zuora::Objects::Export do + + it_should_behave_like "ActiveModel" + + it "extends Base object" do + subject.should be_a_kind_of(Zuora::Objects::Base) + end + + it "has defined attributes" do + subject.attributes.keys.map(&:to_s).sort.should == + ["created_by_id", "created_date", "encrypted", "file_id", "format", "id", "name", "query", "size", "status", "status_reason", "updated_by_id", "updated_date", "zip"] + end + + it "has default values" do + subject.format.should == 'csv' + end + + describe :download do + it "makes a get request to the configured DOWNLOAD_URL with the correct header" do + subject.stub(:connector).and_return(mock(Object)) + subject.connector.should_receive(:download).with(subject) + + subject.download + end + end + + describe :ready? do + it "returns true if the status is Completed" do + subject.status = 'Completed' + subject.should be_ready + end + + it "returns false if the status is not Completed" do + subject.status = 'NOTREADY' + subject.should_not be_ready + end + end +end diff --git a/spec/zuora/sqlite_connector_spec.rb b/spec/zuora/sqlite_connector_spec.rb index e11553f5..06d22fe1 100644 --- a/spec/zuora/sqlite_connector_spec.rb +++ b/spec/zuora/sqlite_connector_spec.rb @@ -2,6 +2,15 @@ require 'zuora/sqlite_connector' describe Zuora::SqliteConnector do + around :each do |example| + Zuora::Objects::Base.connector_class, old = described_class, + Zuora::Objects::Base.connector_class + + example.run + + Zuora::Objects::Base.connector_class = old + end + describe :build_schema do before :each do mod = Zuora::Objects @@ -179,4 +188,27 @@ end end + describe :download do + subject { described_class.new(nil) } + + before :each do + acc1 = ::Zuora::Objects::Account.new + acc1.name = 'FOO' + acc1.status = 'Completed' + acc1.create + + acc2 = ::Zuora::Objects::Account.new + acc2.name = 'BAR' + acc2.status = 'Draft' + acc2.create + + @export = ::Zuora::Objects::Export.new + @export.query = 'SELECT Account.Name, Account.Status FROM Account' + end + + it "performs the query and returns the output as CSV" do + subject.download(@export).should == "FOO,Completed\nBAR,Draft\n" + end + end + end diff --git a/zuora.gemspec b/zuora.gemspec index 0056f08b..3a25db08 100644 --- a/zuora.gemspec +++ b/zuora.gemspec @@ -17,18 +17,19 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.extra_rdoc_files = [ "README.md" ] - s.add_runtime_dependency(%q, ["~> 0.9.8"]) - s.add_runtime_dependency(%q, [">= 3.0.0", "< 4.0.0"]) - s.add_runtime_dependency(%q, [">= 3.0.0", "< 4.0.0"]) - s.add_runtime_dependency(%q, ['~> 0.2.6']) + s.add_runtime_dependency('savon', ["~> 0.9.8"]) + s.add_runtime_dependency('activesupport', [">= 3.0.0", "< 4.0.0"]) + s.add_runtime_dependency('activemodel', [">= 3.0.0", "< 4.0.0"]) + s.add_runtime_dependency('libxml4r', ['~> 0.2.6']) - s.add_development_dependency(%q, ["~> 0.8.7"]) - s.add_development_dependency(%q, ["~> 0.6.0"]) - s.add_development_dependency(%q, ["~> 0.6.0"]) - s.add_development_dependency(%q, ["~> 0.7.5"]) - s.add_development_dependency(%q, ["~> 2.8.0"]) - s.add_development_dependency(%q, ["~> 2.1.0"]) - s.add_development_dependency(%q, ["~> 2.6.4"]) - s.add_development_dependency(%q, ["~> 0.4.1"]) - s.add_development_dependency(%q, ["~> 1.3.0"]) + s.add_development_dependency('rake', ["~> 0.8.7"]) + s.add_development_dependency('guard-rspec', ["~> 0.6.0"]) + s.add_development_dependency('artifice', ["~> 0.6.0"]) + s.add_development_dependency('yard', ["~> 0.7.5"]) + s.add_development_dependency('rspec', ["~> 2.8.0"]) + s.add_development_dependency('redcarpet', ["~> 2.1.0"]) + s.add_development_dependency('factory_girl', ["~> 2.6.4"]) + s.add_development_dependency('appraisal', ["~> 0.4.1"]) + s.add_development_dependency('sqlite3', ["~> 1.3.0"]) + s.add_development_dependency('simplecov', ["~> 0.6.4"]) end From b2f15c2c5580d90c49d58ed8ba0643869ec06ce5 Mon Sep 17 00:00:00 2001 From: Dave Elliott Date: Thu, 14 Jun 2012 11:16:32 +0100 Subject: [PATCH 18/36] Updated dependencies --- zuora.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zuora.gemspec b/zuora.gemspec index 0056f08b..4ad6ca0c 100644 --- a/zuora.gemspec +++ b/zuora.gemspec @@ -17,9 +17,10 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.extra_rdoc_files = [ "README.md" ] - s.add_runtime_dependency(%q, ["~> 0.9.8"]) + s.add_runtime_dependency(%q, ["0.9.9"]) s.add_runtime_dependency(%q, [">= 3.0.0", "< 4.0.0"]) s.add_runtime_dependency(%q, [">= 3.0.0", "< 4.0.0"]) + s.add_runtime_dependency(%q, ["0.9"]) s.add_runtime_dependency(%q, ['~> 0.2.6']) s.add_development_dependency(%q, ["~> 0.8.7"]) From 115f64fe1a1b3f6fc2b54e381c76eecb80a7990c Mon Sep 17 00:00:00 2001 From: Dave Elliott Date: Thu, 14 Jun 2012 11:27:09 +0100 Subject: [PATCH 19/36] Updated dependecies to good versions --- zuora.gemspec | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/zuora.gemspec b/zuora.gemspec index b8929623..1cda6055 100644 --- a/zuora.gemspec +++ b/zuora.gemspec @@ -17,11 +17,11 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.extra_rdoc_files = [ "README.md" ] - s.add_runtime_dependency(%q, ["0.9.9"]) - s.add_runtime_dependency(%q, [">= 3.0.0", "< 4.0.0"]) - s.add_runtime_dependency(%q, [">= 3.0.0", "< 4.0.0"]) - s.add_runtime_dependency(%q, ["0.9"]) - s.add_runtime_dependency(%q, ['~> 0.2.6']) + s.add_runtime_dependency('savon', ["0.9.9"]) + s.add_runtime_dependency('activesupport', [">= 3.0.0", "< 4.0.0"]) + s.add_runtime_dependency('activemodel', [">= 3.0.0", "< 4.0.0"]) + s.add_runtime_dependency('httpi', ["0.9.7"]) + s.add_runtime_dependency('libxml4r', ['~> 0.2.6']) s.add_development_dependency('rake', ["~> 0.8.7"]) s.add_development_dependency('guard-rspec', ["~> 0.6.0"]) From b44d855be94973616c8b9f23b56c2b038ac2617e Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Wed, 14 Nov 2012 17:58:05 +0000 Subject: [PATCH 20/36] Added support for invoiceownerid --- Gemfile | 2 +- lib/zuora/objects/subscription.rb | 1 + spec/zuora/objects/subscription_spec.rb | 8 ++++++++ wsdl/zuora.a.38.0.wsdl | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 spec/zuora/objects/subscription_spec.rb diff --git a/Gemfile b/Gemfile index e811baf1..2214ea86 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source :rubygems -gem 'wasabi', :git => 'git://github.com/skiz/wasabi.git' +gem 'wasabi', '2.3.0' gemspec diff --git a/lib/zuora/objects/subscription.rb b/lib/zuora/objects/subscription.rb index 02d67304..2e6242ad 100644 --- a/lib/zuora/objects/subscription.rb +++ b/lib/zuora/objects/subscription.rb @@ -4,6 +4,7 @@ class Subscription < Base belongs_to :ancestor_account, :class_name => 'Account' belongs_to :creator_account, :class_name => 'Account' belongs_to :creator_invoice_owner, :class_name => 'Account' + belongs_to :invoice_owner, :class_name => 'Account' has_many :rate_plans has_many :amendments diff --git a/spec/zuora/objects/subscription_spec.rb b/spec/zuora/objects/subscription_spec.rb new file mode 100644 index 00000000..4029fc70 --- /dev/null +++ b/spec/zuora/objects/subscription_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +describe Zuora::Objects::Subscription do + it "has a invoice_owner" do + subject.respond_to?(:invoice_owner=).should be_true + subject.respond_to?(:invoice_owner).should be_true + end +end diff --git a/wsdl/zuora.a.38.0.wsdl b/wsdl/zuora.a.38.0.wsdl index bd097028..4b2e826e 100644 --- a/wsdl/zuora.a.38.0.wsdl +++ b/wsdl/zuora.a.38.0.wsdl @@ -659,6 +659,7 @@ + From 875144a5a750e4ce4a5834033cc7304bc322925d Mon Sep 17 00:00:00 2001 From: Angela Silva Date: Wed, 30 Apr 2014 10:35:15 +0100 Subject: [PATCH 21/36] Support for custom attributes with __c on the end (apply same changes to forgotten connector) --- lib/zuora/soap_connector.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/zuora/soap_connector.rb b/lib/zuora/soap_connector.rb index 6aa46bfe..8d8f1e2c 100644 --- a/lib/zuora/soap_connector.rb +++ b/lib/zuora/soap_connector.rb @@ -17,7 +17,7 @@ def create current_client.request(:create) 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.camelize.to_sym, v) unless v.nil? + a.__send__(ons, api_name(k), v) unless v.nil? end generate_complex_objects(a, :create) end @@ -32,7 +32,7 @@ def update a.__send__(ons, :Id, obj_id) change_syms = @model.changed.map(&:to_sym) obj_attrs.reject{|k,v| @model.read_only_attributes.include?(k) }.each do |k,v| - a.__send__(ons, k.to_s.camelize.to_sym, v) if change_syms.include?(k) + a.__send__(ons, api_name(k), v) if change_syms.include?(k) end generate_complex_objects(a, :update) end @@ -100,7 +100,7 @@ def parse_attributes(type, attrs={}) klass = attrs['@xsi:type'.to_sym].base_name if klass attrs.each do |a,v| - ref = a.to_s.camelcase + ref = @model.api_attr(a) z = tdefs.find{|d| d[0] == [klass, ref] } if z case z[1] @@ -136,11 +136,11 @@ def generate_complex_objects(builder, action) case action when :create object.to_hash.each do |k,v| - td.__send__(ons, k.to_s.camelize.to_sym, v) unless v.nil? + td.__send__(ons, api_name(k), v) unless v.nil? end when :update object.to_hash.reject{|k,v| object.read_only_attributes.include?(k) || object.restrain_attributes.include?(k) }.each do |k,v| - td.__send__(ons, k.to_s.camelize.to_sym, v) unless v.nil? + td.__send__(ons, api_name(k), v) unless v.nil? end end end @@ -152,7 +152,7 @@ def generate_complex_objects(builder, action) def generate_bill_to_contact(builder) if @model.bill_to_contact.new_record? @model.bill_to_contact.to_hash.each do |k,v| - builder.__send__(ons, k.to_s.camelize.to_sym, v) unless v.nil? + builder.__send__(ons, api_name(k), v) unless v.nil? end else builder.__send__(ons, :Id, @model.bill_to_contact.id) @@ -162,7 +162,7 @@ def generate_bill_to_contact(builder) def generate_sold_to_contact(builder) if @model.sold_to_contact.new_record? @model.sold_to_contact.to_hash.each do |k,v| - builder.__send__(ons, k.to_s.camelize.to_sym, v) unless v.nil? + builder.__send__(ons, api_name(k), v) unless v.nil? end else builder.__send__(ons, :Id, @model.sold_to_contact.id) @@ -172,7 +172,7 @@ def generate_sold_to_contact(builder) def generate_account(builder) if @model.account.new_record? @model.account.to_hash.each do |k,v| - builder.__send__(ons, k.to_s.camelize.to_sym, v) unless v.nil? + builder.__send__(ons, api_name(k), v) unless v.nil? end else builder.__send__(ons, :Id, @model.account.id) @@ -182,7 +182,7 @@ def generate_account(builder) def generate_payment_method(builder) if @model.payment_method.new_record? @model.payment_method.to_hash.each do |k,v| - builder.__send__(ons, k.to_s.camelize.to_sym, v) unless v.nil? + builder.__send__(ons, api_name(k), v) unless v.nil? end else builder.__send__(ons, :Id, @model.payment_method.id) @@ -191,15 +191,19 @@ def generate_payment_method(builder) def generate_subscription(builder) @model.subscription.to_hash.each do |k,v| - builder.__send__(ons, k.to_s.camelize.to_sym, v) unless v.nil? + builder.__send__(ons, api_name(k), v) unless v.nil? end end def generate_subscribe_options(builder) @model.subscribe_options.each do |k,v| - builder.__send__(zns, k.to_s.camelize.to_sym, v) + builder.__send__(zns, api_name(k), v) end end + # return the attribute name for api + def api_name(key) + @model.class.api_attr(key).to_sym + end end end From 8f227e7209df64185e4dd18483b6cfff607c3705 Mon Sep 17 00:00:00 2001 From: SeanArmstrong Date: Tue, 24 Jun 2014 09:56:48 +0100 Subject: [PATCH 22/36] Add ability to amend to mysageone --- lib/zuora/objects.rb | 2 ++ lib/zuora/objects/amendment.rb | 27 +++++++++++++++++++++- lib/zuora/objects/rate_plan_charge_data.rb | 12 ++++++++++ lib/zuora/objects/rate_plan_data.rb | 12 ++++++++++ lib/zuora/soap_connector.rb | 27 +++++++++++++++++++++- 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 lib/zuora/objects/rate_plan_charge_data.rb create mode 100644 lib/zuora/objects/rate_plan_data.rb diff --git a/lib/zuora/objects.rb b/lib/zuora/objects.rb index 2443ba25..c0f93c57 100644 --- a/lib/zuora/objects.rb +++ b/lib/zuora/objects.rb @@ -24,6 +24,8 @@ module Objects autoload :RatePlan, 'zuora/objects/rate_plan' autoload :RatePlanCharge, 'zuora/objects/rate_plan_charge' autoload :RatePlanChargeTier, 'zuora/objects/rate_plan_charge_tier' + autoload :RatePlanData, 'zuora/objects/rate_plan_data' + autoload :RatePlanChargeData, 'zuora/objects/rate_plan_charge_data' # autoload :Refund, 'zuora/objects/refund' end end diff --git a/lib/zuora/objects/amendment.rb b/lib/zuora/objects/amendment.rb index 4cd26659..3bdf6f17 100644 --- a/lib/zuora/objects/amendment.rb +++ b/lib/zuora/objects/amendment.rb @@ -19,10 +19,35 @@ class Amendment < Base 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) } + + attr_accessor :amendment_ids + attr_accessor :invoice_id + attr_accessor :payment_transaction_number define_attributes do - read_only :created_by_id, :created_date, :updated_by_id, :updated_date + read_only :created_by_id, :created_date, :updated_by_id, :updated_date, :amendment_ids, :invoice_id, :payment_transaction_number defaults :status => 'Draft' end + + def create + result = self.connector.amend + apply_response(result.to_hash, :amend_response) + end + + def apply_response(response_hash, type) + result = response_hash[type][:results] + if result[:success] + self.amendment_ids = result[:amendment_ids] + self.invoice_id = result[:invoice_id] + self.payment_transaction_number = result[:payment_transaction_number] + @previously_changed = changes + @changed_attributes.clear + return true + else + self.errors.add(:base, result[:errors][:message]) + return false + end + end end end diff --git a/lib/zuora/objects/rate_plan_charge_data.rb b/lib/zuora/objects/rate_plan_charge_data.rb new file mode 100644 index 00000000..f35ae345 --- /dev/null +++ b/lib/zuora/objects/rate_plan_charge_data.rb @@ -0,0 +1,12 @@ +module Zuora::Objects + class RatePlanChargeData < Base + attr_accessor :rate_plan_charge + + has_many :rate_plan_charge_tiers + belongs_to :rate_plan_data + + validates_presence_of :rate_plan_charge + + define_attributes {} + end +end diff --git a/lib/zuora/objects/rate_plan_data.rb b/lib/zuora/objects/rate_plan_data.rb new file mode 100644 index 00000000..27952486 --- /dev/null +++ b/lib/zuora/objects/rate_plan_data.rb @@ -0,0 +1,12 @@ +module Zuora::Objects + class RatePlanData < Base + attr_accessor :rate_plan + + has_many :rate_plan_charge_data + belongs_to :amendment + + validates_presence_of :rate_plan + + define_attributes {} + end +end diff --git a/lib/zuora/soap_connector.rb b/lib/zuora/soap_connector.rb index 8d8f1e2c..8d4d9382 100644 --- a/lib/zuora/soap_connector.rb +++ b/lib/zuora/soap_connector.rb @@ -13,11 +13,23 @@ def query(sql) end end + def serialize(xml, key, value) + if value.kind_of?(Zuora::Objects::Base) + xml.__send__(zns, key.to_sym) do |child| + value.to_hash.each do |k, v| + serialize(child, k.to_s.zuora_camelize, convert_value(v)) unless v.nil? + end + end + else + xml.__send__(ons, key.to_sym, convert_value(value)) + end + end + def create current_client.request(:create) do |xml| xml.__send__(zns, :zObjects, 'xsi:type' => "#{ons}:#{remote_name}") do |a| @model.to_hash.each do |k,v| - a.__send__(ons, api_name(k), v) unless v.nil? + serialize(a, k.to_s.zuora_camelize.to_sym, convert_value(v)) unless v.nil? end generate_complex_objects(a, :create) end @@ -46,6 +58,19 @@ def destroy end end + def amend + Zuora::Api.instance.request(:amend) do |xml| + xml.__send__(zns, :requests) do |r| + r.__send__(zns, :Amendments) do |a| + @model.to_hash.each do |k,v| + serialize(a, k.to_s.zuora_camelize.to_sym, conert_value(v)) unless v.nil? + end + generate_complex_objects(a, :create) + end + end + end + end + def subscribe current_client.request(:subscribe) do |xml| xml.__send__(zns, :subscribes) do |s| From 1269110e709b36c71145a0ab1ce75f33a6d57006 Mon Sep 17 00:00:00 2001 From: SeanArmstrong Date: Tue, 24 Jun 2014 11:18:30 +0100 Subject: [PATCH 23/36] Add zuora camelize method --- lib/zuora/soap_connector.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/zuora/soap_connector.rb b/lib/zuora/soap_connector.rb index 8d4d9382..e386c40b 100644 --- a/lib/zuora/soap_connector.rb +++ b/lib/zuora/soap_connector.rb @@ -230,5 +230,13 @@ def generate_subscribe_options(builder) def api_name(key) @model.class.api_attr(key).to_sym end + + def zuora_camelize + if match(/__c$/) + self.gsub("__c","").zuora_camelize + "__c" + else + camelize + end + end end end From 0c330a69de8e9e8fabb89cb8e2187de67306efd1 Mon Sep 17 00:00:00 2001 From: SeanArmstrong Date: Tue, 24 Jun 2014 11:37:40 +0100 Subject: [PATCH 24/36] Move camelize method --- lib/zuora/core_ext/string.rb | 7 +++++++ lib/zuora/soap_connector.rb | 8 -------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/zuora/core_ext/string.rb b/lib/zuora/core_ext/string.rb index 0a6364c3..573054da 100644 --- a/lib/zuora/core_ext/string.rb +++ b/lib/zuora/core_ext/string.rb @@ -6,6 +6,13 @@ def base_name dup.scan(/\w+$/).first end unless method_defined?(:base_name) + def zuora_camelize + if match(/__c$/) + self.gsub("__c","").zuora_camelize + "__c" + else + camelize + end + end unless method_defined?(:zuora_camelize) end end end diff --git a/lib/zuora/soap_connector.rb b/lib/zuora/soap_connector.rb index e386c40b..8d4d9382 100644 --- a/lib/zuora/soap_connector.rb +++ b/lib/zuora/soap_connector.rb @@ -230,13 +230,5 @@ def generate_subscribe_options(builder) def api_name(key) @model.class.api_attr(key).to_sym end - - def zuora_camelize - if match(/__c$/) - self.gsub("__c","").zuora_camelize + "__c" - else - camelize - end - end end end From 7ca0176ced6534b7e5f89e3fc1b435c1590c1479 Mon Sep 17 00:00:00 2001 From: SeanArmstrong Date: Tue, 24 Jun 2014 11:46:24 +0100 Subject: [PATCH 25/36] Add convert_value method for date and time --- lib/zuora/soap_connector.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/zuora/soap_connector.rb b/lib/zuora/soap_connector.rb index 8d4d9382..6698c0a4 100644 --- a/lib/zuora/soap_connector.rb +++ b/lib/zuora/soap_connector.rb @@ -150,6 +150,15 @@ def current_client protected + # Zuora doesn't like the default string format of ruby dates/times + def convert_value(value) + if [Date, Time, DateTime].any? { |klass| value.is_a?(klass) } + value.strftime('%FT%T') + else + 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| From abdadf1e38c8212ddeec9a972015f58d41f68df5 Mon Sep 17 00:00:00 2001 From: SeanArmstrong Date: Wed, 25 Jun 2014 11:25:46 +0100 Subject: [PATCH 26/36] Update soap connector amend --- lib/zuora/soap_connector.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zuora/soap_connector.rb b/lib/zuora/soap_connector.rb index 6698c0a4..ff0fc1f0 100644 --- a/lib/zuora/soap_connector.rb +++ b/lib/zuora/soap_connector.rb @@ -59,11 +59,11 @@ def destroy end def amend - Zuora::Api.instance.request(:amend) do |xml| + current_client.request(:amend) do |xml| xml.__send__(zns, :requests) do |r| r.__send__(zns, :Amendments) do |a| @model.to_hash.each do |k,v| - serialize(a, k.to_s.zuora_camelize.to_sym, conert_value(v)) unless v.nil? + serialize(a, k.to_s.zuora_camelize.to_sym, convert_value(v)) unless v.nil? end generate_complex_objects(a, :create) end From 950e1b51134f129fb2530f25cddae9a74645c657 Mon Sep 17 00:00:00 2001 From: SeanArmstrong Date: Thu, 26 Jun 2014 11:59:54 +0100 Subject: [PATCH 27/36] Add Amend options to amend SOAP Call --- lib/zuora/soap_connector.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/zuora/soap_connector.rb b/lib/zuora/soap_connector.rb index ff0fc1f0..270a5068 100644 --- a/lib/zuora/soap_connector.rb +++ b/lib/zuora/soap_connector.rb @@ -59,6 +59,9 @@ def destroy end def amend + #TODO Don't hard code this + @amend_options = { 'process_payments' => false } + current_client.request(:amend) do |xml| xml.__send__(zns, :requests) do |r| r.__send__(zns, :Amendments) do |a| @@ -67,6 +70,12 @@ def amend end generate_complex_objects(a, :create) end + + r.__send__(zns, :AmendOptions) do |ao| + @amend_options.each do |k,v| + xml.__send__(zns, k.to_s.zuora_camelize.to_sym, convert_value(v)) unless v.nil? + end + end end end end From efb2712f987d49bddfdd246317f890f139b6a73b Mon Sep 17 00:00:00 2001 From: SeanArmstrong Date: Thu, 26 Jun 2014 13:53:31 +0100 Subject: [PATCH 28/36] Remove amendment create override --- lib/zuora/objects/amendment.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/zuora/objects/amendment.rb b/lib/zuora/objects/amendment.rb index 3bdf6f17..efe787c6 100644 --- a/lib/zuora/objects/amendment.rb +++ b/lib/zuora/objects/amendment.rb @@ -19,7 +19,7 @@ class Amendment < Base 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) } + 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 @@ -30,12 +30,12 @@ class Amendment < Base defaults :status => 'Draft' end - def create + def apply_percentage_discount result = self.connector.amend - apply_response(result.to_hash, :amend_response) + apply_percentage_discount_response(result.to_hash, :amend_response) end - def apply_response(response_hash, type) + def apply_percentage_discount_response(response_hash, type) result = response_hash[type][:results] if result[:success] self.amendment_ids = result[:amendment_ids] From 8cdc21fa3cd1982077f02942b670073a059562cf Mon Sep 17 00:00:00 2001 From: nigel surtees Date: Fri, 27 Jun 2014 12:13:18 +0100 Subject: [PATCH 29/36] updated sqliteconnector to include amend method. Added amendoptions param to amend call from amendment --- lib/zuora/objects/amendment.rb | 2 +- lib/zuora/soap_connector.rb | 7 ++----- lib/zuora/sqlite_connector.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/zuora/objects/amendment.rb b/lib/zuora/objects/amendment.rb index efe787c6..22eb8126 100644 --- a/lib/zuora/objects/amendment.rb +++ b/lib/zuora/objects/amendment.rb @@ -31,7 +31,7 @@ class Amendment < Base end def apply_percentage_discount - result = self.connector.amend + result = self.connector.amend({ 'process_payments' => false }) apply_percentage_discount_response(result.to_hash, :amend_response) end diff --git a/lib/zuora/soap_connector.rb b/lib/zuora/soap_connector.rb index 270a5068..0eb942f6 100644 --- a/lib/zuora/soap_connector.rb +++ b/lib/zuora/soap_connector.rb @@ -58,10 +58,7 @@ def destroy end end - def amend - #TODO Don't hard code this - @amend_options = { 'process_payments' => false } - + def amend(amend_options={}) current_client.request(:amend) do |xml| xml.__send__(zns, :requests) do |r| r.__send__(zns, :Amendments) do |a| @@ -72,7 +69,7 @@ def amend end r.__send__(zns, :AmendOptions) do |ao| - @amend_options.each do |k,v| + amend_options.each do |k,v| xml.__send__(zns, k.to_s.zuora_camelize.to_sym, convert_value(v)) unless v.nil? end end diff --git a/lib/zuora/sqlite_connector.rb b/lib/zuora/sqlite_connector.rb index 2700759d..3f680de1 100644 --- a/lib/zuora/sqlite_connector.rb +++ b/lib/zuora/sqlite_connector.rb @@ -60,6 +60,32 @@ def create } end + def amend(options={}) + table = self.class.table_name(@model.class) + hash = @model.to_hash + hash.delete(:id) + keys = [] + values = [] + hash.each do |key, value| + keys << @model.class.api_attr(key) + values << value.to_s + end + place_holder = ['?'] * keys.length + keys = keys.join(', ') + place_holder = place_holder.join(', ') + insert = "INSERT into '#{table}'(#{keys}) VALUES(#{place_holder})" + db.execute insert, values + new_id = db.last_insert_row_id + { + :create_response => { + :result => { + :success => true, + :id => new_id + } + } + } + end + def update table = self.class.table_name(@model.class) hash = @model.to_hash From 3bb4db66fc473c1943de430c4a174bf6a458adf4 Mon Sep 17 00:00:00 2001 From: nigel surtees Date: Fri, 27 Jun 2014 13:40:24 +0100 Subject: [PATCH 30/36] added status='Completed to amendment object --- lib/zuora/objects/amendment.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/zuora/objects/amendment.rb b/lib/zuora/objects/amendment.rb index 22eb8126..d141b5a6 100644 --- a/lib/zuora/objects/amendment.rb +++ b/lib/zuora/objects/amendment.rb @@ -31,6 +31,7 @@ class Amendment < Base end def apply_percentage_discount + self.status = 'Completed' result = self.connector.amend({ 'process_payments' => false }) apply_percentage_discount_response(result.to_hash, :amend_response) end From 8abe81cd6a84d008986520fdb7c0fa03fda6c85c Mon Sep 17 00:00:00 2001 From: SeanArmstrong Date: Wed, 16 Jul 2014 13:45:17 +0100 Subject: [PATCH 31/36] Final changes --- lib/zuora/objects/amendment.rb | 2 ++ lib/zuora/sqlite_connector.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/zuora/objects/amendment.rb b/lib/zuora/objects/amendment.rb index d141b5a6..0a3f342b 100644 --- a/lib/zuora/objects/amendment.rb +++ b/lib/zuora/objects/amendment.rb @@ -36,6 +36,8 @@ def apply_percentage_discount 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] diff --git a/lib/zuora/sqlite_connector.rb b/lib/zuora/sqlite_connector.rb index 3f680de1..811a49d4 100644 --- a/lib/zuora/sqlite_connector.rb +++ b/lib/zuora/sqlite_connector.rb @@ -60,6 +60,7 @@ def create } end + #TODO Schema update needed for this method def amend(options={}) table = self.class.table_name(@model.class) hash = @model.to_hash From 43d2f3fc6f56a76e3ce48c96e6e2eec8ef3ee353 Mon Sep 17 00:00:00 2001 From: nigel surtees Date: Thu, 23 Oct 2014 14:46:32 +0100 Subject: [PATCH 32/36] UKIEBUGS769 improve ex handling --- lib/zuora/objects/amendment.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/zuora/objects/amendment.rb b/lib/zuora/objects/amendment.rb index 0a3f342b..b8b8441e 100644 --- a/lib/zuora/objects/amendment.rb +++ b/lib/zuora/objects/amendment.rb @@ -48,8 +48,7 @@ def apply_percentage_discount_response(response_hash, type) @changed_attributes.clear return true else - self.errors.add(:base, result[:errors][:message]) - return false + raise StandardError.new(result[:errors][:message]) end end end From d24e550d8235e319f6767f8667bb13e9e5fdc995 Mon Sep 17 00:00:00 2001 From: nigel surtees Date: Wed, 26 Nov 2014 11:48:43 +0000 Subject: [PATCH 33/36] change zuora api specific exception to standard exception --- .idea/scopes/scope_settings.xml | 5 + .idea/workspace.xml | 341 +++++++++++++++++++++++++++++ .idea/zuora.iml | 69 ++++++ lib/zuora/objects/base.rb | 2 +- spec/zuora/objects/account_spec.rb | 2 +- spec/zuora/objects/base_spec.rb | 2 +- 6 files changed, 418 insertions(+), 3 deletions(-) create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/workspace.xml create mode 100644 .idea/zuora.iml diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 00000000..922003b8 --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..56bb210d --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,341 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1416300736844 + 1416300736844 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/zuora.iml b/.idea/zuora.iml new file mode 100644 index 00000000..261b6395 --- /dev/null +++ b/.idea/zuora.iml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/zuora/objects/base.rb b/lib/zuora/objects/base.rb index aa82964e..55a1c108 100644 --- a/lib/zuora/objects/base.rb +++ b/lib/zuora/objects/base.rb @@ -175,7 +175,7 @@ def apply_response(response_hash, type) @changed_attributes.clear return true else - raise Zuora::ApiFailure.new result[:errors][:message] + raise StandardError.new(result[:errors][:message]) end end diff --git a/spec/zuora/objects/account_spec.rb b/spec/zuora/objects/account_spec.rb index f823a05c..16df0d3d 100644 --- a/spec/zuora/objects/account_spec.rb +++ b/spec/zuora/objects/account_spec.rb @@ -154,7 +154,7 @@ a.payment_term = 'Due Upon Receipt' a.status = 'Draft' a.should be_valid - expect { a.save }.to raise_error Zuora::ApiFailure + expect { a.save }.to raise_error StandardError a.id.should be_nil end end diff --git a/spec/zuora/objects/base_spec.rb b/spec/zuora/objects/base_spec.rb index 10964830..186c5214 100644 --- a/spec/zuora/objects/base_spec.rb +++ b/spec/zuora/objects/base_spec.rb @@ -32,7 +32,7 @@ def initialize(model) describe :apply_response do context "when a failure" do it "raises an exception" do - expect { subject.send(:apply_response, { :foo => { :result => { :errors => { :message => 'Some error' } } } }, :foo )}.to raise_error Zuora::ApiFailure, 'Some error' + expect { subject.send(:apply_response, { :foo => { :result => { :errors => { :message => 'Some error' } } } }, :foo )}.to raise_error StandardError, 'Some error' end end end From 9dd107008f61d8c9d6bac7ee89ddceeec9950aeb Mon Sep 17 00:00:00 2001 From: nigel surtees Date: Wed, 26 Nov 2014 12:01:17 +0000 Subject: [PATCH 34/36] remove unwanted rubymine files --- .idea/scopes/scope_settings.xml | 5 - .idea/workspace.xml | 341 -------------------------------- .idea/zuora.iml | 69 ------- 3 files changed, 415 deletions(-) delete mode 100644 .idea/scopes/scope_settings.xml delete mode 100644 .idea/workspace.xml delete mode 100644 .idea/zuora.iml diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b8..00000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 56bb210d..00000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,341 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1416300736844 - 1416300736844 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.idea/zuora.iml b/.idea/zuora.iml deleted file mode 100644 index 261b6395..00000000 --- a/.idea/zuora.iml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From cb6ec9ccdc9d22e9c15c3f6ff46f0bbf08811976 Mon Sep 17 00:00:00 2001 From: Andrew Chilton Date: Thu, 11 Feb 2016 15:33:56 +0000 Subject: [PATCH 35/36] Upgraded for rails 4 and added release notes --- RELEASE_NOTES.md | 16 ++++++++++++++++ zuora.gemspec | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 RELEASE_NOTES.md diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md new file mode 100644 index 00000000..699d14d0 --- /dev/null +++ b/RELEASE_NOTES.md @@ -0,0 +1,16 @@ +# Version Next + +### Changes + * SOP Upgrade - rails 4.0 + +### Dependencies + * None + +### Deploy tasks + * None + +### Migration Details + * None + +### Obfuscation PR + * None \ No newline at end of file diff --git a/zuora.gemspec b/zuora.gemspec index 1cda6055..4ac09481 100644 --- a/zuora.gemspec +++ b/zuora.gemspec @@ -18,8 +18,8 @@ Gem::Specification.new do |s| s.extra_rdoc_files = [ "README.md" ] s.add_runtime_dependency('savon', ["0.9.9"]) - s.add_runtime_dependency('activesupport', [">= 3.0.0", "< 4.0.0"]) - s.add_runtime_dependency('activemodel', [">= 3.0.0", "< 4.0.0"]) + s.add_runtime_dependency('activesupport', [">= 4.0.0", "< 5.0.0"]) + s.add_runtime_dependency('activemodel', [">= 4.0.0", "< 5.0.0"]) s.add_runtime_dependency('httpi', ["0.9.7"]) s.add_runtime_dependency('libxml4r', ['~> 0.2.6']) From e6dd01f4af10ba8ec808a1977255f8c5d78524f7 Mon Sep 17 00:00:00 2001 From: Andrew Chilton Date: Thu, 11 Feb 2016 15:43:03 +0000 Subject: [PATCH 36/36] Upgraded for rails 4 - change range --- zuora.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zuora.gemspec b/zuora.gemspec index 4ac09481..7c0a3401 100644 --- a/zuora.gemspec +++ b/zuora.gemspec @@ -18,8 +18,8 @@ Gem::Specification.new do |s| s.extra_rdoc_files = [ "README.md" ] s.add_runtime_dependency('savon', ["0.9.9"]) - s.add_runtime_dependency('activesupport', [">= 4.0.0", "< 5.0.0"]) - s.add_runtime_dependency('activemodel', [">= 4.0.0", "< 5.0.0"]) + s.add_runtime_dependency('activesupport', [">= 3.0.0", "< 5.0.0"]) + s.add_runtime_dependency('activemodel', [">= 3.0.0", "< 5.0.0"]) s.add_runtime_dependency('httpi', ["0.9.7"]) s.add_runtime_dependency('libxml4r', ['~> 0.2.6'])