class PreviouslyPublishedValidator < ActiveModel::Validator
  def validate(record)
    if record.previously_published.nil?
      record.errors[:base] << "You must specify whether the document has been published before"
      record.has_previously_published_error = true
    elsif record.previously_published
      if record.first_published_at.blank?
        record.errors.add(:first_published_at, "can't be blank")
      elsif record.first_published_at > Time.zone.now
        record.errors.add(:first_published_at, "can't be set to a future date")
      end
    end
  end
end

class PreviouslyPublishedValidator < ActiveModel::Validator
  def validate(record)
    record.has_previously_published_error = false

    if record.previously_published.nil?
      record.errors[:base] << "You must specify whether the document has been published before"
      record.has_previously_published_error = true
    elsif record.previously_published && record.first_published_at.blank?
      record.errors.add(:first_published_at, "can't be blank")
    end

    if record.first_published_at && Time.zone.now < record.first_published_at
      record.errors.add(:first_published_at, "can't be set to a future date")
    end
  end
end

Adjust first published at validator logic
Adjust first published at validator logic

It shouldn't be possible to set first_published_at to
a future date regardless of whether the document has
been previously published. The UI would prevent the user
from setting a future date if previously published was
false but a model level validation is probably more sensible
prevention.
