提交 e50fe851 编写于 作者: Y Yves Senn

descriptive error message when fixtures contian a missing column.

Closes #21201.
上级 9d70ec35
* Descriptive error message when fixtures contain a missing column.
Closes #21201.
*Yves Senn*
* `ActiveRecord::Tasks::PostgreSQLDatabaseTasks` fail if shellout to
postgresql commands (like `pg_dump`) is not successful.
......
......@@ -289,8 +289,12 @@ def insert_fixture(fixture, table_name)
columns = schema_cache.columns_hash(table_name)
binds = fixture.map do |name, value|
type = lookup_cast_type_from_column(columns[name])
Relation::QueryAttribute.new(name, value, type)
if column = columns[name]
type = lookup_cast_type_from_column(column)
Relation::QueryAttribute.new(name, value, type)
else
raise Fixture::FixtureError, %(table "#{table_name}" has no column named "#{name}".)
end
end
key_list = fixture.keys.map { |name| quote_column_name(name) }
value_list = prepare_binds_for_database(binds).map do |value|
......
......@@ -217,6 +217,13 @@ def test_dirty_dirty_yaml_file
end
end
def test_yaml_file_with_invalid_column
e = assert_raise(ActiveRecord::Fixture::FixtureError) do
ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/naked/yml", "parrots")
end
assert_equal(%(table "parrots" has no column named "arrr".), e.message)
end
def test_omap_fixtures
assert_nothing_raised do
fixtures = ActiveRecord::FixtureSet.new(Account.connection, 'categories', Category, FIXTURES_ROOT + "/categories_ordered")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册