Skip to content

Commit

Permalink
fixing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
angelasilva committed Jul 22, 2024
1 parent 163a9f9 commit a5646f1
Show file tree
Hide file tree
Showing 17 changed files with 574 additions and 1,122 deletions.
3 changes: 1 addition & 2 deletions lib/zuora/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
23 changes: 13 additions & 10 deletions lib/zuora/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/zuora/objects/amendment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions lib/zuora/objects/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def reload!
self.send("#{k}=", v)
}
@previously_changed = changes
@changed_attributes.clear
clear_changes_information
self
end

Expand Down Expand Up @@ -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])
Expand Down
3 changes: 1 addition & 2 deletions lib/zuora/objects/subscribe_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -68,4 +68,3 @@ def destroy ; end
def save ; end
end
end

2 changes: 1 addition & 1 deletion spec/factories/payment_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns1:queryResponse xmlns:ns1="http://api.zuora.com/"><ns1:result><ns1:done>true</ns1:done><ns1:queryLocator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="1" /><ns1:records xmlns:ns2="http://object.api.zuora.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:PaymentMethod"><ns2:Id>4028e48834aa10a30134c50f40901ea7</ns2:Id><ns2:AccountId>4028e48834aa10a30134c50f40191ea6</ns2:AccountId><ns2:Active>false</ns2:Active><ns2:BankIdentificationNumber>411111</ns2:BankIdentificationNumber><ns2:CreatedById>4028e488346987860134866a562363d4</ns2:CreatedById><ns2:CreatedDate>2012-01-09T16:40:38.000-08:00</ns2:CreatedDate><ns2:CreditCardAddress1>123 Testing Lane</ns2:CreditCardAddress1><ns2:CreditCardCity>San Francisco</ns2:CreditCardCity><ns2:CreditCardExpirationMonth>9</ns2:CreditCardExpirationMonth><ns2:CreditCardExpirationYear>2018</ns2:CreditCardExpirationYear><ns2:CreditCardHolderName>Example User</ns2:CreditCardHolderName><ns2:CreditCardMaskNumber>************1111</ns2:CreditCardMaskNumber><ns2:CreditCardPostalCode>95611</ns2:CreditCardPostalCode><ns2:CreditCardState>California</ns2:CreditCardState><ns2:CreditCardType>Visa</ns2:CreditCardType><ns2:LastTransactionDateTime>2012-01-09T16:40:38.000-08:00</ns2:LastTransactionDateTime><ns2:LastTransactionStatus>Approved</ns2:LastTransactionStatus><ns2:NumConsecutiveFailures>0</ns2:NumConsecutiveFailures><ns2:PaymentMethodStatus>Active</ns2:PaymentMethodStatus><ns2:TotalNumberOfErrorPayments>0</ns2:TotalNumberOfErrorPayments><ns2:TotalNumberOfProcessedPayments>0</ns2:TotalNumberOfProcessedPayments><ns2:Type>CreditCard</ns2:Type><ns2:UpdatedById>4028e488346987860134866a562363d4</ns2:UpdatedById><ns2:UpdatedDate>2012-01-09T16:40:38.000-08:00</ns2:UpdatedDate><ns2:UseDefaultRetryRule>true</ns2:UseDefaultRetryRule></ns1:records><ns1:size>1</ns1:size></ns1:result></ns1:queryResponse></soapenv:Body></soapenv:Envelope>
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns1:queryResponse xmlns:ns1="http://api.zuora.com/"><ns1:result><ns1:done>true</ns1:done><ns1:queryLocator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="1" /><ns1:records xmlns:ns2="http://object.api.zuora.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:PaymentMethod"><ns2:Id>4028e48834aa10a30134c50f40901ea7</ns2:Id><ns2:AccountId>4028e48834aa10a30134c50f40191ea6</ns2:AccountId><ns2:Active>false</ns2:Active><ns2:BankIdentificationNumber>411111</ns2:BankIdentificationNumber><ns2:CreatedById>4028e488346987860134866a562363d4</ns2:CreatedById><ns2:CreatedDate>2012-01-09T16:40:38.000-08:00</ns2:CreatedDate><ns2:CreditCardAddress1>123 Testing Lane</ns2:CreditCardAddress1><ns2:CreditCardCity>San Francisco</ns2:CreditCardCity><ns2:CreditCardExpirationMonth>9</ns2:CreditCardExpirationMonth><ns2:CreditCardExpirationYear>2028</ns2:CreditCardExpirationYear><ns2:CreditCardHolderName>Example User</ns2:CreditCardHolderName><ns2:CreditCardMaskNumber>************1111</ns2:CreditCardMaskNumber><ns2:CreditCardPostalCode>95611</ns2:CreditCardPostalCode><ns2:CreditCardState>California</ns2:CreditCardState><ns2:CreditCardType>Visa</ns2:CreditCardType><ns2:LastTransactionDateTime>2012-01-09T16:40:38.000-08:00</ns2:LastTransactionDateTime><ns2:LastTransactionStatus>Approved</ns2:LastTransactionStatus><ns2:NumConsecutiveFailures>0</ns2:NumConsecutiveFailures><ns2:PaymentMethodStatus>Active</ns2:PaymentMethodStatus><ns2:TotalNumberOfErrorPayments>0</ns2:TotalNumberOfErrorPayments><ns2:TotalNumberOfProcessedPayments>0</ns2:TotalNumberOfProcessedPayments><ns2:Type>CreditCard</ns2:Type><ns2:UpdatedById>4028e488346987860134866a562363d4</ns2:UpdatedById><ns2:UpdatedDate>2012-01-09T16:40:38.000-08:00</ns2:UpdatedDate><ns2:UseDefaultRetryRule>true</ns2:UseDefaultRetryRule></ns1:records><ns1:size>1</ns1:size></ns1:result></ns1:queryResponse></soapenv:Body></soapenv:Envelope>
3 changes: 1 addition & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -33,5 +34,3 @@ def zns
def ons
zuora_namespace('http://object.api.zuora.com/')
end


11 changes: 3 additions & 8 deletions spec/zuora/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit a5646f1

Please sign in to comment.