postgresqldateruby-on-rails-3.1factory-botrails-postgresql

Factory_girl_rails and postgres date format?


How do I format a date to put it in a factory_girl_rails factory eg:

Factory.define(:profile) do |t|
  t.length 110
  t.shipdate 1993-04-06
end

If it matters, I'm using postgresql and factory_girl_rails 1.0. The error I've been getting is ActiveRecord::StatementInvalid: PGError: ERROR: invalid input syntax for type date: "1982" The rails version is 3.1


Solution

  • You're missing the quotes around your date string:

    Factory.define(:profile) do |t|
      t.length 110
      t.shipdate '1993-04-06'
    end
    

    1993 minus 4 is 1989, 1989 minus 6 is 1983. Are you sure you copied the error message correctly?