Last active
August 7, 2020 15:24
-
-
Save danini-the-panini/0fc858c67a19e57b39d833c12b8244b1 to your computer and use it in GitHub Desktop.
Revisions
-
Daniel Smith revised this gist
Aug 7, 2020 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ # Test validity of all your fixtures in one simple test. # Just put this file somewhere, like maybe `test/models`, and run `bin/rails test test/models/fixture_test.rb`. # Even gives you the line number of the fixture definition in the failure message! require 'test_helper' class FixturesTest < ActiveSupport::TestCase -
Daniel Smith revised this gist
Aug 7, 2020 . 1 changed file with 0 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +0,0 @@ -
Daniel Smith revised this gist
Aug 7, 2020 . No changes.There are no files selected for viewing
-
Daniel Smith created this gist
Jul 17, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ Test validity of all your fixtures in one simple test. Just put this file somewhere, like maybe `test/models`, and run `bin/rails test test/models/fixture_test.rb`. Even gives you the line number of the fixture definition in the failure message! This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ require 'test_helper' class FixturesTest < ActiveSupport::TestCase Dir.glob(Rails.root.join('test', 'fixtures', '*.yml')).each do |filename| set_name = File.basename(filename, '.yml') test "#{set_name} fixtures are valid" do ActiveRecord::FixtureSet.all_loaded_fixtures[set_name].each do |fixture_name, fixture| value = fixture.find unless value.valid? line_number = File.read(filename).each_line.find_index { |l| l.chomp.match?(/\A#{fixture_name}:\z/) } + 1 fail "#{filename}:#{line_number}: #{value.errors.full_messages.to_sentence}" end end end end end