Created
May 6, 2014 11:33
-
-
Save skarm61/11559351 to your computer and use it in GitHub Desktop.
Rake task: validate all objects in database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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