Skip to content

Commit

Permalink
fixing rails 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 3241528
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
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
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 3241528

Please sign in to comment.