Created
August 5, 2014 21:22
-
-
Save replaid/5ecc5d7391ef18574385 to your computer and use it in GitHub Desktop.
Validating your Fixtures in Rails 4
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
# Adapted for Rails 4 from http://trevorturk.com/2008/09/20/validating-your-fixtures/ | |
# I put this in test/models/. Trevor put his in test/integration/. | |
require 'test_helper' | |
class FixtureValidationTest < ActiveSupport::TestCase | |
test "fixtures should be valid" do | |
models = ActiveRecord::FixtureSet.all_loaded_fixtures.keys | |
models.each do |model| | |
model = model.camelize.singularize.constantize | |
fixtures = model.all | |
fixtures.each do |fixture| | |
if !fixture.valid? | |
puts; puts "WARNING: Invalid fixture: #{fixture.inspect}" | |
end | |
assert fixture.valid?, fixture.errors.full_messages | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment