Created
November 1, 2012 01:43
-
-
Save alto/3991095 to your computer and use it in GitHub Desktop.
fixtures validity
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
require 'test_helper' | |
class FixturesTest < ActiveSupport::TestCase | |
def test_fixtures_for_validity | |
fixture_tables = all_fixture_tables | |
assert_not_equal 0, fixture_tables.size, "Unable to find any fixtures in #{fixture_files_path}" | |
fixture_tables.each do |table_name| | |
ActiveRecord::Fixtures.all_loaded_fixtures[table_name].each do |f| | |
fixture_name = f[0] | |
if fixture_name =~ /^invalid_/ | |
assert !self.send(table_name, fixture_name).valid?, "#{table_name}(:#{fixture_name}) is a valid fixture, but marked as invalid" | |
else | |
assert self.send(table_name, fixture_name).valid?, "#{table_name}(:#{fixture_name}) is an invalid fixture" | |
end | |
end | |
end | |
end | |
private | |
def fixture_files_path | |
File.join(File.dirname(__FILE__) + "/../fixtures", "*.yml") | |
end | |
def all_fixture_tables | |
Dir[fixture_files_path].map { |file| File.basename(file[/^(.+)\.[^.]+?$/, 1]) } | |
end | |
end |
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
user: | |
name: Any User | |
email: user@my_app.com | |
user_without_email: | |
name: User Without Email | |
invalid_user: | |
name: Invalid User |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment