AgileVentures / MetPlus_tracker

Git Repository for the Waffle issue in MetPlus project
2 stars 4 forks source link

Seeds file broken #721

Closed patmbolger closed 6 years ago

patmbolger commented 6 years ago

rake db:seeds fails because of a bug in the seeds file. The JobSeeker validation of attribute year_of_birth should also be modified to give a better error message when the value of the attribute does not fall within an acceptable range.

seeds.rb, line 318:

year_of_birth = 2016 - r.rand(100)

1) This should generate a year of birth between 16 and 65 years ago, inclusive (or whatever the acceptable range of years should be).

2) This sometimes generates a year of birth earlier than 100 years ago (e.g. 1917).

year_of_birth_validator.rb:

class YearOfBirthValidator < ActiveModel::EachValidator

  def validate_each(object, attribute, value)
    return if value == nil
    reg = /\A\d{4}\z/

    if !value=~reg  || !((100.years.ago.year..Date.today.year).member?(value.to_i))
        object.errors[attribute] << (options[:message] || 'incorrect format')
    end
  end
end

1) When this sees "1917", it issues a validation error on the format, not on the year not falling within the acceptable range. The model error message should indicate the real problem. 2) The validation should check that the year falls within an acceptable range (e.g. between 16 and 65 years ago, inclusive - check with client on what the range should be).