Skip to content

Validation doesn't work if the value is represented as a string #91

Description

@krtschmr

We have an object that can hold a value which is just a string. Depends on the STI Child of the object, a specific validation is running.

t.string :value, null: true

class SmartField < ApplicationRecord
  validates :value, date: true
end


SmartField.create! value: Date.today
ActiveRecord::RecordInvalid: Validatie mislukt: Value is geen datum

this looks very odd to me and was unexpected.

      def is_time?(object)
        object.is_a?(Time) || (defined?(Date) and object.is_a?(Date)) || (defined?(ActiveSupport::TimeWithZone) and object.is_a?(ActiveSupport::TimeWithZone))
      end

do we need a string check, aka Date.parse rescue false?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions