From 32415282c9772f44e898ac989b9f2a163da45e5d Mon Sep 17 00:00:00 2001 From: Angela Silva Date: Mon, 22 Jul 2024 11:48:34 +0100 Subject: [PATCH] fixing rails 7 specs --- lib/zuora/validations.rb | 10 +++++----- spec/zuora/validations_spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/zuora/validations.rb b/lib/zuora/validations.rb index 647fdbb..fa31f8e 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/validations_spec.rb b/spec/zuora/validations_spec.rb index f6c34ca..a202f05 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