Skip to content

Instantly share code, notes, and snippets.

@replaid
Created August 5, 2014 21:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save replaid/5ecc5d7391ef18574385 to your computer and use it in GitHub Desktop.
Save replaid/5ecc5d7391ef18574385 to your computer and use it in GitHub Desktop.
Validating your Fixtures in Rails 4
# 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