Trying to implement a couple tests for my custom validations and I came across this example.
My validator looks like this
class FutureValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value == nil
record.errors[attribute] << " can't be nil"
elsif value < Time.now
record.errors[attribute] << (options[:message] || "can't be in the past!")
end
end
end
And I've gotten as far as this using the above mentioned example as a guideline.
require 'test_helper'
class FutureValidatorable
include ActiveModel::Validations
# validates_with FutureValidator
attr_accessor :future
validates :future, future: true
end
class FutureValidator < ActiveSupport::TestCase
future_value = [nil]
def obj; @obj ||= FutureValidatorable.new; end
test 'future validator returns proper error code when nil is passed to it' do
future_value.each do |value|
@obj.value = value
assert_not obj.valid?
end
end
At this stage I'm getting the error message I am getting is as follows.
rake aborted! TypeError: superclass mismatch for class FutureValidator
I'm not sure how to proceed from here.