From 3e018eca32dd5bedaefe03845f076849a6fc5e4b Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Thu, 15 Dec 2016 15:19:34 -0500 Subject: 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. --- activerecord/lib/active_record/fixture_set/file.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/fixture_set/file.rb') diff --git a/activerecord/lib/active_record/fixture_set/file.rb b/activerecord/lib/active_record/fixture_set/file.rb index 5ba354d758..6cf2e01179 100644 --- a/activerecord/lib/active_record/fixture_set/file.rb +++ b/activerecord/lib/active_record/fixture_set/file.rb @@ -66,10 +66,13 @@ module ActiveRecord # Validate our unmarshalled data. def validate(data) unless Hash === data || YAML::Omap === data - raise Fixture::FormatError, "fixture is not a hash" + raise Fixture::FormatError, "fixture is not a hash: #{@file}" end - raise Fixture::FormatError unless data.all? { |name, row| Hash === row } + invalid = data.reject { |_, row| Hash === row } + if invalid.any? + raise Fixture::FormatError, "fixture key is not a hash: #{@file}, keys: #{invalid.keys.inspect}" + end data end end -- cgit v1.2.3