aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/fixtures_test.rb
diff options
context:
space:
mode:
authorKir Shatrov <shatrov@me.com>2016-12-15 15:19:34 -0500
committerKir Shatrov <shatrov@me.com>2016-12-15 17:07:58 -0500
commit3e018eca32dd5bedaefe03845f076849a6fc5e4b (patch)
treec335c7ff19da69b60a5ae6650f11e787f98deed0 /activerecord/test/cases/fixtures_test.rb
parent753da21322a2701f8b2294da1c26df8a783436d5 (diff)
downloadrails-3e018eca32dd5bedaefe03845f076849a6fc5e4b.tar.gz
rails-3e018eca32dd5bedaefe03845f076849a6fc5e4b.tar.bz2
rails-3e018eca32dd5bedaefe03845f076849a6fc5e4b.zip
Throw friendly error message when fixture is not a hash
Right now, when fixture is not a Hash we throw an error message saying "fixture is not a hash". This is not very user friendly because it's not saying which fixture is invalid.
Diffstat (limited to 'activerecord/test/cases/fixtures_test.rb')
-rw-r--r--activerecord/test/cases/fixtures_test.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb
index f3d0e4a1b1..ea3e8d7727 100644
--- a/activerecord/test/cases/fixtures_test.rb
+++ b/activerecord/test/cases/fixtures_test.rb
@@ -211,9 +211,19 @@ class FixturesTest < ActiveRecord::TestCase
end
def test_dirty_dirty_yaml_file
- assert_raise(ActiveRecord::Fixture::FormatError) do
- ActiveRecord::FixtureSet.new(Account.connection, "courses", Course, FIXTURES_ROOT + "/naked/yml/courses")
+ fixture_path = FIXTURES_ROOT + "/naked/yml/courses"
+ error = assert_raise(ActiveRecord::Fixture::FormatError) do
+ ActiveRecord::FixtureSet.new(Account.connection, "courses", Course, fixture_path)
end
+ assert_equal "fixture is not a hash: #{fixture_path}.yml", error.to_s
+ end
+
+ def test_yaml_file_with_one_invalid_fixture
+ fixture_path = FIXTURES_ROOT + "/naked/yml/courses_with_invalid_key"
+ error = assert_raise(ActiveRecord::Fixture::FormatError) do
+ ActiveRecord::FixtureSet.new(Account.connection, "courses", Course, fixture_path)
+ end
+ assert_equal "fixture key is not a hash: #{fixture_path}.yml, keys: [\"two\"]", error.to_s
end
def test_yaml_file_with_invalid_column