Skip to content

Instantly share code, notes, and snippets.

@jesperronn
Created February 7, 2010 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesperronn/297427 to your computer and use it in GitHub Desktop.
Save jesperronn/297427 to your computer and use it in GitHub Desktop.
#put this file in /lib/tasks and run `rake db:models:validate`
#created 2010-02-07 by Jesper Rønn-Jensen
require 'find'
namespace :db do
namespace :models do
desc 'Dumps all models into fixtures.'
task :validate => :environment do
models = []
Find.find(RAILS_ROOT + '/app/models') do |path|
unless File.directory?(path) then models << path.match(/(\w+).rb/)[1] end
end
puts "Found models: " + models.join(', ')
errors = []
models.each do |m|
puts "Validating #{m.camelize} items"
# m.camelize.constantize.transaction do
m.camelize.constantize.all.each do |item|
if item.valid?
print "."
else
print "E"
errors << item
end
end
# end#end transaction
puts ""
end
errors.each do |item|
puts "ERROR in #{item.inspect}"
end
end#end task
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment