Created
February 7, 2010 13:06
-
-
Save jesperronn/297427 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
#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