Skip to content

Instantly share code, notes, and snippets.

@skarm61
Created May 6, 2014 11:33
Show Gist options
  • Select an option

  • Save skarm61/11559351 to your computer and use it in GitHub Desktop.

Select an option

Save skarm61/11559351 to your computer and use it in GitHub Desktop.
Rake task: validate all objects in database
namespace :test_db do
task validate_all_objects: :environment do
Dir[Rails.root.to_s + '/app/models/**/*.rb'].each do |file|
begin
require file
rescue
end
end
ActiveRecord::Base.descendants.each do |model|
print model
print "\n"
begin
array = model.try(:all)
array.each do |object|
unless object.valid?
print object.id
print ' : '
print object.errors.to_json
print "\n"
end
end
rescue
end
print "\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment