Created
May 13, 2013 06:11
-
-
Save hartct/5566449 to your computer and use it in GitHub Desktop.
This file contains 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 :validate do | |
desc "Validates all model records" | |
task :models => :environment do | |
Dir.glob(Rails.root.to_s + '/app/models/*.rb').each { |file| require file } | |
objects = ObjectSpace.each_object(Class) do |klass| | |
if ActiveRecord::Base > klass | |
begin | |
all_records = klass.all | |
rescue | |
puts "Error querying model #{klass} - maybe the table doesn't exist?" | |
next | |
end | |
all_records.each do |r| | |
if !r.valid? | |
puts "Invalid record in model #{klass} with id #{r.id}!" | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment