提交 f98d487f 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #27375 from kirs/fixture-error-message

Throw friendly error message when fixture is not a hash
......@@ -66,10 +66,13 @@ def render(content)
# 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
......
......@@ -211,9 +211,19 @@ def test_nonexistent_fixture_file
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册