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