PG and date validation

@benorenstein, you mentioned in a recent Weekly Iteration that you did with @jferris that PG has a weird problem where it doesn’t work with dates outside of a certain nearby span, and specifically that 0 AC/CE caused an issue. I’m currently having the following problem, and was wondering if you or anyone else had a solution:

Here’s my spec, which passes on my local machine, but fails on Travis:
it { should validate_uniqueness_of(:date).scoped_to(:weather_location_id) }

I get a failure on Travis that looks like this

  1. DailyWeatherForecast uniqueness constriants should require case sensitive unique value for date scoped to weather_location_id
    Failure/Error: it { should validate_uniqueness_of(:date).scoped_to(:weather_location_id) }
    PG::DatetimeFieldOverflow: ERROR: date/time field value out of range: "0"
    HINT: Perhaps you need a different “datestyle” setting.
    : INSERT INTO “daily_weather_forecasts” (“created_at”, “date”, “updated_at”, “weather_location_id”) VALUES ($1, $2, $3, $4) RETURNING “id”

I tried setting the date by explicitly setting subject:
describe 'uniqueness constriants' do # Postgres has a weird bug where it thinks a date of 0 CE doesn't exist # Without setting the subject's date explicitly, we get a failure on # Travis. subject { described_class.create(date: } it { should validate_uniqueness_of(:date).scoped_to(:weather_location_id) } end

But I still have the same problem, where the failure only happens on Travis builds. Is there a technique to ensure that RSpec/shoulda/Rails doesn’t set the test date to a date outside of PG’s allowed range?

Answering my own question, because I had a brain fart while coding this example:

I wasn’t actually creating a new model, because I was using Model.create rather than Model.create!.

I’m still curious if anyone has had issues with PG and a date of zero.