Closed
Description
Fixtures for Rails tests cannot be created if an ActiveRecord model is created on a view instead of a table and the tables primary key is an IDENTITY column.
While creating fixtures for such a model the rails test environment needs to turn on IDENTITY_INSERT. This fails for views as it has to be executed on the underlying table.
The error message is:
IDENTITY_INSERT could not be turned OFF for table [xyz]
([xyz] would be the name of the view).
Expected behavior
Should call "SET IDENTITY_INSERT" on the underlying table.
Actual behavior
Calls "SET IDENTITY_INSERT" on the view the model is based on.
Solution
See def set_identity_insert(table_name, conn, enable)
(lib/active_record/connection_adapters/sqlserver/database_statements.rb line 303)
table_name
is view name here.