mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
descriptive error message when fixtures contian a missing column.
Closes #21201.
This commit is contained in:
parent
9d70ec3551
commit
e50fe85180
4 changed files with 21 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
* 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 @@ module ActiveRecord
|
|||
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 @@ class FixturesTest < ActiveRecord::TestCase
|
|||
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")
|
||||
|
|
2
activerecord/test/fixtures/naked/yml/parrots.yml
vendored
Normal file
2
activerecord/test/fixtures/naked/yml/parrots.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
george:
|
||||
arrr: "Curious George"
|
Loading…
Reference in a new issue