Skip to content

Commit

Permalink
fixing rails 4 and 7 specs
Browse files Browse the repository at this point in the history
  • Loading branch information
angelasilva committed Jul 22, 2024
1 parent a5646f1 commit f3a77da
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/zuora/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions lib/zuora/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,4 +38,4 @@ def validates_date_of(*attr_names)
end
end
end
end
end
7 changes: 2 additions & 5 deletions spec/zuora/objects/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,8 @@
expect(Zuora::Api.instance.client).to receive(:call).with(
:update,
{
message: '<zns:zObjects xsi:type="ons:Account"><ons:Id>4028e488348752ce0134876a25867cb2</ons:Id>'\
'<ons:AccountNumber>test-1</ons:AccountNumber><ons:AutoPay>false</ons:AutoPay><ons:Batch>Batch1'\
'</ons:Batch><ons:BillCycleDay>1</ons:BillCycleDay><ons:Currency>USD</ons:Currency><ons:Name>FooMax'\
'</ons:Name><ons:PaymentTerm>Due Upon Receipt</ons:PaymentTerm><ons:Status>Draft</ons:Status>'\
'</zns:zObjects>',
message: '<zns:zObjects xsi:type="ons:Account"><ons:Id>4028e488348752ce0134876a25867cb2</ons:Id><ons:Name>'\
'FooMax</ons:Name></zns:zObjects>',
soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } }
}
).and_call_original
Expand Down
21 changes: 11 additions & 10 deletions spec/zuora/objects/subscribe_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
'<zns:PaymentMethod><ons:Id>4028e48834aa10a30134c50f40901ea7</ons:Id></zns:PaymentMethod>'\
'<zns:BillToContact><ons:Id>4028e4873491cc770134972e75746e4c</ons:Id></zns:BillToContact>'\
'<zns:SubscriptionData><zns:Subscription><ons:AutoRenew>false</ons:AutoRenew><ons:ContractEffectiveDate>'\
"#{Time.now.rfc3339}</ons:ContractEffectiveDate><ons:InitialTerm>1</ons:InitialTerm>"\
"#{Time.now.iso8601}</ons:ContractEffectiveDate><ons:InitialTerm>1</ons:InitialTerm>"\
"<ons:IsInvoiceSeparate>false</ons:IsInvoiceSeparate><ons:Name>#{sub_name}</ons:Name>"\
"<ons:RenewalTerm>0</ons:RenewalTerm><ons:TermStartDate>#{Time.now.rfc3339}</ons:TermStartDate>"\
"<ons:RenewalTerm>0</ons:RenewalTerm><ons:TermStartDate>#{Time.now.iso8601}</ons:TermStartDate>"\
'</zns:Subscription><zns:RatePlanData><zns:RatePlan><ons:ProductRatePlanId>'\
'4028e4883491c50901349d0e1e571341</ons:ProductRatePlanId></zns:RatePlan></zns:RatePlanData>'\
'</zns:SubscriptionData></zns:subscribes>',
Expand All @@ -79,9 +79,9 @@
'<ons:Status>Draft</ons:Status></zns:Account><zns:PaymentMethod><ons:Id>4028e48834aa10a30134c50f40901ea7'\
'</ons:Id></zns:PaymentMethod><zns:BillToContact><ons:Id>4028e4873491cc770134972e75746e4c</ons:Id>'\
'</zns:BillToContact><zns:SubscriptionData><zns:Subscription><ons:AutoRenew>false</ons:AutoRenew>'\
"<ons:ContractEffectiveDate>#{Time.now.rfc3339}</ons:ContractEffectiveDate><ons:InitialTerm>1"\
"<ons:ContractEffectiveDate>#{Time.now.iso8601}</ons:ContractEffectiveDate><ons:InitialTerm>1"\
"</ons:InitialTerm><ons:IsInvoiceSeparate>false</ons:IsInvoiceSeparate><ons:Name>#{sub_name}</ons:Name>"\
"<ons:RenewalTerm>0</ons:RenewalTerm><ons:TermStartDate>#{Time.now.rfc3339}</ons:TermStartDate>"\
"<ons:RenewalTerm>0</ons:RenewalTerm><ons:TermStartDate>#{Time.now.iso8601}</ons:TermStartDate>"\
'</zns:Subscription><zns:RatePlanData><zns:RatePlan><ons:ProductRatePlanId>'\
'4028e4883491c50901349d0e1e571341</ons:ProductRatePlanId></zns:RatePlan></zns:RatePlanData>'\
'</zns:SubscriptionData></zns:subscribes>',
Expand All @@ -104,10 +104,10 @@
'<zns:PaymentMethod><ons:Id>4028e48834aa10a30134c50f40901ea7</ons:Id></zns:PaymentMethod>'\
'<zns:BillToContact><ons:AccountId>4028e488348752ce0134876a25867cb2</ons:AccountId><ons:FirstName>'\
'Example</ons:FirstName><ons:LastName>User 1</ons:LastName></zns:BillToContact><zns:SubscriptionData>'\
"<zns:Subscription><ons:AutoRenew>false</ons:AutoRenew><ons:ContractEffectiveDate>#{Time.now.rfc3339}"\
"<zns:Subscription><ons:AutoRenew>false</ons:AutoRenew><ons:ContractEffectiveDate>#{Time.now.iso8601}"\
'</ons:ContractEffectiveDate><ons:InitialTerm>1</ons:InitialTerm><ons:IsInvoiceSeparate>false'\
"</ons:IsInvoiceSeparate><ons:Name>#{sub_name}</ons:Name><ons:RenewalTerm>0</ons:RenewalTerm>"\
"<ons:TermStartDate>#{Time.now.rfc3339}</ons:TermStartDate></zns:Subscription><zns:RatePlanData>"\
"<ons:TermStartDate>#{Time.now.iso8601}</ons:TermStartDate></zns:Subscription><zns:RatePlanData>"\
'<zns:RatePlan><ons:ProductRatePlanId>4028e4883491c50901349d0e1e571341</ons:ProductRatePlanId>'\
'</zns:RatePlan></zns:RatePlanData></zns:SubscriptionData></zns:subscribes>',
soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } }
Expand All @@ -132,9 +132,9 @@
'Bank of Zuora</ons:AchBankName><ons:Type>ACH</ons:Type><ons:UseDefaultRetryRule>true'\
'</ons:UseDefaultRetryRule></zns:PaymentMethod><zns:BillToContact><ons:Id>4028e4873491cc770134972e75746e4c'\
'</ons:Id></zns:BillToContact><zns:SubscriptionData><zns:Subscription><ons:AutoRenew>false</ons:AutoRenew>'\
"<ons:ContractEffectiveDate>#{Time.now.rfc3339}</ons:ContractEffectiveDate><ons:InitialTerm>1"\
"<ons:ContractEffectiveDate>#{Time.now.iso8601}</ons:ContractEffectiveDate><ons:InitialTerm>1"\
"</ons:InitialTerm><ons:IsInvoiceSeparate>false</ons:IsInvoiceSeparate><ons:Name>#{sub_name}"\
"</ons:Name><ons:RenewalTerm>0</ons:RenewalTerm><ons:TermStartDate>#{Time.now.rfc3339}</ons:TermStartDate>"\
"</ons:Name><ons:RenewalTerm>0</ons:RenewalTerm><ons:TermStartDate>#{Time.now.iso8601}</ons:TermStartDate>"\
'</zns:Subscription><zns:RatePlanData><zns:RatePlan><ons:ProductRatePlanId>'\
'4028e4883491c50901349d0e1e571341</ons:ProductRatePlanId></zns:RatePlan></zns:RatePlanData>'\
'</zns:SubscriptionData></zns:subscribes>',
Expand Down Expand Up @@ -165,10 +165,10 @@
'<zns:BillToContact><ons:Id>4028e4873491cc770134972e75746e4c</ons:Id></zns:BillToContact>'\
'<zns:SubscribeOptions><zns:GenerateInvoice>true</zns:GenerateInvoice><zns:ProcessPayments>true'\
'</zns:ProcessPayments></zns:SubscribeOptions><zns:SubscriptionData><zns:Subscription><ons:AutoRenew>'\
"false</ons:AutoRenew><ons:ContractEffectiveDate>#{Time.now.rfc3339}</ons:ContractEffectiveDate>"\
"false</ons:AutoRenew><ons:ContractEffectiveDate>#{Time.now.iso8601}</ons:ContractEffectiveDate>"\
'<ons:InitialTerm>1</ons:InitialTerm><ons:IsInvoiceSeparate>false</ons:IsInvoiceSeparate><ons:Name>'\
"#{sub_name}</ons:Name><ons:RenewalTerm>0</ons:RenewalTerm><ons:TermStartDate>"\
"#{Time.now.rfc3339}</ons:TermStartDate></zns:Subscription><zns:RatePlanData><zns:RatePlan>"\
"#{Time.now.iso8601}</ons:TermStartDate></zns:Subscription><zns:RatePlanData><zns:RatePlan>"\
'<ons:ProductRatePlanId>4028e4883491c50901349d0e1e571341</ons:ProductRatePlanId></zns:RatePlan>'\
'</zns:RatePlanData></zns:SubscriptionData></zns:subscribes>',
soap_header: { 'env:SessionHeader' => { 'zns:Session' => 'session_key' } }
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/zuora/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3a77da

Please sign in to comment.