Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabling validations #42

Open
adamwong246 opened this issue Nov 1, 2012 · 5 comments
Open

enabling validations #42

adamwong246 opened this issue Nov 1, 2012 · 5 comments

Comments

@adamwong246
Copy link

I noticed that using seed(), validations are skipped. Is there any way to override this? I want my validations to run on seed().

@DaveSanders
Copy link

I concur. It's sort of a big deal for us because we are seeding data as a migration process from an old system - so we can find any bad data naturally.

@svyatov
Copy link

svyatov commented Jul 24, 2014

Agree. Just bump into that problem. I cannot use before_validation callbacks to process some properties :(

@PratheepV
Copy link

@svyatov , @DaveSanders @adamwong246 , as a work around I am using this

https://gist.github.com/PratheepV/504f39176ee43032b5ec

Thanks,
Pratheepv

@ffloyd
Copy link

ffloyd commented May 30, 2018

Another way is to create config/initializers/seed_fu.rb:

# Reason: seed_fu has no validations and there is no option to turn it on.
# But when using seeds on production/stages we want to be sure that generated data are correct.
module SeedFuValidations
  def seed(*args)
    super.each(&:validate!)
  end

  def seed_once(*args)
    super.each(&:validate!)
  end
end

ActiveRecord::Base.extend(SeedFuValidations)

@swistaczek
Copy link

It would be great to set this as switch in configuration :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants