Sha256: 8f307528acaf4c343008ce9529dc781d788d69319065a1e73ec254fc6a93bdf6

Contents?: true

Size: 944 Bytes

Versions: 1

Compression:

Stored size: 944 Bytes

Contents

# Requires at least one test in the project
# Require 'fixture_validation_test' in test_helper after rails/test_help is required

class FixtureValidation::Test < ActiveSupport::TestCase
  fixtures :all

  test 'fixtures are valid' do
    count = 0
    klasses = []
    fixture_table_names.each do |fixture_name|
      klass_name = fixture_name.classify
      begin
        klasses << klass_name.constantize
      rescue NameError
        Rails.logger.debug "No model class (#{klass_name}) found for fixture #{fixture_name}"
      end
    end

    errors = []
    klasses.each do |klass|
      klass.all.each do |obj|
        errors << "Expected #{klass.to_s} fixture #{obj.id} to be valid.  Errors: #{obj.errors.to_a.join(', ')}.  Attribute values: #{obj.attributes.to_s}." unless obj.valid?
        count += 1
      end
    end

    assert errors.empty?, "\n#{errors.join("\n")}"
    Rails.logger.debug "Validated #{count} fixtures"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fixture_validation-0.1.2 lib/fixture_validation_test.rb